Search in sources :

Example 1 with ConsumerOperationMeta

use of io.servicecomb.core.provider.consumer.ConsumerOperationMeta in project java-chassis by ServiceComb.

the class TestConsumerSchemaFactory method testConnectToConsumerDiff.

@Test
public void testConnectToConsumerDiff() {
    MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateConsumer("ms", "latest");
    SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta("schema");
    Map<String, ConsumerOperationMeta> consumerOperationMap = new HashMap<>();
    consumerSchemaFactory.connectToConsumer(schemaMeta, Intf.class, consumerOperationMap);
    Assert.assertEquals(1, consumerOperationMap.size());
    ConsumerOperationMeta consumerOperationMeta = consumerOperationMap.get("add");
    Assert.assertEquals(ConsumerArgumentToBodyField.class, consumerOperationMeta.getArgsMapper().getArgumentMapper(0).getClass());
    Assert.assertEquals(ConsumerResponseSame.class, consumerOperationMeta.getResponseMapper().getClass());
}
Also used : HashMap(java.util.HashMap) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta) Test(org.junit.Test)

Example 2 with ConsumerOperationMeta

use of io.servicecomb.core.provider.consumer.ConsumerOperationMeta in project java-chassis by ServiceComb.

the class Invoker method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Invocation invocation = InvocationFactory.forConsumer(config, schemaMeta, method.getName(), null);
    ConsumerOperationMeta consumerOperation = consumerOperationMap.get(method.getName());
    consumerOperation.getArgsMapper().toInvocation(args, invocation);
    Response response = InvokerUtils.innerSyncInvoke(invocation);
    if (response.isSuccessed()) {
        return consumerOperation.getResponseMapper().mapResponse(response);
    }
    throw ExceptionFactory.convertConsumerException((Throwable) response.getResult());
//        return InvokerUtils.invoke(invocation);
}
Also used : Response(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta)

Example 3 with ConsumerOperationMeta

use of io.servicecomb.core.provider.consumer.ConsumerOperationMeta in project java-chassis by ServiceComb.

the class TestConsumerSchemaFactory method testConnectToConsumerSame.

@Test
public void testConnectToConsumerSame() {
    MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateConsumer("ms", "latest");
    SchemaMeta schemaMeta = microserviceMeta.ensureFindSchemaMeta("schema");
    Map<String, ConsumerOperationMeta> consumerOperationMap = new HashMap<>();
    consumerSchemaFactory.connectToConsumer(schemaMeta, null, consumerOperationMap);
    Assert.assertEquals(1, consumerOperationMap.size());
    ConsumerOperationMeta consumerOperationMeta = consumerOperationMap.get("add");
    Assert.assertEquals(ConsumerArgumentSame.class, consumerOperationMeta.getArgsMapper().getArgumentMapper(0).getClass());
    Assert.assertEquals(ConsumerResponseSame.class, consumerOperationMeta.getResponseMapper().getClass());
}
Also used : HashMap(java.util.HashMap) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta) Test(org.junit.Test)

Example 4 with ConsumerOperationMeta

use of io.servicecomb.core.provider.consumer.ConsumerOperationMeta in project java-chassis by ServiceComb.

the class ConsumerSchemaFactory method createOperation.

protected void createOperation(ConsumerSchemaContext context, OperationMeta operationMeta, ConsumerArgumentsMapper argsMapper) {
    if (context.getConsumerOperationMap() == null) {
        return;
    }
    Method method = ReflectUtils.findMethod(context.getProviderClass(), operationMeta.getMethod().getName());
    ConsumerResponseMapper responseMapper = responseMapperFactory.createResponseMapper(method.getReturnType());
    ConsumerOperationMeta consumerOperationMeta = new ConsumerOperationMeta(operationMeta, argsMapper, responseMapper);
    context.getConsumerOperationMap().put(operationMeta.getMethod().getName(), consumerOperationMeta);
}
Also used : ConsumerResponseMapper(io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapper) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta) Method(java.lang.reflect.Method)

Aggregations

ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)4 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)2 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Invocation (io.servicecomb.core.Invocation)1 Response (io.servicecomb.core.Response)1 ConsumerResponseMapper (io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapper)1 Method (java.lang.reflect.Method)1