Search in sources :

Example 26 with InvocationContext

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

the class TestPojoConsumerEqualSwagger method testContext.

@Test
public void testContext() throws Exception {
    InvocationContext threadContext = new InvocationContext();
    threadContext.addContext("ta", "tvalue");
    ContextUtils.setInvocationContext(threadContext);
    InvocationContext context = new InvocationContext();
    context.addContext("a", "value");
    String result = proxy.testContext(context, "name");
    Assert.assertEquals(3, invoker.getInvocation().getContext().size());
    Assert.assertEquals("tvalue", invoker.getContext("ta"));
    Assert.assertEquals("value", invoker.getContext("a"));
    Assert.assertEquals("name", invoker.getContext("name"));
    Assert.assertEquals("name", (String) invoker.getSwaggerArgument(0));
    Assert.assertEquals("name sayhi", result);
}
Also used : InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) Test(org.junit.Test)

Example 27 with InvocationContext

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

the class CodeFirstRestTemplate method testTraceIdOnContextContainsTraceId.

private void testTraceIdOnContextContainsTraceId(RestTemplate template, String cseUrlPrefix) {
    String traceIdUrl = cseUrlPrefix + "traceId";
    InvocationContext invocationContext = new InvocationContext();
    invocationContext.addContext(Const.TRACE_ID_NAME, String.valueOf(Long.MIN_VALUE));
    ContextUtils.setInvocationContext(invocationContext);
    String result = template.getForObject(traceIdUrl, String.class);
    TestMgr.check(String.valueOf(Long.MIN_VALUE), result);
    ContextUtils.removeInvocationContext();
}
Also used : InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext)

Example 28 with InvocationContext

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

the class ConsumerInvocationContextMapper method invocationArgumentToSwaggerArguments.

@Override
public void invocationArgumentToSwaggerArguments(SwaggerInvocation invocation, Map<String, Object> swaggerArguments, Map<String, Object> invocationArguments) {
    InvocationContext context = (InvocationContext) invocationArguments.get(invocationArgumentName);
    invocation.addContext(context.getContext());
    invocation.addLocalContext(context.getLocalContext());
}
Also used : InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext)

Example 29 with InvocationContext

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

the class CodeFirstSpringmvc method responseEntity.

@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@RequestMapping(path = "/responseEntity", method = RequestMethod.POST)
public ResponseEntity<Date> responseEntity(InvocationContext c1, @RequestAttribute("date") Date date) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE));
    InvocationContext c2 = ContextUtils.getInvocationContext();
    headers.add("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE));
    return new ResponseEntity<>(date, headers, HttpStatus.ACCEPTED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with InvocationContext

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

the class CodeFirstSpringmvc method cseResponse.

// This definition is not correct, response type is not
// same as the actual one. May be not support in future.
@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@RequestMapping(path = "/cseResponse", method = RequestMethod.GET)
public Response cseResponse(InvocationContext c1) {
    Response response = Response.createSuccess(Status.ACCEPTED, new User());
    response.addHeader("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE));
    InvocationContext c2 = ContextUtils.getInvocationContext();
    response.addHeader("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE));
    return response;
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) DecodeTestResponse(org.apache.servicecomb.demo.springmvc.decoderesponse.DecodeTestResponse) ApiResponse(io.swagger.annotations.ApiResponse) User(org.apache.servicecomb.demo.server.User) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) ApiResponse(io.swagger.annotations.ApiResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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