Apache CXF API

org.apache.cxf.jaxrs.client
Class AbstractClient

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

public abstract class AbstractClient
extends Object
implements Client

Common proxy and http-centric client implementation


Nested Class Summary
protected  class AbstractClient.AbstractBodyWriter
           
 
Field Summary
protected  ClientConfiguration cfg
           
protected static String HTTP_SCHEME
           
protected static String KEEP_CONDUIT_ALIVE
           
protected static String REQUEST_CONTEXT
           
protected static String RESPONSE_CONTEXT
           
 
Constructor Summary
protected AbstractClient(ClientState initialState)
           
 
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  void addMatrixQueryParamsToBuilder(javax.ws.rs.core.UriBuilder ub, String paramName, ParameterType pt, Annotation[] anns, Object... pValues)
           
protected  URI calculateNewRequestURI(Map<String,Object> reqContext)
           
protected  void checkClientException(Message outMessage, Exception ex)
           
protected  Object checkIfBodyEmpty(Object body)
           
 void close()
          Releases the internal state and configuration associated with this client
protected  void completeExchange(Object response, Exchange exchange, boolean proxy)
           
protected  String convertParamValue(Object pValue, Annotation[] anns)
           
protected  javax.ws.rs.WebApplicationException convertToWebApplicationException(javax.ws.rs.core.Response r)
           
 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)
           
protected  void doRunInterceptorChain(Message m)
           
 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
 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)
           
 Client query(String name, Object... values)
          Updates the current URI query parameters
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)
           
 Client reset()
          Resets the headers and response state if any
protected  void resetBaseAddress(URI uri)
           
protected  void resetCurrentBuilder(URI uri)
           
protected  void resetResponse()
           
protected  boolean responseStreamCanBeClosed(Message outMessage, Class<?> cls)
           
protected  Object[] retryInvoke(BindingOperationInfo oi, Object[] params, Map<String,Object> context, Exchange exchange)
           
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 setEmptyRequestPropertyIfNeeded(Message outMessage, Object body)
           
protected  void setPlainOperationNameProperty(Message outMessage, String name)
           
protected  javax.ws.rs.core.Response.ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange)
           
protected static MessageObserver setupInFaultObserver(ClientConfiguration cfg)
           
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, 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

HTTP_SCHEME

protected static final String HTTP_SCHEME
See Also:
Constant Field Values

cfg

protected ClientConfiguration cfg
Constructor Detail

AbstractClient

protected AbstractClient(ClientState initialState)
Method Detail

query

public Client query(String name,
                    Object... values)
Updates the current URI query parameters

Specified by:
query in interface Client
Parameters:
name - query name
values - query values
Returns:
updated WebClient

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

close

public void close()
Description copied from interface: Client
Releases the internal state and configuration associated with this client

Specified by:
close in interface 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,
                             OutputStream os)

convertToWebApplicationException

protected javax.ws.rs.WebApplicationException convertToWebApplicationException(javax.ws.rs.core.Response r)

readBody

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

responseStreamCanBeClosed

protected boolean responseStreamCanBeClosed(Message outMessage,
                                            Class<?> cls)

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)

doRunInterceptorChain

protected void doRunInterceptorChain(Message m)

retryInvoke

protected Object[] retryInvoke(BindingOperationInfo oi,
                               Object[] params,
                               Map<String,Object> context,
                               Exchange exchange)
                        throws Exception
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

addMatrixQueryParamsToBuilder

protected void addMatrixQueryParamsToBuilder(javax.ws.rs.core.UriBuilder ub,
                                             String paramName,
                                             ParameterType pt,
                                             Annotation[] anns,
                                             Object... pValues)

convertParamValue

protected String convertParamValue(Object pValue,
                                   Annotation[] anns)

reportMessageHandlerProblem

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

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)

setupInFaultObserver

protected static MessageObserver setupInFaultObserver(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)

setEmptyRequestPropertyIfNeeded

protected void setEmptyRequestPropertyIfNeeded(Message outMessage,
                                               Object body)

checkIfBodyEmpty

protected Object checkIfBodyEmpty(Object body)

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)

setPlainOperationNameProperty

protected void setPlainOperationNameProperty(Message outMessage,
                                             String name)

Apache CXF API

Apache CXF