Search in sources :

Example 81 with HttpClientRequest

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));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) MultiMap(io.vertx.core.MultiMap) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Mock(mockit.Mock) Test(org.junit.Test)

Example 82 with HttpClientRequest

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);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 83 with HttpClientRequest

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;
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 84 with HttpClientRequest

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);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 85 with HttpClientRequest

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();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) VertxException(io.vertx.core.VertxException) MultiMap(io.vertx.core.MultiMap) TimeoutException(java.util.concurrent.TimeoutException) Context(io.vertx.core.Context) InetAddress(java.net.InetAddress) HttpFrame(io.vertx.core.http.HttpFrame) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) UUID(java.util.UUID) Future(io.vertx.core.Future) FileNotFoundException(java.io.FileNotFoundException) Nullable(io.vertx.codegen.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpServerResponse(io.vertx.core.http.HttpServerResponse) AbstractVerticle(io.vertx.core.AbstractVerticle) WorkerContext(io.vertx.core.impl.WorkerContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) IntStream(java.util.stream.IntStream) HeadersAdaptor(io.vertx.core.http.impl.HeadersAdaptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) OutputStreamWriter(java.io.OutputStreamWriter) Assume(org.junit.Assume) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) BufferedWriter(java.io.BufferedWriter) Vertx(io.vertx.core.Vertx) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) EventLoopContext(io.vertx.core.impl.EventLoopContext) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) DeploymentOptions(io.vertx.core.DeploymentOptions) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) Handler(io.vertx.core.Handler) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) TemporaryFolder(org.junit.rules.TemporaryFolder) TestUtils.assertIllegalArgumentException(io.vertx.test.core.TestUtils.assertIllegalArgumentException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Test(org.junit.Test)

Aggregations

HttpClientRequest (io.vertx.core.http.HttpClientRequest)159 Test (org.junit.Test)82 Buffer (io.vertx.core.buffer.Buffer)73 HttpClient (io.vertx.core.http.HttpClient)56 HttpMethod (io.vertx.core.http.HttpMethod)51 HttpClientOptions (io.vertx.core.http.HttpClientOptions)50 HttpClientResponse (io.vertx.core.http.HttpClientResponse)42 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 Handler (io.vertx.core.Handler)40 HttpServerResponse (io.vertx.core.http.HttpServerResponse)40 CompletableFuture (java.util.concurrent.CompletableFuture)38 CountDownLatch (java.util.concurrent.CountDownLatch)36 TimeUnit (java.util.concurrent.TimeUnit)36 Vertx (io.vertx.core.Vertx)35 HttpServerOptions (io.vertx.core.http.HttpServerOptions)35 ArrayList (java.util.ArrayList)35 List (java.util.List)35 AtomicReference (java.util.concurrent.atomic.AtomicReference)34 MultiMap (io.vertx.core.MultiMap)33 HttpVersion (io.vertx.core.http.HttpVersion)31