use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstSpringmvcBase method responseEntity.
public ResponseEntity<Date> responseEntity(InvocationContext c1, Date date) {
HttpHeaders headers = new HttpHeaders();
headers.add("h1", "h1v " + c1.getContext().toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.add("h2", "h2v " + c2.getContext().toString());
return new ResponseEntity<Date>(date, headers, HttpStatus.ACCEPTED);
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstSpringmvcBase method cseResponse.
public Response cseResponse(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
Headers headers = response.getHeaders();
headers.addHeader("h1", "h1v " + c1.getContext().toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.addHeader("h2", "h2v " + c2.getContext().toString());
return response;
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstJaxrs method cseResponse.
// public Response getUserResponse() {
//
// }
@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());
Headers headers = response.getHeaders();
headers.addHeader("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.addHeader("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString());
return response;
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
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);
CompletableFuture<String> future = ((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone");
future.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);
}
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstRestTemplate method testTraceIdOnContextContainsTraceId.
protected 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();
}
Aggregations