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();
}
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);
}
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);
}
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();
}
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();
}
Aggregations