use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestCseClientHttpRequest method testNormal.
@Test
public void testNormal() throws IOException {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.setServiceRegistry(serviceRegistry);
UnitTestMeta meta = new UnitTestMeta();
CseContext.getInstance().getSchemaListenerManager().setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));
SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(SpringmvcImpl.class);
CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);
Holder<Invocation> holder = new Holder<>();
CseClientHttpRequest client = new CseClientHttpRequest(URI.create("cse://app:test/" + SpringmvcImpl.class.getSimpleName() + "/bytes"), HttpMethod.POST) {
/**
* {@inheritDoc}
*/
@Override
protected Response doInvoke(Invocation invocation) {
holder.value = invocation;
return Response.ok("result");
}
};
byte[] body = "abc".getBytes();
client.setRequestBody(body);
client.execute();
Assert.assertArrayEquals(body, holder.value.getSwaggerArgument(0));
}
use of org.apache.servicecomb.core.Invocation 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);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestInvoker method completableFutureInvoke_failed.
@Test
public void completableFutureInvoke_failed(@Mocked Invocation invocation, @Mocked SwaggerConsumerOperation consumerOperation, @Mocked ConsumerResponseMapper mapper) {
Throwable error = new Error("failed");
Response response = Response.createConsumerFail(error);
new MockUp<InvokerUtils>() {
@Mock
void reactiveInvoke(Invocation invocation, AsyncResponse asyncResp) {
asyncResp.handle(response);
;
}
};
Invoker invoker = new Invoker("test", null, IPerson.class);
CompletableFuture<Object> future = invoker.completableFutureInvoke(invocation, consumerOperation);
future.whenComplete((result, ex) -> {
Assert.assertEquals(null, result);
Assert.assertSame(error, ex);
});
}
use of org.apache.servicecomb.core.Invocation in project incubator-skywalking by apache.
the class ProducerOperationHandlerInterceptor method afterMethod.
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
Invocation invocation = (Invocation) allArguments[0];
AbstractSpan span = ContextManager.activeSpan();
int statusCode = invocation.getStatus().getStatusCode();
if (statusCode >= 400) {
span.errorOccurred();
Tags.STATUS_CODE.set(span, Integer.toString(statusCode));
}
ContextManager.stopSpan();
return ret;
}
use of org.apache.servicecomb.core.Invocation in project incubator-skywalking by apache.
the class ProducerOperationHandlerInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
Invocation invocation = (Invocation) allArguments[0];
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
next.setHeadValue(invocation.getContext().get(next.getHeadKey()));
}
String operationName = invocation.getMicroserviceQualifiedName();
AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier);
String url = invocation.getOperationMeta().getOperationPath();
Tags.URL.set(span, url);
span.setComponent(ComponentsDefine.SERVICECOMB);
SpanLayer.asRPCFramework(span);
}
Aggregations