Class AbstractRestStub.Request
java.lang.Object
de.aristaflow.ilm.ws.rest.base.service.AbstractRestStub.Request
- Enclosing class:
- AbstractRestStub
A
Request represents a request sent to the REST callback and also provides the
return value sent via callback response.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe message body of the request.protected final Map<jakarta.ws.rs.core.Response.Status.Family,Pair<Boolean, Class<? extends IlmException>>> The expected exceptional responses for specific status families.protected final Map<jakarta.ws.rs.core.Response.StatusType,Pair<Boolean, Class<? extends IlmException>>> The expected exceptional responses for specific status types.The headers to be set in the request before sending it.protected final StringThe HTTP method of the request.protected final StringThe context path of the request, that is, the operation which to call.The query parameters to be set in the request before sending it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionalResponse(jakarta.ws.rs.core.Response.Status.Family family, boolean allowPlainText, Class<? extends IlmException> excpClass) Adds the designated response status and the class as expected exception.addExceptionalResponse(jakarta.ws.rs.core.Response.StatusType status, boolean allowPlainText, Class<? extends IlmException> excpClass) Adds the designated response status and the class as expected exception.addHeaderParam(String name, String value) Add the designated key and value as header to this request.addQueryParam(String name, String value) Add the designated key and value as query parameter to (the URL of) this request.protected <T> TgetResponse(jakarta.ws.rs.core.Response.StatusType expStatus, boolean allowPlainText, Class<T> expType) Gets the response (body) for this request.protected <T> TgetResponse(jakarta.ws.rs.core.Response.StatusType expStatus, boolean allowPlainText, String expTypeName, Function<InputStream, Pair<T, IOException>> readValue) Gets the response (body) for this request.<T> TgetResponse(jakarta.ws.rs.core.Response.StatusType expStatus, com.fasterxml.jackson.core.type.TypeReference<T> expType) Gets the response (body) for this request.<T> TgetResponse(jakarta.ws.rs.core.Response.StatusType expStatus, Class<T> expType) Gets the response (body) for this request.Gets the media type for the response of the designated connection including the corresponding encoding.getStringResponse(jakarta.ws.rs.core.Response.StatusType expStatus) Gets the string response for this request.voidJust waits for the void response, i.protected IlmExceptionreadExceptionalBody(URL url, int respCode, boolean excpCode, String respMsg, InputStream respBody, Charset charset, String expType) Tries to read an exception body from the response of the designated URL having the designated (exceptional) response code and message.protected StringreadString(InputStream is, Charset charset) Reads a string from the designated input stream using the designated character set.Sets the body of this request to the designated string.toString()
-
Field Details
-
path
The context path of the request, that is, the operation which to call. -
method
The HTTP method of the request. -
headerParams
The headers to be set in the request before sending it. -
queryParams
The query parameters to be set in the request before sending it. -
body
The message body of the request. This may benull. -
excpRespStatus
protected final Map<jakarta.ws.rs.core.Response.StatusType,Pair<Boolean, excpRespStatusClass<? extends IlmException>>> The expected exceptional responses for specific status types. This maps from status types to the corresponding exception class and whether the response may also be plain text instead of the exception provided as JSON object. -
excpRespFamily
protected final Map<jakarta.ws.rs.core.Response.Status.Family,Pair<Boolean, excpRespFamilyClass<? extends IlmException>>> The expected exceptional responses for specific status families. This maps from status families to the corresponding exception class and whether the response may also be plain text instead of the exception provided as JSON object.
-
-
Constructor Details
-
Request
Creates a new request for calling a callback method via REST.- Parameters:
path- The context path of the request, that is, the operation which to call.method- The HTTP method of the request.
-
-
Method Details
-
addHeaderParam
Add the designated key and value as header to this request.- Parameters:
name- The header name.value- The header value.- Returns:
- This request.
-
addQueryParam
Add the designated key and value as query parameter to (the URL of) this request. Both will be escaped for HTML 4.0.- Parameters:
name- The query parameter name.value- The query parameter value.- Returns:
- This request.
-
setBody
Sets the body of this request to the designated string. This has to be formatted appropriately, e. g. a JSON string.- Parameters:
value- The value to be set as body of this request.- Returns:
- This request.
-
addExceptionalResponse
public AbstractRestStub.Request addExceptionalResponse(jakarta.ws.rs.core.Response.StatusType status, boolean allowPlainText, Class<? extends IlmException> excpClass) Adds the designated response status and the class as expected exception. In case the designated response status is received, the designated exception type will be parsed from the response body.- Parameters:
status- The response status which represents the designated exception.allowPlainText- Whether a plain text response is allowed (instead of an exception provided as JSON object).excpClass- The exception which is expected in case of the designated response status.- Returns:
- This request.
-
addExceptionalResponse
public AbstractRestStub.Request addExceptionalResponse(jakarta.ws.rs.core.Response.Status.Family family, boolean allowPlainText, Class<? extends IlmException> excpClass) Adds the designated response status and the class as expected exception. In case the designated response status is received, the designated exception type will be parsed from the response body.- Parameters:
family- The response status family which represents the the designated exception.allowPlainText- Whether a plain text response is allowed (instead of an exception provided as JSON object).excpClass- The exception which is expected in case of the designated response status family.- Returns:
- This request.
-
getVoidResponse
Just waits for the void response, i. e.Response.Status.NO_CONTENT. If the response has a different status or is an exception, an appropriate exception will be thrown.- Throws:
IlmException- If the response contains an expected or unexpected response status and the body is an exception conforming to the API, the correspondingIlmExceptionwill be parsed from the response body and thrown.InternalServiceException- If there are problems creating the request or retrieving the response, anInternalServiceExceptionwrapping anIOExceptionwill be thrown; if parsing the response body fails, anInternalServiceExceptionwrapping aWebApplicationExceptionwill be thrown.- See Also:
-
getStringResponse
public String getStringResponse(jakarta.ws.rs.core.Response.StatusType expStatus) throws IlmException, InternalServiceException Gets the string response for this request. This expects either a plain string or a simple JSON string in the response body.- Parameters:
expStatus- The response status which is expected in case of a string response.- Returns:
- The string value from the response of this request.
- Throws:
IlmException- If the response contains an expected or unexpected response status and the body is an exception conforming to the API, the correspondingIlmExceptionwill be parsed from the response body and thrown.InternalServiceException- If there are problems creating the request or retrieving the response, anInternalServiceExceptionwrapping anIOExceptionwill be thrown; if parsing the response body fails, anInternalServiceExceptionwrapping aWebApplicationExceptionwill be thrown.- See Also:
-
getResponse
public <T> T getResponse(jakarta.ws.rs.core.Response.StatusType expStatus, Class<T> expType) throws IlmException, InternalServiceException Gets the response (body) for this request. That is, the request is sent and the corresponding response is handled by interpreting the response code and parsing the response body.
UsegetResponse(StatusType, TypeReference)if you expect a generic type and need the inner type to be handled properly.- Parameters:
expStatus- The response status which is expected in case of the response of the designated type.expType- The expected type in case of the designated response status. Usenullfor no expected response body.- Returns:
- The value of the designated expected type retrieved from the response of this request.
- Throws:
IlmException- If the response contains an expected or unexpected response status and the body is an exception conforming to the API, the correspondingIlmExceptionwill be parsed from the response body and thrown.InternalServiceException- If there are problems creating the request or retrieving the response, anInternalServiceExceptionwrapping anIOExceptionwill be thrown; if parsing the response body fails, anInternalServiceExceptionwrapping aWebApplicationExceptionwill be thrown.- See Also:
-
getResponse
public <T> T getResponse(jakarta.ws.rs.core.Response.StatusType expStatus, com.fasterxml.jackson.core.type.TypeReference<T> expType) throws IlmException, InternalServiceException Gets the response (body) for this request. That is, the request is sent and the corresponding response is handled by interpreting the response code and parsing the response body.Unlike
getResponse(StatusType, Class)this handles generic types with inner types properly. For instancenew TypeReference<List<Integer>>() { }leads to<List<Integer>>while usingList.classwill let Jackson guess the inner type according to the received JSON.- Type Parameters:
T- The type of the expected response.- Parameters:
expStatus- The response status which is expected in case of the response of the designated type.expType- The expected type (may be a generic type) in case of the designated response status. Usenullfor no expected response body.- Returns:
- The value of the designated expected type retrieved from the response of this request.
- Throws:
IlmException- If the response contains an expected or unexpected response status and the body is an exception conforming to the API, the correspondingIlmExceptionwill be parsed from the response body and thrown.InternalServiceException- If there are problems creating the request or retrieving the response, anInternalServiceExceptionwrapping anIOExceptionwill be thrown; if parsing the response body fails, anInternalServiceExceptionwrapping aWebApplicationExceptionwill be thrown.
-
getResponse
protected <T> T getResponse(jakarta.ws.rs.core.Response.StatusType expStatus, boolean allowPlainText, Class<T> expType) throws IlmException, InternalServiceException Gets the response (body) for this request. That is, the request is sent and the corresponding response is handled by interpreting the response code and parsing the response body.- Parameters:
expStatus- The response status which is expected in case of the response of the designated type.allowPlainText- Whether a plain text response is allowed (instead of a JSON object). This is only useful when expectingStringas type.expType- The expected type in case of the designated response status. Usenullfor no expected response body.- Returns:
- The value of the designated expected type retrieved from the response of this request.
- Throws:
IlmException- If the response contains an expected or unexpected response status and the body is an exception conforming to the API, the correspondingIlmExceptionwill be parsed from the response body and thrown.InternalServiceException- If there are problems creating the request or retrieving the response, anInternalServiceExceptionwrapping anIOExceptionwill be thrown; if parsing the response body fails, anInternalServiceExceptionwrapping aWebApplicationExceptionwill be thrown.
-
getResponse
protected <T> T getResponse(jakarta.ws.rs.core.Response.StatusType expStatus, boolean allowPlainText, String expTypeName, Function<InputStream, Pair<T, throws IlmException, InternalServiceExceptionIOException>> readValue) Gets the response (body) for this request. That is, the request is sent and the corresponding response is handled by interpreting the response code and parsing the response body.- Type Parameters:
T- The type of the expected response.- Parameters:
expStatus- The response status which is expected in case of the response of the designated type.allowPlainText- Whether a plain text response is allowed (instead of a JSON object). This is only useful when expectingStringas type.expTypeName- The name of the expected type in case of the designated response status. Usenullfor no expected response body.readValue- A function to read the typed response from the body. This will only be used if the expected type is notnulland the received body is JSON. It may return anIOExceptionwhich will then be actually thrown.- Returns:
- The value of the designated expected type retrieved from the response of this request.
- Throws:
IlmException- If the response contains an expected or unexpected response status and the body is an exception conforming to the API, the correspondingIlmExceptionwill be parsed from the response body and thrown.InternalServiceException- If there are problems creating the request or retrieving the response, anInternalServiceExceptionwrapping anIOExceptionwill be thrown; if parsing the response body fails, anInternalServiceExceptionwrapping aWebApplicationExceptionwill be thrown.
-
getResponseMediaType
Gets the media type for the response of the designated connection including the corresponding encoding. This will try to retrieve the encoding from the content type and afterwards from the content encoding. If none is found,UTF-8will be returned.- Parameters:
conn- The connection for which to get the encoding for the response.- Returns:
- The media type and the character set used for the response of the designated connection.
-
readString
Reads a string from the designated input stream using the designated character set. Each read line will be terminated by a line feed (\n).- Parameters:
is- The input stream from which to read the string.charset- The character set used to read from the stream.- Returns:
- The string read from the designated input stream.
- Throws:
IOException- If there are problems reading from the stream, anIOExceptionwill be thrown.
-
readExceptionalBody
protected IlmException readExceptionalBody(URL url, int respCode, boolean excpCode, String respMsg, InputStream respBody, Charset charset, String expType) Tries to read an exception body from the response of the designated URL having the designated (exceptional) response code and message. This either returns the readIlmExceptionor it throws anInternalServiceExceptionwrapping aWebApplicationException.- Parameters:
url- The URL from which the response has been returned.respCode- The response code.excpCode- Whether the response code is an exceptional response code.respMsg- The response message.respBody- The response body as marked input stream.charset- The character set to use forexpType- The string representation of the expected type which could not be read from the response body so far. This may benullif no expected response body.- Returns:
- The
IlmExceptionthat has been read from the designated response body. If this could not be read, anInternalServiceExceptionwrapping aWebApplicationExceptionwill be thrown.
-
toString
-