feign
Class RequestTemplate

java.lang.Object
  extended by feign.RequestTemplate
All Implemented Interfaces:
java.io.Serializable

public final class RequestTemplate
extends java.lang.Object
implements java.io.Serializable

Builds a request to an http target. Not thread safe.


relationship to JAXRS 2.0

A combination of javax.ws.rs.client.WebTarget and javax.ws.rs.client.Invocation.Builder, ensuring you can modify any part of the request. However, this object is mutable, so needs to be guarded with the copy constructor.

See Also:
Serialized Form

Constructor Summary
RequestTemplate()
           
RequestTemplate(RequestTemplate toCopy)
           
 
Method Summary
 RequestTemplate append(java.lang.CharSequence value)
           
 java.lang.String body()
           
 RequestTemplate body(java.lang.String body)
          replaces the Util.CONTENT_LENGTH header.
 java.lang.String bodyTemplate()
           
 RequestTemplate bodyTemplate(java.lang.String bodyTemplate)
          populated by Body
static java.lang.String expand(java.lang.String template, java.util.Map<java.lang.String,?> variables)
          Expands a template, such as username, using the variables supplied.
 RequestTemplate header(java.lang.String configKey, java.lang.Iterable<java.lang.String> values)
           
 RequestTemplate header(java.lang.String configKey, java.lang.String... values)
          Replaces headers with the specified configKey with the values supplied.
 java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> headers()
          Returns an immutable copy of the current headers.
 RequestTemplate headers(java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> headers)
          Replaces all existing headers with the newly supplied headers.
 RequestTemplate insert(int pos, java.lang.CharSequence value)
           
 java.lang.String method()
           
 RequestTemplate method(java.lang.String method)
           
 java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> queries()
          Returns an immutable copy of the url decoded queries.
 RequestTemplate queries(java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> queries)
          Replaces all existing queries with the newly supplied url decoded queries.
 RequestTemplate query(java.lang.String configKey, java.lang.Iterable<java.lang.String> values)
           
 RequestTemplate query(java.lang.String configKey, java.lang.String... values)
          Replaces queries with the specified configKey with url decoded values supplied.
 java.lang.String queryLine()
           
 void replaceQueryValues(java.util.Map<java.lang.String,?> unencoded)
          Replaces query values which are templated with corresponding values from the unencoded map.
 Request request()
           
 RequestTemplate resolve(java.util.Map<java.lang.String,?> unencoded)
          Resolves any templated variables in the requests path, query, or headers against the supplied unencoded arguments.
 java.lang.String toString()
           
 java.lang.String url()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RequestTemplate

public RequestTemplate()

RequestTemplate

public RequestTemplate(RequestTemplate toCopy)
Method Detail

resolve

public RequestTemplate resolve(java.util.Map<java.lang.String,?> unencoded)
Resolves any templated variables in the requests path, query, or headers against the supplied unencoded arguments.


relationship to JAXRS 2.0

This call is similar to javax.ws.rs.client.WebTarget.resolveTemplates(templateValues, true) , except that the template values apply to any part of the request, not just the URL


request

public Request request()

expand

public static java.lang.String expand(java.lang.String template,
                                      java.util.Map<java.lang.String,?> variables)
Expands a template, such as username, using the variables supplied. Any unresolved parameters will remain.
Note that if you'd like curly braces literally in the template, urlencode them first.

Parameters:
template - URI template that can be in level 1 RFC6570 form.
variables - to the URI template
Returns:
expanded template, leaving any unresolved parameters literal

method

public RequestTemplate method(java.lang.String method)

method

public java.lang.String method()

append

public RequestTemplate append(java.lang.CharSequence value)

insert

public RequestTemplate insert(int pos,
                              java.lang.CharSequence value)

url

public java.lang.String url()

query

public RequestTemplate query(java.lang.String configKey,
                             java.lang.String... values)
Replaces queries with the specified configKey with url decoded values supplied.
When the value is null, all queries with the configKey are removed.


relationship to JAXRS 2.0

Like WebTarget.query, except the values can be templatized.
ex.
 template.query("Signature", "{signature}");
 

Parameters:
configKey - the configKey of the query
values - can be a single null to imply removing all values. Else no values are expected to be null.
See Also:
queries()

query

public RequestTemplate query(java.lang.String configKey,
                             java.lang.Iterable<java.lang.String> values)

queries

public RequestTemplate queries(java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> queries)
Replaces all existing queries with the newly supplied url decoded queries.


relationship to JAXRS 2.0

Like WebTarget.queries, except the values can be templatized.
ex.
 template.queries(ImmutableMultimap.of("Signature", "{signature}"));
 

Parameters:
queries - if null, remove all queries. else value to replace all queries with.
See Also:
queries()

queries

public java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> queries()
Returns an immutable copy of the url decoded queries.

See Also:
Request.url()

header

public RequestTemplate header(java.lang.String configKey,
                              java.lang.String... values)
Replaces headers with the specified configKey with the values supplied.
When the value is null, all headers with the configKey are removed.


relationship to JAXRS 2.0

Like WebTarget.queries and javax.ws.rs.client.Invocation.Builder.header, except the values can be templatized.
ex.
 template.query("X-Application-Version", "{version}");
 

Parameters:
configKey - the configKey of the header
values - can be a single null to imply removing all values. Else no values are expected to be null.
See Also:
headers()

header

public RequestTemplate header(java.lang.String configKey,
                              java.lang.Iterable<java.lang.String> values)

headers

public RequestTemplate headers(java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> headers)
Replaces all existing headers with the newly supplied headers.


relationship to JAXRS 2.0

Like Invocation.Builder.headers(MultivaluedMap), except the values can be templatized.
ex.
 template.headers(ImmutableMultimap.of("X-Application-Version", "{version}"));
 

Parameters:
headers - if null, remove all headers. else value to replace all headers with.
See Also:
headers()

headers

public java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> headers()
Returns an immutable copy of the current headers.

See Also:
Request.headers()

body

public RequestTemplate body(java.lang.String body)
replaces the Util.CONTENT_LENGTH header.
Usually populated by an Encoder.

See Also:
Request.body()

body

public java.lang.String body()

bodyTemplate

public RequestTemplate bodyTemplate(java.lang.String bodyTemplate)
populated by Body

See Also:
Request.body()

bodyTemplate

public java.lang.String bodyTemplate()
See Also:
Request.body(), expand(String, Map)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

replaceQueryValues

public void replaceQueryValues(java.util.Map<java.lang.String,?> unencoded)
Replaces query values which are templated with corresponding values from the unencoded map. Any unresolved queries are removed.


queryLine

public java.lang.String queryLine()