Search in sources :

Example 1 with SwaggerConsumerOperation

use of org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation 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();
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) CompletableFuture(java.util.concurrent.CompletableFuture) SwaggerConsumerOperation(org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)

Example 2 with SwaggerConsumerOperation

use of org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation in project incubator-servicecomb-java-chassis by apache.

the class Invoker method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (swaggerConsumer == null) {
        synchronized (this) {
            if (swaggerConsumer == null) {
                prepare();
            }
        }
    }
    SwaggerConsumerOperation consumerOperation = swaggerConsumer.findOperation(method.getName());
    Invocation invocation = InvocationFactory.forConsumer(referenceConfig, schemaMeta, consumerOperation.getSwaggerMethod().getName(), null);
    consumerOperation.getArgumentsMapper().toInvocation(args, invocation);
    if (CompletableFuture.class.equals(method.getReturnType())) {
        return completableFutureInvoke(invocation, consumerOperation);
    }
    return syncInvoke(invocation, consumerOperation);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) SwaggerConsumerOperation(org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation)

Aggregations

SwaggerConsumerOperation (org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 Invocation (org.apache.servicecomb.core.Invocation)1 SwaggerProducerOperation (org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)1 SwaggerInvocation (org.apache.servicecomb.swagger.invocation.SwaggerInvocation)1