All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.plugins.spincast-request.spincast-request.html Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
{#==========================================
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 isJsonRequest()
    Will return true if the request specifies that Json should be returned.
  • 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.
    @return the Content-Type of the request or null if none was specified.
  • String getFullUrl()
    Returns the full URL, including the queryString.
  • String getOriginalFullUrl()
    If the request has been forwarded, getFullUrl() is going to return the new, forwarded, url.
    This method will always return the original url.
  • String getRequestPath()
    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()
    The queryString of the request, without the "?".
    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.

{% endblock %}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy