{% extends "../../layout.html" %} {% block sectionClasses %}plugins hasBreadCrumb plugins-spincast-cookies {% endblock %} {% block meta_title %}Plugins - Spincast Cookies{% endblock %} {% block meta_description %}Spincast Cookies plugin provides functionalities to read and write cookies.{% endblock %} {% block scripts %} {% endblock %} {% block body %}

Overview

This plugin provides functionalities to read and write HTTP cookies. It also provides an implementation for the Cookie interface : CookieDefault.

Quick Examples

  • Using the .cookies() add-on from a Route Handler to get a cookie :

    public void myHandler(AppRequestContext context) {
        Cookie myCookie = context.cookies().getCookie("myCookie");
        //...
    }

  • Creating a cookie using the .cookies() add-on :

    public void myHandler(AppRequestContext context) {
        context.cookies().addCookie("myCookie", "someValue");
        //...
    }

  • Using the injected CookieFactory instance to create a cookie :

    public class SomeService {
    
        private final CookieFactory cookieFactory;
    
        @Inject
        public AppService(CookieFactory cookieFactory) {
            this.cookieFactory = cookieFactory;
        }
    
        protected CookieFactory getCookieFactory() {
            return this.cookieFactory;
        }
    
        public Cookie someServiceMethod() {
            Cookie cookie = getCookieFactory().createCookie("myCookie", "some value");
            return cookie;
        }
    }

Installation

If you use the spincast-default artifact and the standard Bootstrapper, this plugin is already installed by default so you have nothing to do!

If you start from scratch, using the spincast-core artifact, you can use the plugin by :

1. Adding this Maven artifact to your project:

<dependency>
    <groupId>org.spincast</groupId>
    <artifactId>spincast-plugins-cookies</artifactId>
    <version>{{spincast.spincastCurrrentVersion}}</version>
</dependency>

2. Installing the provided SpincastCookiesPluginModule module to your Guice context.

Plugin class

The class implementing the SpincastPlugin interface is SpincastCookiesPlugin.

Suggested add-on

This add-on is already installed by default on the Request Context type.

Javadoc

{% endblock %}