Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * #%L
   * wcm.io
   * %%
   * Copyright (C) 2014 wcm.io
   * %%
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
  */
 package io.wcm.caravan.io.http.request;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.util.Map;
 
 
An immutable request to a HTTP server.
 
 public final class CaravanHttpRequest {

  
Correlation ID Header name
 
   public static final String CORRELATION_ID_HEADER_NAME = "Caravan-Correlation-Id";
 
   private final String serviceId;
   private final String method;
   private final String url;
   private final Multimap<StringStringheaders;
   private final byte[] body;
   private final Charset charset;

Parameters:
serviceId Logical name of the request service. Used by io.wcm.caravan.io.http.CaravanHttpClient to resolve the real URL. If null, only url is used
method HTTP method verb
url Service request URL. Can be an absolute URL or just an path getting combined with the URL of the logical service ID
headers HTTP headers
body HTTP Payload
charset Payload charset
 
   CaravanHttpRequest(final String serviceIdfinal String methodfinal String urlfinal Multimap<StringStringheadersfinal byte[] body,
       final Charset charset) {
     this. = serviceId// nullable
     this. = checkNotNull(method"method of %s"url);
     this. = checkNotNull(url"url");
     this. = ImmutableMultimap.copyOf(LinkedHashMultimap.create(checkNotNull(headers"headers of %s %s"methodurl)));
     this. = body// nullable
     this. = charset// nullable
     this. = PerformanceMetrics.createNew(
         StringUtils.defaultString(serviceId"UNKNOWN SERVICE") + " : " + StringUtils.defaultString(method"UNKNOWN METHOD"), urlgetCorrelationId());
   }

  
Method to invoke on the server.

Returns:
HTTP method
 
   public String getMethod() {
     return ;
   }

  
Fully resolved url including query.

Returns:
URL
 
   public String getUrl() {
     return ;
   }

  
Ordered list of headers that will be sent to the server.

Returns:
HTTP headers
 
  public Multimap<StringStringgetHeaders() {
    return ;
  }

  
Collects all "Cache-Control" directives from the response headers into a single map. The keys in the map are the directive names (e.g. "max-age", "no-cache"), and everything after the "=" is taken as value. For directives that don't have a value "true" is used as a value instead.

Returns:
the map of Cache-Control directives
  public Map<StringStringgetCacheControl() {
    return CaravanHttpHelper.convertMultiValueHeaderToMap(.get("Cache-Control"));
  }

  

Parameters:
name of the query parameter
Returns:
true if the parameter exists in this request's query
  public boolean hasParameter(String name) {
    return Pattern.compile("[\\?|\\&](" + name + "\\=[^\\&]).*$").matcher().find();
  }

  
The character set with which the body is encoded, or null if unknown or not applicable. When this is present, you can use new String(req.body(), req.charset()) to access the body as a String.

Returns:
Charset
  public Charset getCharset() {
    return ;
  }

  
If present, this is the replayable body to send to the server. In some cases, this may be interpretable as text.

Returns:
HTTP body
See also:
getCharset()
  public byte[] getBody() {
    return ;
  }
  public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append().append(' ').append().append(" HTTP/1.1\n");
    for (String field : .keySet()) {
      builder.append(field).append(": ").append(StringUtils.join(.get(field), ", ")).append('\n');
    }
    if ( != null) {
      builder.append('\n').append( != null ? new String() : "Binary data");
    }
    return builder.toString();
  }

  

Returns:
the service ID
  public String getServiceId() {
    return ;
  }

  

Deprecated:
Please use getServiceId()
Returns:
the service ID
  public String getServiceName() {
    return ;
  }

  

Returns:
the value of the correlation-id header or null if it wasn't set
  public String getCorrelationId() {
    return correlationHeaders.isEmpty() ? null : correlationHeaders.iterator().next();
  }
    return this.;
  }
New to GrepCode? Check out our FAQ X