Package org.actioncontroller.client
Interface ApiClientExchange
-
- All Known Implementing Classes:
FakeJakartaApiClient.FakeApiClientExchange,FakeServletClient.FakeApiClientExchange,HttpURLConnectionApiClient.ClientExchange
public interface ApiClientExchangeAbstracts a HTTP request and response from the client perspective. Can be implemented with various HTTP clients and with fake Servlet classes.Usage example
exchange.setTarget("GET", "/index"); exchange.setRequestParameter("foo", "bar"); exchange.execute(); exchange.getResponseBody()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddRequestCookie(String name, Object value)Sets the specified HTTP cookie value.voidcheckForError()voidexecuteRequest()StringgetApiURL()Returns the path to where the controllers paths are evaluated relative to, that is, the Servlet's context URL.StringgetPathInfo()StringgetRequestMethod()URLgetRequestURL()ReadergetResponseBodyReader()InputStreamgetResponseBodyStream()intgetResponseCode()List<String>getResponseCookies(String name)List<String>getResponseHeaders(String name)voidoutput(String contentType, ApiHttpExchange.OutputStreamConsumer consumer)voidsetClientCertificate(X509Certificate[] certificate)voidsetHeader(String name, Object value)voidsetPathInfo(String pathInfo)voidsetRequestParameter(String name, Object value)Sets the specified HTTP request parameter to be included in URL query (for GET requests) or application/x-www-form-urlencoded body (for other request methods).voidsetTarget(String method, String pathInfo)voidwrite(String contentType, ApiHttpExchange.WriterConsumer consumer)
-
-
-
Method Detail
-
getRequestMethod
String getRequestMethod()
-
getPathInfo
String getPathInfo()
-
setPathInfo
void setPathInfo(String pathInfo)
-
getRequestURL
URL getRequestURL()
-
setRequestParameter
void setRequestParameter(String name, Object value)
Sets the specified HTTP request parameter to be included in URL query (for GET requests) or application/x-www-form-urlencoded body (for other request methods).- Parameters:
name- Name of the HTTP request parameter to setvalue- If null or Optional.empty, parameter will be unset; if Optional, value will be extracted
-
getApiURL
String getApiURL()
Returns the path to where the controllers paths are evaluated relative to, that is, the Servlet's context URL. For example, if anApiServletis bound as "/api/*" in a webapp mounted at "/app", getApiURL might returnhttps://example.com:7443/app/api.
-
addRequestCookie
void addRequestCookie(String name, Object value)
Sets the specified HTTP cookie value. The cookie value will be URL encoded before sent in the Cookie-header- Parameters:
name- Name of the HTTP cookie to setvalue- If null or Optional.empty, cookie will be unset; if Optional, value will be extracted
-
executeRequest
void executeRequest() throws IOException- Throws:
IOException
-
getResponseCode
int getResponseCode() throws IOException- Throws:
IOException
-
getResponseBodyReader
Reader getResponseBodyReader() throws IOException
- Throws:
IOException
-
getResponseBodyStream
InputStream getResponseBodyStream() throws IOException
- Throws:
IOException
-
checkForError
void checkForError() throws HttpClientException, IOException- Throws:
HttpClientExceptionIOException
-
setClientCertificate
void setClientCertificate(X509Certificate[] certificate)
-
write
void write(String contentType, ApiHttpExchange.WriterConsumer consumer) throws IOException
- Throws:
IOException
-
output
void output(String contentType, ApiHttpExchange.OutputStreamConsumer consumer) throws IOException
- Throws:
IOException
-
-