org.jboss.resteasy.client
Class ClientRequest
java.lang.Object
org.jboss.resteasy.client.core.ClientInterceptorRepositoryImpl
org.jboss.resteasy.client.ClientRequest
- All Implemented Interfaces:
- Cloneable, ClientInterceptorRepository
public class ClientRequest
- extends ClientInterceptorRepositoryImpl
- implements Cloneable
Create a hand coded request to send to the server. You call methods like accept(), body(), pathParameter()
etc. to create the state of the request. Then you call a get(), post(), etc. method to execute the request.
After an execution of a request, the internal state remains the same. You can invoke the request again.
You can clear the request with the clear() method.
- Version:
- $Revision: 1 $
- Author:
- Solomon Duskis, Bill Burke
Method Summary |
ClientRequest |
accept(MediaType accepts)
|
ClientRequest |
accept(String accept)
|
ClientRequest |
addLink(Link link)
|
ClientRequest |
addLink(String title,
String rel,
String href,
String type)
|
ClientRequest |
body(MediaType contentType,
Object data)
|
ClientRequest |
body(MediaType contentType,
Object data,
Class type,
Type genericType,
Annotation[] annotations)
|
ClientRequest |
body(MediaType contentType,
Object data,
GenericType genericType)
|
ClientRequest |
body(MediaType contentType,
Object data,
Type genericType)
|
ClientRequest |
body(String contentType,
Object data)
|
void |
clear()
Clear this request's state so that it can be re-used |
ClientRequest |
cookie(Cookie cookie)
|
ClientRequest |
cookie(String cookieName,
Object value)
|
Link |
create()
Automatically does POST/Create pattern. |
ClientRequest |
createSubsequentRequest(URI uri)
|
ClientResponse |
delete()
|
|
delete(Class<T> returnType)
|
|
delete(Class<T> returnType,
Type genericType)
|
|
delete(GenericType type)
|
ClientResponse |
execute()
|
boolean |
followRedirects()
|
ClientRequest |
followRedirects(boolean followRedirects)
|
ClientRequest |
formParameter(String parameterName,
Object value)
|
ClientResponse |
get()
|
|
get(Class<T> returnType)
Templates the returned ClientResponse for easy access to returned entity |
|
get(Class<T> returnType,
Type genericType)
|
|
get(GenericType type)
|
Map<String,Object> |
getAttributes()
|
Object |
getBody()
|
Annotation[] |
getBodyAnnotations()
|
MediaType |
getBodyContentType()
|
Type |
getBodyGenericType()
|
Class |
getBodyType()
|
static ClientExecutor |
getDefaultExecutor()
|
ClientExecutor |
getExecutor()
|
MultivaluedMap<String,String> |
getFormParameters()
|
MultivaluedMap<String,String> |
getHeaders()
|
MultivaluedMap<String,Object> |
getHeadersAsObjects()
|
String |
getHttpMethod()
|
MultivaluedMap<String,String> |
getMatrixParameters()
|
List<String> |
getPathParameterList()
|
MultivaluedMap<String,String> |
getPathParameters()
|
ResteasyProviderFactory |
getProviderFactory()
|
MultivaluedMap<String,String> |
getQueryParameters()
|
|
getTarget(Class<T> returnType)
Tries to automatically unmarshal to target type. |
String |
getUri()
This method populates all path, matrix, and query parameters and saves it
internally. |
ClientResponse |
head()
|
ClientRequest |
header(String headerName,
Object value)
|
ClientResponse |
httpMethod(String httpMethod)
|
|
httpMethod(String method,
Class<T> returnType)
|
|
httpMethod(String method,
Class<T> returnType,
Type genericType)
|
|
httpMethod(String method,
GenericType type)
|
ClientRequest |
matrixParameter(String parameterName,
Object value)
|
ClientResponse |
options()
|
|
options(Class<T> returnType)
|
|
options(Class<T> returnType,
Type genericType)
|
|
options(GenericType type)
|
void |
overrideUri(URI uri)
|
ClientRequest |
pathParameter(String parameterName,
Object value)
|
ClientRequest |
pathParameters(Object... values)
|
ClientResponse |
post()
|
|
post(Class<T> returnType)
|
|
post(Class<T> returnType,
Type genericType)
|
|
post(GenericType type)
|
|
postTarget(Class<T> returnType)
|
ClientResponse |
put()
|
|
put(Class<T> returnType)
|
|
put(Class<T> returnType,
Type genericType)
|
|
put(GenericType type)
|
ClientRequest |
queryParameter(String parameterName,
Object value)
|
static void |
setDefaultExecutorClass(String classname)
Set the default executor class name. |
void |
setHttpMethod(String httpMethod)
|
protected String |
toHeaderString(Object object)
|
protected String |
toString(Object object)
|
void |
writeRequestBody(MultivaluedMap<String,Object> headers,
OutputStream outputStream)
|
Methods inherited from class org.jboss.resteasy.client.core.ClientInterceptorRepositoryImpl |
copyClientInterceptorsTo, getExecutionInterceptorList, getExecutionInterceptors, getInterceptors, getInterceptors, getReaderInterceptorList, getReaderInterceptors, getWriterInterceptorList, getWriterInterceptors, prefixClientInterceptorsTo, registerInterceptor, setExecutionInterceptors, setExecutionInterceptors, setReaderInterceptors, setReaderInterceptors, setWriterInterceptors, setWriterInterceptors |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
providerFactory
protected ResteasyProviderFactory providerFactory
uri
protected UriBuilderImpl uri
executor
protected ClientExecutor executor
headers
protected MultivaluedMap<String,Object> headers
queryParameters
protected MultivaluedMap<String,String> queryParameters
formParameters
protected MultivaluedMap<String,String> formParameters
pathParameters
protected MultivaluedMap<String,String> pathParameters
matrixParameters
protected MultivaluedMap<String,String> matrixParameters
body
protected Object body
bodyType
protected Class bodyType
bodyGenericType
protected Type bodyGenericType
bodyAnnotations
protected Annotation[] bodyAnnotations
bodyContentType
protected MediaType bodyContentType
followRedirects
protected boolean followRedirects
httpMethod
protected String httpMethod
finalUri
protected String finalUri
pathParameterList
protected List<String> pathParameterList
linkHeader
protected LinkHeader linkHeader
attributes
protected Map<String,Object> attributes
ClientRequest
public ClientRequest(String uriTemplate)
ClientRequest
public ClientRequest(String uriTemplate,
ClientExecutor executor)
ClientRequest
public ClientRequest(UriBuilder uri,
ClientExecutor executor)
ClientRequest
public ClientRequest(UriBuilder uri,
ClientExecutor executor,
ResteasyProviderFactory providerFactory)
setDefaultExecutorClass
public static void setDefaultExecutorClass(String classname)
- Set the default executor class name.
- Parameters:
classname
-
getDefaultExecutor
public static ClientExecutor getDefaultExecutor()
clear
public void clear()
- Clear this request's state so that it can be re-used
followRedirects
public boolean followRedirects()
getAttributes
public Map<String,Object> getAttributes()
followRedirects
public ClientRequest followRedirects(boolean followRedirects)
accept
public ClientRequest accept(MediaType accepts)
accept
public ClientRequest accept(String accept)
toString
protected String toString(Object object)
toHeaderString
protected String toHeaderString(Object object)
addLink
public ClientRequest addLink(Link link)
addLink
public ClientRequest addLink(String title,
String rel,
String href,
String type)
formParameter
public ClientRequest formParameter(String parameterName,
Object value)
queryParameter
public ClientRequest queryParameter(String parameterName,
Object value)
matrixParameter
public ClientRequest matrixParameter(String parameterName,
Object value)
header
public ClientRequest header(String headerName,
Object value)
cookie
public ClientRequest cookie(String cookieName,
Object value)
cookie
public ClientRequest cookie(Cookie cookie)
pathParameter
public ClientRequest pathParameter(String parameterName,
Object value)
pathParameters
public ClientRequest pathParameters(Object... values)
body
public ClientRequest body(String contentType,
Object data)
body
public ClientRequest body(MediaType contentType,
Object data)
body
public ClientRequest body(MediaType contentType,
Object data,
GenericType genericType)
body
public ClientRequest body(MediaType contentType,
Object data,
Type genericType)
body
public ClientRequest body(MediaType contentType,
Object data,
Class type,
Type genericType,
Annotation[] annotations)
getProviderFactory
public ResteasyProviderFactory getProviderFactory()
getExecutor
public ClientExecutor getExecutor()
getHeaders
public MultivaluedMap<String,String> getHeaders()
- Returns:
- a copy of all header objects converted to a string
getHeadersAsObjects
public MultivaluedMap<String,Object> getHeadersAsObjects()
getQueryParameters
public MultivaluedMap<String,String> getQueryParameters()
getFormParameters
public MultivaluedMap<String,String> getFormParameters()
getPathParameters
public MultivaluedMap<String,String> getPathParameters()
getPathParameterList
public List<String> getPathParameterList()
getMatrixParameters
public MultivaluedMap<String,String> getMatrixParameters()
getBody
public Object getBody()
getBodyType
public Class getBodyType()
getBodyGenericType
public Type getBodyGenericType()
getBodyAnnotations
public Annotation[] getBodyAnnotations()
getBodyContentType
public MediaType getBodyContentType()
getHttpMethod
public String getHttpMethod()
setHttpMethod
public void setHttpMethod(String httpMethod)
execute
public ClientResponse execute()
throws Exception
- Throws:
Exception
writeRequestBody
public void writeRequestBody(MultivaluedMap<String,Object> headers,
OutputStream outputStream)
throws IOException
- Throws:
IOException
get
public ClientResponse get()
throws Exception
- Throws:
Exception
getTarget
public <T> T getTarget(Class<T> returnType)
throws Exception
- Tries to automatically unmarshal to target type.
- Type Parameters:
T
- - Parameters:
returnType
-
- Returns:
-
- Throws:
Exception
get
public <T> ClientResponse<T> get(Class<T> returnType)
throws Exception
- Templates the returned ClientResponse for easy access to returned entity
- Type Parameters:
T
- - Parameters:
returnType
-
- Returns:
-
- Throws:
Exception
get
public <T> ClientResponse<T> get(Class<T> returnType,
Type genericType)
throws Exception
- Throws:
Exception
get
public <T> ClientResponse<T> get(GenericType type)
throws Exception
- Throws:
Exception
head
public ClientResponse head()
throws Exception
- Throws:
Exception
put
public ClientResponse put()
throws Exception
- Throws:
Exception
put
public <T> ClientResponse<T> put(Class<T> returnType)
throws Exception
- Throws:
Exception
put
public <T> ClientResponse<T> put(Class<T> returnType,
Type genericType)
throws Exception
- Throws:
Exception
put
public <T> ClientResponse<T> put(GenericType type)
throws Exception
- Throws:
Exception
post
public ClientResponse post()
throws Exception
- Throws:
Exception
post
public <T> ClientResponse<T> post(Class<T> returnType)
throws Exception
- Throws:
Exception
postTarget
public <T> T postTarget(Class<T> returnType)
throws Exception
- Throws:
Exception
post
public <T> ClientResponse<T> post(Class<T> returnType,
Type genericType)
throws Exception
- Throws:
Exception
post
public <T> ClientResponse<T> post(GenericType type)
throws Exception
- Throws:
Exception
create
public Link create()
throws Exception,
ClientResponseFailure
- Automatically does POST/Create pattern. Will throw a ClientResponseFailure
if status is something other than 201
- Returns:
- Link to created resource
- Throws:
Exception,
- ClientResponseFailure
Exception
ClientResponseFailure
delete
public ClientResponse delete()
throws Exception
- Throws:
Exception
delete
public <T> ClientResponse<T> delete(Class<T> returnType)
throws Exception
- Throws:
Exception
delete
public <T> ClientResponse<T> delete(Class<T> returnType,
Type genericType)
throws Exception
- Throws:
Exception
delete
public <T> ClientResponse<T> delete(GenericType type)
throws Exception
- Throws:
Exception
options
public ClientResponse options()
throws Exception
- Throws:
Exception
options
public <T> ClientResponse<T> options(Class<T> returnType)
throws Exception
- Throws:
Exception
options
public <T> ClientResponse<T> options(Class<T> returnType,
Type genericType)
throws Exception
- Throws:
Exception
options
public <T> ClientResponse<T> options(GenericType type)
throws Exception
- Throws:
Exception
httpMethod
public ClientResponse httpMethod(String httpMethod)
throws Exception
- Throws:
Exception
httpMethod
public <T> ClientResponse<T> httpMethod(String method,
Class<T> returnType)
throws Exception
- Throws:
Exception
httpMethod
public <T> ClientResponse<T> httpMethod(String method,
Class<T> returnType,
Type genericType)
throws Exception
- Throws:
Exception
httpMethod
public <T> ClientResponse<T> httpMethod(String method,
GenericType type)
throws Exception
- Throws:
Exception
overrideUri
public void overrideUri(URI uri)
getUri
public String getUri()
throws Exception
- This method populates all path, matrix, and query parameters and saves it
internally. Once its called once it returns the cached value.
- Returns:
-
- Throws:
Exception
createSubsequentRequest
public ClientRequest createSubsequentRequest(URI uri)
Copyright © 2012. All Rights Reserved.