Annotation Interface ClientHeaderParam
The value of the header to send can be specified explicitly by using the value
attribute. The value can
also be computed via a default method on the client interface or a public static method on a different class. The
compute method must return a String or String[] (indicating a multivalued header) value. This method must be
specified in the value
attribute but wrapped in curly-braces. The compute method's signature must either
contain no arguments or a single String
argument. The String argument is the name of the header.
Here is an example that explicitly defines a header value and computes a value:
public interface MyClient { static AtomicInteger counter = new AtomicInteger(1); default String determineHeaderValue(String headerName) { if ("SomeHeader".equals(headerName)) { return "InvokedCount " + counter.getAndIncrement(); } throw new UnsupportedOperationException("unknown header name"); } @ClientHeaderParam(name="SomeHeader", value="ExplicitlyDefinedValue") @GET Response useExplicitHeaderValue(); @ClientHeaderParam(name="SomeHeader", value="{determineHeaderValue}") @DELETE Response useComputedHeaderValue(); }The implementation should fail to deploy a client interface if the annotation contains a
@ClientHeaderParam
annotation with a value
attribute that references a method that does not
exist, or contains an invalid signature.
The required
attribute will determine what action the implementation should take if the method specified
in the value
attribute throws an exception. If the attribute is true (default), then the implementation
will abort the request and will throw the exception back to the caller. If the required
attribute is set
to false, then the implementation will not send this header if the method throws an exception.
Note that if an interface method contains an argument annotated with @HeaderParam
, that argument will
take priority over anything specified in a ClientHeaderParam annotation.
- Since:
- 1.2
-
Required Element Summary
-
Optional Element Summary
-
Element Details
-
-
required
boolean required- Returns:
- whether to abort the request if the method to compute the header value throws an exception (true; default) or just skip this header (false)
- Default:
- true
-