List of usage examples for org.apache.http.nio NHttpServerConnection isResponseSubmitted
boolean isResponseSubmitted();
From source file:org.apache.synapse.transport.passthru.SourceHandler.java
public void exception(NHttpServerConnection conn, Exception ex) { boolean isFault = false; if (ex instanceof IOException) { logIOException(conn, (IOException) ex); metrics.incrementFaultsReceiving(); ProtocolState state = SourceContext.getState(conn); if (state == ProtocolState.REQUEST_BODY || state == ProtocolState.REQUEST_HEAD) { informReaderError(conn);/* www . j a va 2s . c o m*/ } else if (state == ProtocolState.RESPONSE_BODY || state == ProtocolState.RESPONSE_HEAD) { informWriterError(conn); } else if (state == ProtocolState.REQUEST_DONE) { informWriterError(conn); } else if (state == ProtocolState.RESPONSE_DONE) { informWriterError(conn); } isFault = true; SourceContext.updateState(conn, ProtocolState.CLOSED); sourceConfiguration.getSourceConnections().shutDownConnection(conn, true); } else if (ex instanceof HttpException) { try { if (conn.isResponseSubmitted()) { sourceConfiguration.getSourceConnections().shutDownConnection(conn, true); 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); SourceContext.updateState(conn, ProtocolState.CLOSED); conn.close(); } catch (Exception ex1) { log.error(ex.getMessage(), ex); SourceContext.updateState(conn, ProtocolState.CLOSED); sourceConfiguration.getSourceConnections().shutDownConnection(conn, true); isFault = true; } } else { log.error("Unexpected error: " + ex.getMessage(), ex); SourceContext.updateState(conn, ProtocolState.CLOSED); sourceConfiguration.getSourceConnections().shutDownConnection(conn, true); isFault = true; } if (isFault) { rollbackTransaction(conn); } }
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 a2 s .c o 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); } }