/** * 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) { String sessionId = extractSessionID(synCtx, SET_COOKIE); if (sessionId != null) { if (log.isDebugEnabled()) { log.debug("Found the HTTP header 'Set-Cookie: " + sessionId + "' for updating the session"); log.debug("Using the session id '" + sessionId + "' extracted from the Set-Cookie header "); } SALSessions.getInstance().updateSession(synCtx, sessionId); } }
/** * 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); } }
/** * As this is a server initiated session, this method will only be called for response messages. * It extracts the service group context ID (if available) from the message and updates the * session (service group context ID) -> endpoint map. * * @param synCtx MessageContext of the response message. */ public void updateSession(MessageContext synCtx) { // get the service group context id // check if service group context id is a key of any entry // if not, add an entry <service group context id, endpoint> SOAPHeader header = synCtx.getEnvelope().getHeader(); if (header != null) { OMElement replyTo = header.getFirstChildWithName( AddressingConstants.Final.QNAME_WSA_REPLY_TO); if (replyTo != null) { OMElement referenceParameters = replyTo.getFirstChildWithName(new QName( "http://www.w3.org/2005/08/addressing", "ReferenceParameters", "wsa")); if (referenceParameters != null) { SALSessions.getInstance().updateSession(synCtx, extractSessionID(referenceParameters, QNAME_SERVICE_GROUP_ID)); } else if (log.isDebugEnabled()) { log.debug("Couldn't find the WSA ReferenceParameters in the Reply-To " + "header to retrieve the ServiceQroupId"); } } else if (log.isDebugEnabled()) { log.debug("Couldn't find the WSA Reply-To header to retrieve the ServiceQroupId"); } } }
/** * As this is a server initiated session, this method will only be called for response messages. * It extracts the service group context ID (if available) from the message and updates the * session (service group context ID) -> endpoint map. * * @param synCtx MessageContext of the response message. */ public void updateSession(MessageContext synCtx) { // get the service group context id // check if service group context id is a key of any entry // if not, add an entry <service group context id, endpoint> SOAPHeader header = synCtx.getEnvelope().getHeader(); if (header != null) { OMElement replyTo = header.getFirstChildWithName( AddressingConstants.Final.QNAME_WSA_REPLY_TO); if (replyTo != null) { OMElement referenceParameters = replyTo.getFirstChildWithName(new QName( "http://www.w3.org/2005/08/addressing", "ReferenceParameters", "wsa")); if (referenceParameters != null) { SALSessions.getInstance().updateSession(synCtx, extractSessionID(referenceParameters, QNAME_SERVICE_GROUP_ID)); } else if (log.isDebugEnabled()) { log.debug("Couldn't find the WSA ReferenceParameters in the Reply-To " + "header to retrieve the ServiceQroupId"); } } else if (log.isDebugEnabled()) { log.debug("Couldn't find the WSA Reply-To header to retrieve the ServiceQroupId"); } } }
public void updateSession(MessageContext synCtx) { SALSessions.getInstance().updateSession(synCtx, extractSessionID(synCtx.getEnvelope().getHeader(), CSID_QNAME)); }
public void updateSession(MessageContext synCtx) { SALSessions.getInstance().updateSession(synCtx, extractSessionID(synCtx.getEnvelope().getHeader(), CSID_QNAME)); }
sessionCookie.setSessionId("testCookie2"); sessionCookie.setPath("samplePath"); salSessions.updateSession(messageContext, sessionCookie);
/** * Test updating session with session id * * @throws Exception */ @Test public void testUpdateWithId() 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); salSessions.updateSession(messageContext, "testSession"); SessionInformation sessionInformation = salSessions.getSession("testSession"); Assert.assertEquals("Session not updated!", "testSession", sessionInformation.getId()); }
/** * Test updating session with session id and old session * * @throws Exception */ @Test public void testUpdateWithOldSession() 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); SALSessions salSessions = SALSessions.getInstance(); salSessions.initialize(false, cfgCtx); SessionInformation oldSessionInfo = new SessionInformation("oldTestSession", endpoints, 30000); messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo); salSessions.updateSession(messageContext, "testSession2"); SessionInformation sessionInformation = salSessions.getSession("testSession2"); Assert.assertEquals("Session not updated!", "testSession2", sessionInformation.getId()); }
/** * Test updating session with session id and old session where the old session id is same as current session id * * @throws Exception */ @Test public void testUpdateWithOldSessionSameName() 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); SessionInformation oldSessionInfo = new SessionInformation("testSession3", endpoints, 30000); messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo); salSessions.updateSession(messageContext, "testSession3"); SessionInformation sessionInformation = salSessions.getSession("testSession3"); Assert.assertEquals("Session not updated!", "testSession3", sessionInformation.getId()); }
sessionCookie.setSessionId("testCookie3"); sessionCookie.setPath("samplePath"); salSessions.updateSession(messageContext, sessionCookie);
/** * 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()); }