use of org.apache.servicecomb.swagger.invocation.SwaggerInvocation in project incubator-servicecomb-java-chassis by apache.
the class TestConfig method testContextUtils.
@Test
public void testContextUtils() {
ThreadLocal<InvocationContext> contextMgr = new ThreadLocal<>();
Assert.assertEquals(contextMgr.get(), ContextUtils.getInvocationContext());
SwaggerInvocation invocation = new SwaggerInvocation();
invocation.addContext("test1", "testObject");
Assert.assertEquals("testObject", invocation.getContext("test1"));
Map<String, String> context = new HashMap<>();
context.put("test2", new String("testObject"));
invocation.setContext(context);
Assert.assertEquals(context, invocation.getContext());
invocation.setStatus(Status.OK);
Assert.assertEquals(200, invocation.getStatus().getStatusCode());
invocation.setStatus(204);
Assert.assertEquals(204, invocation.getStatus().getStatusCode());
invocation.setStatus(Status.OK);
Assert.assertEquals((Status.OK).getStatusCode(), invocation.getStatus().getStatusCode());
invocation.setStatus(203, "Done");
Assert.assertEquals(203, invocation.getStatus().getStatusCode());
ContextUtils.setInvocationContext(invocation);
Assert.assertEquals(invocation, ContextUtils.getInvocationContext());
ContextUtils.removeInvocationContext();
Assert.assertEquals(null, ContextUtils.getInvocationContext());
}
use of org.apache.servicecomb.swagger.invocation.SwaggerInvocation in project incubator-servicecomb-java-chassis by apache.
the class LocalProducerInvoker method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
invocation = new SwaggerInvocation();
SwaggerConsumerOperation consumerOp = consumer.findOperation(method.getName());
SwaggerProducerOperation producerOp = producer.findOperation(consumerOp.getSwaggerMethod().getName());
consumerOp.getArgumentsMapper().toInvocation(args, invocation);
CompletableFuture<Object> future = new CompletableFuture<>();
producerOp.invoke(invocation, ar -> {
producerResponse = ar;
Object realResult = consumerOp.getResponseMapper().mapResponse(producerResponse);
future.complete(realResult);
});
if (CompletableFuture.class.equals(method.getReturnType())) {
return future;
}
return future.get();
}
use of org.apache.servicecomb.swagger.invocation.SwaggerInvocation in project incubator-servicecomb-java-chassis by apache.
the class ProducerHttpRequestArgMapper method createContextArg.
@Override
public Object createContextArg(SwaggerInvocation swaggerInvocation) {
Invocation invocation = (Invocation) swaggerInvocation;
// 从rest transport来
HttpServletRequest request = (HttpServletRequest) invocation.getHandlerContext().get(RestConst.REST_REQUEST);
if (request != null) {
return request;
}
// 通过args模拟request
return new InvocationToHttpServletRequest(invocation);
}
Aggregations