use of org.apache.http.RequestLine in project elasticsearch by elastic.
the class FailureTrackingResponseListenerTests 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.RequestLine in project okhttp by square.
the class OkApacheClient method transformRequest.
private static Request transformRequest(HttpRequest request) {
Request.Builder builder = new Request.Builder();
RequestLine requestLine = request.getRequestLine();
String method = requestLine.getMethod();
builder.url(requestLine.getUri());
String contentType = null;
for (Header header : request.getAllHeaders()) {
String name = header.getName();
if ("Content-Type".equalsIgnoreCase(name)) {
contentType = header.getValue();
} else {
builder.header(name, header.getValue());
}
}
RequestBody body = null;
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
if (entity != null) {
// Wrap the entity in a custom Body which takes care of the content, length, and type.
body = new HttpEntityBody(entity, contentType);
Header encoding = entity.getContentEncoding();
if (encoding != null) {
builder.header(encoding.getName(), encoding.getValue());
}
} else {
body = Util.EMPTY_REQUEST;
}
}
builder.method(method, body);
return builder.build();
}
use of org.apache.http.RequestLine in project XobotOS by xamarin.
the class HttpRequestParser method parseHead.
protected HttpMessage parseHead(final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException {
this.lineBuf.clear();
int i = sessionBuffer.readLine(this.lineBuf);
if (i == -1) {
throw new ConnectionClosedException("Client closed connection");
}
ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
RequestLine requestline = this.lineParser.parseRequestLine(this.lineBuf, cursor);
return this.requestFactory.newHttpRequest(requestline);
}
use of org.apache.http.RequestLine in project incubator-skywalking by apache.
the class HttpClientExecuteInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
ServiceManager.INSTANCE.boot();
httpClientExecuteInterceptor = new HttpClientExecuteInterceptor();
PowerMockito.mock(HttpHost.class);
when(statusLine.getStatusCode()).thenReturn(200);
when(httpResponse.getStatusLine()).thenReturn(statusLine);
when(httpHost.getHostName()).thenReturn("127.0.0.1");
when(httpHost.getSchemeName()).thenReturn("http");
when(request.getRequestLine()).thenReturn(new RequestLine() {
@Override
public String getMethod() {
return "GET";
}
@Override
public ProtocolVersion getProtocolVersion() {
return new ProtocolVersion("http", 1, 1);
}
@Override
public String getUri() {
return "http://127.0.0.1:8080/test-web/test";
}
});
when(httpHost.getPort()).thenReturn(8080);
allArguments = new Object[] { httpHost, request };
argumentsType = new Class[] { httpHost.getClass(), request.getClass() };
}
use of org.apache.http.RequestLine in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnection method logRequest.
// logging code
private void logRequest(final HttpRequest request, final String requestId, final CommunicatorLogger logger) {
try {
RequestLine requestLine = request.getRequestLine();
String method = requestLine.getMethod();
String uri = requestLine.getUri();
final RequestLogMessageBuilder logMessageBuilder = new RequestLogMessageBuilder(requestId, method, uri);
addHeaders(logMessageBuilder, request.getAllHeaders());
if (request instanceof HttpEntityEnclosingRequest) {
final HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) request;
HttpEntity entity = entityEnclosingRequest.getEntity();
if (entity != null && !entity.isRepeatable()) {
entity = new BufferedHttpEntity(entity);
entityEnclosingRequest.setEntity(entity);
}
setBody(logMessageBuilder, entity, request.getFirstHeader(HttpHeaders.CONTENT_TYPE));
}
logger.log(logMessageBuilder.getMessage());
} catch (Exception e) {
logger.log(String.format("An error occurred trying to log request '%s'", requestId), e);
return;
}
}
Aggregations