Example usage for org.apache.http.protocol ExecutionContext HTTP_REQUEST

List of usage examples for org.apache.http.protocol ExecutionContext HTTP_REQUEST

Introduction

In this page you can find the example usage for org.apache.http.protocol ExecutionContext HTTP_REQUEST.

Prototype

String HTTP_REQUEST

To view the source code for org.apache.http.protocol ExecutionContext HTTP_REQUEST.

Click Source Link

Usage

From source file:org.siddhiesb.transport.passthru.SourceHandler.java

public void exception(NHttpServerConnection conn, Exception ex) {
    if (ex instanceof IOException) {
        logIOException(conn, (IOException) ex);

        org.siddhiesb.transport.passthru.ProtocolState state = org.siddhiesb.transport.passthru.SourceContext
                .getState(conn);//from w w w . j a v  a 2s. co  m
        if (state == org.siddhiesb.transport.passthru.ProtocolState.REQUEST_BODY
                || state == org.siddhiesb.transport.passthru.ProtocolState.REQUEST_HEAD) {
            informReaderError(conn);
        } else if (state == org.siddhiesb.transport.passthru.ProtocolState.RESPONSE_BODY
                || state == org.siddhiesb.transport.passthru.ProtocolState.RESPONSE_HEAD) {
            informWriterError(conn);
        } else if (state == org.siddhiesb.transport.passthru.ProtocolState.REQUEST_DONE) {
            informWriterError(conn);
        } else if (state == org.siddhiesb.transport.passthru.ProtocolState.RESPONSE_DONE) {
            informWriterError(conn);
        }

        org.siddhiesb.transport.passthru.SourceContext.updateState(conn,
                org.siddhiesb.transport.passthru.ProtocolState.CLOSED);
        sourceConfiguration.getSourceConnections().shutDownConnection(conn);
    } else if (ex instanceof HttpException) {
        try {
            if (conn.isResponseSubmitted()) {
                sourceConfiguration.getSourceConnections().shutDownConnection(conn);
                return;
            }
            HttpContext httpContext = conn.getContext();

            HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_REQUEST,
                    "Bad request");
            response.setParams(
                    new DefaultedHttpParams(sourceConfiguration.getHttpParams(), response.getParams()));
            response.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);

            // Pre-process HTTP request
            httpContext.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
            httpContext.setAttribute(ExecutionContext.HTTP_REQUEST, null);
            httpContext.setAttribute(ExecutionContext.HTTP_RESPONSE, response);

            sourceConfiguration.getHttpProcessor().process(response, httpContext);

            conn.submitResponse(response);
            org.siddhiesb.transport.passthru.SourceContext.updateState(conn,
                    org.siddhiesb.transport.passthru.ProtocolState.CLOSED);
            conn.close();
        } catch (Exception ex1) {
            log.error(ex.getMessage(), ex);
            org.siddhiesb.transport.passthru.SourceContext.updateState(conn,
                    org.siddhiesb.transport.passthru.ProtocolState.CLOSED);
            sourceConfiguration.getSourceConnections().shutDownConnection(conn);
        }
    } else {
        log.error("Unexoected error: " + ex.getMessage(), ex);
        org.siddhiesb.transport.passthru.SourceContext.updateState(conn,
                org.siddhiesb.transport.passthru.ProtocolState.CLOSED);
        sourceConfiguration.getSourceConnections().shutDownConnection(conn);
    }
}