use of org.apache.http.message.BasicRequestLine in project elasticsearch by elastic.
the class SyncResponseListenerTests method mockResponse.
private static Response mockResponse() {
ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
HttpResponse httpResponse = new BasicHttpResponse(statusLine);
return new Response(requestLine, new HttpHost("localhost", 9200), httpResponse);
}
use of org.apache.http.message.BasicRequestLine in project elasticsearch by elastic.
the class ResponseExceptionTests method testResponseException.
public void testResponseException() throws IOException {
ProtocolVersion protocolVersion = new ProtocolVersion("http", 1, 1);
StatusLine statusLine = new BasicStatusLine(protocolVersion, 500, "Internal Server Error");
HttpResponse httpResponse = new BasicHttpResponse(statusLine);
String responseBody = "{\"error\":{\"root_cause\": {}}}";
boolean hasBody = getRandom().nextBoolean();
if (hasBody) {
HttpEntity entity;
if (getRandom().nextBoolean()) {
entity = new StringEntity(responseBody, ContentType.APPLICATION_JSON);
} else {
//test a non repeatable entity
entity = new InputStreamEntity(new ByteArrayInputStream(responseBody.getBytes(StandardCharsets.UTF_8)), ContentType.APPLICATION_JSON);
}
httpResponse.setEntity(entity);
}
RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
HttpHost httpHost = new HttpHost("localhost", 9200);
Response response = new Response(requestLine, httpHost, httpResponse);
ResponseException responseException = new ResponseException(response);
assertSame(response, responseException.getResponse());
if (hasBody) {
assertEquals(responseBody, EntityUtils.toString(responseException.getResponse().getEntity()));
} else {
assertNull(responseException.getResponse().getEntity());
}
String message = response.getRequestLine().getMethod() + " " + response.getHost() + response.getRequestLine().getUri() + ": " + response.getStatusLine().toString();
if (hasBody) {
message += "\n" + responseBody;
}
assertEquals(message, responseException.getMessage());
}
use of org.apache.http.message.BasicRequestLine in project XobotOS by xamarin.
the class RequestWrapper method getRequestLine.
public RequestLine getRequestLine() {
String method = getMethod();
ProtocolVersion ver = getProtocolVersion();
String uritext = null;
if (uri != null) {
uritext = uri.toASCIIString();
}
if (uritext == null || uritext.length() == 0) {
uritext = "/";
}
return new BasicRequestLine(method, uritext, ver);
}
use of org.apache.http.message.BasicRequestLine in project robovm by robovm.
the class RequestWrapper method getRequestLine.
public RequestLine getRequestLine() {
String method = getMethod();
ProtocolVersion ver = getProtocolVersion();
String uritext = null;
if (uri != null) {
uritext = uri.toASCIIString();
}
if (uritext == null || uritext.length() == 0) {
uritext = "/";
}
return new BasicRequestLine(method, uritext, ver);
}
use of org.apache.http.message.BasicRequestLine in project LogHub by fbacchella.
the class TestHttpSsl method TestHcComplex.
@Test
public void TestHcComplex() throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, KeyManagementException {
CloseableHttpClient client = null;
;
try {
int publisherThreads = 1;
int timeout = 2;
// The HTTP connection management
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setUserAgent(VersionInfo.getUserAgent("LogHub-HttpClient", "org.apache.http.client", HttpClientBuilder.class));
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", new SSLConnectionSocketFactory(getContext.get(), localhostVerifier)).build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
cm.setDefaultMaxPerRoute(2);
cm.setMaxTotal(2 * publisherThreads);
cm.setValidateAfterInactivity(timeout * 1000);
builder.setConnectionManager(cm);
builder.setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(timeout * 1000).setConnectTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build());
builder.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).setSoTimeout(timeout * 1000).build());
builder.setDefaultConnectionConfig(ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build());
builder.disableCookieManagement();
client = builder.build();
HttpClientContext context = HttpClientContext.create();
HttpHost host;
RequestLine requestLine = new BasicRequestLine("GET", theurl.getPath(), HttpVersion.HTTP_1_1);
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(requestLine);
host = new HttpHost(theurl.getHost(), theurl.getPort(), "https");
CloseableHttpResponse response = client.execute(host, request, context);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
try {
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
} finally {
response.close();
}
} finally {
if (client != null) {
client.close();
}
}
}
Aggregations