use of io.servicecomb.core.context.InvocationContext in project java-chassis by ServiceComb.
the class ProducerOperation method invoke.
public void invoke(Invocation invocation, AsyncResponse asyncResp) {
InvocationContext context = new InvocationContext(invocation.getContext());
ContextUtils.setInvocationContext(context);
Response response = null;
try {
Object[] args = argsMapper.toProducerArgs(invocation);
Object result = method.invoke(instance, args);
response = responseMapper.mapResponse(context.getStatus(), result);
} catch (Throwable e) {
response = processException(e);
}
ContextUtils.removeInvocationContext();
asyncResp.handle(response);
}
use of io.servicecomb.core.context.InvocationContext in project java-chassis by ServiceComb.
the class TestConfig method testContextUtils.
@Test
public void testContextUtils() {
ThreadLocal<InvocationContext> contextMgr = new ThreadLocal<>();
Assert.assertEquals(contextMgr.get(), ContextUtils.getInvocationContext());
Map<String, String> oContext = new HashMap<>();
oContext.put("test1", new String("testObject"));
InvocationContext oInnovation = new InvocationContext(oContext);
Assert.assertEquals(oContext, oInnovation.getContext());
oContext.put("test2", new String("testObject"));
oInnovation.setContext(oContext);
Assert.assertEquals(oContext, oInnovation.getContext());
oInnovation.setStatus(Status.OK);
Assert.assertEquals(200, oInnovation.getStatus().getStatusCode());
oInnovation.setStatus(204);
Assert.assertEquals(204, oInnovation.getStatus().getStatusCode());
oInnovation.setStatus(Status.OK);
Assert.assertEquals((Status.OK).getStatusCode(), oInnovation.getStatus().getStatusCode());
oInnovation.setStatus(203, "Done");
Assert.assertEquals(203, oInnovation.getStatus().getStatusCode());
ContextUtils.setInvocationContext(oInnovation);
Assert.assertEquals(oInnovation, ContextUtils.getInvocationContext());
ContextUtils.removeInvocationContext();
Assert.assertNotEquals(oContext, oInnovation);
}
Aggregations