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