Package org.apache.axis2.context

Examples of org.apache.axis2.context.SessionContext


        super();
        this.sessionmap = new HashMap();
    }
   
    public synchronized SessionContext getSessionContext(String sessionKey) {
        SessionContext sessionContext = null;
        if (sessionKey != null && sessionKey.length() != 0) {
            sessionContext = (SessionContext) this.sessionmap.get(sessionKey);
        }
        if (sessionContext == null) {
            sessionKey = UUIDGenerator.getUUID();
            sessionContext = new SessionContext(null);
            sessionContext.setCookieID(sessionKey);
            this.sessionmap.put(sessionKey, sessionContext);
        }
        sessionContext.touch();
        cleanupServiceGroupContexts();
        return sessionContext;
    }
View Full Code Here


    private void cleanupServiceGroupContexts() {
        long currentTime = System.currentTimeMillis();
        for (Iterator it = this.sessionmap.keySet().iterator(); it.hasNext(); ) {
            String cookieID = (String) it.next();
            SessionContext sessionContext = (SessionContext) this.sessionmap.get(cookieID);
            if ((currentTime - sessionContext.getLastTouchedTime()) >
                    sessionContext.sessionContextTimeoutInterval) {
                it.remove();
                Iterator serviceGroupContext = sessionContext.getServiceGroupContext();
                if (serviceGroupContext != null) {
                    while (serviceGroupContext.hasNext()) {
                        ServiceGroupContext groupContext = (ServiceGroupContext) serviceGroupContext.next();
                        cleanupServiceContexts(groupContext);
                    }
View Full Code Here

     * @return SessionContext
     */
    public SessionContext getSessionContext(MessageContext messageContext) {
        HttpServletRequest req = (HttpServletRequest) messageContext.getProperty(
                HTTPConstants.MC_HTTP_SERVLETREQUEST);
        SessionContext sessionContext =
                (SessionContext) req.getSession(true).getAttribute(
                        Constants.SESSION_CONTEXT_PROPERTY);
        String sessionId = req.getSession().getId();
        if (sessionContext == null) {
            sessionContext = new SessionContext(null);
            sessionContext.setCookieID(sessionId);
            req.getSession().setAttribute(Constants.SESSION_CONTEXT_PROPERTY,
                    sessionContext);
        }
        messageContext.setSessionContext(sessionContext);
        messageContext.setProperty(SESSION_ID, sessionId);
View Full Code Here

    private void fillContextsFromSessionContext(MessageContext msgContext) throws AxisFault {
        AxisService service = msgContext.getAxisService();
        if (service == null) {
            throw new AxisFault(Messages.getMessage("unabletofindservice"));
        }
        SessionContext sessionContext = msgContext.getSessionContext();
        if (sessionContext == null) {
            TransportListener listener = msgContext.getTransportIn().getReceiver();
            sessionContext = listener.getSessionContext(msgContext);
            if (sessionContext == null) {
                createAndFillContexts(service, msgContext, sessionContext);
                return;
            }
        }
        String serviceGroupName = msgContext.getAxisServiceGroup().getServiceGroupName();
        ServiceGroupContext serviceGroupContext =
                sessionContext.getServiceGroupContext(serviceGroupName);
        if (serviceGroupContext != null) {
            //setting service group context
            msgContext.setServiceGroupContext(serviceGroupContext);
            // setting Service context
            msgContext.setServiceContext(serviceGroupContext.getServiceContext(service));
        } else {
            createAndFillContexts(service, msgContext, sessionContext);
        }
        ServiceContext serviceContext = sessionContext.getServiceContext(service);
        //found the serviceContext from session context , so adding that into msgContext
        if (serviceContext != null) {
            msgContext.setServiceContext(serviceContext);
            serviceContext.setProperty(HTTPConstants.COOKIE_STRING, sessionContext.getCookieID());
        }
    }
View Full Code Here

            msgContext.getOperationContext().getServiceContext().getServiceConfig();

        Parameter scopeParam = service.getParameter(SCOPE);
        QName serviceName = service.getName();
        if (scopeParam != null &&  Constants.SESSION_SCOPE.equals(scopeParam.getValue())) {
            SessionContext sessionContext = msgContext.getSessionContext();
            synchronized(sessionContext){
                Object obj = sessionContext.getProperty(serviceName.getLocalPart());
                if (obj == null) {
                    obj = makeNewServiceObject(msgContext);
                    sessionContext.setProperty(serviceName.getLocalPart(), obj);
                }
                return obj;
            }
        } else if (scopeParam != null &&  Constants.APPLICATION_SCOPE.equals(scopeParam.getValue())) {
            SessionContext globalContext = msgContext.getSessionContext();
            synchronized(globalContext){
                Object obj = globalContext.getProperty(serviceName.getLocalPart());
                if (obj == null) {
                    obj = makeNewServiceObject(msgContext);
                    globalContext.setProperty(serviceName.getLocalPart(), obj);
                }
                return obj;
            }
        } else {
            return makeNewServiceObject(msgContext);
View Full Code Here

    public MiscTest(String testName) {
        super(testName);
    }

    public void testSessionContext() {
        SessionContext sc = new SessionContext(null);
        String key = "Hello";
        Object val = new Object();
        sc.setProperty(key, val);
        assertEquals(sc.getProperty(key), val);
    }
View Full Code Here

        OutputStream out =null;
        try {
            Object sessionContext =
                    httpServletRequest.getSession().getAttribute(Constants.SESSION_CONTEXT_PROPERTY);
            if (sessionContext == null) {
                sessionContext = new SessionContext(null);
                httpServletRequest.getSession().setAttribute(
                        Constants.SESSION_CONTEXT_PROPERTY,
                        sessionContext);
            }
View Full Code Here

        MessageContext msgContext = null;
        try {
            Object sessionContext =
                    req.getSession().getAttribute(Constants.SESSION_CONTEXT_PROPERTY);
            if (sessionContext == null) {
                sessionContext = new SessionContext(null);
                req.getSession().setAttribute(Constants.SESSION_CONTEXT_PROPERTY, sessionContext);
            }
            msgContext =
                    new MessageContext(
                            configContext,
View Full Code Here

    /**
     * Test get session context.
     */
    public void testGetSessionContext() {
        String sessionKey = null;
        SessionContext ctx1 = manager.getSessionContext(sessionKey);
        sessionKey = ctx1.getCookieID();
        assertNotNull(ctx1);
        assertNotNull(sessionKey);

        SessionContext ctx2 = manager.getSessionContext(sessionKey);
        assertNotNull(ctx2);
        assertEquals(ctx1, ctx2);
        assertEquals(sessionKey, ctx2.getCookieID());

        SessionContext ctx3 = manager.getSessionContext(null);
        assertNotNull(ctx3);
        assertNotSame(ctx1, ctx3);
        assertFalse(sessionKey.equals(ctx3.getCookieID()));
    }
View Full Code Here

    public MiscTest(String testName) {
        super(testName);
    }

    public void testSessionContext() {
        SessionContext sc = new SessionContext(null);
        String key = "Hello";
        Object val = new Object();
        sc.setProperty(key, val);
        assertEquals(sc.getProperty(key), val);
    }
View Full Code Here

TOP

Related Classes of org.apache.axis2.context.SessionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.