public final class HttpMethods extends Object
Constructor and Description |
---|
HttpMethods(io.toro.martini.service.UrlRewriter urlRewriter,
io.toro.martini.gloop.http.GloopHttpRequestFactory requestFactory,
io.toro.martini.gloop.http.GloopResponseHandlerFactory responseHandlerFactory,
io.toro.martini.gloop.http.GloopHttpContextFactory httpClientContextFactory,
Supplier<org.apache.http.impl.client.HttpClientBuilder> httpClientBuilder,
Predicate<HttpServletRequest> requestAuthenticator) |
Modifier and Type | Method and Description |
---|---|
static boolean |
authenticated(HttpServletRequest request)
Checks if the current
HttpServletRequest is authenticated. |
static boolean |
authenticated(HttpServletRequest request,
boolean throwException)
Checks if the current
HttpServletRequest is authenticated. |
static io.toro.gloop.object.property.GloopModel |
http(io.toro.gloop.object.property.GloopModel requestModel,
io.toro.gloop.object.property.GloopModel authModel,
String returnAs,
String responseType,
boolean throwHttpExceptions,
io.toro.gloop.object.property.GloopModel trackableModel,
io.toro.gloop.engine.GloopExecutionContext context)
Send an HTTP request to a web service, and then parse the response into a model.
|
static boolean |
prepareResponse(HttpServletResponse response,
io.toro.gloop.object.property.GloopModel content,
String format,
int responseCode)
Set the appropriate
responseCode and write the given GloopModel content
to the HttpServletResponse in the specified format . |
static io.toro.gloop.object.property.GloopModel |
soap(String url,
io.toro.gloop.object.property.GloopModel authModel,
String soapAction,
String style,
String soapProtocol,
io.toro.gloop.object.property.GloopModel messageHeader,
io.toro.gloop.object.property.GloopModel messageBody,
io.toro.gloop.object.property.GloopModel trackable,
io.toro.gloop.engine.GloopExecutionContext context)
Send a request to a SOAP web service, and then parse the response into a model.
|
public HttpMethods(io.toro.martini.service.UrlRewriter urlRewriter, io.toro.martini.gloop.http.GloopHttpRequestFactory requestFactory, io.toro.martini.gloop.http.GloopResponseHandlerFactory responseHandlerFactory, io.toro.martini.gloop.http.GloopHttpContextFactory httpClientContextFactory, Supplier<org.apache.http.impl.client.HttpClientBuilder> httpClientBuilder, Predicate<HttpServletRequest> requestAuthenticator)
@GloopObjectParameter(value="output{\nresponse#io.toro.martini.http.Response{\n}\n}") public static io.toro.gloop.object.property.GloopModel http(@GloopObjectParameter(value="request#io.toro.martini.http.Request{\n}") io.toro.gloop.object.property.GloopModel requestModel, @GloopObjectParameter(value="auth#io.toro.martini.http.Auth{\n}") io.toro.gloop.object.property.GloopModel authModel, @GloopParameter(choices={"InputStream","String","byte[]","GloopObject"},defaultValue="String") String returnAs, @GloopParameter(choices={"Xml","Json","Auto Detect"},defaultValue="Auto Detect") String responseType, @GloopParameter(defaultValue="false") boolean throwHttpExceptions, @GloopObjectParameter(value="trackable#io.toro.martini.tracker.Trackable{\n}") io.toro.gloop.object.property.GloopModel trackableModel, io.toro.gloop.engine.GloopExecutionContext context) throws IOException
Send an HTTP request to a web service, and then parse the response into a model.
This one-liner sends an HTTP request with the same
HTTP method, URI, content type, headers, cookies, parameters, and body as the provided requestModel
.
At a minimum, the requestModel
's uri
field must be provided.
For requests that require authorization, the authModel
must be provided.
When provided, the request will be sent with the same authorization details specified by the authModel
.
Else, the one-liner assumes authorization is not needed to access the web service.
The server's response is returned as a model.
responseType
is used to indicate the expected response content format.
Through the returnAs
argument, one can specify the data type of the response content
– which can be accessed by the response model's content
property.
If the response received has an HTTP status code of 5xx,
then an error will be thrown by this one-liner if throwHttpExceptions
is set to true.
Else, the one-liner will return the response as usual.
To log your request call to Tracker, populate the trackableModel
.
The trackableModel
must at least have its
internalId
and trackingScope
properties set.
requestModel
- describes the HTTP request to sendauthModel
- authentication model to be used for the requestreturnAs
- determines the desired data type for the response contentresponseType
- determines the content type of the server's responsethrowHttpExceptions
- determines whether or not exceptions should be thrown
when the server receives a response code >= 500.trackableModel
- tracking metadata to be used by Martini's Tracker enginecontext
- the Gloop execution context (automatically mapped by Gloop)IOException
- in case of a problem or if the connection was aborted@GloopObjectParameter(value="output{\nresponse#io.toro.martini.http.Response{\n}\n}") public static io.toro.gloop.object.property.GloopModel soap(String url, @GloopObjectParameter(value="auth#io.toro.martini.http.Auth{\n}") io.toro.gloop.object.property.GloopModel authModel, String soapAction, @GloopParameter(defaultValue="false") String style, @GloopParameter(defaultValue="false") String soapProtocol, io.toro.gloop.object.property.GloopModel messageHeader, io.toro.gloop.object.property.GloopModel messageBody, @GloopObjectParameter(value="trackable#io.toro.martini.tracker.Trackable{\n}") io.toro.gloop.object.property.GloopModel trackable, io.toro.gloop.engine.GloopExecutionContext context) throws Exception
Send a request to a SOAP web service, and then parse the response into a model.
To log your request call to Tracker, populate trackable
model.
The trackable
model must at least have its
internalId
and trackingScope
properties set.
Example:
url = 'http://localhost:8080/soap/apis.soapApi.HelloYouSOAP?wsdl=' soapAction = 'apis.service.HelloYouService' messageBody = messageBody { HelloYouServiceInput { name 'world' } } HttpMethods.soap(url, null, soapAction, false, false, null, messageBody, null)
url
- the URL of the recipient SOAP endpointauthModel
- authentication model to be used for the requestsoapAction
- the SOAP action to usestyle
- determines whether or not to use an RPC style model; set to true
to use RPC stylesoapProtocol
- determines whether or not the service is implemented in SOAP v1.2;
set to true
to use SOAP v1.2messageHeader
- the message header to be sent along with the requestmessageBody
- the message body to be sent along with the requesttrackable
- tracking metadata to be used by Martini's Tracker enginecontext
- the Gloop execution context (automatically mapped by Gloop)IOException
- in case of a problem or if the connection was abortedException
@GloopParameter(name="requestHandled") public static boolean prepareResponse(HttpServletResponse response, io.toro.gloop.object.property.GloopModel content, @GloopParameter(choices={"json","xml","yaml"},defaultValue="json",allowNull=false) String format, int responseCode)
responseCode
and write the given GloopModel
content
to the HttpServletResponse
in the specified format
.response
- the response object of the requestcontent
- a model representing the content to be written to the response bodyformat
- the format (json, xml, or yaml) in which the content will be writtenresponseCode
- the code indicating the status of the requestpublic static boolean authenticated(@GloopParameter(allowNull=false) HttpServletRequest request)
HttpServletRequest
is authenticated.request
- the http requestpublic static boolean authenticated(@GloopParameter(allowNull=false) HttpServletRequest request, @GloopParameter(defaultValue="false") boolean throwException)
HttpServletRequest
is authenticated. If the parameter throwException
is set to true
, this will throw a RequestUnauthorizedException
if the current
HttpServletRequest
is not authenticated.request
- the http requestthrowException
- the flag that tells whether to throw an exception if the request failed to authenticateCopyright © 2020. All rights reserved.