Search in sources :

Example 1 with RoutingContext

use of io.vertx.ext.web.RoutingContext 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);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Router(io.vertx.ext.web.Router) Handler(io.vertx.core.Handler) BodyHandler(io.vertx.ext.web.handler.BodyHandler)

Example 2 with RoutingContext

use of io.vertx.ext.web.RoutingContext 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);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) RoutingContext(io.vertx.ext.web.RoutingContext) Invocation(io.servicecomb.core.Invocation) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 3 with RoutingContext

use of io.vertx.ext.web.RoutingContext 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);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) RoutingContext(io.vertx.ext.web.RoutingContext) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 4 with RoutingContext

use of io.vertx.ext.web.RoutingContext in project java-chassis by ServiceComb.

the class TestRestVertxHttpRequest method testGetCookieParam.

@Test
public void testGetCookieParam() {
    Cookie cookie = Mockito.mock(Cookie.class);
    RoutingContext context = Mockito.mock(RoutingContext.class);
    Deencapsulation.setField(instance, "context", context);
    Mockito.when(context.getCookie("key")).thenReturn(cookie);
    Assert.assertNull(instance.getCookieParam("key"));
}
Also used : Cookie(io.vertx.ext.web.Cookie) RoutingContext(io.vertx.ext.web.RoutingContext) Test(org.junit.Test)

Example 5 with RoutingContext

use of io.vertx.ext.web.RoutingContext in project java-chassis by ServiceComb.

the class TestVertxRestServer method testFailureHandler.

@Test
public void testFailureHandler() {
    RoutingContext context = Mockito.mock(RoutingContext.class);
    Mockito.when(context.response()).thenReturn(Mockito.mock(HttpServerResponse.class));
    boolean status = false;
    try {
        Deencapsulation.invoke(instance, "failureHandler", context);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Test(org.junit.Test)

Aggregations

RoutingContext (io.vertx.ext.web.RoutingContext)5 Test (org.junit.Test)4 HttpServerRequest (io.vertx.core.http.HttpServerRequest)3 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)2 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)2 OperationMeta (io.servicecomb.core.definition.OperationMeta)2 Buffer (io.vertx.core.buffer.Buffer)2 Invocation (io.servicecomb.core.Invocation)1 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)1 Handler (io.vertx.core.Handler)1 HttpClientResponse (io.vertx.core.http.HttpClientResponse)1 HttpServerResponse (io.vertx.core.http.HttpServerResponse)1 Cookie (io.vertx.ext.web.Cookie)1 Router (io.vertx.ext.web.Router)1 BodyHandler (io.vertx.ext.web.handler.BodyHandler)1