List of usage examples for org.apache.http.nio NHttpServerConnection suspendInput
void suspendInput();
From source file:org.apache.synapse.transport.passthru.SourceHandler.java
/** * Commit the response to the connection. Processes the response through the configured * HttpProcessor and submits it to be sent out. This method hides any exceptions and is targetted * for non critical (i.e. browser requests etc) requests, which are not core messages * @param conn the connection being processed * @param response the response to commit over the connection *///from w w w . j ava 2 s. c om public void commitResponseHideExceptions(final NHttpServerConnection conn, final HttpResponse response) { try { conn.suspendInput(); sourceConfiguration.getHttpProcessor().process(response, conn.getContext()); conn.submitResponse(response); } catch (HttpException e) { handleException("Unexpected HTTP protocol error : " + e.getMessage(), e, conn); } catch (IOException e) { handleException("IO error submiting response : " + e.getMessage(), e, conn); } }
From source file:org.apache.synapse.transport.nhttp.ServerHandler.java
/** * Commit the response to the connection. Processes the response through the configured * HttpProcessor and submits it to be sent out. This method hides any exceptions and is targetted * for non critical (i.e. browser requests etc) requests, which are not core messages * @param conn the connection being processed * @param response the response to commit over the connection *///w w w . j a v a 2 s. co m public void commitResponseHideExceptions(final NHttpServerConnection conn, final HttpResponse response) { try { conn.suspendInput(); httpProcessor.process(response, conn.getContext()); conn.submitResponse(response); } catch (HttpException e) { handleException("Unexpected HTTP protocol error : " + e.getMessage(), e, conn); } catch (IOException e) { handleException("IO error submiting response : " + e.getMessage(), e, conn); } }
From source file:org.apache.synapse.transport.passthru.SourceRequest.java
/** * Produce the content in to the pipe.//w w w . j av a2 s. c o m * @param conn the connection * @param decoder content decoder * * @throws java.io.IOException if an error occurs * @return number of bytes read */ public int read(NHttpServerConnection conn, ContentDecoder decoder) throws IOException { if (pipe == null) { throw new IllegalStateException("A Pipe must be connected before calling read"); } if (entityEnclosing) { int bytes = pipe.produce(decoder); if (decoder.isCompleted()) { conn.getContext().setAttribute(PassThroughConstants.REQ_FROM_CLIENT_READ_END_TIME, System.currentTimeMillis()); sourceConfiguration.getMetrics() .notifyReceivedMessageSize(conn.getMetrics().getReceivedBytesCount()); // Update connection state SourceContext.updateState(conn, ProtocolState.REQUEST_DONE); // Suspend client input conn.suspendInput(); } return bytes; } else { throw new IllegalStateException("Only Entity Enclosing Requests " + "can read content in to the pipe"); } }
From source file:org.apache.synapse.transport.passthru.SourceRequest.java
/** * Start processing the request by connecting the pipe if this request has an entity body. * @param conn connection/*from w w w .j a v a 2 s . co m*/ * @throws IOException if an error occurs * @throws HttpException if an error occurs */ public void start(NHttpServerConnection conn) throws IOException, HttpException { if (entityEnclosing) { pipe = new Pipe(conn, sourceConfiguration.getBufferFactory().getBuffer(), "source", sourceConfiguration); SourceContext.get(conn).setReader(pipe); // See if the client expects a 100-Continue if (((HttpEntityEnclosingRequest) request).expectContinue()) { HttpResponse ack = new BasicHttpResponse(version, HttpStatus.SC_CONTINUE, "Continue"); conn.submitResponse(ack); } } else { // this request is completed, there is nothing more to read SourceContext.updateState(conn, ProtocolState.REQUEST_DONE); // No httpRequest content expected. Suspend client input conn.suspendInput(); } }
From source file:org.apache.synapse.transport.nhttp.ServerHandler.java
/** * Commit the response to the connection. Processes the response through the configured * HttpProcessor and submits it to be sent out. Re-Throws exceptions, after closing connections * @param conn the connection being processed * @param response the response to commit over the connection * @throws IOException if an IO error occurs while sending the response * @throws HttpException if a HTTP protocol violation occurs while sending the response *///from w w w . j a v a2 s . c o m public void commitResponse(final NHttpServerConnection conn, final HttpResponse response) throws IOException, HttpException { try { BasicHttpEntity entity = (BasicHttpEntity) response.getEntity(); Header[] headers = response.getAllHeaders(); int contentLength = -1; if (canResponseHaveBody(response, conn)) { if (entity == null) { entity = new BasicHttpEntity(); } for (Header header : headers) { if (header.getName().equals(HTTP.CONTENT_LEN) && Integer.parseInt(header.getValue()) > 0) { contentLength = Integer.parseInt(header.getValue()); response.removeHeader(header); } } if (contentLength != -1) { entity.setChunked(false); entity.setContentLength(contentLength); } else { entity.setChunked(true); } } else { if (entity != null) { entity.setChunked(false); entity.setContentLength(contentLength); } } response.setEntity(entity); conn.suspendInput(); HttpContext context = conn.getContext(); httpProcessor.process(response, context); conn.getContext().setAttribute(NhttpConstants.RES_TO_CLIENT_WRITE_START_TIME, System.currentTimeMillis()); conn.submitResponse(response); } catch (HttpException e) { shutdownConnection(conn, true, e.getMessage()); throw e; } catch (IOException e) { shutdownConnection(conn, true, e.getMessage()); throw e; } }