use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project LiveSDK-for-Android by liveservices.
the class ApiTest method loadPathInvalidResponse.
/**
* Loads an invalid path response into the HttpClient.
*
* @param requestPath
* @throws Exception
*/
protected void loadPathInvalidResponse(String requestPath) throws Exception {
JSONObject error = new JSONObject();
error.put(JsonKeys.CODE, ErrorCodes.REQUEST_URL_INVALID);
String message = String.format(ErrorMessages.URL_NOT_VALID, requestPath.toLowerCase());
error.put(JsonKeys.MESSAGE, message);
JSONObject response = new JSONObject();
response.put(JsonKeys.ERROR, error);
byte[] bytes = response.toString().getBytes();
this.mockResponse.addHeader(HTTP.CONTENT_LEN, Long.toString(bytes.length));
this.mockEntity.setInputStream(new ByteArrayInputStream(bytes));
StatusLine status = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_REQUEST, "Bad Request");
this.mockResponse.setStatusLine(status);
this.mockClient.setHttpResponse(this.mockResponse);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project LiveSDK-for-Android by liveservices.
the class UploadTest method loadUploadLocationResponseBody.
protected void loadUploadLocationResponseBody() throws Exception {
/* create folder response */
JSONObject folder = new JSONObject();
folder.put(JsonKeys.UPLOAD_LOCATION, "https://upload.location.com/some/path");
InputStream uploadLocationStream = new ByteArrayInputStream(folder.toString().getBytes());
MockHttpEntity uploadLocationEntity = new MockHttpEntity(uploadLocationStream);
StatusLine ok = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "");
MockHttpResponse uploadLocationResponse = new MockHttpResponse(uploadLocationEntity, ok);
this.mockClient.setHttpResponse(uploadLocationResponse);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project dropwizard by dropwizard.
the class DropwizardApacheConnectorTest method multiple_headers_with_the_same_name_are_processed_successfully.
@Test
void multiple_headers_with_the_same_name_are_processed_successfully() throws Exception {
final CloseableHttpClient client = mock(CloseableHttpClient.class);
final DropwizardApacheConnector dropwizardApacheConnector = new DropwizardApacheConnector(client, null, false);
final Header[] apacheHeaders = { new BasicHeader("Set-Cookie", "test1"), new BasicHeader("Set-Cookie", "test2") };
final CloseableHttpResponse apacheResponse = mock(CloseableHttpResponse.class);
when(apacheResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(apacheResponse.getAllHeaders()).thenReturn(apacheHeaders);
when(client.execute(Mockito.any())).thenReturn(apacheResponse);
final ClientRequest jerseyRequest = mock(ClientRequest.class);
when(jerseyRequest.getUri()).thenReturn(URI.create("http://localhost"));
when(jerseyRequest.getMethod()).thenReturn("GET");
when(jerseyRequest.getHeaders()).thenReturn(new MultivaluedHashMap<>());
final ClientResponse jerseyResponse = dropwizardApacheConnector.apply(jerseyRequest);
assertThat(jerseyResponse.getStatus()).isEqualTo(apacheResponse.getStatusLine().getStatusCode());
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project saga-android by AnandChowdhary.
the class HurlStack method performRequest.
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
String url = request.getUrl();
HashMap<String, String> map = new HashMap<String, String>();
map.putAll(request.getHeaders());
map.putAll(additionalHeaders);
if (mUrlRewriter != null) {
String rewritten = mUrlRewriter.rewriteUrl(url);
if (rewritten == null) {
throw new IOException("URL blocked by rewriter: " + url);
}
url = rewritten;
}
URL parsedUrl = new URL(url);
HttpURLConnection connection = openConnection(parsedUrl, request);
for (String headerName : map.keySet()) {
connection.addRequestProperty(headerName, map.get(headerName));
}
setConnectionParametersForRequest(connection, request);
// Initialize HttpResponse with data from the HttpURLConnection.
ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
int responseCode = connection.getResponseCode();
if (responseCode == -1) {
// Signal to the caller that something was wrong with the connection.
throw new IOException("Could not retrieve response code from HttpUrlConnection.");
}
StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(), connection.getResponseMessage());
BasicHttpResponse response = new BasicHttpResponse(responseStatus);
response.setEntity(entityFromConnection(connection));
for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
if (header.getKey() != null) {
Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
response.addHeader(h);
}
}
return response;
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project cdap-ingest by caskdata.
the class RestClientTest method testForbiddenResponseCodeAnalysis.
@Test
public void testForbiddenResponseCodeAnalysis() {
StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_FORBIDDEN, "Forbidden");
when(response.getStatusLine()).thenReturn(statusLine);
TestUtils.verifyResponse(HttpStatus.SC_FORBIDDEN, response);
verify(response).getStatusLine();
}
Aggregations