Package org.apache.cxf.jaxrs.client
Class AbstractClient
- java.lang.Object
-
- 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
Nested Classes Modifier and Type Class Description protected static classAbstractClient.AbstractBodyWriterprotected classAbstractClient.AbstractClientAsyncResponseInterceptor
-
Field Summary
Fields Modifier and Type Field Description protected ClientConfigurationcfgstatic StringEXECUTOR_SERVICE_PROPERTYprotected static StringHTTP_SCHEMEprotected static StringKEEP_CONDUIT_ALIVEprotected static StringREQUEST_CONTEXTprotected static StringRESPONSE_CONTEXT
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractClient(ClientState initialState)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Clientaccept(String... types)Set HTTP Accept headerClientaccept(javax.ws.rs.core.MediaType... types)Set HTTP Accept headerClientacceptEncoding(String... encs)Set HTTP Accept-Encoding headerClientacceptLanguage(String... languages)Set HTTP Accept-Language headerprotected voidaddMatrixQueryParamsToBuilder(javax.ws.rs.core.UriBuilder ub, String paramName, ParameterType pt, Annotation[] anns, Object... pValues)Clientauthorization(Object auth)Set HTTP Authorization headerprotected URIcalculateNewRequestURI(Map<String,Object> reqContext)protected voidcheckClientException(Message outMessage, Exception ex)protected voidcheckClosed()protected ObjectcheckIfBodyEmpty(Object body, String contentType)voidclose()Release the internal state and configuration associated with this clientprotected voidcompleteExchange(Exchange exchange, boolean proxy)protected StringconvertParamValue(Object pValue, Annotation[] anns)protected StringconvertParamValue(Object pValue, Class<?> pClass, Annotation[] anns)protected javax.ws.rs.WebApplicationExceptionconvertToWebApplicationException(javax.ws.rs.core.Response r)Clientcookie(javax.ws.rs.core.Cookie cookie)Set HTTP Cookie headerprotected ExchangecreateExchange(Message m, Exchange exchange)protected MessagecreateMessage(Object body, String httpMethod, javax.ws.rs.core.MultivaluedMap<String,String> headers, URI currentURI, Exchange exchange, Map<String,Object> invocationContext, boolean proxy)protected voiddoRunInterceptorChain(Message m)Clientencoding(String enc)Set HTTP Content-Encoding headerprotected static ParameterizedTypefindCallbackType(Class<?> cls)URIgetBaseURI()Get the base URI this Client has been intialized withprotected static Class<?>getCallbackClass(Type outType)protected static TypegetCallbackType(javax.ws.rs.client.InvocationCallback<?> callback)ClientConfigurationgetConfiguration()protected List<?>getContentsList(Object body)protected javax.ws.rs.core.UriBuildergetCurrentBuilder()URIgetCurrentURI()Get the current URI this Client is working withjavax.ws.rs.core.MultivaluedMap<String,String>getHeaders()Get the copy of request headersprotected Map<String,Object>getRequestContext(Message outMessage)javax.ws.rs.core.ResponsegetResponse()Get the response state if anyprotected ClientStategetState()protected javax.ws.rs.core.MultivaluedMap<String,String>getTemplateParametersMap(URITemplate template, List<Object> values)Clientheader(String name, Object... values)Set arbitrary HTTP HeaderClientheaders(javax.ws.rs.core.MultivaluedMap<String,String> map)Set HTTP HeadersClientlanguage(String language)Set HTTP Content-Language headerClientmatch(javax.ws.rs.core.EntityTag tag, boolean ifNot)Set HTTP If-Match or If-None-Match headerClientmodified(Date date, boolean ifNot)Set HTTP If-Modified-Since or If-Unmodified-Since headerprotected String[]parseQuotedHeaderValue(String originalValue)protected voidprepareConduitSelector(Message message, URI currentURI, boolean proxy)protected Object[]preProcessResult(Message message)Clientquery(String name, Object... values)Update the current URI query parametersprotected <T> TreadBody(javax.ws.rs.core.Response r, Message outMessage, Class<T> cls, Type type, Annotation[] anns)voidremoveAllHeaders()protected static voidreportMessageHandlerProblem(String name, Class<?> cls, javax.ws.rs.core.MediaType ct, Throwable ex)Clientreset()Reset the headers and response state if anyprotected voidresetBaseAddress(URI uri)protected voidresetCurrentBuilder(URI uri)protected voidresetResponse()protected voidresetResponseStateImmediatelyIfNeeded()protected booleanresponseStreamCanBeClosed(Message outMessage, Class<?> cls)protected abstract ObjectretryInvoke(URI newRequestURI, javax.ws.rs.core.MultivaluedMap<String,String> headers, Object body, Exchange exchange, Map<String,Object> invContext)protected Object[]retryInvoke(BindingOperationInfo oi, Object[] params, Map<String,Object> context, Exchange exchange)protected voidsetAsyncMessageObserverIfNeeded(Exchange exchange)protected voidsetConfiguration(ClientConfiguration config)protected voidsetContexts(Message message, Exchange exchange, Map<String,Object> context, boolean proxy)protected voidsetEmptyRequestPropertyIfNeeded(Message outMessage, Object body)protected voidsetPlainOperationNameProperty(Message outMessage, String name)protected javax.ws.rs.core.Response.ResponseBuildersetResponseBuilder(Message outMessage, Exchange exchange)protected voidsetSupportOnewayResponseProperty(Message outMessage)protected static MessageObserversetupInFaultObserver(ClientConfiguration cfg)protected static PhaseInterceptorChainsetupInInterceptorChain(ClientConfiguration cfg)protected static PhaseInterceptorChainsetupOutInterceptorChain(ClientConfiguration cfg)Clienttype(String type)Set HTTP Content-Type headerClienttype(javax.ws.rs.core.MediaType ct)Set HTTP Content-Type headerprotected voidwaitForResponseCode(Exchange exchange)protected <T> voidwriteBody(T o, Message outMessage, Class<?> cls, Type type, Annotation[] anns, OutputStream os)
-
-
-
Field Detail
-
EXECUTOR_SERVICE_PROPERTY
public static final String EXECUTOR_SERVICE_PROPERTY
- See Also:
- Constant Field Values
-
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
-
headers
public Client headers(javax.ws.rs.core.MultivaluedMap<String,String> map)
Set HTTP Headers
-
accept
public Client accept(javax.ws.rs.core.MediaType... types)
Set HTTP Accept header
-
type
public Client type(javax.ws.rs.core.MediaType ct)
Set HTTP Content-Type header
-
cookie
public Client cookie(javax.ws.rs.core.Cookie cookie)
Set HTTP Cookie header
-
authorization
public Client authorization(Object auth)
Set HTTP Authorization header- Specified by:
authorizationin interfaceClient- Parameters:
auth- Authorization value- Returns:
- the updated Client
-
modified
public Client modified(Date date, boolean ifNot)
Set HTTP If-Modified-Since or If-Unmodified-Since header
-
match
public Client match(javax.ws.rs.core.EntityTag tag, boolean ifNot)
Set HTTP If-Match or If-None-Match header
-
acceptLanguage
public Client acceptLanguage(String... languages)
Set HTTP Accept-Language header- Specified by:
acceptLanguagein interfaceClient- Parameters:
languages- list of Accept-Language header values- Returns:
- the updated Client
-
acceptEncoding
public Client acceptEncoding(String... encs)
Set HTTP Accept-Encoding header- Specified by:
acceptEncodingin interfaceClient- Parameters:
encs- list of Accept-Encoding header value- Returns:
- the updated Client
-
getHeaders
public javax.ws.rs.core.MultivaluedMap<String,String> getHeaders()
Get the copy of request headers- Specified by:
getHeadersin interfaceClient- Returns:
- request headers
-
getBaseURI
public URI getBaseURI()
Get the base URI this Client has been intialized with- Specified by:
getBaseURIin interfaceClient- Returns:
- base URI
-
getCurrentURI
public URI getCurrentURI()
Get the current URI this Client is working with- Specified by:
getCurrentURIin interfaceClient- Returns:
- current URI
-
getResponse
public javax.ws.rs.core.Response getResponse()
Get the response state if any- Specified by:
getResponsein interfaceClient- Returns:
- JAXRS Response response
-
reset
public Client reset()
Reset the headers and response state if any
-
close
public void close()
Description copied from interface:ClientRelease the internal state and configuration associated with this client
-
removeAllHeaders
public void removeAllHeaders()
-
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(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)
-
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)
-
convertParamValue
protected String convertParamValue(Object pValue, Class<?> pClass, Annotation[] anns)
-
reportMessageHandlerProblem
protected static void reportMessageHandlerProblem(String name, Class<?> cls, javax.ws.rs.core.MediaType ct, Throwable ex)
-
getConfiguration
public 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)
-
setSupportOnewayResponseProperty
protected void setSupportOnewayResponseProperty(Message outMessage)
-
checkClosed
protected void checkClosed()
-
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)
-
setAsyncMessageObserverIfNeeded
protected void setAsyncMessageObserverIfNeeded(Exchange exchange)
-
setContexts
protected void setContexts(Message message, Exchange exchange, Map<String,Object> context, boolean proxy)
-
setPlainOperationNameProperty
protected void setPlainOperationNameProperty(Message outMessage, String name)
-
getCallbackType
protected static Type getCallbackType(javax.ws.rs.client.InvocationCallback<?> callback)
-
findCallbackType
protected static ParameterizedType findCallbackType(Class<?> cls)
-
resetResponseStateImmediatelyIfNeeded
protected void resetResponseStateImmediatelyIfNeeded()
-
-