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

com.expanset.jersey.session.SessionFeature Maven / Gradle / Ivy

The newest version!
package com.expanset.jersey.session;

import javax.inject.Singleton;
import javax.servlet.http.HttpSession;
import javax.ws.rs.ConstrainedTo;
import javax.ws.rs.RuntimeType;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;

import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.process.internal.RequestScoped;

/**
 * Ability to use session scoped data injection through {@link SessionInject} annotation.
 * Session key determined form {@literal @}Named annotation or class name used. 
 * 

Support of {@link javax.servlet.http.HttpSession} injection.

*

Session must be enabled in servlet container.

*/ @ConstrainedTo(RuntimeType.SERVER) public class SessionFeature implements Feature { @Override public boolean configure(FeatureContext context) { context.register(new AbstractBinder() { @Override protected void configure() { bind(SessionInjectResolver.class) .to(new TypeLiteral>(){}) .in(Singleton.class); bindFactory(HttpSessionFactory.class) .to(HttpSession.class) .in(RequestScoped.class) .proxyForSameScope(false); } }); return true; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy