reactor.netty.http.client.HttpClientRequest Java Examples

The following examples show how to use reactor.netty.http.client.HttpClientRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Override
public void accept(HttpClientRequest req, Connection connection) {
	PendingSpan pendingSpan = req.currentContext().getOrDefault(PendingSpan.class,
			null);
	if (pendingSpan == null) {
		return; // Somehow TracingMapConnect was not invoked.. skip out
	}

	// All completion hooks clear this reference. If somehow this has a span upon
	// re-entry, the state model in reactor-netty has changed and we need to
	// update this code!
	Span span = pendingSpan.getAndSet(null);
	if (span != null) {
		assert false : "span exists when it shouldn't!";
		span.abandon(); // abandon instead of break
	}

	// Start a new client span with the appropriate parent
	TraceContext parent = req.currentContext().getOrDefault(TraceContext.class,
			null);
	HttpClientRequestWrapper request = new HttpClientRequestWrapper(req);

	span = handler().handleSendWithParent(request, parent);
	parseConnectionAddress(connection, span);
	pendingSpan.set(span);
}
 
Example #2
Source File: ReactorClientHttpRequest.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public ReactorClientHttpRequest(HttpMethod method, URI uri, HttpClientRequest request, NettyOutbound outbound) {
	this.httpMethod = method;
	this.uri = uri;
	this.request = request;
	this.outbound = outbound;
	this.bufferFactory = new NettyDataBufferFactory(outbound.alloc());
}
 
Example #3
Source File: ReactorClientHttpRequest.java    From java-technology-stack with MIT License 5 votes vote down vote up
public ReactorClientHttpRequest(HttpMethod method, URI uri, HttpClientRequest request, NettyOutbound outbound) {
	this.httpMethod = method;
	this.uri = uri;
	this.request = request;
	this.outbound = outbound;
	this.bufferFactory = new NettyDataBufferFactory(outbound.alloc());
}
 
Example #4
Source File: HttpServerTests.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
private void doTestDropData(
		BiFunction<? super HttpServerRequest, ? super
				HttpServerResponse, ? extends Publisher<Void>> serverFn,
		BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>> clientFn)
		throws Exception {
	disposableServer =
			HttpServer.create()
			          .port(0)
			          .handle(serverFn)
			          .wiretap(true)
			          .bindNow(Duration.ofSeconds(30));

	CountDownLatch latch = new CountDownLatch(1);
	String response =
			HttpClient.create()
			          .port(disposableServer.port())
			          .wiretap(true)
			          .doOnRequest((req, conn) -> conn.onTerminate()
			                                          .subscribe(null, null, latch::countDown))
			          .request(HttpMethod.GET)
			          .uri("/")
			          .send(clientFn)
			          .responseContent()
			          .aggregate()
			          .asString()
			          .switchIfEmpty(Mono.just("Empty"))
			          .block(Duration.ofSeconds(30));

	assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
	assertThat(response).isEqualTo("Empty");
}
 
Example #5
Source File: HttpClientFinalizerSendInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                         MethodInterceptResult result) throws Throwable {
    EnhanceObjectCache enhanceObjectCache = (EnhanceObjectCache) objInst.getSkyWalkingDynamicField();
    AbstractSpan span = ContextManager.activeSpan();
    span.prepareForAsync();

    if (!StringUtil.isEmpty(enhanceObjectCache.getUrl())) {
        URL url = new URL(enhanceObjectCache.getUrl());

        ContextCarrier contextCarrier = new ContextCarrier();
        AbstractSpan abstractSpan = ContextManager.createExitSpan(
            "SpringCloudGateway/sendRequest", contextCarrier, getPeer(url));
        Tags.URL.set(abstractSpan, enhanceObjectCache.getUrl());
        abstractSpan.prepareForAsync();
        abstractSpan.setComponent(SPRING_CLOUD_GATEWAY);

        ContextManager.stopSpan(abstractSpan);
        ContextManager.stopSpan(span);

        BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>> finalSender = (BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>>) allArguments[0];
        allArguments[0] = new BiFunction<HttpClientRequest, NettyOutbound, Publisher<Void>>() {
            @Override
            public Publisher<Void> apply(HttpClientRequest request, NettyOutbound outbound) {
                Publisher publisher = finalSender.apply(request, outbound);

                CarrierItem next = contextCarrier.items();
                while (next.hasNext()) {
                    next = next.next();
                    request.requestHeaders().remove(next.getHeadKey());
                    request.requestHeaders().set(next.getHeadKey(), next.getHeadValue());
                }
                return publisher;
            }
        };
        enhanceObjectCache.setCacheSpan(abstractSpan);
    }

    enhanceObjectCache.setSpan1(span);
}
 
Example #6
Source File: ReactorClientHttpConnector.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private ReactorClientHttpRequest adaptRequest(HttpMethod method, URI uri, HttpClientRequest request,
		NettyOutbound nettyOutbound) {

	return new ReactorClientHttpRequest(method, uri, request, nettyOutbound);
}
 
Example #7
Source File: ReactorClientHttpConnector.java    From java-technology-stack with MIT License 4 votes vote down vote up
private ReactorClientHttpRequest adaptRequest(HttpMethod method, URI uri, HttpClientRequest request,
		NettyOutbound nettyOutbound) {

	return new ReactorClientHttpRequest(method, uri, request, nettyOutbound);
}
 
Example #8
Source File: HttpClientBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
HttpClientHandler<brave.http.HttpClientRequest, brave.http.HttpClientResponse> handler() {
	if (this.handler == null) {
		this.handler = HttpClientHandler.create(httpTracing.get());
	}
	return this.handler;
}
 
Example #9
Source File: HttpClientBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public void accept(HttpClientRequest req, Throwable error) {
	handle(req.currentContext(), null, error);
}
 
Example #10
Source File: HttpClientBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
HttpClientHandler<brave.http.HttpClientRequest, brave.http.HttpClientResponse> handler() {
	if (this.handler == null) {
		this.handler = HttpClientHandler.create(httpTracing.get());
	}
	return this.handler;
}
 
Example #11
Source File: HttpClientBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
HttpClientRequestWrapper(HttpClientRequest delegate) {
	this.delegate = delegate;
}