SessionCookie c = new SessionCookie(); c.setSessionId(sessionId); c.setPath(path); return c;
protected String extractSessionID(MessageContext synCtx, String key) { SessionCookie sessionCookie = extractSessionCookie(synCtx, key); if (sessionCookie != null) { return sessionCookie.getSessionId(); } return null; }
/** * Searches for "Set-Cookie" HTTP header in the message context. If found and that given * session ID is not already in the session map update the session map by mapping the cookie * to the endpoint. * * @param synCtx MessageContext possibly containing the "Set-Cookie" HTTP header. */ public void updateSession(MessageContext synCtx) { SessionCookie cookie = extractSessionCookie(synCtx, SET_COOKIE); if (cookie != null) { if (log.isDebugEnabled()) { log.debug("Found the HTTP header [Set-Cookie]: " + cookie.toString() + "' for updating the session"); } SALSessions.getInstance().updateSession(synCtx, cookie); } }
/** * Test updating session with cookie * * @throws Exception */ @Test public void testUpdateWithCookie() throws Exception { BasicConfigurator.configure(); SynapseConfiguration synapseConfiguration = new SynapseConfiguration(); AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration(); ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration); SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration); Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment); MessageContext messageContext = axis2MessageContext; Endpoint endpoint = new AddressEndpoint(); List<Endpoint> endpoints = new ArrayList<>(); endpoints.add(endpoint); messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints); SALSessions salSessions = SALSessions.getInstance(); salSessions.initialize(false, cfgCtx); SessionCookie sessionCookie = new SessionCookie(); sessionCookie.setSessionId("testCookie"); salSessions.updateSession(messageContext, sessionCookie); SessionInformation sessionInformation = salSessions.getSession("testCookie"); Assert.assertEquals("Session not updated!", "testCookie", sessionInformation.getId()); }
if (cookie == null || "".equals(cookie.getSessionId())) { if (log.isDebugEnabled()) { log.debug("Cannot find Session ID from the cookie."); String sessionId = cookie.getSessionId(); String path = cookie.getPath();
oldSessionInfo.setPath(path); messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo); SessionCookie sessionCookie = new SessionCookie(); sessionCookie.setSessionId("testCookie2"); sessionCookie.setPath("samplePath"); salSessions.updateSession(messageContext, sessionCookie);
oldSessionInfo.setPath(path); messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo); SessionCookie sessionCookie = new SessionCookie(); sessionCookie.setSessionId("testCookie3"); sessionCookie.setPath("samplePath"); salSessions.updateSession(messageContext, sessionCookie);