Apache CXF API

org.apache.cxf.jaxrs.client
Class AbstractClient

java.lang.Object
  extended by org.apache.cxf.jaxrs.client.AbstractClient
All Implemented Interfaces:
Retryable, Client
Direct Known Subclasses:
ClientProxyImpl, WebClient

public abstract class AbstractClient
extends Object
implements Client, Retryable

Common proxy and http-centric client implementation


Field Summary
protected  ClientConfiguration cfg
           
protected static String KEEP_CONDUIT_ALIVE
           
protected static String REQUEST_CONTEXT
           
protected static String RESPONSE_CONTEXT
           
 
Constructor Summary
protected AbstractClient(ClientState initialState)
           
protected AbstractClient(URI baseURI)
           
 
Method Summary
 Client accept(javax.ws.rs.core.MediaType... types)
          sets HTTP Accept header
 Client accept(String... types)
          sets HTTP Accept header
 Client acceptEncoding(String... encs)
          sets HTTP Accept-Encoding header
 Client acceptLanguage(String... languages)
          sets HTTP Accept-Language header
protected static void addParametersToBuilder(javax.ws.rs.core.UriBuilder ub, String paramName, Object pValue, ParameterType pt)
           
protected  URI calculateNewRequestURI(Map<String,Object> reqContext)
           
protected  void checkClientException(Message outMessage, Exception ex)
           
protected  void completeExchange(Object response, Exchange exchange, boolean proxy)
           
 Client cookie(javax.ws.rs.core.Cookie cookie)
          sets HTTP Cookie header
protected  Exchange createExchange(Message m, Exchange exchange)
           
protected  Message createMessage(Object body, String httpMethod, javax.ws.rs.core.MultivaluedMap<String,String> headers, URI currentURI, Exchange exchange, Map<String,Object> invocationContext, boolean proxy)
           
 Client encoding(String enc)
          sets HTTP Content-Encoding header
 URI getBaseURI()
          Gets the base URI this Client has been intialized with
protected  ClientConfiguration getConfiguration()
           
protected  List<?> getContentsList(Object body)
           
protected  javax.ws.rs.core.UriBuilder getCurrentBuilder()
           
 URI getCurrentURI()
          Gets the current URI this Client is working with
 javax.ws.rs.core.MultivaluedMap<String,String> getHeaders()
          Gets the copy of request headers
protected  Map<String,Object> getRequestContext(Message outMessage)
           
 javax.ws.rs.core.Response getResponse()
          Gets the response state if any
protected  ClientState getState()
           
protected  javax.ws.rs.core.MultivaluedMap<String,String> getTemplateParametersMap(URITemplate template, List<Object> values)
           
 Client header(String name, Object... values)
          Sets arbitrary HTTP Header
 Client headers(javax.ws.rs.core.MultivaluedMap<String,String> map)
          Sets HTTP Headers
 Object[] invoke(BindingOperationInfo oi, Object[] params, Map<String,Object> context, Exchange exchange)
           
 Client language(String language)
          sets HTTP Content-Language header
 Client match(javax.ws.rs.core.EntityTag tag, boolean ifNot)
          sets HTTP If-Match or If-None-Match header
 Client modified(Date date, boolean ifNot)
          sets HTTP If-Modified-Since or If-Unmodified-Since header
protected  String[] parseQuotedHeaderValue(String originalValue)
           
protected  void prepareConduitSelector(Message message, URI currentURI, boolean proxy)
           
protected  Object[] preProcessResult(Message message)
           
protected
<T> T
readBody(javax.ws.rs.core.Response r, Message outMessage, Class<T> cls, Type type, Annotation[] anns)
           
protected static void reportMessageHandlerProblem(String name, Class<?> cls, javax.ws.rs.core.MediaType ct, Throwable cause, javax.ws.rs.core.Response response)
           
 Client reset()
          Resets the headers and response state if any
protected  void resetBaseAddress(URI uri)
           
protected  void resetCurrentBuilder(URI uri)
           
protected  void resetResponse()
           
protected abstract  Object retryInvoke(URI newRequestURI, javax.ws.rs.core.MultivaluedMap<String,String> headers, Object body, Exchange exchange, Map<String,Object> invContext)
           
protected static void setAllHeaders(javax.ws.rs.core.MultivaluedMap<String,String> headers, HttpURLConnection conn)
           
protected  void setConfiguration(ClientConfiguration config)
           
protected  void setContexts(Message message, Exchange exchange, Map<String,Object> context, boolean proxy)
           
protected  void setEmptyRequestProperty(Message outMessage, String httpMethod)
           
protected  void setPlainOperationNameProperty(Message outMessage, String name)
           
protected  javax.ws.rs.core.Response.ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange)
           
protected static PhaseInterceptorChain setupInInterceptorChain(ClientConfiguration cfg)
           
protected static PhaseInterceptorChain setupOutInterceptorChain(ClientConfiguration cfg)
           
 Client type(javax.ws.rs.core.MediaType ct)
          sets HTTP Content-Type header
 Client type(String type)
          sets HTTP Content-Type header
protected  void waitForResponseCode(Exchange exchange)
           
protected
<T> void
writeBody(T o, Message outMessage, Class<?> cls, Type type, Annotation[] anns, javax.ws.rs.core.MultivaluedMap<String,Object> headers, OutputStream os)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUEST_CONTEXT

protected static final String REQUEST_CONTEXT
See Also:
Constant Field Values

RESPONSE_CONTEXT

protected static final String RESPONSE_CONTEXT
See Also:
Constant Field Values

KEEP_CONDUIT_ALIVE

protected static final String KEEP_CONDUIT_ALIVE
See Also:
Constant Field Values

cfg

protected ClientConfiguration cfg
Constructor Detail

AbstractClient

protected AbstractClient(URI baseURI)

AbstractClient

protected AbstractClient(ClientState initialState)
Method Detail

header

public Client header(String name,
                     Object... values)
Sets arbitrary HTTP Header

Specified by:
header in interface Client
Parameters:
name - header name
values - list of header values
Returns:
the updated Client

headers

public Client headers(javax.ws.rs.core.MultivaluedMap<String,String> map)
Sets HTTP Headers

Specified by:
headers in interface Client
Parameters:
map - headers
Returns:
the updated Client

accept

public Client accept(javax.ws.rs.core.MediaType... types)
sets HTTP Accept header

Specified by:
accept in interface Client
Parameters:
types - list of JAXRS MediaTypes representing Accept header values
Returns:
the updated Client

type

public Client type(javax.ws.rs.core.MediaType ct)
sets HTTP Content-Type header

Specified by:
type in interface Client
Parameters:
ct - JAXRS MediaType representing Content-Type value
Returns:
the updated Client

type

public Client type(String type)
sets HTTP Content-Type header

Specified by:
type in interface Client
Parameters:
type - Content-Type value
Returns:
the updated Client

accept

public Client accept(String... types)
sets HTTP Accept header

Specified by:
accept in interface Client
Parameters:
types - list of Accept header values
Returns:
the updated Client

cookie

public Client cookie(javax.ws.rs.core.Cookie cookie)
sets HTTP Cookie header

Specified by:
cookie in interface Client
Parameters:
cookie - Cookie value
Returns:
the updated Client

modified

public Client modified(Date date,
                       boolean ifNot)
sets HTTP If-Modified-Since or If-Unmodified-Since header

Specified by:
modified in interface Client
Parameters:
date - Date value, will be formated as "EEE, dd MMM yyyy HH:mm:ss zzz"
ifNot - if true then If-Unmodified-Since is set, If-Modified-Since otherwise
Returns:
the updated Client

language

public Client language(String language)
sets HTTP Content-Language header

Specified by:
language in interface Client
Parameters:
language - Content-Language header value
Returns:
the updated Client

match

public Client match(javax.ws.rs.core.EntityTag tag,
                    boolean ifNot)
sets HTTP If-Match or If-None-Match header

Specified by:
match in interface Client
Parameters:
tag - ETag value
ifNot - if true then If-None-Match is set, If-Match otherwise
Returns:
the updated Client

acceptLanguage

public Client acceptLanguage(String... languages)
sets HTTP Accept-Language header

Specified by:
acceptLanguage in interface Client
Parameters:
languages - list of Accept-Language header values
Returns:
the updated Client

acceptEncoding

public Client acceptEncoding(String... encs)
sets HTTP Accept-Encoding header

Specified by:
acceptEncoding in interface Client
Parameters:
encs - list of Accept-Encoding header value
Returns:
the updated Client

encoding

public Client encoding(String enc)
sets HTTP Content-Encoding header

Specified by:
encoding in interface Client
Parameters:
enc - Content-Encoding header value
Returns:
the updated Client

getHeaders

public javax.ws.rs.core.MultivaluedMap<String,String> getHeaders()
Gets the copy of request headers

Specified by:
getHeaders in interface Client
Returns:
request headers

getBaseURI

public URI getBaseURI()
Gets the base URI this Client has been intialized with

Specified by:
getBaseURI in interface Client
Returns:
base URI

getCurrentURI

public URI getCurrentURI()
Gets the current URI this Client is working with

Specified by:
getCurrentURI in interface Client
Returns:
current URI

getResponse

public javax.ws.rs.core.Response getResponse()
Gets the response state if any

Specified by:
getResponse in interface Client
Returns:
JAXRS Response response

reset

public Client reset()
Resets the headers and response state if any

Specified by:
reset in interface Client
Returns:
the updated Client

getState

protected ClientState getState()

getCurrentBuilder

protected javax.ws.rs.core.UriBuilder getCurrentBuilder()

resetResponse

protected void resetResponse()

resetBaseAddress

protected void resetBaseAddress(URI uri)

resetCurrentBuilder

protected void resetCurrentBuilder(URI uri)

getTemplateParametersMap

protected javax.ws.rs.core.MultivaluedMap<String,String> getTemplateParametersMap(URITemplate template,
                                                                                  List<Object> values)

setResponseBuilder

protected javax.ws.rs.core.Response.ResponseBuilder setResponseBuilder(Message outMessage,
                                                                       Exchange exchange)
                                                                throws Exception
Throws:
Exception

writeBody

protected <T> void writeBody(T o,
                             Message outMessage,
                             Class<?> cls,
                             Type type,
                             Annotation[] anns,
                             javax.ws.rs.core.MultivaluedMap<String,Object> headers,
                             OutputStream os)

readBody

protected <T> T readBody(javax.ws.rs.core.Response r,
                         Message outMessage,
                         Class<T> cls,
                         Type type,
                         Annotation[] anns)

completeExchange

protected void completeExchange(Object response,
                                Exchange exchange,
                                boolean proxy)

preProcessResult

protected Object[] preProcessResult(Message message)
                             throws Exception
Throws:
Exception

checkClientException

protected void checkClientException(Message outMessage,
                                    Exception ex)
                             throws Exception
Throws:
Exception

waitForResponseCode

protected void waitForResponseCode(Exchange exchange)

calculateNewRequestURI

protected URI calculateNewRequestURI(Map<String,Object> reqContext)

invoke

public Object[] invoke(BindingOperationInfo oi,
                       Object[] params,
                       Map<String,Object> context,
                       Exchange exchange)
                throws Exception
Specified by:
invoke in interface Retryable
Throws:
Exception

retryInvoke

protected abstract Object retryInvoke(URI newRequestURI,
                                      javax.ws.rs.core.MultivaluedMap<String,String> headers,
                                      Object body,
                                      Exchange exchange,
                                      Map<String,Object> invContext)
                               throws Throwable
Throws:
Throwable

addParametersToBuilder

protected static void addParametersToBuilder(javax.ws.rs.core.UriBuilder ub,
                                             String paramName,
                                             Object pValue,
                                             ParameterType pt)

reportMessageHandlerProblem

protected static void reportMessageHandlerProblem(String name,
                                                  Class<?> cls,
                                                  javax.ws.rs.core.MediaType ct,
                                                  Throwable cause,
                                                  javax.ws.rs.core.Response response)

setAllHeaders

protected static void setAllHeaders(javax.ws.rs.core.MultivaluedMap<String,String> headers,
                                    HttpURLConnection conn)

parseQuotedHeaderValue

protected String[] parseQuotedHeaderValue(String originalValue)

getConfiguration

protected ClientConfiguration getConfiguration()

setConfiguration

protected void setConfiguration(ClientConfiguration config)

prepareConduitSelector

protected void prepareConduitSelector(Message message,
                                      URI currentURI,
                                      boolean proxy)

setupOutInterceptorChain

protected static PhaseInterceptorChain setupOutInterceptorChain(ClientConfiguration cfg)

setupInInterceptorChain

protected static PhaseInterceptorChain setupInInterceptorChain(ClientConfiguration cfg)

createMessage

protected Message createMessage(Object body,
                                String httpMethod,
                                javax.ws.rs.core.MultivaluedMap<String,String> headers,
                                URI currentURI,
                                Exchange exchange,
                                Map<String,Object> invocationContext,
                                boolean proxy)

getRequestContext

protected Map<String,Object> getRequestContext(Message outMessage)

getContentsList

protected List<?> getContentsList(Object body)

createExchange

protected Exchange createExchange(Message m,
                                  Exchange exchange)

setContexts

protected void setContexts(Message message,
                           Exchange exchange,
                           Map<String,Object> context,
                           boolean proxy)

setEmptyRequestProperty

protected void setEmptyRequestProperty(Message outMessage,
                                       String httpMethod)

setPlainOperationNameProperty

protected void setPlainOperationNameProperty(Message outMessage,
                                             String name)

Apache CXF API

Apache CXF