org.jboss.resteasy.client
Class ClientRequest

java.lang.Object
  extended by org.jboss.resteasy.client.core.ClientInterceptorRepositoryImpl
      extended by org.jboss.resteasy.client.ClientRequest
All Implemented Interfaces:
ClientInterceptorRepository

public class ClientRequest
extends ClientInterceptorRepositoryImpl

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

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jboss.resteasy.client.core.ClientInterceptorRepositoryImpl
ClientInterceptorRepositoryImpl.InterceptorType
 
Field Summary
protected  ResteasyProviderFactory providerFactory
           
 
Constructor Summary
ClientRequest(java.lang.String uriTemplate)
           
ClientRequest(java.lang.String uriTemplate, ClientExecutor executor)
           
ClientRequest(UriBuilder uri, ClientExecutor executor)
           
ClientRequest(UriBuilder uri, ClientExecutor executor, ResteasyProviderFactory providerFactory)
           
 
Method Summary
 ClientRequest accept(MediaType accepts)
           
 ClientRequest accept(java.lang.String accept)
           
 ClientRequest addLink(Link link)
           
 ClientRequest addLink(java.lang.String title, java.lang.String rel, java.lang.String href, java.lang.String type)
           
 ClientRequest body(MediaType contentType, java.lang.Object data)
           
 ClientRequest body(MediaType contentType, java.lang.Object data, java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations)
           
 ClientRequest body(MediaType contentType, java.lang.Object data, GenericType genericType)
           
 ClientRequest body(MediaType contentType, java.lang.Object data, java.lang.reflect.Type genericType)
           
 ClientRequest body(java.lang.String contentType, java.lang.Object data)
           
 void clear()
          Clear this request's state so that it can be re-used
 ClientRequest cookie(Cookie cookie)
           
 ClientRequest cookie(java.lang.String cookieName, java.lang.Object value)
           
 Link create()
          Automatically does POST/Create pattern.
 ClientResponse delete()
           
<T> ClientResponse<T>
delete(java.lang.Class<T> returnType)
           
<T> ClientResponse<T>
delete(java.lang.Class<T> returnType, java.lang.reflect.Type genericType)
           
<T> ClientResponse<T>
delete(GenericType type)
           
 ClientResponse execute()
           
 boolean followRedirects()
           
 ClientRequest followRedirects(boolean followRedirects)
           
 ClientRequest formParameter(java.lang.String parameterName, java.lang.Object value)
           
 ClientResponse get()
           
<T> ClientResponse<T>
get(java.lang.Class<T> returnType)
          Templates the returned ClientResponse for easy access to returned entity
<T> ClientResponse<T>
get(java.lang.Class<T> returnType, java.lang.reflect.Type genericType)
           
<T> ClientResponse<T>
get(GenericType type)
           
 java.lang.Object getBody()
           
 java.lang.annotation.Annotation[] getBodyAnnotations()
           
 MediaType getBodyContentType()
           
 java.lang.reflect.Type getBodyGenericType()
           
 java.lang.Class getBodyType()
           
static ClientExecutor getDefaultExecutor()
           
 ClientExecutor getExecutor()
           
 MultivaluedMap<java.lang.String,java.lang.String> getFormParameters()
           
 MultivaluedMap<java.lang.String,java.lang.String> getHeaders()
           
 java.lang.String getHttpMethod()
           
 MultivaluedMap<java.lang.String,java.lang.String> getMatrixParameters()
           
 java.util.List<java.lang.String> getPathParameterList()
           
 MultivaluedMap<java.lang.String,java.lang.String> getPathParameters()
           
 ResteasyProviderFactory getProviderFactory()
           
 MultivaluedMap<java.lang.String,java.lang.String> getQueryParameters()
           
<T> T
getTarget(java.lang.Class<T> returnType)
          Tries to automatically unmarshal to target type.
 java.lang.String getUri()
          This method populates all path, matrix, and query parameters and saves it internally.
 ClientResponse head()
           
 ClientRequest header(java.lang.String headerName, java.lang.Object value)
           
 ClientResponse httpMethod(java.lang.String httpMethod)
           
<T> ClientResponse<T>
httpMethod(java.lang.String method, java.lang.Class<T> returnType)
           
<T> ClientResponse<T>
httpmethod(java.lang.String method, java.lang.Class<T> returnType, java.lang.reflect.Type genericType)
           
<T> ClientResponse<T>
httpMethod(java.lang.String method, GenericType type)
           
 ClientRequest matrixParameter(java.lang.String parameterName, java.lang.Object value)
           
 ClientResponse options()
           
<T> ClientResponse<T>
options(java.lang.Class<T> returnType)
           
<T> ClientResponse<T>
options(java.lang.Class<T> returnType, java.lang.reflect.Type genericType)
           
<T> ClientResponse<T>
options(GenericType type)
           
 void overrideUri(java.net.URI uri)
           
 ClientRequest pathParameter(java.lang.String parameterName, java.lang.Object value)
           
 ClientRequest pathParameters(java.lang.Object... values)
           
 ClientResponse post()
           
<T> ClientResponse<T>
post(java.lang.Class<T> returnType)
           
<T> ClientResponse<T>
post(java.lang.Class<T> returnType, java.lang.reflect.Type genericType)
           
<T> ClientResponse<T>
post(GenericType type)
           
<T> T
postTarget(java.lang.Class<T> returnType)
           
 ClientResponse put()
           
<T> ClientResponse<T>
put(java.lang.Class<T> returnType)
           
<T> ClientResponse<T>
put(java.lang.Class<T> returnType, java.lang.reflect.Type genericType)
           
<T> ClientResponse<T>
put(GenericType type)
           
 ClientRequest queryParameter(java.lang.String parameterName, java.lang.Object value)
           
static void setDefaultExecutorClass(java.lang.String classname, boolean createPerRequestInstance)
          Set the default executor class name.
 void setHttpMethod(java.lang.String httpMethod)
           
protected  java.lang.String toHeaderString(java.lang.Object object)
           
protected  java.lang.String toString(java.lang.Object object)
           
 void writeRequestBody(MultivaluedMap<java.lang.String,java.lang.Object> headers, java.io.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
 

Field Detail

providerFactory

protected ResteasyProviderFactory providerFactory
Constructor Detail

ClientRequest

public ClientRequest(java.lang.String uriTemplate)

ClientRequest

public ClientRequest(java.lang.String uriTemplate,
                     ClientExecutor executor)

ClientRequest

public ClientRequest(UriBuilder uri,
                     ClientExecutor executor)

ClientRequest

public ClientRequest(UriBuilder uri,
                     ClientExecutor executor,
                     ResteasyProviderFactory providerFactory)
Method Detail

setDefaultExecutorClass

public static void setDefaultExecutorClass(java.lang.String classname,
                                           boolean createPerRequestInstance)
Set the default executor class name.

Parameters:
classname -
createPerRequestInstance - whether the instance can be used by every request

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()

followRedirects

public ClientRequest followRedirects(boolean followRedirects)

accept

public ClientRequest accept(MediaType accepts)

accept

public ClientRequest accept(java.lang.String accept)

toString

protected java.lang.String toString(java.lang.Object object)

toHeaderString

protected java.lang.String toHeaderString(java.lang.Object object)

addLink

public ClientRequest addLink(Link link)

addLink

public ClientRequest addLink(java.lang.String title,
                             java.lang.String rel,
                             java.lang.String href,
                             java.lang.String type)

formParameter

public ClientRequest formParameter(java.lang.String parameterName,
                                   java.lang.Object value)

queryParameter

public ClientRequest queryParameter(java.lang.String parameterName,
                                    java.lang.Object value)

matrixParameter

public ClientRequest matrixParameter(java.lang.String parameterName,
                                     java.lang.Object value)

header

public ClientRequest header(java.lang.String headerName,
                            java.lang.Object value)

cookie

public ClientRequest cookie(java.lang.String cookieName,
                            java.lang.Object value)

cookie

public ClientRequest cookie(Cookie cookie)

pathParameter

public ClientRequest pathParameter(java.lang.String parameterName,
                                   java.lang.Object value)

pathParameters

public ClientRequest pathParameters(java.lang.Object... values)

body

public ClientRequest body(java.lang.String contentType,
                          java.lang.Object data)

body

public ClientRequest body(MediaType contentType,
                          java.lang.Object data)

body

public ClientRequest body(MediaType contentType,
                          java.lang.Object data,
                          GenericType genericType)

body

public ClientRequest body(MediaType contentType,
                          java.lang.Object data,
                          java.lang.reflect.Type genericType)

body

public ClientRequest body(MediaType contentType,
                          java.lang.Object data,
                          java.lang.Class type,
                          java.lang.reflect.Type genericType,
                          java.lang.annotation.Annotation[] annotations)

getProviderFactory

public ResteasyProviderFactory getProviderFactory()

getExecutor

public ClientExecutor getExecutor()

getHeaders

public MultivaluedMap<java.lang.String,java.lang.String> getHeaders()

getQueryParameters

public MultivaluedMap<java.lang.String,java.lang.String> getQueryParameters()

getFormParameters

public MultivaluedMap<java.lang.String,java.lang.String> getFormParameters()

getPathParameters

public MultivaluedMap<java.lang.String,java.lang.String> getPathParameters()

getPathParameterList

public java.util.List<java.lang.String> getPathParameterList()

getMatrixParameters

public MultivaluedMap<java.lang.String,java.lang.String> getMatrixParameters()

getBody

public java.lang.Object getBody()

getBodyType

public java.lang.Class getBodyType()

getBodyGenericType

public java.lang.reflect.Type getBodyGenericType()

getBodyAnnotations

public java.lang.annotation.Annotation[] getBodyAnnotations()

getBodyContentType

public MediaType getBodyContentType()

getHttpMethod

public java.lang.String getHttpMethod()

setHttpMethod

public void setHttpMethod(java.lang.String httpMethod)

execute

public ClientResponse execute()
                       throws java.lang.Exception
Throws:
java.lang.Exception

writeRequestBody

public void writeRequestBody(MultivaluedMap<java.lang.String,java.lang.Object> headers,
                             java.io.OutputStream outputStream)
                      throws java.io.IOException
Throws:
java.io.IOException

get

public ClientResponse get()
                   throws java.lang.Exception
Throws:
java.lang.Exception

getTarget

public <T> T getTarget(java.lang.Class<T> returnType)
            throws java.lang.Exception
Tries to automatically unmarshal to target type.

Type Parameters:
T -
Parameters:
returnType -
Returns:
Throws:
java.lang.Exception

get

public <T> ClientResponse<T> get(java.lang.Class<T> returnType)
                      throws java.lang.Exception
Templates the returned ClientResponse for easy access to returned entity

Type Parameters:
T -
Parameters:
returnType -
Returns:
Throws:
java.lang.Exception

get

public <T> ClientResponse<T> get(java.lang.Class<T> returnType,
                                 java.lang.reflect.Type genericType)
                      throws java.lang.Exception
Throws:
java.lang.Exception

get

public <T> ClientResponse<T> get(GenericType type)
                      throws java.lang.Exception
Throws:
java.lang.Exception

head

public ClientResponse head()
                    throws java.lang.Exception
Throws:
java.lang.Exception

put

public ClientResponse put()
                   throws java.lang.Exception
Throws:
java.lang.Exception

put

public <T> ClientResponse<T> put(java.lang.Class<T> returnType)
                      throws java.lang.Exception
Throws:
java.lang.Exception

put

public <T> ClientResponse<T> put(java.lang.Class<T> returnType,
                                 java.lang.reflect.Type genericType)
                      throws java.lang.Exception
Throws:
java.lang.Exception

put

public <T> ClientResponse<T> put(GenericType type)
                      throws java.lang.Exception
Throws:
java.lang.Exception

post

public ClientResponse post()
                    throws java.lang.Exception
Throws:
java.lang.Exception

post

public <T> ClientResponse<T> post(java.lang.Class<T> returnType)
                       throws java.lang.Exception
Throws:
java.lang.Exception

postTarget

public <T> T postTarget(java.lang.Class<T> returnType)
             throws java.lang.Exception
Throws:
java.lang.Exception

post

public <T> ClientResponse<T> post(java.lang.Class<T> returnType,
                                  java.lang.reflect.Type genericType)
                       throws java.lang.Exception
Throws:
java.lang.Exception

post

public <T> ClientResponse<T> post(GenericType type)
                       throws java.lang.Exception
Throws:
java.lang.Exception

create

public Link create()
            throws java.lang.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
java.lang.Exception
ClientResponseFailure

delete

public ClientResponse delete()
                      throws java.lang.Exception
Throws:
java.lang.Exception

delete

public <T> ClientResponse<T> delete(java.lang.Class<T> returnType)
                         throws java.lang.Exception
Throws:
java.lang.Exception

delete

public <T> ClientResponse<T> delete(java.lang.Class<T> returnType,
                                    java.lang.reflect.Type genericType)
                         throws java.lang.Exception
Throws:
java.lang.Exception

delete

public <T> ClientResponse<T> delete(GenericType type)
                         throws java.lang.Exception
Throws:
java.lang.Exception

options

public ClientResponse options()
                       throws java.lang.Exception
Throws:
java.lang.Exception

options

public <T> ClientResponse<T> options(java.lang.Class<T> returnType)
                          throws java.lang.Exception
Throws:
java.lang.Exception

options

public <T> ClientResponse<T> options(java.lang.Class<T> returnType,
                                     java.lang.reflect.Type genericType)
                          throws java.lang.Exception
Throws:
java.lang.Exception

options

public <T> ClientResponse<T> options(GenericType type)
                          throws java.lang.Exception
Throws:
java.lang.Exception

httpMethod

public ClientResponse httpMethod(java.lang.String httpMethod)
                          throws java.lang.Exception
Throws:
java.lang.Exception

httpMethod

public <T> ClientResponse<T> httpMethod(java.lang.String method,
                                        java.lang.Class<T> returnType)
                             throws java.lang.Exception
Throws:
java.lang.Exception

httpmethod

public <T> ClientResponse<T> httpmethod(java.lang.String method,
                                        java.lang.Class<T> returnType,
                                        java.lang.reflect.Type genericType)
                             throws java.lang.Exception
Throws:
java.lang.Exception

httpMethod

public <T> ClientResponse<T> httpMethod(java.lang.String method,
                                        GenericType type)
                             throws java.lang.Exception
Throws:
java.lang.Exception

overrideUri

public void overrideUri(java.net.URI uri)

getUri

public java.lang.String getUri()
                        throws java.lang.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:
java.lang.Exception


Copyright © 2010. All Rights Reserved.