protected void createSession()

in server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java [239:308]


    protected void createSession(BoshRequest br) throws IOException {
        final Stanza stanza = br.getBody();

        if (stanza.getInnerElements().size() > 0) {
            // we can see this behavior when the server-side session is aborted, but 
            // the client keeps sending stanzas
            LOGGER.error("session creation request has content.");
            throw new IOException("session creation request has content.");
        }
        
        BoshBackedSessionContext session = createSessionContext();
        if (session.propagateSessionContext() && br.getHttpServletRequest() != null) {
            final HttpSession httpSession = br.getHttpServletRequest().getSession(true);
            httpSession.setAttribute(BoshBackedSessionContext.HTTP_SESSION_ATTRIBUTE, session);
        }
        
        final String contentAttribute = stanza.getAttributeValue("content");
        if (contentAttribute != null) session.setContentType(contentAttribute);

        String waitAttribute = stanza.getAttributeValue("wait");
        if (waitAttribute != null) {
            try {
                final int wait = Integer.parseInt(waitAttribute);
                session.setWait(wait);
            } catch (NumberFormatException e) {
                LOGGER.warn("wait value is expected to be an Integer, not {}", waitAttribute);
            }
        }

        final String holdAttribute = stanza.getAttributeValue("hold");
        if (holdAttribute != null) {
            try {
                int hold = Integer.parseInt(holdAttribute);
                session.setHold(hold);
            } catch (NumberFormatException e) {
                LOGGER.warn("hold value is expected to be an Integer, not {}", holdAttribute);
            }
        }

        final String versionAttribute = stanza.getAttributeValue("ver");
        if (versionAttribute != null) {
            try {
                session.setBoshVersion(versionAttribute);
            } catch (NumberFormatException e) {
                LOGGER.warn("bosh version is expected to be of form nn.mm, not {}", versionAttribute);
            }
        }

        final String langAttribute = stanza.getAttributeValue(NamespaceURIs.XML, "lang");
        if (langAttribute != null) session.setXMLLang(langAttribute);

        final String ackAttribute = stanza.getAttributeValue("ack");
        final boolean clientAcknowledgements = "1".equals(ackAttribute);
        session.setClientAcknowledgements(clientAcknowledgements);
        
        session.insertRequest(br);
        sessions.put(session.getSessionId(), session);

        if (LOGGER.isInfoEnabled()) {
            StringBuilder logMsg = new StringBuilder();
            logMsg.append("BOSH session created with session id = ").append(session.getSessionId());
            logMsg.append(", ver = ").append(session.getBoshVersion()).append(" (").append(versionAttribute).append(")");
            logMsg.append(", hold = ").append(session.getHold()).append(" (").append(holdAttribute).append(")");
            logMsg.append(", wait = ").append(session.getWait()).append(" (").append(waitAttribute).append(")");
            logMsg.append(", ack = ").append(session.isClientAcknowledgements()).append(" (").append(ackAttribute).append(")");
            LOGGER.info(logMsg.toString());
        }

        session.writeBoshResponse(getSessionCreationResponse(session));
    }