Package org.chiba.web.session

Examples of org.chiba.web.session.XFormsSession


            LOGGER.debug("requested session: " + key);
        }

        //todo: inherit from ChibaServlet for getXFormsSessionManager() method ? hm, weak reaon
        XFormsSessionManager sessionManager = DefaultXFormsSessionManagerImpl.getInstance();
        XFormsSession xFormsSession = sessionManager.getXFormsSession(key);

        if (session != null) {
            if(LOGGER.isDebugEnabled()){
                Enumeration keys = session.getAttributeNames();
                if(keys.hasMoreElements()){
                    LOGGER.debug("--- existing keys in session --- ");
                }
                while (keys.hasMoreElements()) {
                    String s = (String) keys.nextElement();
                    LOGGER.debug("existing sessionkey: " + s + ":" + session.getAttribute(s));
                }
            }

            // lookup attribute containing submission response map
            Map submissionResponse = (Map) xFormsSession.getProperty(ChibaServlet.CHIBA_SUBMISSION_RESPONSE);
            if (submissionResponse != null) {

                if(LOGGER.isDebugEnabled()){
                    LOGGER.debug("handling submission/@replace='all'");
                    Enumeration keys = session.getAttributeNames();
                    if(keys.hasMoreElements()){
                        LOGGER.debug("--- existing keys in session  --- ");
                        while (keys.hasMoreElements()) {
                            String s = (String) keys.nextElement();
                            LOGGER.debug("existing sessionkey: " + s + ":" + session.getAttribute(s));
                        }
                    }else{
                        LOGGER.debug("--- no keys left in session  --- ");
                    }
                }

                // copy header fields
                Map headerMap = (Map) submissionResponse.get("header");
                String name;
                String value;
                Iterator iterator = headerMap.keySet().iterator();
                while (iterator.hasNext()) {
                    name = (String) iterator.next();
                    if (name.equalsIgnoreCase("Transfer-Encoding")) {
                        // Some servers (e.g. WebSphere) may set a "Transfer-Encoding"
                        // with the value "chunked". This may confuse the client since
                        // ChibaServlet output is not encoded as "chunked", so this
                        // header is ignored.
                        continue;
                    }

                    value = (String) headerMap.get(name);
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("added header: " + name + "=" + value);
                    }

                    response.setHeader(name, value);
                }

                // copy body stream
                InputStream bodyStream = (InputStream) submissionResponse.get("body");
                OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
                for (int b = bodyStream.read(); b > -1; b = bodyStream.read()) {
                    outputStream.write(b);
                }

                // close streams
                bodyStream.close();
                outputStream.close();

                //kill XFormsSession
                sessionManager.deleteXFormsSession(xFormsSession.getKey());

                return;
            }
        }
View Full Code Here


        String key = request.getParameter("sessionKey");
        try {

            XFormsSessionManager manager = (XFormsSessionManager) session.getAttribute(XFormsSessionManager.XFORMS_SESSION_MANAGER);
            XFormsSession xFormsSession = manager.getXFormsSession(key);

            webAdapter = xFormsSession.getAdapter();
            if (webAdapter == null) {
                throw new ServletException(Config.getInstance().getErrorMessage("session-invalid"));
            }
            ChibaEvent chibaEvent = new DefaultChibaEventImpl();
            chibaEvent.initEvent("http-request", null, request);
View Full Code Here

            LOGGER.debug("handling session: " + key);
            LOGGER.debug("referer: " + referer);
        }
        try {
            XFormsSessionManager manager = (XFormsSessionManager) session.getAttribute(XFormsSessionManager.XFORMS_SESSION_MANAGER);
            XFormsSession xFormsSession = manager.getXFormsSession(key);
            if (xFormsSession == null) {
                LOGGER.info("session does not exist: " + key + " - creating new one");
                response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/XFormsServlet?" + referer));

            } else {
                webAdapter = xFormsSession.getAdapter();
                if (webAdapter == null) {
                    throw new ServletException(Config.getInstance().getErrorMessage("session-invalid"));
                }
                response.setContentType(HTML_CONTENT_TYPE);

                UIGenerator uiGenerator = (UIGenerator) xFormsSession.getProperty(XFormsSession.UIGENERATOR);
                uiGenerator.setInput(webAdapter.getXForms());
                uiGenerator.setOutput(response.getOutputStream());
                uiGenerator.generate();

                response.getOutputStream().close();
View Full Code Here

        WebAdapter adapter = null;
        HttpSession session = request.getSession(true);

        XFormsSessionManager sessionManager = getXFormsSessionManager();
        XFormsSession xFormsSession = sessionManager.createXFormsSession();

        /*
        the XFormsSessionManager is kept in the http-session though it is accessible as singleton. Subsequent
        servlets should access the manager through the http-session attribute as below to ensure the http-session
        is refreshed.
        */
        session.setAttribute(XFormsSessionManager.XFORMS_SESSION_MANAGER,sessionManager);

        if (LOGGER.isDebugEnabled()) {
            printSessionKeys(session);
            LOGGER.debug("created XFormsSession with key: " + xFormsSession.getKey());
        }

        request.setCharacterEncoding("UTF-8");
        response.setHeader("Cache-Control","private, no-store,  no-cache, must-revalidate");
        response.setHeader("Pragma","no-cache");
        response.setDateHeader("Expires",-1);

        try {
            // determine Form to load
            String formURI = getRequestURI(request) + request.getParameter(FORM_PARAM_NAME);
            if (formURI == null) {
                throw new IOException("Resource not found: " + formURI + " not found");
            }
           
            String xslFile = request.getParameter(XSL_PARAM_NAME);
            String javascriptPresent = request.getParameter(JAVASCRIPT_PARAM_NAME);

            String actionURL = null;
            if (javascriptPresent != null) {
                //do AJAX
                adapter = new FluxAdapter();
                actionURL = getActionURL(request, response, true);
            } else {
                //do standard browser support without scripting
                adapter = new ServletAdapter();
                actionURL = getActionURL(request, response, false);
            }
            adapter.setXFormsSession(xFormsSession);

            //setup Adapter
            adapter = setupAdapter(adapter, xFormsSession.getKey(), formURI);
            setContextParams(request, adapter);
            storeCookies(request, adapter);
            storeAcceptLanguage(request, adapter);
            adapter.init();
            XMLEvent exitEvent = adapter.checkForExitEvent();

            if (exitEvent != null) {
                handleExit(exitEvent, xFormsSession, session,  request, response);
            } else {
                //todo: review: the following may be substituted with the ViewServlet
                response.setContentType(HTML_CONTENT_TYPE);
                UIGenerator uiGenerator = createUIGenerator(request, xFormsSession, actionURL, xslFile == null ? xsltDefault : xslFile, javascriptPresent);
                uiGenerator.setInput(adapter.getXForms());
                uiGenerator.setOutput(response.getOutputStream());
                uiGenerator.generate();

                //store WebAdapter in XFormsSession
                xFormsSession.setAdapter(adapter);
                //store UIGenerator in XFormsSession as property
                xFormsSession.setProperty(XFormsSession.UIGENERATOR, uiGenerator);
                //store queryString as 'referer' in XFormsSession
                xFormsSession.setProperty(XFormsSession.REFERER,request.getQueryString());
                //actually add the XFormsSession ot the manager
                sessionManager.addXFormsSession(xFormsSession);
            }

            printSessionKeys(session);

        }
        catch (Exception e) {
            shutdown(adapter, session, e, response, request, xFormsSession.getKey());
        }
    }
View Full Code Here

        response.setHeader("Expires","-1");

        String key = request.getParameter("sessionKey");
        try {
            XFormsSessionManager manager = (XFormsSessionManager) session.getAttribute(XFormsSessionManager.XFORMS_SESSION_MANAGER);
            XFormsSession xFormsSession = manager.getXFormsSession(key);

            String referer = (String) xFormsSession.getProperty(XFormsSession.REFERER);
            if(LOGGER.isDebugEnabled()){
                LOGGER.debug("referer: " + referer);
            }

            webAdapter = xFormsSession.getAdapter();
            if (webAdapter == null) {
                throw new ServletException(Config.getInstance().getErrorMessage("session-invalid"));
            }
            ChibaEvent chibaEvent = new DefaultChibaEventImpl();
            chibaEvent.initEvent("http-request", null, request);
            webAdapter.dispatch(chibaEvent);

            XMLEvent exitEvent = webAdapter.checkForExitEvent();

            if (exitEvent != null) {
                handleExit(exitEvent, xFormsSession, session, request,response);
            } else {
                response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/view?sessionKey=" + xFormsSession.getKey() + "&referer=" + referer));
            }
        } catch (Exception e) {
            shutdown(webAdapter, session, e, response, request, key);
        }
    }
View Full Code Here

            //if session info is not found for some reason return 100 for safety which allows to exit
            //javascript polling of progress info
            progress = "100";
        }
        XFormsSessionManager manager = (XFormsSessionManager) session.getAttribute(XFormsSessionManager.XFORMS_SESSION_MANAGER);
        XFormsSession xFormsSession = manager.getXFormsSession(sessionKey);

        FluxAdapter adapter = (FluxAdapter) xFormsSession.getAdapter();
        EventLog eventLog = adapter.getEventLog();

        Element eventlogElement = eventLog.getLog();
        eventLog.flush();
View Full Code Here

    public void keepAlive(String sessionKey) throws FluxException {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("FluxFacade keepAlive: " + sessionKey);
        }
        XFormsSessionManager manager = (XFormsSessionManager) session.getAttribute(XFormsSessionManager.XFORMS_SESSION_MANAGER);
        XFormsSession xFormsSession = manager.getXFormsSession(sessionKey);
        xFormsSession.getKey();
    }
View Full Code Here

    public void close(String sessionKey) throws FluxException {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("FluxFacade close: " + sessionKey);
        }
        XFormsSessionManager manager = (XFormsSessionManager) session.getAttribute(XFormsSessionManager.XFORMS_SESSION_MANAGER);
        XFormsSession xFormsSession = manager.getXFormsSession(sessionKey);
        try {

            // don't use getXFormsSession to avoid needless error
            if (xFormsSession == null) return;
            WebAdapter adapter = xFormsSession.getAdapter();
            if (adapter == null) return;
            adapter.shutdown();
        } catch (XFormsException e) {
            LOGGER.warn("FluxFacade close: " + sessionKey, e);
        } finally {
View Full Code Here

        }
    }

    private org.w3c.dom.Element dispatch(ChibaEvent event, String sessionKey) throws FluxException {
        XFormsSessionManager manager = (XFormsSessionManager) session.getAttribute(XFormsSessionManager.XFORMS_SESSION_MANAGER);
        XFormsSession xFormsSession = manager.getXFormsSession(sessionKey);

        if(xFormsSession == null){
            LOGGER.fatal("XFormsSession not found - stopping");
            throw new FluxException("Your session has expired - Please start again.");
        }

        FluxAdapter adapter = (FluxAdapter) xFormsSession.getAdapter();
        if (adapter != null) {
            try {
                adapter.dispatch(event);
            }
            catch (XFormsException e) {
View Full Code Here

     * factory method for c�?�reating a XFormsSession object.
     *
     * @return an object of type XFormsSession
     */
    public XFormsSession createXFormsSession() {
        XFormsSession xFormsSession = new DefaultXFormsSessionImpl(this);
        this.xformsSessions.put(xFormsSession.getKey(), xFormsSession);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("created XFormsSession: " + xFormsSession.getKey());
        }

        return xFormsSession;
    }
View Full Code Here

TOP

Related Classes of org.chiba.web.session.XFormsSession

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.