Can OWIN middleware use the http session?

Yes, but it’s quite a hack. It also won’t work with SignalR because SignalR MUST run before session is acquired to prevent long session locks. Do this to enable session for any request: public static class AspNetSessionExtensions { public static IAppBuilder RequireAspNetSession(this IAppBuilder app) { app.Use((context, next) => { // Depending on the handler the … Read more

How to inject dependencies into HttpSessionListener, using Spring?

Since the Servlet 3.0 ServletContext has an “addListener” method, instead of adding your listener in your web.xml file you could add through code like so: @Component public class MyHttpSessionListener implements javax.servlet.http.HttpSessionListener, ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if (applicationContext instanceof WebApplicationContext) { ((WebApplicationContext) applicationContext).getServletContext().addListener(this); } else { //Either throw an exception … Read more

How can I load Java HttpSession from JSESSIONID?

You’ll basically need to manually collect them all in a Map using a HttpSessionListener yourself. @WebListener public class HttpSessionCollector implements HttpSessionListener { private static final Map<String, HttpSession> SESSIONS = new ConcurrentHashMap<>(); @Override public void sessionCreated(HttpSessionEvent event) { HttpSession session = event.getSession(); SESSIONS.put(session.getId(), session); } @Override public void sessionDestroyed(HttpSessionEvent event) { SESSIONS.remove(event.getSession().getId()); } public static HttpSession … Read more

How do you store Java objects in HttpSession?

You are not adding the object to the session, instead you are adding it to the request. What you need is: HttpSession session = request.getSession(); session.setAttribute(“MySessionVariable”, param); In Servlets you have 4 scopes where you can store data. Application Session Request Page Make sure you understand these. For more look here

Spring 3 MVC accessing HttpRequest from controller

Spring MVC will give you the HttpRequest if you just add it to your controller method signature: For instance: /** * Generate a PDF report… */ @RequestMapping(value = “/report/{objectId}”, method = RequestMethod.GET) public @ResponseBody void generateReport( @PathVariable(“objectId”) Long objectId, HttpServletRequest request, HttpServletResponse response) { // … // Here you can use the request and response … Read more

How to invalidate session in JSF 2.0?

Firstly, is this method correct? Is there a way without touching the ServletAPI? You can use ExternalContext#invalidateSession() to invalidate the session without the need to grab the Servlet API. @ManagedBean @SessionScoped public class UserManager { private User current; public String logout() { FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); return “/home.xhtml?faces-redirect=true”; } // … } what will happen to my current … Read more