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));
}
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);
}
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;
}
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();
}
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());
}
Aggregations