Class MockRestClient
- All Implemented Interfaces:
Closeable,AutoCloseable,HttpClient,HttpClientConnection,HttpConnection
RestClient.
This class is used for performing serverless unit testing of @Rest-annotated and @Remote-annotated classes.
The class itself extends from RestClient providing it with the rich feature set of that API and combines
it with the Apache HttpClient HttpClientConnection interface for processing requests.
The class converts HttpRequest objects to instances of MockServletRequest and MockServletResponse which are passed directly
to the call handler on the resource class RestContext.execute(Object,HttpServletRequest,HttpServletResponse).
In effect, you're fully testing your REST API as if it were running in a live servlet container, yet not
actually having to run in a servlet container.
All aspects of the client and server side code are tested, yet no servlet container is required. The actual
over-the-wire transmission is the only aspect being bypassed.
The following shows a simple example of invoking a PUT method on a simple REST interface and asserting the correct status code and response body:
Example:
Breaking apart the fluent method call above will help you understand how this works.
The
The MockRestRequest object has convenience methods provided to allow you to set any properties
directly on the underlying HttpServletRequest object. The following example shows how
this can be used to directly set roles on the request object to perform security testing.
Example:
Debug mode is provided that will cause your HTTP requests and responses to be sent to the console:
Example:
MockRestClient
The class can also be used for testing of @Remote-annotated interfaces against @Rest-annotated resources.
Example:
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.juneau.rest.client.RestClient
detectLeaks, formData, headerData, httpClient, ignoreErrors, interceptors, keepHttpClientOpen, logRequests, logRequestsLevel, logRequestsPredicate, parsers, partParser, partSerializer, pathData, queryData, serializers, skipEmptyFormData, skipEmptyHeaderData, skipEmptyQueryData, urlEncodingSerializerFields inherited from class org.apache.juneau.BeanContextable
beanContextFields inherited from class org.apache.juneau.Context
CONTEXT_APPLY_FILTER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MockRestClientCreates a newRestClientwith no registered serializer or parser.static MockRestClientCreates a newRestClientwith JSON marshalling support.static MockRestClientbuildJson5(Object impl) Creates a newRestClientwith Simplified-JSON marshalling support.static MockRestClientbuildJson5Lax(Object impl) Creates a newRestClientwith Simplified-JSON marshalling support.static MockRestClientbuildJsonLax(Object impl) Creates a newRestClientwith JSON marshalling support.static MockRestClientCreates a newRestClientwith no registered serializer or parser.Performs a REST call where the entire call is specified in a simple string.voidclose()CallsCloseable.close()on the underlyingCloseableHttpClient.static MockRestClient.BuilderCreates a newRestClient.Builderconfigured with the specified REST implementation bean or bean class.static MockRestClient.BuilderCreates a newRestClient.Builderconfigured with the specified REST implementation bean or bean class.protected MockRestRequestcreateRequest(URI uri, String method, boolean hasBody) Creates aRestRequestobject from the specifiedHttpRequestobject.protected MockRestResponsecreateResponse(RestRequest req, HttpResponse httpResponse, Parser parser) Creates aRestResponseobject from the specifiedHttpResponseobject.Perform aDELETE request against the specified URI.voidflush()Same asRestClient.formPost(Object, Object)but doesn't specify the input yet.Perform aPOST request with a content type ofapplication/x-www-form-urlencoded against the specified URI.formPostPairs(Object url, String... parameters) Perform aPOST request with a content type ofapplication/x-www-form-urlencoded against the specified URI.get()Perform aGET request against the root URI.Perform aGET request against the specified URI.Returns the current client-side REST request.Returns the current client-side REST response.Returns the current server-side REST request.Returns the current server-side REST response.intPerform aHEAD request against the specified URI.booleanisOpen()booleanisResponseAvailable(int timeout) booleanisStale()Perform anOPTIONS request against the specified URI.Same asRestClient.patch(Object, Object)but don't specify the input yet.Perform aPATCH request against the specified URI.patch(Object url, String body, ContentType contentType) Perform aPATCH request against the specified URI as a plain text body bypassing the serializer.Same asRestClient.post(Object, Object)but don't specify the input yet.Perform aPOST request against the specified URI.post(Object url, String body, ContentType contentType) Perform aPOST request against the specified URI as a plain text body bypassing the serializer.Same asRestClient.put(Object, Object)but don't specify the input yet.Perform aPUT request against the specified URI.put(Object url, String body, ContentType contentType) Perform aPUT request against the specified URI using a plain text body bypassing the serializer.voidreceiveResponseEntity(HttpResponse response) Perform a generic REST call.Perform a generic REST call.Perform a generic REST call.request(RestOperation op) Perform an arbitrary request against the specified URI.voidvoidsendRequestHeader(HttpRequest request) voidsetSocketTimeout(int timeout) voidshutdown()Methods inherited from class org.apache.juneau.rest.client.RestClient
closeQuietly, copy, create, createFormData, createHeaderData, createPathData, createQueryData, execute, execute, execute, execute, execute, execute, execute, execute, finalize, getConnectionManager, getHttpClientConnectionManager, getParams, getPartParser, getPartParser, getPartSerializer, getPartSerializer, getRemote, getRemote, getRemote, getRrpcInterface, getRrpcInterface, getRrpcInterface, init, isSkipEmptyFormData, isSkipEmptyHeaderData, isSkipEmptyQueryData, log, log, onCallClose, onCallConnect, onCallInit, properties, runMethods inherited from class org.apache.juneau.BeanContextable
getBeanContextMethods inherited from class org.apache.juneau.Context
createBuilder, createSession, getAnnotationProvider, getSession, init, isDebug, toString
-
Constructor Details
-
MockRestClient
Constructor.- Parameters:
builder- The builder for this object.
-
-
Method Details
-
build
Creates a newRestClientwith no registered serializer or parser.Equivalent to calling:
MockRestClient.
create (impl ).build();- Parameters:
impl- The REST bean or bean class annotated with@Rest.
If a class, it must have a no-arg constructor.- Returns:
- A new builder.
-
buildJson
Creates a newRestClientwith JSON marshalling support.Equivalent to calling:
MockRestClient.
create (impl ).json().build();- Parameters:
impl- The REST bean or bean class annotated with@Rest.
If a class, it must have a no-arg constructor.- Returns:
- A new builder.
-
buildJson5
Creates a newRestClientwith Simplified-JSON marshalling support.Equivalent to calling:
MockRestClient.
create (impl ).json().build();- Parameters:
impl- The REST bean or bean class annotated with@Rest.
If a class, it must have a no-arg constructor.- Returns:
- A new builder.
-
buildJson5Lax
Creates a newRestClientwith Simplified-JSON marshalling support.Same as
buildJson5(Object)but HTTP 400+ codes don't triggerRestCallExceptions.Equivalent to calling:
MockRestClient.
create (impl ).json().ignoreErrors().build();- Parameters:
impl- The REST bean or bean class annotated with@Rest.
If a class, it must have a no-arg constructor.- Returns:
- A new builder.
-
buildJsonLax
Creates a newRestClientwith JSON marshalling support.Same as
buildJson(Object)but HTTP 400+ codes don't triggerRestCallExceptions.Equivalent to calling:
MockRestClient.
create (impl ).json().ignoreErrors().build();- Parameters:
impl- The REST bean or bean class annotated with@Rest.
If a class, it must have a no-arg constructor.- Returns:
- A new builder.
-
buildLax
Creates a newRestClientwith no registered serializer or parser.Same as
build(Object)but HTTP 400+ codes don't triggerRestCallExceptions.Equivalent to calling:
MockRestClient.
create (impl ).ignoreErrors().noTrace().build();- Parameters:
impl- The REST bean or bean class annotated with@Rest.
If a class, it must have a no-arg constructor.- Returns:
- A new builder.
-
create
Creates a newRestClient.Builderconfigured with the specified REST implementation bean or bean class.- Parameters:
impl- The REST bean or bean class annotated with@Rest.
If a class, it must have a no-arg constructor.- Returns:
- A new builder.
-
createLax
Creates a newRestClient.Builderconfigured with the specified REST implementation bean or bean class.Same as
create(Object)but HTTP 400+ codes don't triggerRestCallExceptions.- Parameters:
impl- The REST bean or bean class annotated with@Rest.
If a class, it must have a no-arg constructor.- Returns:
- A new builder.
-
callback
Description copied from class:RestClientPerforms a REST call where the entire call is specified in a simple string.This method is useful for performing callbacks when the target of a callback is passed in on an initial request, for example to signal when a long-running process has completed.
The call string can be any of the following formats:
-
"[method] [uri]" - e.g."GET http://localhost/callback" -
"[method] [uri] [payload]" - e.g."POST http://localhost/callback some text payload" -
"[method] [headers] [uri] [payload]" - e.g."POST {'Content-Type':'text/json'} http://localhost/callback {'some':'json'}"
The payload will always be sent using a simple
StringEntity.- Overrides:
callbackin classRestClient- Parameters:
callString- The call string.
Can benull or empty (treated as empty string, will result in an invalid request).- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- REST call failed.
-
-
close
Description copied from class:RestClientCallsCloseable.close()on the underlyingCloseableHttpClient.It's good practice to call this method after the client is no longer used.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceHttpConnection- Overrides:
closein classRestClient- Throws:
IOException- Thrown by underlying stream.
-
delete
Description copied from class:RestClientPerform aDELETE request against the specified URI.- Overrides:
deletein classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
flush
- Specified by:
flushin interfaceHttpClientConnection- Throws:
IOException
-
formPost
Description copied from class:RestClientSame asRestClient.formPost(Object, Object)but doesn't specify the input yet.- Overrides:
formPostin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
formPost
Description copied from class:RestClientPerform aPOST request with a content type ofapplication/x-www-form-urlencoded against the specified URI.- Overrides:
formPostin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
body- The object to serialize and transmit to the URI as the body of the request.NameValuePair- URL-encoded as a single name-value pair.NameValuePairarray - URL-encoded as name value pairs.PartList- URL-encoded as name value pairs.Reader/InputStream- Streamed directly andContent-Type set to"application/x-www-form-urlencoded" HttpResource- Raw contents will be serialized to remote resource. Additional headers and media type will be set on request.HttpEntity- Bypass Juneau serialization and pass HttpEntity directly to HttpClient.Object- Converted to aSerializedEntityusingUrlEncodingSerializerto serialize.Supplier- A supplier of anything on this list.
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
formPostPairs
Description copied from class:RestClientPerform aPOST request with a content type ofapplication/x-www-form-urlencoded against the specified URI.- Overrides:
formPostPairsin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
parameters- The parameters of the form post.
The parameters represent name/value pairs and must be an even number of arguments.
Parameters are converted toBasicPartobjects.- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
get
Description copied from class:RestClientPerform aGET request against the root URI.- Overrides:
getin classRestClient- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
get
Description copied from class:RestClientPerform aGET request against the specified URI.- Overrides:
getin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
getCurrentClientRequest
Returns the current client-side REST request.Note that this uses a
ThreadLocalobject for storage and so will not work on requests executed in separate threads such as when usingFutures.- Returns:
- The current client-side REST request, or
null if not set.
-
getCurrentClientResponse
Returns the current client-side REST response.Note that this uses a
ThreadLocalobject for storage and so will not work on requests executed in separate threads such as when usingFutures.- Returns:
- The current client-side REST response, or
null if not set.
-
getCurrentServerRequest
Returns the current server-side REST request.Note that this uses a
ThreadLocalobject for storage and so will not work on requests executed in separate threads such as when usingFutures.- Returns:
- The current server-side REST request, or
null if not set.
-
getCurrentServerResponse
Returns the current server-side REST response.Note that this uses a
ThreadLocalobject for storage and so will not work on requests executed in separate threads such as when usingFutures.- Returns:
- The current server-side REST response, or
null if not set.
-
getMetrics
- Specified by:
getMetricsin interfaceHttpConnection
-
getSocketTimeout
- Specified by:
getSocketTimeoutin interfaceHttpConnection
-
head
Description copied from class:RestClientPerform aHEAD request against the specified URI.- Overrides:
headin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
isOpen
- Specified by:
isOpenin interfaceHttpConnection
-
isResponseAvailable
- Specified by:
isResponseAvailablein interfaceHttpClientConnection- Throws:
IOException
-
isStale
- Specified by:
isStalein interfaceHttpConnection
-
options
Description copied from class:RestClientPerform anOPTIONS request against the specified URI.- Overrides:
optionsin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
patch
Description copied from class:RestClientSame asRestClient.patch(Object, Object)but don't specify the input yet.You must call
RestRequest.content(Object)to set the contents on the result object.- Overrides:
patchin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- REST call failed.
-
patch
Description copied from class:RestClientPerform aPATCH request against the specified URI.- Overrides:
patchin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
body- The object to serialize and transmit to the URI as the body of the request. Can be of the following types:-
Reader- Raw contents ofReaderwill be serialized to remote resource. -
InputStream- Raw contents ofInputStreamwill be serialized to remote resource. -
HttpResource- Raw contents will be serialized to remote resource. Additional headers and media type will be set on request. -
HttpEntity- Bypass Juneau serialization and pass HttpEntity directly to HttpClient. -
Object- POJO to be converted to text using theSerializerregistered with theRestClient. -
PartList- Converted to a URL-encoded FORM post. -
Supplier- A supplier of anything on this list.
-
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
patch
public MockRestRequest patch(Object url, String body, ContentType contentType) throws RestCallException Description copied from class:RestClientPerform aPATCH request against the specified URI as a plain text body bypassing the serializer.- Overrides:
patchin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
body- The object to serialize and transmit to the URI as the body of the request bypassing the serializer.contentType- The content type of the request.- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
post
Description copied from class:RestClientSame asRestClient.post(Object, Object)but don't specify the input yet.You must call either
RestRequest.content(Object)orRestRequest.formData(String, Object)to set the contents on the result object.Notes:
- Use
RestClient.formPost(Object, Object)forapplication/x-www-form-urlencoded form posts.
- Overrides:
postin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- REST call failed.
- Use
-
post
Description copied from class:RestClientPerform aPOST request against the specified URI.Notes:
- Use
RestClient.formPost(Object, Object)forapplication/x-www-form-urlencoded form posts.
- Overrides:
postin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
body- The object to serialize and transmit to the URI as the body of the request. Can be of the following types:-
Reader- Raw contents ofReaderwill be serialized to remote resource. -
InputStream- Raw contents ofInputStreamwill be serialized to remote resource. -
Object- POJO to be converted to text using theSerializerregistered with theRestClient. -
HttpEntity/HttpResource- Bypass Juneau serialization and pass HttpEntity directly to HttpClient. -
PartList- Converted to a URL-encoded FORM post. -
Supplier- A supplier of anything on this list.
-
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
- Use
-
post
public MockRestRequest post(Object url, String body, ContentType contentType) throws RestCallException Description copied from class:RestClientPerform aPOST request against the specified URI as a plain text body bypassing the serializer.- Overrides:
postin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
body- The object to serialize and transmit to the URI as the body of the request bypassing the serializer.contentType- The content type of the request.- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
put
Description copied from class:RestClientSame asRestClient.put(Object, Object)but don't specify the input yet.You must call either
RestRequest.content(Object)orRestRequest.formData(String, Object)to set the contents on the result object.- Overrides:
putin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- REST call failed.
-
put
Description copied from class:RestClientPerform aPUT request against the specified URI.- Overrides:
putin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
body- The object to serialize and transmit to the URI as the body of the request. Can be of the following types:-
Reader- Raw contents ofReaderwill be serialized to remote resource. -
InputStream- Raw contents ofInputStreamwill be serialized to remote resource. -
Object- POJO to be converted to text using theSerializerregistered with theRestClient. -
HttpEntity/HttpResource- Bypass Juneau serialization and pass HttpEntity directly to HttpClient. -
PartList- Converted to a URL-encoded FORM post. -
Supplier- A supplier of anything on this list.
-
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
put
public MockRestRequest put(Object url, String body, ContentType contentType) throws RestCallException Description copied from class:RestClientPerform aPUT request against the specified URI using a plain text body bypassing the serializer.- Overrides:
putin classRestClient- Parameters:
url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
body- The object to serialize and transmit to the URI as the body of the request bypassing the serializer.contentType- The content type of the request.- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
receiveResponseEntity
- Specified by:
receiveResponseEntityin interfaceHttpClientConnection- Throws:
HttpExceptionIOException
-
receiveResponseHeader
- Specified by:
receiveResponseHeaderin interfaceHttpClientConnection- Throws:
HttpExceptionIOException
-
request
Description copied from class:RestClientPerform an arbitrary request against the specified URI.All requests feed through this method so it can be used to intercept request creations and make modifications (such as add headers).
- Overrides:
requestin classRestClient- Parameters:
op- The operation that identifies the HTTP method, URL, and optional payload.- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
request
Description copied from class:RestClientPerform a generic REST call.- Overrides:
requestin classRestClient- Parameters:
method- The HTTP method.
Cannot benull .url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
Can benull (will result in an invalid request).- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
request
Description copied from class:RestClientPerform a generic REST call.Typically you're going to use
RestClient.request(String, Object)orRestClient.request(String, Object, Object), but this method is provided to allow you to perform non-standard HTTP methods (e.g. HTTP FOO).- Overrides:
requestin classRestClient- Parameters:
method- The method name (e.g."GET" ,"OPTIONS" ).
Cannot benull .url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
Can benull (will result in an invalid request).hasBody- Boolean flag indicating if the specified request has content associated with it.- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
request
Description copied from class:RestClientPerform a generic REST call.- Overrides:
requestin classRestClient- Parameters:
method- The HTTP method.
Cannot benull .url- The URI of the remote REST resource.
Can be any of the following types:URIBuilderURIURLStringObject- Converted toString usingtoString()
Can benull (will result in an invalid request).body- The HTTP body content. Can be of the following types:-
Reader- Raw contents ofReaderwill be serialized to remote resource. -
InputStream- Raw contents ofInputStreamwill be serialized to remote resource. -
HttpResource- Raw contents will be serialized to remote resource. Additional headers and media type will be set on request. -
HttpEntity- Bypass Juneau serialization and pass HttpEntity directly to HttpClient. -
Object- POJO to be converted to text using theSerializerregistered with theRestClient. -
PartList- Converted to a URL-encoded FORM post. -
Supplier- A supplier of anything on this list.
-
- Returns:
- A
RestRequestobject that can be further tailored before executing the request and getting the response as a parsed object. - Throws:
RestCallException- If any authentication errors occurred.
-
sendRequestEntity
- Specified by:
sendRequestEntityin interfaceHttpClientConnection- Throws:
HttpExceptionIOException
-
sendRequestHeader
- Specified by:
sendRequestHeaderin interfaceHttpClientConnection- Throws:
HttpExceptionIOException
-
setSocketTimeout
- Specified by:
setSocketTimeoutin interfaceHttpConnection
-
shutdown
- Specified by:
shutdownin interfaceHttpConnection- Throws:
IOException
-
createRequest
protected MockRestRequest createRequest(URI uri, String method, boolean hasBody) throws RestCallException Description copied from class:RestClientCreates aRestRequestobject from the specifiedHttpRequestobject.Subclasses can override this method to provide their own specialized
RestRequestobjects.- Overrides:
createRequestin classRestClient- Parameters:
uri- The target.method- The HTTP method (uppercase).hasBody- Whether this method has a request entity.- Returns:
- A new
RestRequestobject. - Throws:
RestCallException- If an exception or non-200 response code occurred during the connection attempt.
-
createResponse
protected MockRestResponse createResponse(RestRequest req, HttpResponse httpResponse, Parser parser) throws RestCallException Description copied from class:RestClientCreates aRestResponseobject from the specifiedHttpResponseobject.Subclasses can override this method to provide their own specialized
RestResponseobjects.- Overrides:
createResponsein classRestClient- Parameters:
req- The request creating this response.httpResponse- The response object to wrap.parser- The parser to use to parse the response.- Returns:
- A new
RestResponseobject. - Throws:
RestCallException- If an exception or non-200 response code occurred during the connection attempt.
-