{#========================================== 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 %}
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.
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>{{spincastLatestStableVersion}}</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)
// 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()));
// other modules...
}
// ...
}
public void myHandler(IAppRequestContext context) {
String userId = context.request().getPathParam("userId");
//...
}
HttpMethod getHttpMethod()
HTTP method.
ContentTypeDefaults getContentTypeBestMatch()
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 isJsonRequest()
true if the request specifies
that Json should be returned.
Locale getLocaleBestMatch()
Locale to use for a response
using the "Accept-Language" header of
the request.
Locale (taken from the configurations)
if nothing more specific is found.
Map<String, List<String>> getHeaders()
TreeMap which iscase insensitive for the keys.
List<String> getHeader(String name)
name is case insensitive.
String getHeaderFirst(String name)
name is case insensitive.
null if the header is not found.
String getFullUrl()
String getOriginalFullUrl()
getFullUrl() is
going to return the new, forwarded, url.
String getRequestPath()
Map<String, String> getPathParams()
String getPathParam(String name)
name is case sensitive, since you have easy control over it.
String getQueryString()
Map<String, List<String>> getQueryStringParams()
List<String> getQueryStringParam(String name)
String getQueryStringParamFirst(String name)
null if the parameter doesn't exist.
InputStream getBodyAsInputStream()
byte[] getBodyAsByteArray()
String getBodyAsString()
UTF-8 encoding.
String getBodyAsString(String encoding)
IJsonObject getJsonBodyAsJsonObject()
IJsonObject. A valid Json body
is expected.
Map<String, Object> getJsonBodyAsMap()
Map<String, Object>. A valid Json body
is expected.
<T> T getJsonBody(Class<T> clazz)
class. A valid Json body
is expected.
IJsonObject getXmlBodyAsJsonObject()
IJsonObject. A valid XML body
is expected.
Map<String, Object> getXmlBodyAsMap()
Map<String, Object>. A valid XML body
is expected.
<T> T getXmlBody(Class<T> clazz)
class. A valid XML body
is expected.
Map<String, List<String>> getFormDatas()
FORM via a POST method.
key is possible.
List<String> getFormData(String name)
FORM via a POST method.
name is possible.
name is case sensitive.
String getFormDataFirst(String name)
FORM via a POST method.
name is case sensitive.
null if the parameter doesn't exist.
Map<String, List<File>> getUploadedFiles()
List<File> getUploadedFiles(String name)
name is possible.
File getUploadedFileFirst(String name)
null if no uploaded file of this name exists.