use of io.vertx.core.http.HttpClientRequest in project java-chassis by ServiceComb.
the class TestRestClientRequestImpl method testCookie.
@Test
public void testCookie() throws Exception {
HttpClientRequest request = new MockUp<HttpClientRequest>() {
MultiMap map = MultiMap.caseInsensitiveMultiMap();
@Mock
public HttpClientRequest putHeader(CharSequence key, CharSequence val) {
map.add(key, val);
return null;
}
@Mock
public MultiMap headers() {
return map;
}
}.getMockInstance();
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(request, null, null);
restClientRequest.addCookie("sessionid", "abcdefghijklmnopqrstuvwxyz");
restClientRequest.addCookie("region", "china-north");
restClientRequest.write(Buffer.buffer("I love servicecomb"));
restClientRequest.end();
Buffer buffer = restClientRequest.getBodyBuffer();
Assert.assertEquals("I love servicecomb", buffer.toString());
Assert.assertEquals("sessionid=abcdefghijklmnopqrstuvwxyz; region=china-north; ", restClientRequest.request.headers().get(HttpHeaders.COOKIE));
}
use of io.vertx.core.http.HttpClientRequest in project java-chassis by ServiceComb.
the class RestClientDecoder method createDecodeException.
protected InvocationException createDecodeException(Invocation invocation, Response response, Exception e) {
RestClientTransportContext transportContext = invocation.getTransportContext();
HttpClientRequest httpClientRequest = transportContext.getHttpClientRequest();
LOGGER.warn("failed to decode response body, operation={}, method={}, endpoint={}, uri={}, statusCode={}, reasonPhrase={}, content-type={}.", invocation.getMicroserviceQualifiedName(), httpClientRequest.getMethod(), invocation.getEndpoint().getEndpoint(), httpClientRequest.getURI(), response.getStatusCode(), response.getReasonPhrase(), response.getHeader(HttpHeaders.CONTENT_TYPE));
if (response.isSucceed()) {
return Exceptions.consumer(FAILED_TO_DECODE_REST_SUCCESS_RESPONSE, "failed to decode success response body.", e);
}
return Exceptions.consumer(FAILED_TO_DECODE_REST_FAIL_RESPONSE, "failed to decode fail response body.", e);
}
use of io.vertx.core.http.HttpClientRequest in project pinpoint by naver.
the class PromiseImplInterceptor method getAsyncContext.
@Override
public AsyncContext getAsyncContext(Object target, Object[] args) {
if (isSamplingRateFalse(args)) {
final HttpClientRequest request = (HttpClientRequest) args[0];
this.requestTraceWriter.write(request);
return null;
}
if (validate(args)) {
return AsyncContextAccessorUtils.getAsyncContext(args, 0);
}
return null;
}
use of io.vertx.core.http.HttpClientRequest in project pinpoint by naver.
the class PromiseImplInterceptor method doInBeforeTrace.
@Override
public void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncContext, Object target, Object[] args) {
final HttpClientRequest request = (HttpClientRequest) args[0];
String host = request.getHost();
if (host == null) {
host = "UNKNOWN";
}
// generate next trace id.
final TraceId nextId = asyncContext.currentAsyncTraceObject().getTraceId().getNextTraceId();
recorder.recordNextSpanId(nextId.getSpanId());
requestTraceWriter.write(request, nextId, host);
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class HttpTest method testFollowRedirectSendHeadThenBody.
@Test
public void testFollowRedirectSendHeadThenBody() throws Exception {
Buffer expected = Buffer.buffer(TestUtils.randomAlphaString(2048));
AtomicBoolean redirected = new AtomicBoolean();
server.requestHandler(req -> {
req.bodyHandler(body -> {
assertEquals(HttpMethod.PUT, req.method());
assertEquals(body, expected);
if (redirected.compareAndSet(false, true)) {
req.response().setStatusCode(307).putHeader(HttpHeaders.LOCATION, "/whatever").end();
} else {
req.response().end();
}
});
});
startServer();
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
assertEquals(200, resp.statusCode());
testComplete();
}).setFollowRedirects(true);
req.putHeader("Content-Length", "" + expected.length());
req.exceptionHandler(this::fail);
req.sendHead(v -> {
req.end(expected);
});
await();
}
Aggregations