use of io.vertx.core.http.HttpServerRequest in project yyl_example by Relucent.
the class HelloVertxVerticle method start.
/** 运行 */
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.get("/hello").handler(new Handler<RoutingContext>() {
public void handle(RoutingContext event) {
event.response().putHeader("content-type", "text/html").end("Hello Vert.x");
}
});
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest event) {
router.accept(event);
}
}).listen(//监听端口号
8080);
}
use of io.vertx.core.http.HttpServerRequest 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.HttpServerRequest in project java-chassis by ServiceComb.
the class TestGrpcCodec method testDecodeResponse.
@Test
public void testDecodeResponse() {
boolean status = false;
try {
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Buffer bodyBuffer = Mockito.mock(Buffer.class);
Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(routingContext.request()).thenReturn(request);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
Buffer buffer = Mockito.mock(Buffer.class);
GrpcCodec.decodeResponse(invocation, operationProtobuf, httpResponse, buffer);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class TestGrpcCodec method testDecodeRequest.
@Test
public void testDecodeRequest() {
boolean status = false;
try {
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Buffer bodyBuffer = Mockito.mock(Buffer.class);
Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(routingContext.request()).thenReturn(request);
SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
GrpcCodec.setGrpcTransport(new GrpcTransport());
GrpcCodec.decodeRequest(routingContext, operationMeta);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class RestBodyHandler method handle.
@Override
public void handle(RoutingContext context) {
HttpServerRequest request = context.request();
// we need to keep state since we can be called again on reroute
Boolean handled = context.get(BODY_HANDLED);
if (handled == null || !handled) {
BHandler handler = new BHandler(context);
request.handler(handler);
request.endHandler(v -> handler.end());
context.put(BODY_HANDLED, true);
} else {
// on reroute we need to re-merge the form params if that was desired
if (mergeFormAttributes && request.isExpectMultipart()) {
request.params().addAll(request.formAttributes());
}
context.next();
}
}
Aggregations