{#========================================== Spincast Cookies plugin ==========================================#} {% extends "../../layout.html" %} {% block sectionClasses %}plugins 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 %}
The Spincast Cookies plugin provides functionalities
to read and write cookies. It mainly consists of a request context add-on :
"ICookiesRequestContextAddon", which is
mounted as .cookies() on the default Spincast request context.
The plugin also provides an implementation for the "ICookie" object.
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-cookies</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 SpincastCookiesPluginGuiceModule(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 SpincastCookiesPluginGuiceModule(getRequestContextType()));
// other modules...
}
// ...
}
public void myHandler(IAppRequestContext context) {
ICookie myCookie = context.cookies().getCookie("myCookie");
if(myCookie != null) {
System.out.println(myCookie.getName() + " : " + myCookie.getValue());
}
//...
}
Map<String, ICookie> getCookies()
ICookie getCookie(String name)
void addCookie(ICookie cookie)
void addCookie(String name, String value)
void addCookie(String name, String value, String path, String domain, Date expires, boolean secure, boolean httpOnly, boolean discard, int version)
void deleteCookie(String name)
expires date in the
past so the user's browser will remove it.
isExpired() will return true after you called
this method.
void deleteAllCookies()
expires date in the
past so the user's browser will remove them.
void resetCookies()