templates.plugins.spincast-request.spincast-request.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
{#==========================================
Spincast Request plugin
==========================================#}
{% extends "../../layout.html" %}
{% block sectionClasses %}plugins plugins-spincast-request{% endblock %}
{% block meta_title %}Plugins - Spincast Request{% endblock %}
{% block meta_description %}Spincast Request plugin to access information about the current HTTP request.{% endblock %}
{% block scripts %}
{% endblock %}
{% block body %}
Overview
The Spincast Request plugin provides a request context add-on:
"IRequestRequestContextAddon". This add-on allows your route handlers to get information
about the current request. It is mounted as .request()
on the default Spincast request context.
Installation
If you use the spincast-default artifact, this plugin is already installed so
you have nothing more to do!
If you start from scratch using the spincast-core artifact, you can use the
plugin by adding this artifact to your project:
<dependency>
<groupId>org.spincast</groupId>
<artifactId>spincast-plugins-request</artifactId>
<version>{{spincastCurrrentVersion}}</version>
</dependency>
You then install the plugin's Guice module, by passing it to the Guice.createInjector(...) method:
Injector guice = Guice.createInjector(
new SpincastCoreGuiceModule(args),
new SpincastRequestPluginGuiceModule(IAppRequestContext.class, IAppWebsocketContext.class)
// other modules...
);
... or by using the install(...) method from your custom Guice module:
public class AppModule extends SpincastCoreGuiceModule {
@Override
protected void configure() {
super.configure();
install(new SpincastRequestPluginGuiceModule(getRequestContextType(),
getWebsocketContextType()));
// other modules...
}
// ...
}
The request context add-on
Quick example :
public void myHandler(IAppRequestContext context) {
String userId = context.request().getPathParam("userId");
//...
}
Add-on methods :
-
HttpMethod getHttpMethod()
Gets the request's HTTP method.
-
ContentTypeDefaults getContentTypeBestMatch()
Finds the best Content-Type to use for a response
using the "Accept" header of the request. It will
fallback to ContentTypeDefaults.TEXT if nothing more specific
is found.
-
boolean isJsonShouldBeReturn()
Will return true if the request specifies
that Json is the most appropriate format
to return.
-
boolean isHTMLShouldBeReturn()
Will return true if the request specifies
that HTML is the most appropriate format
to return.
-
boolean isXMLShouldBeReturn()
Will return true if the request specifies
that XML is the most appropriate format
to return.
-
boolean isPlainTextShouldBeReturn()
Will return true if the request specifies
that plain-text is the most appropriate format
to return.
-
Locale getLocaleBestMatch()
Find the best Locale to use for a response
using the "Accept-Language" header of
the request.
Returns the default Locale (taken from the configurations)
if nothing more specific is found.
-
Map<String, List<String>> getHeaders()
Returns all headers of the current request. A single header can have multiple values.
The implementation is a TreeMap which iscase insensitive for the keys.
The map is immutable.
-
List<String> getHeader(String name)
Returns the values of the specified header from the current request or
an empty list if not found.
The name is case insensitive.
The list is immutable.
-
String getHeaderFirst(String name)
The first value of the specified header from the current request.
The name is case insensitive.
Returns null if the header is not found.
-
String getContentType()
The Content-Type of the request, if any.
-
String getFullUrl()
Returns the current full URL, including the queryString, if any.
Cache buster codes are removed, if there were any.
In case the request has been forwarded, this will be the *new*,
the current URL. Use getFullUrlOriginal()
to get the original URL, before the request was forwarded.
If a reverse proxy has been used, this URL will contain the
scheme, host and port from the
original URL, as seen by the user.
In general, this is what you want to use in your application.
-
String getFullUrl(boolean keepCacheBusters)
Returns the current full URL, including the queryString, if any.
In case the request has been forwarded, this will be the *new*,
the current URL. Use getFullUrlOriginal()
to get the original URL, before the request was forwarded.
If a reverse proxy has been used, this URL will contain the
scheme, host and port from the
original URL, as seen by the user.
In general, this is what you want to use in your application.
-
String getFullUrlOriginal()
If the request has been forwarded, this is going to return the original
URL, not the current, forwarded, one.
Cache buster codes are removed, if there were any.
Use getFullUrl() to get the current, potentially
forwarded URL.
If a reverse proxy has been used, this URL will contain the
scheme, host and port from the
original URL, as seen by the user.
In general, this is what you want to use in your application.
-
String getFullUrlOriginal(boolean keepCacheBusters)
If the request has been forwarded, this is going to return the original
URL, not the current, forwarded, one.
Use getFullUrl() to get the current, potentially
forwarded URL.
If a reverse proxy has been used, this URL will contain the
scheme, host and port from the
original URL, as seen by the user.
In general, this is what you want to use in your application.
-
String getFullUrlProxied()
If a reverse proxy has been used, this URL will contain the
scheme, host and port
as forwarded by the reserve proxy, not as seen by the user.
Cache buster codes are removed, if there were any.
If the request has been forwarded, this is going to return the original
URL, not the current, forwarded, one.
In general, you should probably use getFullUrl()
or getFullUrlOriginal() instead of this
one.
-
String getFullUrlProxied(boolean keepCacheBusters)
If a reverse proxy has been used, this URL will contain the
scheme, host and port
as forwarded by the reserve proxy, not as seen by the user.
Cache buster codes are removed, if there were any.
If the request has been forwarded, this is going to return the original
URL, not the current, forwarded, one.
In general, you should probably use getFullUrl()
or getFullUrlOriginal() instead of this
one.
-
String getRequestPath()
The path of the request (no querystring).
-
String getRequestPath(boolean keepCacheBusters)
The path of the request (no querystring).
-
Map<String, String> getPathParams()
The values parsed from the dynamic parameters of the route path.
The map is immutable.
-
String getPathParam(String name)
A specific value parsed from a dynamic parameter of the route path.
The name is case sensitive, since you have easy control over it.
-
String getQueryString(boolean withQuestionMark)
The queryString of the request.
Returns an empty String if there is no queryString.
-
Map<String, List<String>> getQueryStringParams()
The parameters taken from the queryString of the request.
A queryString parameter may have multiple values.
Returns an empty list if there is no queryString.
The map is immutable.
-
List<String> getQueryStringParam(String name)
A specific parameter taken from the queryString of the request.
A queryString parameter may have multiple values.
Returns an empty list if the parameter doesn't exist.
The list is immutable.
-
String getQueryStringParamFirst(String name)
The first (and often only) value of a specific parameter taken from the
queryString of the request.
Returns null if the parameter doesn't exist.
-
InputStream getBodyAsInputStream()
The raw InputStream of the request's body.
Note that what's read from the InputStream cannot be read again!
-
byte[] getBodyAsByteArray()
The bytes of the request's body.
Note that the bytes read cannot be read again!
-
String getBodyAsString()
The request's body as a String, using the UTF-8 encoding.
Note that the characters read cannot be read again!
-
String getBodyAsString(String encoding)
The request's body as a String, using the specified encoding.
Note that the characters read cannot be read again!
-
IJsonObject getJsonBodyAsJsonObject()
The request's body deserialized to a IJsonObject. A valid Json body
is expected.
Note that this can only be called once.
-
Map<String, Object> getJsonBodyAsMap()
The request's body deserialized to a Map<String, Object>. A valid Json body
is expected.
Note that this can only be called once.
-
<T> T getJsonBody(Class<T> clazz)
The request's body deserialized to the specified class. A valid Json body
is expected.
Note that this can only be called once.
-
IJsonObject getXmlBodyAsJsonObject()
The request's body deserialized to a IJsonObject. A valid XML body
is expected.
Note that this can only be called once.
-
Map<String, Object> getXmlBodyAsMap()
The request's body deserialized to a Map<String, Object>. A valid XML body
is expected.
Note that this can only be called once.
-
<T> T getXmlBody(Class<T> clazz)
The request's body deserialized to the specified class. A valid XML body
is expected.
Note that this can only be called once.
-
Map<String, List<String>> getFormDatas()
The parameters submitted from a FORM via a POST method.
More than one value with the same key is possible.
The names are case sensitive.
The map is immutable.
-
List<String> getFormData(String name)
A specific parameter submitted from a FORM via a POST method.
More than one value with the same name is possible.
The name is case sensitive.
The list is immutable.
-
String getFormDataFirst(String name)
The first (and often only) value of a specific parameter submitted from a FORM via a POST method.
The name is case sensitive.
Returns null if the parameter doesn't exist.
-
Map<String, List<File>> getUploadedFiles()
The uploaded files, with their names as the keys.
More than one uploaded file with the same name is possible.
The map is immutable.
Returns an empty map if there are no uploadded file.
-
List<File> getUploadedFiles(String name)
The uploaded files of the specified name.
More than one uploaded file with the same name is possible.
The list is immutable.
Returns an empty list if no uploaded files of this name exists.
-
File getUploadedFileFirst(String name)
The first (and often only) uploaded file of the specified name.
Returns null if no uploaded file of this name exists.
-
boolean isHttps()
Is the request a secure HTTPS one?
-
List<IETag> getEtagsFromIfNoneMatchHeader()
Returns the ETags from
the If-None-Match header, if any.
-
List<IETag> getEtagsFromIfMatchHeader()
Returns the ETags from
the If-Match header, if any.
-
Date getDateFromIfModifiedSinceHeader()
Return the value of the If-Modified-Since
header as a Date or null if it doesn't
exist.
-
Date getDateFromIfUnmodifiedSinceHeader()
Return the value of the If-Unmodified-Since
header as a Date or null if it doesn't
exist.
{% endblock %} 

Spincast Request