Search in sources :

Example 76 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project camel by apache.

the class HipchatComponentConsumerTest method sendInOnlyMultipleUsers.

//TODO
@Test
public void sendInOnlyMultipleUsers() throws Exception {
    result.expectedMessageCount(1);
    String expectedResponse = "{\n" + "  \"items\" : [\n" + "    {\n" + "      \"date\" : \"2015-01-19T22:07:11.030740+00:00\",\n" + "      \"from\" : {\n" + "        \"id\" : 1647095,\n" + "        \"links\" : {\n" + "          \"self\" : \"https://api.hipchat.com/v2/user/1647095\"\n" + "        },\n" + "        \"mention_name\" : \"notifier\",\n" + "        \"name\" : \"Message Notifier\"\n" + "      },\n" + "      \"id\" : \"6567c6f7-7c1b-43cf-bed0-792b1d092919\",\n" + "      \"mentions\" : [ ],\n" + "      \"message\" : \"Unit test Alert\",\n" + "      \"type\" : \"message\"\n" + "    }\n" + "  ],\n" + "  \"links\" : {\n" + "    \"self\" : \"https://api.hipchat.com/v2/user/%40ShreyasPurohit/history/latest\"\n" + "  },\n" + "  \"maxResults\" : 1,\n" + "  \"startIndex\" : 0\n" + "}";
    HttpEntity mockHttpEntity = mock(HttpEntity.class);
    when(mockHttpEntity.getContent()).thenReturn(new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8)));
    when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
    when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
    assertMockEndpointsSatisfied();
    assertCommonResultExchange(result.getExchanges().get(0));
}
Also used : HttpEntity(org.apache.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 77 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project camel by apache.

the class Olingo2AppImpl method parseResponse.

private Olingo2BatchResponse parseResponse(Edm edm, Map<String, String> contentIdLocationMap, Olingo2BatchRequest request, BatchSingleResponse response) throws EntityProviderException, ODataApplicationException {
    // validate HTTP status
    final int statusCode = Integer.parseInt(response.getStatusCode());
    final String statusInfo = response.getStatusInfo();
    final BasicHttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, statusInfo));
    final Map<String, String> headers = response.getHeaders();
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        httpResponse.setHeader(entry.getKey(), entry.getValue());
    }
    ByteArrayInputStream content = null;
    try {
        if (response.getBody() != null) {
            final ContentType partContentType = receiveWithCharsetParameter(ContentType.parse(headers.get(HttpHeaders.CONTENT_TYPE)), Consts.UTF_8);
            final String charset = partContentType.getCharset().toString();
            final String body = response.getBody();
            content = body != null ? new ByteArrayInputStream(body.getBytes(charset)) : null;
            httpResponse.setEntity(new StringEntity(body, charset));
        }
        AbstractFutureCallback.checkStatus(httpResponse);
    } catch (ODataApplicationException e) {
        return new Olingo2BatchResponse(statusCode, statusInfo, response.getContentId(), response.getHeaders(), e);
    } catch (UnsupportedEncodingException e) {
        return new Olingo2BatchResponse(statusCode, statusInfo, response.getContentId(), response.getHeaders(), e);
    }
    // resolve resource path and query params and parse batch part uri
    final String resourcePath = request.getResourcePath();
    final String resolvedResourcePath;
    if (resourcePath.startsWith("$") && !(METADATA.equals(resourcePath) || BATCH.equals(resourcePath))) {
        resolvedResourcePath = findLocation(resourcePath, contentIdLocationMap);
    } else {
        final String resourceLocation = response.getHeader(HttpHeaders.LOCATION);
        resolvedResourcePath = resourceLocation != null ? resourceLocation.substring(serviceUri.length()) : resourcePath;
    }
    final Map<String, String> resolvedQueryParams = request instanceof Olingo2BatchQueryRequest ? ((Olingo2BatchQueryRequest) request).getQueryParams() : null;
    final UriInfoWithType uriInfo = parseUri(edm, resolvedResourcePath, resolvedQueryParams);
    // resolve response content
    final Object resolvedContent = content != null ? readContent(uriInfo, content) : null;
    return new Olingo2BatchResponse(statusCode, statusInfo, response.getContentId(), response.getHeaders(), resolvedContent);
}
Also used : ContentType(org.apache.http.entity.ContentType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ODataApplicationException(org.apache.olingo.odata2.api.exception.ODataApplicationException) BasicStatusLine(org.apache.http.message.BasicStatusLine) Olingo2BatchQueryRequest(org.apache.camel.component.olingo2.api.batch.Olingo2BatchQueryRequest) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) Olingo2BatchResponse(org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) HashMap(java.util.HashMap)

Example 78 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project ddf by codice.

the class BackupCommandTest method prepareResponse.

private HttpResponse prepareResponse(int statusCode, String responseBody) {
    HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), statusCode, ""));
    httpResponse.setStatusCode(statusCode);
    try {
        httpResponse.setEntity(new StringEntity(responseBody));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(e);
    }
    return httpResponse;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 79 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opennms by OpenNMS.

the class IfTttTriggerTest method triggerTest.

@Test
public void triggerTest() throws IOException {
    final IfTttTrigger ifTttTrigger = new IfTttTrigger();
    final CloseableHttpResponse closeableHttpResponse = mock(CloseableHttpResponse.class);
    when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    final CloseableHttpClient closeableHttpClient = mock(CloseableHttpClient.class);
    when(closeableHttpClient.execute(Matchers.anyObject())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            HttpPost httpPost = invocationOnMock.getArgumentAt(0, HttpPost.class);
            Assert.assertEquals("POST https://maker.ifttt.com/trigger/" + TEST_EVENT + "/with/key/" + TEST_KEY + " HTTP/1.1", httpPost.getRequestLine().toString());
            Assert.assertEquals("{\"value1\":\"abc1\",\"value2\":\"abc2\",\"value3\":\"abc3\"}", IOUtils.toString(httpPost.getEntity().getContent()));
            return closeableHttpResponse;
        }
    });
    mockStatic(HttpClients.class);
    when(HttpClients.createDefault()).thenReturn(closeableHttpClient);
    ifTttTrigger.key(TEST_KEY).event(TEST_EVENT).value1("abc1").value2("will-be-overwritten").value2("abc2").value3("abc3").trigger();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 80 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project dataverse by IQSS.

the class DataCaptureModuleUtilTest method testMakeUploadRequest.

@Test
public void testMakeUploadRequest() throws UnsupportedEncodingException {
    System.out.println("makeUploadRequest");
    HttpResponseFactory factory = new DefaultHttpResponseFactory();
    org.apache.http.HttpResponse response = factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null), null);
    response.setEntity(new StringEntity("received"));
    HttpResponse<String> httpResponse = new HttpResponse<>(response, String.class);
    UploadRequestResponse result = DataCaptureModuleUtil.makeUploadRequest(httpResponse);
    assertEquals(200, result.getHttpStatusCode());
    assertEquals("received", result.getResponse());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpResponse(com.mashape.unirest.http.HttpResponse) DefaultHttpResponseFactory(org.apache.http.impl.DefaultHttpResponseFactory) HttpResponseFactory(org.apache.http.HttpResponseFactory) DefaultHttpResponseFactory(org.apache.http.impl.DefaultHttpResponseFactory) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

BasicStatusLine (org.apache.http.message.BasicStatusLine)118 ProtocolVersion (org.apache.http.ProtocolVersion)67 Test (org.junit.Test)56 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)54 StatusLine (org.apache.http.StatusLine)45 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)33 StringEntity (org.apache.http.entity.StringEntity)32 ByteArrayInputStream (java.io.ByteArrayInputStream)29 HttpResponse (org.apache.http.HttpResponse)27 IOException (java.io.IOException)19 HttpEntity (org.apache.http.HttpEntity)19 BasicHeader (org.apache.http.message.BasicHeader)19 URL (java.net.URL)17 HttpURLConnection (java.net.HttpURLConnection)16 List (java.util.List)16 Header (org.apache.http.Header)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HashMap (java.util.HashMap)14 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)13 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)12