use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project wso2-synapse by wso2.
the class SourceHandler method dropSourceConnection.
/**
* Closes the source side HTTP connection.
*
* @param conn HTTP server connection reference
*/
private void dropSourceConnection(NHttpServerConnection conn) {
try {
HttpContext httpContext = conn.getContext();
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_REQUEST_TOO_LONG, "Payload Too Large");
response.setParams(new DefaultedHttpParams(sourceConfiguration.getHttpParams(), response.getParams()));
response.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
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 ex) {
log.error(ex.getMessage(), ex);
SourceContext.updateState(conn, ProtocolState.CLOSED);
sourceConfiguration.getSourceConnections().shutDownConnection(conn, true);
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project wso2-synapse by wso2.
the class SourceRequest method start.
/**
* Start processing the request by connecting the pipe if this request has an entity body.
* @param conn connection
* @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();
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project scribejava by scribejava.
the class OauthAsyncCompletionHandlerTest method shouldReleaseLatchOnCancel.
@Test
public void shouldReleaseLatchOnCancel() throws Exception {
handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER);
final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok"));
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream(new byte[0]));
response.setEntity(entity);
handler.cancelled();
assertNull(callback.getResponse());
assertNotNull(callback.getThrowable());
assertTrue(callback.getThrowable() instanceof CancellationException);
// verify latch is released
try {
handler.getResult();
fail();
} catch (ExecutionException expected) {
// expected
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project scribejava by scribejava.
the class OauthAsyncCompletionHandlerTest method shouldReleaseLatchOnSuccess.
@Test
public void shouldReleaseLatchOnSuccess() throws Exception {
handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER);
final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok"));
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream(new byte[0]));
response.setEntity(entity);
handler.completed(response);
assertNotNull(callback.getResponse());
assertNull(callback.getThrowable());
// verify latch is released
assertEquals("All good", handler.getResult());
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project JSCover by tntim96.
the class PersistentStaticHttpServer method rejectMethod.
protected void rejectMethod(HttpServerConnection conn) throws IOException, HttpException {
BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_METHOD_NOT_ALLOWED, "Must be GET, POST or PUT");
conn.sendResponseHeader(response);
conn.flush();
logger.log(FINE, "Sent 405 Method Not Allowed");
}
Aggregations