use of io.servicecomb.core.provider.producer.ProducerOperation in project java-chassis by ServiceComb.
the class TestProducerSchemaFactory method testGetOrCreateProducer.
@Test
public void testGetOrCreateProducer() throws Exception {
OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
Assert.assertEquals("add", operationMeta.getOperationId());
ProducerOperation producerOperation = operationMeta.getExtData(Const.PRODUCER_OPERATION);
Object addBody = Class.forName("cse.gen.app.ms.schema.addBody").newInstance();
ReflectUtils.setField(addBody, "x", 1);
ReflectUtils.setField(addBody, "y", 2);
Invocation invocation = new Invocation((Endpoint) null, operationMeta, new Object[] { addBody });
Holder<Response> holder = new Holder<>();
producerOperation.invoke(invocation, resp -> {
holder.value = resp;
});
Assert.assertEquals(3, (int) holder.value.getResult());
invocation = new Invocation((Endpoint) null, operationMeta, new Object[] { 1, 2 });
producerOperation.invoke(invocation, resp -> {
holder.value = resp;
});
Assert.assertEquals(true, holder.value.isFailed());
InvocationException exception = (InvocationException) holder.value.getResult();
CommonExceptionData data = (CommonExceptionData) exception.getErrorData();
Assert.assertEquals("Cse Internal Server Error", data.getMessage());
}
use of io.servicecomb.core.provider.producer.ProducerOperation in project java-chassis by ServiceComb.
the class ProducerSchemaFactory method createOperation.
protected void createOperation(ProducerSchemaContext context, OperationMeta operationMeta, ProducerArgumentsMapper argsMapper) {
Object producerInstance = context.getProducerInstance();
Method method = ReflectUtils.findMethod(producerInstance.getClass(), operationMeta.getMethod().getName());
ProducerResponseMapper responseMapper = responseMapperFactory.createResponseMapper(method.getReturnType());
ProducerOperation producerOperation = new ProducerOperation(producerInstance, method, argsMapper, responseMapper);
operationMeta.putExtData(Const.PRODUCER_OPERATION, producerOperation);
}
use of io.servicecomb.core.provider.producer.ProducerOperation in project java-chassis by ServiceComb.
the class ProducerOperationHandler method handle.
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
ProducerOperation producerOperation = invocation.getOperationMeta().getExtData(Const.PRODUCER_OPERATION);
if (producerOperation == null) {
asyncResp.producerFail(ExceptionUtils.producerOperationNotExist(invocation.getSchemaId(), invocation.getOperationName()));
return;
}
producerOperation.invoke(invocation, asyncResp);
}
Aggregations