Search in sources :

Example 16 with BasicHttpResponse

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);
    }
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpContext(org.apache.http.protocol.HttpContext) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams) HttpException(org.apache.http.HttpException) SSLException(javax.net.ssl.SSLException) IOException(java.io.IOException) ConnectionClosedException(org.apache.http.ConnectionClosedException)

Example 17 with BasicHttpResponse

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();
    }
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse)

Example 18 with BasicHttpResponse

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
    }
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) CancellationException(java.util.concurrent.CancellationException) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) ProtocolVersion(org.apache.http.ProtocolVersion) ExecutionException(java.util.concurrent.ExecutionException) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 19 with BasicHttpResponse

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());
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 20 with BasicHttpResponse

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");
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse)

Aggregations

BasicHttpResponse (org.apache.http.message.BasicHttpResponse)107 BasicStatusLine (org.apache.http.message.BasicStatusLine)64 ProtocolVersion (org.apache.http.ProtocolVersion)58 HttpResponse (org.apache.http.HttpResponse)51 StatusLine (org.apache.http.StatusLine)39 Test (org.junit.Test)39 StringEntity (org.apache.http.entity.StringEntity)34 IOException (java.io.IOException)33 List (java.util.List)24 Header (org.apache.http.Header)22 HttpHost (org.apache.http.HttpHost)19 HashMap (java.util.HashMap)18 URL (java.net.URL)17 BasicHeader (org.apache.http.message.BasicHeader)17 HttpURLConnection (java.net.HttpURLConnection)16 HttpEntity (org.apache.http.HttpEntity)14 MainResponse (org.elasticsearch.action.main.MainResponse)14 Before (org.junit.Before)13 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)12