Class ClientPOJOAdapter
- java.lang.Object
-
- org.apache.hc.core5.testing.framework.ClientPOJOAdapter
-
- Direct Known Subclasses:
ClassicTestClientAdapter
public abstract class ClientPOJOAdapter extends java.lang.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" }', ]
- Since:
- 5.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
BODY
static java.lang.String
CONTENT_TYPE
static java.lang.String
HEADERS
static java.lang.String
METHOD
static java.lang.String
NAME
static java.lang.String
PATH
static java.lang.String
PROTOCOL_VERSION
static java.lang.String
QUERY
static java.lang.String
REQUEST
static java.lang.String
RESPONSE
static java.lang.String
STATUS
static java.lang.String
TIMEOUT
-
Constructor Summary
Constructors Constructor Description ClientPOJOAdapter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
assertRequestSupported(java.util.Map<java.lang.String,java.lang.Object> request)
Assert that the request is supportedjava.lang.String
checkRequestSupport(java.util.Map<java.lang.String,java.lang.Object> request)
Check if a request is supported.abstract java.util.Map<java.lang.String,java.lang.Object>
execute(java.lang.String defaultURI, java.util.Map<java.lang.String,java.lang.Object> request)
Execute an HTTP request.abstract java.lang.String
getClientName()
Name of the HTTP Client that this adapter uses.java.util.Map<java.lang.String,java.lang.Object>
modifyRequest(java.util.Map<java.lang.String,java.lang.Object> request)
Modify the request.
-
-
-
Field Detail
-
BODY
public static final java.lang.String BODY
- See Also:
- Constant Field Values
-
CONTENT_TYPE
public static final java.lang.String CONTENT_TYPE
- See Also:
- Constant Field Values
-
HEADERS
public static final java.lang.String HEADERS
- See Also:
- Constant Field Values
-
METHOD
public static final java.lang.String METHOD
- See Also:
- Constant Field Values
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
PATH
public static final java.lang.String PATH
- See Also:
- Constant Field Values
-
PROTOCOL_VERSION
public static final java.lang.String PROTOCOL_VERSION
- See Also:
- Constant Field Values
-
QUERY
public static final java.lang.String QUERY
- See Also:
- Constant Field Values
-
REQUEST
public static final java.lang.String REQUEST
- See Also:
- Constant Field Values
-
RESPONSE
public static final java.lang.String RESPONSE
- See Also:
- Constant Field Values
-
STATUS
public static final java.lang.String STATUS
- See Also:
- Constant Field Values
-
TIMEOUT
public static final java.lang.String TIMEOUT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getClientName
public abstract java.lang.String getClientName()
Name of the HTTP Client that this adapter uses.- Returns:
- name of the HTTP Client.
-
execute
public abstract java.util.Map<java.lang.String,java.lang.Object> execute(java.lang.String defaultURI, java.util.Map<java.lang.String,java.lang.Object> request) throws java.lang.Exception
Execute an HTTP request.- Parameters:
defaultURI
- the URI used by default. The path in the request is usually appended to it.request
- the request as specified above.- Returns:
- the response to the request as specified above.
- Throws:
java.lang.Exception
- in case of a problem
-
checkRequestSupport
public java.lang.String checkRequestSupport(java.util.Map<java.lang.String,java.lang.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.
- Parameters:
request
- the request as specified above.- Returns:
- null if the request is supported; Otherwise, return a reason.
-
assertRequestSupported
public void assertRequestSupported(java.util.Map<java.lang.String,java.lang.Object> request) throws java.lang.Exception
Assert that the request is supported
Usually called by the execute method. Throws an exception if the request is not supported.
- Parameters:
request
- the request as specified above.- Throws:
java.lang.Exception
- if the request is not supported.
-
modifyRequest
public java.util.Map<java.lang.String,java.lang.Object> modifyRequest(java.util.Map<java.lang.String,java.lang.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).
- Parameters:
request
- the request as specified above.- Returns:
- the same request or a modification of it.
-
-