Search in sources :

Example 21 with HttpServerResponse

use of io.vertx.core.http.HttpServerResponse in project vert.x by eclipse.

the class Http2ServerTest method testStatusMessage.

@Test
public void testStatusMessage() throws Exception {
    server.requestHandler(req -> {
        HttpServerResponse resp = req.response();
        resp.setStatusCode(404);
        assertEquals("Not Found", resp.getStatusMessage());
        resp.setStatusMessage("whatever");
        assertEquals("whatever", resp.getStatusMessage());
        testComplete();
    });
    startServer();
    TestClient client = new TestClient();
    ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
        int id = request.nextStreamId();
        request.encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
        request.context.flush();
    });
    fut.sync();
    await();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Test(org.junit.Test)

Example 22 with HttpServerResponse

use of io.vertx.core.http.HttpServerResponse in project java-chassis by ServiceComb.

the class TestSimpleBodyHandler method setUp.

@Before
public void setUp() throws Exception {
    context = Mockito.mock(RoutingContext.class);
    HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
    Mockito.when(context.request()).thenReturn(request);
    HttpServerResponse response = Mockito.mock(HttpServerResponse.class);
    Mockito.when(response.setStatusCode(Status.UNSUPPORTED_MEDIA_TYPE.getStatusCode())).thenReturn(response);
    Mockito.when(context.response()).thenReturn(response);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Before(org.junit.Before)

Example 23 with HttpServerResponse

use of io.vertx.core.http.HttpServerResponse in project java-chassis by ServiceComb.

the class TestVertxRestServer method testDoSend.

@Test
public void testDoSend() {
    boolean status = false;
    try {
        HttpServerResponse httpServerResponse = Mockito.mock(HttpServerResponse.class);
        ProduceProcessor produceProcessor = Mockito.mock(ProduceProcessor.class);
        Response response = Response.create(0, "reasonPhrase", new Object());
        instance.doSendResponse(httpServerResponse, produceProcessor, response);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : HttpServerResponse(io.vertx.core.http.HttpServerResponse) Response(io.servicecomb.core.Response) ProduceProcessor(io.servicecomb.common.rest.codec.produce.ProduceProcessor) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Test(org.junit.Test)

Example 24 with HttpServerResponse

use of io.vertx.core.http.HttpServerResponse in project vert.x by eclipse.

the class Http2ServerTest method testPromiseStreamError.

@Test
public void testPromiseStreamError() throws Exception {
    Context ctx = vertx.getOrCreateContext();
    waitFor(3);
    Future<Void> when = Future.future();
    server.requestHandler(req -> {
        req.response().push(HttpMethod.GET, "/wibble", ar -> {
            assertTrue(ar.succeeded());
            assertOnIOContext(ctx);
            when.complete();
            HttpServerResponse resp = ar.result();
            resp.exceptionHandler(err -> {
                assertSame(ctx, Vertx.currentContext());
                complete();
            });
            resp.closeHandler(v -> {
                assertSame(ctx, Vertx.currentContext());
                complete();
            });
            resp.endHandler(v -> {
                assertSame(ctx, Vertx.currentContext());
                complete();
            });
            resp.setChunked(true).write("whatever");
        });
    });
    startServer(ctx);
    TestClient client = new TestClient();
    ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
        request.decoder.frameListener(new Http2EventAdapter() {

            @Override
            public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
                when.setHandler(ar -> {
                    Http2ConnectionEncoder encoder = request.encoder;
                    encoder.frameWriter().writeHeaders(request.context, promisedStreamId, GET("/"), 0, false, request.context.newPromise());
                    request.context.flush();
                });
            }
        });
        int id = request.nextStreamId();
        Http2ConnectionEncoder encoder = request.encoder;
        encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
        request.context.flush();
    });
    fut.sync();
    await();
}
Also used : Context(io.vertx.core.Context) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelFuture(io.netty.channel.ChannelFuture) Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) HttpServer(io.vertx.core.http.HttpServer) MultiMap(io.vertx.core.MultiMap) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Context(io.vertx.core.Context) Unpooled(io.netty.buffer.Unpooled) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Map(java.util.Map) ApplicationProtocolNegotiationHandler(io.netty.handler.ssl.ApplicationProtocolNegotiationHandler) ReadStream(io.vertx.core.streams.ReadStream) AbstractHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) StreamResetException(io.vertx.core.http.StreamResetException) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelInitializer(io.netty.channel.ChannelInitializer) Http2Flags(io.netty.handler.codec.http2.Http2Flags) Set(java.util.Set) ChannelPipeline(io.netty.channel.ChannelPipeline) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) Future(io.vertx.core.Future) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) SslHandler(io.netty.handler.ssl.SslHandler) Http2Headers(io.netty.handler.codec.http2.Http2Headers) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Http2Error(io.netty.handler.codec.http2.Http2Error) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) Trust(io.vertx.test.core.tls.Trust) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Http2EventAdapter(io.netty.handler.codec.http2.Http2EventAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ByteBuf(io.netty.buffer.ByteBuf) WriteStream(io.vertx.core.streams.WriteStream) Http2Stream(io.netty.handler.codec.http2.Http2Stream) BiConsumer(java.util.function.BiConsumer) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) EventLoopGroup(io.netty.channel.EventLoopGroup) VertxInternal(io.vertx.core.impl.VertxInternal) ClosedChannelException(java.nio.channels.ClosedChannelException) Vertx(io.vertx.core.Vertx) FileOutputStream(java.io.FileOutputStream) ApplicationProtocolNames(io.netty.handler.ssl.ApplicationProtocolNames) Test(org.junit.Test) IOException(java.io.IOException) SSLHelper(io.vertx.core.net.impl.SSLHelper) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) Http2Settings(io.netty.handler.codec.http2.Http2Settings) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Bootstrap(io.netty.bootstrap.Bootstrap) AtomicLong(java.util.concurrent.atomic.AtomicLong) Http2Connection(io.netty.handler.codec.http2.Http2Connection) HttpMethod(io.vertx.core.http.HttpMethod) HttpUtils(io.vertx.core.http.impl.HttpUtils) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Handler(io.vertx.core.Handler) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) Http2Exception(io.netty.handler.codec.http2.Http2Exception) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Http2EventAdapter(io.netty.handler.codec.http2.Http2EventAdapter) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) Test(org.junit.Test)

Example 25 with HttpServerResponse

use of io.vertx.core.http.HttpServerResponse in project vert.x by eclipse.

the class Http2ServerTest method test100ContinueHandledManually.

@Test
public void test100ContinueHandledManually() throws Exception {
    server.requestHandler(req -> {
        assertEquals("100-continue", req.getHeader("expect"));
        HttpServerResponse resp = req.response();
        resp.writeContinue();
        req.bodyHandler(body -> {
            assertEquals("the-body", body.toString());
            resp.putHeader("wibble", "wibble-value").end();
        });
    });
    test100Continue();
}
Also used : HttpServerResponse(io.vertx.core.http.HttpServerResponse) Test(org.junit.Test)

Aggregations

HttpServerResponse (io.vertx.core.http.HttpServerResponse)37 Test (org.junit.Test)29 Buffer (io.vertx.core.buffer.Buffer)20 HttpClientRequest (io.vertx.core.http.HttpClientRequest)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 HttpClientOptions (io.vertx.core.http.HttpClientOptions)17 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 HttpMethod (io.vertx.core.http.HttpMethod)15 HttpServerOptions (io.vertx.core.http.HttpServerOptions)15 NetSocket (io.vertx.core.net.NetSocket)14 TimeUnit (java.util.concurrent.TimeUnit)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 ChannelFuture (io.netty.channel.ChannelFuture)13 HttpConnection (io.vertx.core.http.HttpConnection)13 HttpVersion (io.vertx.core.http.HttpVersion)13 TestUtils.assertIllegalStateException (io.vertx.test.core.TestUtils.assertIllegalStateException)13 ArrayList (java.util.ArrayList)13 Collections (java.util.Collections)13 List (java.util.List)13