Search in sources :

Example 1 with HttpUpgradeHandler

use of javax.servlet.http.HttpUpgradeHandler in project Payara by payara.

the class StandardPipeline method doInvoke.

// ------------------------------------------------------ Private Methods
private void doInvoke(Request request, Response response, boolean chaining) throws IOException, ServletException {
    if (valves.length > 0 || basic != null) {
        // Set the status so that if there are no valves (other than the
        // basic one), the basic valve's request processing logic will
        // be invoked
        int status = INVOKE_NEXT;
        // Iterate over all the valves in the pipeline and invoke
        // each valve's processing logic and then move onto to the
        // next valve in the pipeline only if the previous valve indicated
        // that the pipeline should proceed.
        int i;
        for (i = 0; i < valves.length; i++) {
            Request req = request;
            Response resp = response;
            if (chaining) {
                // Check if the (JASPIC) authentication module has provided a wrapped
                // request and response
                req = getWrappedRequest(request);
                resp = getWrappedResponse(request, response);
            }
            status = valves[i].invoke(req, resp);
            if (status != INVOKE_NEXT) {
                break;
            }
        }
        // Save a reference to the valve[], to ensure that postInvoke()
        // is invoked on the original valve[], in case a valve gets added
        // or removed during the invocation of the basic valve (e.g.,
        // in case access logging is enabled or disabled by some kind of
        // admin servlet), in which case the indices used for postInvoke
        // invocations below would be off
        GlassFishValve[] savedValves = valves;
        // directly.
        if (status == INVOKE_NEXT) {
            if (firstTcValve != null) {
                firstTcValve.invoke((org.apache.catalina.connector.Request) request, (org.apache.catalina.connector.Response) response);
            } else if (basic != null) {
                Request req = request;
                Response resp = response;
                if (chaining) {
                    req = getWrappedRequest(request);
                    resp = getWrappedResponse(request, response);
                }
                basic.invoke(req, resp);
                postInvoke(basic, req, resp);
            }
        }
        // that returned a status of INVOKE_NEXT
        for (int j = i - 1; j >= 0; j--) {
            Request req = request;
            Response resp = response;
            if (chaining) {
                req = getWrappedRequest(request);
                resp = getWrappedResponse(request, response);
            }
            postInvoke(savedValves[j], req, resp);
        }
        savedValves = null;
    } else {
        throw new ServletException(rb.getString(NO_VALVES_IN_PIPELINE_EXCEPTION));
    }
    // Calls the protocol handler's init method if the request is marked to be upgraded
    if (request instanceof org.apache.catalina.connector.Request) {
        org.apache.catalina.connector.Request req = (org.apache.catalina.connector.Request) request;
        if (req.isUpgrade()) {
            HttpUpgradeHandler handler = req.getHttpUpgradeHandler();
            if (handler != null) {
                WebConnectionImpl wc = new WebConnectionImpl(req.getInputStream(), ((org.apache.catalina.connector.Response) req.getResponse()).getOutputStream());
                wc.setRequest(req);
                req.setWebConnection(wc);
                if (response instanceof org.apache.catalina.connector.Response) {
                    wc.setResponse((org.apache.catalina.connector.Response) response);
                }
                Context context = req.getContext();
                try {
                    context.fireContainerEvent(BEFORE_UPGRADE_HANDLER_INITIALIZED, handler);
                    req.initialiseHttpUpgradeHandler(wc);
                } finally {
                    context.fireContainerEvent(AFTER_UPGRADE_HANDLER_INITIALIZED, handler);
                }
            } else {
                log.log(Level.SEVERE, PROTOCOL_HANDLER_REQUIRED_EXCEPTION);
            }
        // req.setUpgrade(false);
        }
    }
}
Also used : Request(org.apache.catalina.Request) GlassFishValve(org.glassfish.web.valve.GlassFishValve) Response(org.apache.catalina.Response) ServletException(javax.servlet.ServletException) org.apache.catalina.connector(org.apache.catalina.connector) org.apache.catalina(org.apache.catalina) HttpUpgradeHandler(javax.servlet.http.HttpUpgradeHandler)

Example 2 with HttpUpgradeHandler

use of javax.servlet.http.HttpUpgradeHandler in project Payara by payara.

the class WebConnectionImpl method close.

@Override
public void close() throws Exception {
    // Make sure we run close logic only once
    if (isClosed.compareAndSet(false, true)) {
        if ((request != null) && (request.isUpgrade())) {
            Context context = request.getContext();
            HttpUpgradeHandler httpUpgradeHandler = request.getHttpUpgradeHandler();
            Exception exception = null;
            try {
                try {
                    context.fireContainerEvent(ContainerEvent.BEFORE_UPGRADE_HANDLER_DESTROYED, httpUpgradeHandler);
                    httpUpgradeHandler.destroy();
                } finally {
                    context.fireContainerEvent(ContainerEvent.AFTER_UPGRADE_HANDLER_DESTROYED, httpUpgradeHandler);
                }
                request.setUpgrade(false);
                if (response != null) {
                    response.setUpgrade(false);
                }
            } finally {
                try {
                    inputStream.close();
                } catch (Exception ex) {
                    exception = ex;
                }
                try {
                    outputStream.close();
                } catch (Exception ex) {
                    exception = ex;
                }
                context.fireContainerEvent(ContainerEvent.PRE_DESTROY, httpUpgradeHandler);
                request.resumeAfterService();
            }
            if (exception != null) {
                throw exception;
            }
        }
    }
}
Also used : Context(org.apache.catalina.Context) IOException(java.io.IOException) HttpUpgradeHandler(javax.servlet.http.HttpUpgradeHandler)

Aggregations

HttpUpgradeHandler (javax.servlet.http.HttpUpgradeHandler)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 org.apache.catalina (org.apache.catalina)1 Context (org.apache.catalina.Context)1 Request (org.apache.catalina.Request)1 Response (org.apache.catalina.Response)1 org.apache.catalina.connector (org.apache.catalina.connector)1 GlassFishValve (org.glassfish.web.valve.GlassFishValve)1