public abstract class ClientPOJOAdapter extends Object
This adapter expects a request to be made up of POJOs such as Maps and Lists. In Groovy the request could be expressed like this:
def request = [ path : "a/path", method : "GET", query : [ parm1 : "1", parm2 : "2", ] headers : [ header1 : "stuff", header2 : "more_stuff", ] contentType : "application/json", body : '{"location" : "home" }', ]
The adapter will translate this request into calls specific to a particular HTTP client.
The response is then returned with POJOs with this structure:
def response = [ status : 200, headers : [ header1 : "response_stuff", ] contentType : "application/json", body : '{"location" : "work" }', ]
Modifier and Type | Field and Description |
---|---|
static String |
BODY |
static String |
CONTENT_TYPE |
static String |
HEADERS |
static String |
METHOD |
static String |
NAME |
static String |
PATH |
static String |
PROTOCOL_VERSION |
static String |
QUERY |
static String |
REQUEST |
static String |
RESPONSE |
static String |
STATUS |
static String |
TIMEOUT |
Constructor and Description |
---|
ClientPOJOAdapter() |
Modifier and Type | Method and Description |
---|---|
void |
assertRequestSupported(Map<String,Object> request)
Assert that the request is supported
|
String |
checkRequestSupport(Map<String,Object> request)
Check if a request is supported.
|
abstract Map<String,Object> |
execute(String defaultURI,
Map<String,Object> request)
Execute an HTTP request.
|
abstract String |
getClientName()
Name of the HTTP Client that this adapter uses.
|
Map<String,Object> |
modifyRequest(Map<String,Object> request)
Modify the request.
|
public static final String BODY
public static final String CONTENT_TYPE
public static final String HEADERS
public static final String METHOD
public static final String NAME
public static final String PATH
public static final String PROTOCOL_VERSION
public static final String QUERY
public static final String REQUEST
public static final String RESPONSE
public static final String STATUS
public static final String TIMEOUT
public abstract String getClientName()
public abstract Map<String,Object> execute(String defaultURI, Map<String,Object> request) throws Exception
defaultURI
- the URI used by default. The path in the request is
usually appended to it.request
- the request as specified above.Exception
- in case of a problempublic String checkRequestSupport(Map<String,Object> request)
Check if a request is supported.
Usually called directly by a testing framework. If an HTTP client does not support a particular request, a non-null reason should be returned. Otherwise, if the request is supported, return null.
If this method is overridden, then the execute method should probably call assertRequestSupported() at the beginning.
request
- the request as specified above.public void assertRequestSupported(Map<String,Object> request) throws Exception
Assert that the request is supported
Usually called by the execute method. Throws an exception if the request is not supported.
request
- the request as specified above.Exception
- if the request is not supported.public Map<String,Object> modifyRequest(Map<String,Object> request)
Modify the request.
In a testing context, a testing framework can call this method to allow the adapter to change the request. The request is then given to a special request handler of the in-process HttpServer which will later check an actual HTTP request against what is expected.
In a production context, this is called by the execute method (if at all).
request
- the request as specified above.Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.