public HttpSession createSession(HttpBindBody body, HttpConnection connection)
        throws UnauthorizedException, HttpBindException, UnknownHostException
    {
        // TODO Check if IP address is allowed to connect to the server
        final Duration wait = body.getWait().compareTo(MAX_WAIT.getValue()) > 0 ? MAX_WAIT.getValue() : body.getWait();
        final Duration defaultInactivityTimeout;
        if (wait.isZero() || body.getHold() == 0) {
            // Session will be polling.
            defaultInactivityTimeout = POLLING_INACTIVITY_TIMEOUT.getValue();
        } else {
            defaultInactivityTimeout = INACTIVITY_TIMEOUT.getValue();
        }
        HttpSession session = createSession(connection, Locale.forLanguageTag(body.getLanguage()), wait, body.getHold(),
            connection.isEncrypted(), POLLING_INTERVAL.getValue(), MAX_REQUESTS.getValue(), MAX_PAUSE.getValue(),
            defaultInactivityTimeout, body.getMajorVersion(), body.getMinorVersion());

        session.resetInactivityTimeout();

        connection.setSession(session);
        try {
            connection.deliverBody(createSessionCreationResponse(session), true);
        }
        catch (HttpConnectionClosedException | DocumentException | IOException e) {
            Log.error("Error creating session.", e);
            throw new HttpBindException("Internal server error", BoshBindingError.internalServerError);
        }
        return session;
    }
Creates an HTTP binding session which will allow a user to exchange packets with Openfire.

@param body the body element that was sent containing the request for a new session.
@param connection the HTTP connection object which abstracts the individual connections to
Openfire over the HTTP binding protocol. The initial session creation response is returned to
this connection.
@return the created HTTP session.

@throws UnauthorizedException if the Openfire server is currently in an uninitialized state.
Either shutting down or starting up.
@throws HttpBindException when there is an internal server error related to the creation of
the initial session creation response.
@throws UnknownHostException if no IP address for the peer could be found
xmppserver/src/main/java/org/jivesoftware/openfire/http/HttpSessionManager.java