Search in sources :

Example 31 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.

the class TestSpringMVCCommonSchemaInterface method testInvocationAlreadyTimeoutInClient.

private void testInvocationAlreadyTimeoutInClient() {
    try {
        InvocationContext context = new InvocationContext();
        context.addLocalContext(ProcessingTimeStrategy.CHAIN_START_TIME, System.nanoTime());
        context.addLocalContext(ProcessingTimeStrategy.CHAIN_PROCESSING, TimeUnit.SECONDS.toNanos(1));
        client.testInvocationTimeout(context, 1, "hello");
        TestMgr.fail("should timeout");
    } catch (InvocationException e) {
        TestMgr.check(408, e.getStatusCode());
        TestMgr.check("Invocation Timeout.", ((CommonExceptionData) e.getErrorData()).getMessage());
    }
}
Also used : InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext)

Example 32 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.

the class PojoClient method testTraceIdOnContextContainsTraceId.

private static void testTraceIdOnContextContainsTraceId() {
    InvocationContext context = new InvocationContext();
    context.addContext(Const.TRACE_ID_NAME, String.valueOf(Long.MIN_VALUE));
    ContextUtils.setInvocationContext(context);
    String traceId = test.testTraceId();
    TestMgr.check(String.valueOf(Long.MIN_VALUE), traceId);
    ContextUtils.removeInvocationContext();
}
Also used : InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext)

Example 33 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.

the class CodeFirstJaxrs method cseResponse.

@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@Path("/cseResponse")
@GET
public Response cseResponse(InvocationContext c1) {
    Response response = Response.createSuccess(Status.ACCEPTED, new User());
    response.setHeader("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE));
    InvocationContext c2 = ContextUtils.getInvocationContext();
    response.setHeader("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE));
    return response;
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) ApiResponse(io.swagger.annotations.ApiResponse) User(org.apache.servicecomb.demo.server.User) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) ApiResponse(io.swagger.annotations.ApiResponse)

Example 34 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.

the class CodeFirstPojoClient method testCodeFirstCompletableFuture.

private void testCodeFirstCompletableFuture(CodeFirstPojoIntf codeFirst) {
    if (!CodeFirstPojoClientIntf.class.isInstance(codeFirst)) {
        return;
    }
    Vertx vertx = VertxUtils.getOrCreateVertxByName("transport", null);
    CountDownLatch latch = new CountDownLatch(1);
    // vertx.runOnContext in normal thread is not a good practice
    // here just a test, not care for this.
    vertx.runOnContext(V -> {
        InvocationContext context = new InvocationContext();
        context.addContext("k", "v");
        ContextUtils.setInvocationContext(context);
        ((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone").thenCompose(result -> {
            TestMgr.check("someone sayhi, context k: v", result);
            TestMgr.check(true, context == ContextUtils.getInvocationContext());
            return ((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone 1");
        }).whenComplete((r, e) -> {
            TestMgr.check("someone 1 sayhi, context k: v", r);
            latch.countDown();
        });
        ContextUtils.removeInvocationContext();
    });
    try {
        latch.await();
    } catch (InterruptedException e) {
        throw new IllegalStateException(e);
    }
}
Also used : Arrays(java.util.Arrays) ParseRequest(org.apache.servicecomb.demo.mapnull.ParseRequest) Date(java.util.Date) CodeFirstPojoIntf(org.apache.servicecomb.demo.CodeFirstPojoIntf) ParseResponse(org.apache.servicecomb.demo.mapnull.ParseResponse) Vertx(io.vertx.core.Vertx) HashMap(java.util.HashMap) ContextUtils(org.apache.servicecomb.swagger.invocation.context.ContextUtils) MapModel(org.apache.servicecomb.demo.server.MapModel) RpcReference(org.apache.servicecomb.provider.pojo.RpcReference) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) Inject(javax.inject.Inject) CountDownLatch(java.util.concurrent.CountDownLatch) Person(org.apache.servicecomb.demo.compute.Person) List(java.util.List) Component(org.springframework.stereotype.Component) User(org.apache.servicecomb.demo.server.User) VertxUtils(org.apache.servicecomb.foundation.vertx.VertxUtils) Map(java.util.Map) CategorizedTestCase(org.apache.servicecomb.demo.CategorizedTestCase) TestMgr(org.apache.servicecomb.demo.TestMgr) Vertx(io.vertx.core.Vertx) CountDownLatch(java.util.concurrent.CountDownLatch) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext)

Example 35 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.

the class CodeFirstJaxrs method response.

@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@Path("/response")
@GET
public Response response(InvocationContext c1) {
    Response response = Response.createSuccess(Status.ACCEPTED, new User());
    response.addHeader("h1", "h1v " + c1.getContext().toString());
    InvocationContext c2 = ContextUtils.getInvocationContext();
    response.addHeader("h2", "h2v " + c2.getContext().toString());
    return response;
}
Also used : ApiResponse(io.swagger.annotations.ApiResponse) Response(org.apache.servicecomb.swagger.invocation.Response) User(org.apache.servicecomb.demo.server.User) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) ApiResponse(io.swagger.annotations.ApiResponse)

Aggregations

InvocationContext (org.apache.servicecomb.swagger.invocation.context.InvocationContext)35 User (org.apache.servicecomb.demo.server.User)11 ResponseHeaders (org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders)10 Response (org.apache.servicecomb.swagger.invocation.Response)9 Test (org.junit.Test)8 ApiResponse (io.swagger.annotations.ApiResponse)7 HttpHeaders (org.springframework.http.HttpHeaders)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 HashMap (java.util.HashMap)5 ResponseEntity (org.springframework.http.ResponseEntity)5 Date (java.util.Date)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Headers (org.apache.servicecomb.swagger.invocation.response.Headers)4 SwaggerInvocation (org.apache.servicecomb.swagger.invocation.SwaggerInvocation)3 Vertx (io.vertx.core.Vertx)2 LocalDate (java.time.LocalDate)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2