This is an automated email from the ASF dual-hosted git repository.
wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 69ba8f2 [SCB-2152] allow pojo invoker process by filter chain
69ba8f2 is described below
commit 69ba8f2e27a0d2924133bb7a5dfda15225439411
Author: wujimin <[email protected]>
AuthorDate: Tue Dec 8 12:36:48 2020 +0800
[SCB-2152] allow pojo invoker process by filter chain
---
.../org/apache/servicecomb/core/Invocation.java | 2 +-
.../core/filter/FilterChainsManager.java | 25 +++++----
.../core/invocation/InvocationFactory.java | 11 ++--
.../core/provider/consumer/InvokerUtils.java | 26 +++++++++
core/src/main/resources/microservice.yaml | 9 ++--
.../servicecomb/it/extend/engine/ITInvoker.java | 12 +++--
.../provider/pojo/FilterInvocationCaller.java | 45 ++++++++++++++++
.../provider/pojo/HandlerInvocationCaller.java | 61 ++++++++++++++++++++++
.../provider/pojo/InvocationCaller.java | 24 +++++++++
.../apache/servicecomb/provider/pojo/Invoker.java | 55 ++++++-------------
...oInvocationCreator.java => PojoInvocation.java} | 22 ++++----
.../provider/pojo/PojoInvocationCreator.java | 22 ++++----
.../pojo/definition/PojoConsumerOperationMeta.java | 12 ++++-
13 files changed, 235 insertions(+), 91 deletions(-)
diff --git a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
index 233e270..ae35727 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
@@ -64,7 +64,7 @@ public class Invocation extends SwaggerInvocation {
return
SPIServiceUtils.getPriorityHighestServices(TraceIdGenerator::getName,
TraceIdGenerator.class);
}
- private ReferenceConfig referenceConfig;
+ protected ReferenceConfig referenceConfig;
private InvocationRuntimeType invocationRuntimeType;
diff --git
a/core/src/main/java/org/apache/servicecomb/core/filter/FilterChainsManager.java
b/core/src/main/java/org/apache/servicecomb/core/filter/FilterChainsManager.java
index 2a8f555..125d1f7 100644
---
a/core/src/main/java/org/apache/servicecomb/core/filter/FilterChainsManager.java
+++
b/core/src/main/java/org/apache/servicecomb/core/filter/FilterChainsManager.java
@@ -25,13 +25,11 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Locale;
import java.util.Map.Entry;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.filter.config.FilterChainsConfig;
import org.apache.servicecomb.core.filter.config.TransportFiltersConfig;
-import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -110,23 +108,24 @@ public class FilterChainsManager {
}
public String collectResolvedChains() {
- // currently not implement consumer filter chain, so not print consumer
information now.
-
StringBuilder sb = new StringBuilder();
- // appendLine(sb, "consumer filters: %s",
filterManager.getConsumerFilters());
- appendLine(sb, "producer filters: %s", filterManager.getProducerFilters());
- // collectChainsByInvocationType(sb, consumerChainsConfig, CONSUMER);
- collectChainsByInvocationType(sb, producerChainsConfig, PRODUCER);
+
+ appendLine(sb, "consumer: ");
+ appendLine(sb, " filters: %s", filterManager.getConsumerFilters());
+ collectChainsByInvocationType(sb, consumerChainsConfig);
+
+ appendLine(sb, "producer: ");
+ appendLine(sb, " filters: %s", filterManager.getProducerFilters());
+ collectChainsByInvocationType(sb, producerChainsConfig);
return deleteLast(sb, 1).toString();
}
- private void collectChainsByInvocationType(StringBuilder sb,
FilterChainsConfig chainsConfig,
- InvocationType invocationType) {
- appendLine(sb, "%s chains:", invocationType.name().toLowerCase(Locale.US));
- appendLine(sb, " default: %s", chainsConfig.getDefaultChain());
+ private void collectChainsByInvocationType(StringBuilder sb,
FilterChainsConfig chainsConfig) {
+ appendLine(sb, " chains:");
+ appendLine(sb, " default: %s", chainsConfig.getDefaultChain());
for (Entry<String, List<Object>> entry :
chainsConfig.getMicroserviceChains().entrySet()) {
- appendLine(sb, " %s: %s", entry.getKey(), entry.getValue());
+ appendLine(sb, " %s: %s", entry.getKey(), entry.getValue());
}
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationFactory.java
b/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationFactory.java
index 5d4ee82..1ade3a7 100644
---
a/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationFactory.java
+++
b/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationFactory.java
@@ -32,17 +32,18 @@ public final class InvocationFactory {
private InvocationFactory() {
}
- private static String getMicroserviceName() {
- return RegistrationManager.INSTANCE.getMicroservice().getServiceName();
- }
-
public static Invocation forConsumer(ReferenceConfig referenceConfig,
OperationMeta operationMeta,
InvocationRuntimeType invocationRuntimeType, Map<String, Object>
swaggerArguments) {
Invocation invocation = new Invocation(referenceConfig,
operationMeta,
invocationRuntimeType,
swaggerArguments);
- invocation.addContext(Const.SRC_MICROSERVICE, getMicroserviceName());
+ return setSrcMicroservice(invocation);
+ }
+
+ public static Invocation setSrcMicroservice(Invocation invocation) {
+ String microserviceName =
RegistrationManager.INSTANCE.getMicroservice().getServiceName();
+ invocation.addContext(Const.SRC_MICROSERVICE, microserviceName);
return invocation;
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
index 42f305b..5648f5f 100644
---
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
+++
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
@@ -31,6 +31,7 @@ import
org.apache.servicecomb.core.definition.InvocationRuntimeType;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.apache.servicecomb.core.exception.Exceptions;
import org.apache.servicecomb.core.invocation.InvocationFactory;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.apache.servicecomb.swagger.invocation.Response;
@@ -214,4 +215,29 @@ public final class InvokerUtils {
// todo: should be extendable to support other reactive return type, eg:
rxJava / project-reactor
return method.getReturnType().equals(CompletableFuture.class);
}
+
+ /**
+ * should never throw exception directly
+ *
+ * @param invocation invocation
+ * @return CompletableFuture<Response>
+ */
+ public static CompletableFuture<Response> invoke(Invocation invocation) {
+ invocation.onStart(null, System.nanoTime());
+ invocation.getInvocationStageTrace().startHandlersRequest();
+
+ return invocation.getMicroserviceMeta().getFilterChain()
+ .onFilter(invocation)
+ .exceptionally(throwable -> convertException(invocation, throwable))
+ .whenComplete((response, throwable) -> processMetrics(invocation,
response));
+ }
+
+ private static Response convertException(Invocation invocation, Throwable
throwable) {
+ throw Exceptions.convert(invocation, throwable);
+ }
+
+ private static void processMetrics(Invocation invocation, Response response)
{
+ invocation.getInvocationStageTrace().finishHandlersResponse();
+ invocation.onFinish(response);
+ }
}
diff --git a/core/src/main/resources/microservice.yaml
b/core/src/main/resources/microservice.yaml
index 7d10f60..cb2c464 100644
--- a/core/src/main/resources/microservice.yaml
+++ b/core/src/main/resources/microservice.yaml
@@ -21,15 +21,14 @@ servicecomb:
filter-chains:
enabled: false
transport-filters:
- #default-consumer-transport:
- # rest: rest-client-codec
- # highway: highway-client-codec
+ default-consumer-transport:
+ rest: rest-client-codec, rest-client-sender
+ highway: highway-client
default-producer-transport:
rest: rest-server-codec
highway: highway-server-codec
consumer:
- default: simple-load-balance
- #default: simple-load-balance, default-consumer-transport,
transport-client
+ default: simple-load-balance, default-consumer-transport
# samples for customize microservice filter chain
#policies:
# ms-1: retry, load-balance, transport-client, ms-1-consumer-transport
diff --git
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITInvoker.java
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITInvoker.java
index edb1e19..c6e63db 100644
---
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITInvoker.java
+++
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/extend/engine/ITInvoker.java
@@ -16,12 +16,13 @@
*/
package org.apache.servicecomb.it.extend.engine;
+import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
import org.apache.servicecomb.provider.pojo.Invoker;
+import org.apache.servicecomb.provider.pojo.PojoConsumerMetaRefresher;
+import org.apache.servicecomb.provider.pojo.PojoInvocation;
import org.apache.servicecomb.provider.pojo.PojoInvocationCreator;
-import
org.apache.servicecomb.provider.pojo.definition.PojoConsumerOperationMeta;
/**
* allow set transport, that makes integration test easier
@@ -35,9 +36,10 @@ public class ITInvoker extends Invoker {
class ITPojoInvocationCreator extends PojoInvocationCreator {
@Override
- public ReferenceConfig createReferenceConfig(PojoConsumerOperationMeta
consumerOperationMeta) {
- return
consumerOperationMeta.getPojoConsumerMeta().getMicroserviceReferenceConfig()
- .createReferenceConfig(transport,
consumerOperationMeta.getOperationMeta());
+ public PojoInvocation create(Method method, PojoConsumerMetaRefresher
metaRefresher, Object[] args) {
+ PojoInvocation invocation = super.create(method, metaRefresher, args);
+ invocation.getReferenceConfig().setTransport(transport);
+ return invocation;
}
}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/FilterInvocationCaller.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/FilterInvocationCaller.java
new file mode 100644
index 0000000..ece166e
--- /dev/null
+++
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/FilterInvocationCaller.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.provider.pojo;
+
+import static
org.apache.servicecomb.core.provider.consumer.InvokerUtils.isAsyncMethod;
+
+import java.lang.reflect.Method;
+import java.util.concurrent.CompletableFuture;
+
+import javax.annotation.Nonnull;
+
+import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
+import org.apache.servicecomb.foundation.common.utils.AsyncUtils;
+
+public class FilterInvocationCaller implements InvocationCaller {
+ // if not a sync method, should never throw exception directly
+ @Override
+ public Object call(Method method, PojoConsumerMetaRefresher metaRefresher,
PojoInvocationCreator invocationCreator,
+ Object[] args) {
+ CompletableFuture<Object> future = AsyncUtils
+ .tryCatchSupplier(() -> invocationCreator.create(method,
metaRefresher, args))
+ .thenCompose(this::doCall);
+
+ return isAsyncMethod(method) ? future : AsyncUtils.toSync(future);
+ }
+
+ protected CompletableFuture<Object> doCall(@Nonnull PojoInvocation
invocation) {
+ return InvokerUtils.invoke(invocation)
+ .thenApply(invocation::convertResponse);
+ }
+}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/HandlerInvocationCaller.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/HandlerInvocationCaller.java
new file mode 100644
index 0000000..301dc72
--- /dev/null
+++
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/HandlerInvocationCaller.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.provider.pojo;
+
+import java.lang.reflect.Method;
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
+import org.apache.servicecomb.swagger.invocation.Response;
+import
org.apache.servicecomb.swagger.invocation.context.InvocationContextCompletableFuture;
+import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
+
+public class HandlerInvocationCaller implements InvocationCaller {
+ @Override
+ public Object call(Method method, PojoConsumerMetaRefresher metaRefresher,
PojoInvocationCreator invocationCreator,
+ Object[] args) {
+ PojoInvocation invocation = invocationCreator.create(method,
metaRefresher, args);
+
+ if (invocation.isSync()) {
+ return syncInvoke(invocation);
+ }
+ return completableFutureInvoke(invocation);
+ }
+
+ protected Object syncInvoke(PojoInvocation invocation) {
+ Response response = InvokerUtils.innerSyncInvoke(invocation);
+ if (response.isSucceed()) {
+ return invocation.convertResponse(response);
+ }
+
+ throw ExceptionFactory.convertConsumerException(response.getResult());
+ }
+
+ protected CompletableFuture<Object> completableFutureInvoke(PojoInvocation
invocation) {
+ CompletableFuture<Object> future = new
InvocationContextCompletableFuture<>(invocation);
+ InvokerUtils.reactiveInvoke(invocation, response -> {
+ if (response.isSucceed()) {
+ Object result = invocation.convertResponse(response);
+ future.complete(result);
+ return;
+ }
+
+ future.completeExceptionally(response.getResult());
+ });
+ return future;
+ }
+}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/InvocationCaller.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/InvocationCaller.java
new file mode 100644
index 0000000..79b1e9f
--- /dev/null
+++
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/InvocationCaller.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.provider.pojo;
+
+import java.lang.reflect.Method;
+
+public interface InvocationCaller {
+ Object call(Method method, PojoConsumerMetaRefresher metaRefresher,
PojoInvocationCreator invocationCreator,
+ Object[] args);
+}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
index 708675c..04e4a1e 100644
---
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
+++
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
@@ -20,16 +20,8 @@ package org.apache.servicecomb.provider.pojo;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.concurrent.CompletableFuture;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
-import org.apache.servicecomb.provider.pojo.definition.PojoConsumerMeta;
-import
org.apache.servicecomb.provider.pojo.definition.PojoConsumerOperationMeta;
-import org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation;
-import org.apache.servicecomb.swagger.invocation.Response;
-import
org.apache.servicecomb.swagger.invocation.context.InvocationContextCompletableFuture;
-import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
+import org.apache.servicecomb.core.SCBEngine;
public class Invoker implements InvocationHandler {
protected final PojoConsumerMetaRefresher metaRefresher;
@@ -38,6 +30,8 @@ public class Invoker implements InvocationHandler {
protected final DefaultMethodMeta defaultMethodMeta = new
DefaultMethodMeta();
+ protected InvocationCaller invocationCaller;
+
@SuppressWarnings("unchecked")
public static <T> T createProxy(String microserviceName, String schemaId,
Class<?> consumerIntf) {
Invoker invoker = new Invoker(microserviceName, schemaId, consumerIntf);
@@ -58,6 +52,14 @@ public class Invoker implements InvocationHandler {
return new PojoInvocationCreator();
}
+ protected InvocationCaller createInvocationCaller() {
+ if (SCBEngine.getInstance().isFilterChainEnabled()) {
+ return new FilterInvocationCaller();
+ }
+
+ return new HandlerInvocationCaller();
+ }
+
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
if (method.isDefault()) {
@@ -65,38 +67,15 @@ public class Invoker implements InvocationHandler {
.invokeWithArguments(args);
}
- PojoConsumerMeta pojoConsumerMeta = metaRefresher.getLatestMeta();
- PojoConsumerOperationMeta consumerOperationMeta =
pojoConsumerMeta.ensureFindOperationMeta(method);
- Invocation invocation = invocationCreator.create(consumerOperationMeta,
args);
-
- if (CompletableFuture.class.equals(method.getReturnType())) {
- return completableFutureInvoke(invocation,
consumerOperationMeta.getSwaggerConsumerOperation());
- }
-
- return syncInvoke(invocation,
consumerOperationMeta.getSwaggerConsumerOperation());
+ prepareInvocationCaller();
+ return invocationCaller.call(method, metaRefresher, invocationCreator,
args);
}
- protected Object syncInvoke(Invocation invocation, SwaggerConsumerOperation
consumerOperation) {
- Response response = InvokerUtils.innerSyncInvoke(invocation);
- if (response.isSucceed()) {
- return consumerOperation.getResponseMapper().mapResponse(response);
+ protected void prepareInvocationCaller() {
+ if (invocationCaller != null) {
+ return;
}
- throw ExceptionFactory.convertConsumerException(response.getResult());
- }
-
- protected CompletableFuture<Object> completableFutureInvoke(Invocation
invocation,
- SwaggerConsumerOperation consumerOperation) {
- CompletableFuture<Object> future = new
InvocationContextCompletableFuture<>(invocation);
- InvokerUtils.reactiveInvoke(invocation, response -> {
- if (response.isSucceed()) {
- Object result =
consumerOperation.getResponseMapper().mapResponse(response);
- future.complete(result);
- return;
- }
-
- future.completeExceptionally(response.getResult());
- });
- return future;
+ this.invocationCaller = createInvocationCaller();
}
}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocationCreator.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocation.java
similarity index 65%
copy from
providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocationCreator.java
copy to
providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocation.java
index 21b732c..c0d7b9b 100644
---
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocationCreator.java
+++
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocation.java
@@ -20,21 +20,25 @@ import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.invocation.InvocationFactory;
import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
import
org.apache.servicecomb.provider.pojo.definition.PojoConsumerOperationMeta;
+import org.apache.servicecomb.swagger.invocation.Response;
-public class PojoInvocationCreator {
- public Invocation create(PojoConsumerOperationMeta consumerOperationMeta,
Object[] args) {
- Invocation invocation = InvocationFactory.forConsumer(
- createReferenceConfig(consumerOperationMeta),
+public class PojoInvocation extends Invocation {
+ protected final PojoConsumerOperationMeta consumerOperationMeta;
+
+ public PojoInvocation(PojoConsumerOperationMeta consumerOperationMeta) {
+ super(consumerOperationMeta.createReferenceConfig(),
consumerOperationMeta.getOperationMeta(),
consumerOperationMeta.getInvocationRuntimeType(),
null);
-
invocation.setSuccessResponseType(consumerOperationMeta.getResponsesType());
-
invocation.setInvocationArguments(consumerOperationMeta.getSwaggerConsumerOperation().toInvocationArguments(args));
+ this.consumerOperationMeta = consumerOperationMeta;
+ InvocationFactory.setSrcMicroservice(this);
+ }
- return invocation;
+ public ReferenceConfig getReferenceConfig() {
+ return referenceConfig;
}
- protected ReferenceConfig createReferenceConfig(PojoConsumerOperationMeta
consumerOperationMeta) {
- return consumerOperationMeta.createReferenceConfig(consumerOperationMeta);
+ public Object convertResponse(Response response) {
+ return
consumerOperationMeta.getSwaggerConsumerOperation().getResponseMapper().mapResponse(response);
}
}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocationCreator.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocationCreator.java
index 21b732c..e8e47d6 100644
---
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocationCreator.java
+++
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoInvocationCreator.java
@@ -16,25 +16,21 @@
*/
package org.apache.servicecomb.provider.pojo;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.invocation.InvocationFactory;
-import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
+import java.lang.reflect.Method;
+
+import org.apache.servicecomb.provider.pojo.definition.PojoConsumerMeta;
import
org.apache.servicecomb.provider.pojo.definition.PojoConsumerOperationMeta;
public class PojoInvocationCreator {
- public Invocation create(PojoConsumerOperationMeta consumerOperationMeta,
Object[] args) {
- Invocation invocation = InvocationFactory.forConsumer(
- createReferenceConfig(consumerOperationMeta),
- consumerOperationMeta.getOperationMeta(),
- consumerOperationMeta.getInvocationRuntimeType(),
- null);
+ public PojoInvocation create(Method method, PojoConsumerMetaRefresher
metaRefresher, Object[] args) {
+ PojoConsumerMeta pojoConsumerMeta = metaRefresher.getLatestMeta();
+ PojoConsumerOperationMeta consumerOperationMeta =
pojoConsumerMeta.ensureFindOperationMeta(method);
+
+ PojoInvocation invocation = new PojoInvocation(consumerOperationMeta);
invocation.setSuccessResponseType(consumerOperationMeta.getResponsesType());
invocation.setInvocationArguments(consumerOperationMeta.getSwaggerConsumerOperation().toInvocationArguments(args));
+ invocation.setSync(consumerOperationMeta.isSync());
return invocation;
}
-
- protected ReferenceConfig createReferenceConfig(PojoConsumerOperationMeta
consumerOperationMeta) {
- return consumerOperationMeta.createReferenceConfig(consumerOperationMeta);
- }
}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/definition/PojoConsumerOperationMeta.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/definition/PojoConsumerOperationMeta.java
index f86bdc3..e84eca0 100644
---
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/definition/PojoConsumerOperationMeta.java
+++
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/definition/PojoConsumerOperationMeta.java
@@ -24,6 +24,7 @@ import javax.servlet.http.Part;
import org.apache.servicecomb.core.definition.InvocationRuntimeType;
import org.apache.servicecomb.core.definition.OperationMeta;
+import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
import org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation;
@@ -42,11 +43,14 @@ public class PojoConsumerOperationMeta {
private InvocationRuntimeType invocationRuntimeType;
+ private boolean sync;
+
public PojoConsumerOperationMeta(PojoConsumerMeta pojoConsumerMeta,
OperationMeta operationMeta,
SwaggerConsumerOperation swaggerConsumerOperation) {
this.pojoConsumerMeta = pojoConsumerMeta;
this.operationMeta = operationMeta;
this.swaggerConsumerOperation = swaggerConsumerOperation;
+ this.sync =
InvokerUtils.isSyncMethod(swaggerConsumerOperation.getConsumerMethod());
initResponseType();
initRuntimeType();
}
@@ -78,9 +82,9 @@ public class PojoConsumerOperationMeta {
return invocationRuntimeType;
}
- public ReferenceConfig createReferenceConfig(PojoConsumerOperationMeta
consumerOperationMeta) {
+ public ReferenceConfig createReferenceConfig() {
return pojoConsumerMeta.getMicroserviceReferenceConfig()
- .createReferenceConfig(consumerOperationMeta.getOperationMeta());
+ .createReferenceConfig(operationMeta);
}
private void initResponseType() {
@@ -98,4 +102,8 @@ public class PojoConsumerOperationMeta {
responseType =
TypeFactory.defaultInstance().constructType(intfResponseType);
}
}
+
+ public boolean isSync() {
+ return sync;
+ }
}