use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.
the class HttpRequestWrapperTest method testRequestWithRelativeURI.
@Test
public void testRequestWithRelativeURI() throws Exception {
final HttpRequest request = new BasicHttpRequest(Method.GET, new URI("/stuff"));
final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request);
Assertions.assertEquals(Method.GET.name(), httpRequestWrapper.getMethod());
Assertions.assertEquals("/stuff", httpRequestWrapper.getPath());
Assertions.assertNull(httpRequestWrapper.getAuthority());
Assertions.assertEquals(new URI("/stuff"), httpRequestWrapper.getUri());
}
use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.
the class HttpRequestWrapperTest method testRequestWithAbsoluteURI.
@Test
public void testRequestWithAbsoluteURI() throws Exception {
final HttpRequest request = new BasicHttpRequest(Method.GET, new URI("https://host:9443/stuff?param=value"));
final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request);
Assertions.assertEquals(Method.GET.name(), httpRequestWrapper.getMethod());
Assertions.assertEquals("/stuff?param=value", httpRequestWrapper.getPath());
Assertions.assertEquals(new URIAuthority("host", 9443), httpRequestWrapper.getAuthority());
Assertions.assertEquals("https", httpRequestWrapper.getScheme());
Assertions.assertEquals(new URI("https://host:9443/stuff?param=value"), httpRequestWrapper.getUri());
httpRequestWrapper.setScheme((URIScheme.HTTP.id));
Assertions.assertEquals("http", httpRequestWrapper.getScheme());
}
use of org.apache.hc.core5.http.message.BasicHttpRequest in project mercury by yellow013.
the class AsyncClientH2FullDuplexExchange method main.
public static void main(final String[] args) throws Exception {
final IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setSoTimeout(Timeout.ofSeconds(5)).build();
final MinimalHttpAsyncClient client = HttpAsyncClients.createMinimal(HttpVersionPolicy.FORCE_HTTP_2, H2Config.DEFAULT, null, ioReactorConfig);
client.start();
final BasicHttpRequest request = BasicRequestBuilder.post("https://nghttp2.org/httpbin/post").build();
final BasicRequestProducer requestProducer = new BasicRequestProducer(request, new BasicAsyncEntityProducer("stuff", ContentType.TEXT_PLAIN));
final BasicResponseConsumer<String> responseConsumer = new BasicResponseConsumer<>(new StringAsyncEntityConsumer());
System.out.println("Executing request " + request);
final CountDownLatch latch = new CountDownLatch(1);
client.execute(new AsyncClientExchangeHandler() {
@Override
public void releaseResources() {
requestProducer.releaseResources();
responseConsumer.releaseResources();
latch.countDown();
}
@Override
public void cancel() {
System.out.println(request + " cancelled");
}
@Override
public void failed(final Exception cause) {
System.out.println(request + "->" + cause);
}
@Override
public void produceRequest(final RequestChannel channel, final HttpContext context) throws HttpException, IOException {
requestProducer.sendRequest(channel, context);
}
@Override
public int available() {
return requestProducer.available();
}
@Override
public void produce(final DataStreamChannel channel) throws IOException {
requestProducer.produce(channel);
}
@Override
public void consumeInformation(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
System.out.println(request + "->" + new StatusLine(response));
}
@Override
public void consumeResponse(final HttpResponse response, final EntityDetails entityDetails, final HttpContext context) throws HttpException, IOException {
System.out.println(request + "->" + new StatusLine(response));
responseConsumer.consumeResponse(response, entityDetails, context, null);
}
@Override
public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
responseConsumer.updateCapacity(capacityChannel);
}
@Override
public void consume(final ByteBuffer src) throws IOException {
responseConsumer.consume(src);
}
@Override
public void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException {
responseConsumer.streamEnd(trailers);
}
});
latch.await(1, TimeUnit.MINUTES);
System.out.println("Shutting down");
client.close(CloseMode.GRACEFUL);
}
use of org.apache.hc.core5.http.message.BasicHttpRequest in project skywalking-java by apache.
the class IOSessionImplPollInterceptor method afterMethod.
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
Command command = (Command) ret;
if (!(command instanceof RequestExecutionCommand)) {
return ret;
}
HttpContext httpContext = ((RequestExecutionCommand) command).getContext();
ContextSnapshot snapshot = (ContextSnapshot) httpContext.getAttribute(Constants.SKYWALKING_CONTEXT_SNAPSHOT);
if (snapshot == null) {
return ret;
}
httpContext.removeAttribute(Constants.SKYWALKING_CONTEXT_SNAPSHOT);
AbstractSpan localSpan = ContextManager.createLocalSpan("httpasyncclient/local");
localSpan.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT);
localSpan.setLayer(SpanLayer.HTTP);
ContextManager.continued(snapshot);
final ContextCarrier contextCarrier = new ContextCarrier();
BasicHttpRequest request = (BasicHttpRequest) httpContext.getAttribute(HttpClientContext.HTTP_REQUEST);
URI uri = request.getUri();
String operationName = uri.getPath();
int port = uri.getPort();
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, uri.getHost() + ":" + (port == -1 ? 80 : port));
span.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT);
Tags.URL.set(span, uri.toURL().toString());
Tags.HTTP.METHOD.set(span, request.getMethod());
SpanLayer.asHttp(span);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
request.setHeader(next.getHeadKey(), next.getHeadValue());
}
return ret;
}
Aggregations