This is an automated email from the ASF dual-hosted git repository.
liubao 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 3d2fcce6d [SCB-2766]remove Handler logic and use Filter (#3669)
3d2fcce6d is described below
commit 3d2fcce6db47741cefad0ef9def8e7d93d5df0fc
Author: liubao68 <[email protected]>
AuthorDate: Sun Feb 26 20:47:50 2023 +0800
[SCB-2766]remove Handler logic and use Filter (#3669)
---
.../common/rest/AbstractRestInvocation.java | 27 ----
.../common/rest/TestAbstractRestInvocation.java | 69 ---------
.../core/handler/AbstractHandlerManager.java | 121 ---------------
.../core/handler/ConsumerHandlerManager.java | 38 -----
.../core/handler/HandlerConfigUtils.java | 52 -------
.../core/handler/ProducerHandlerManager.java | 38 -----
.../handler/impl/ProducerOperationHandler.java | 164 ---------------------
.../core/handler/impl/TransportClientHandler.java | 44 ------
.../handler/impl/TestProducerOperationHandler.java | 53 -------
.../handler/impl/TestServiceProviderHandler.java | 68 ---------
.../handler/impl/TestTransportClientHandler.java | 57 -------
.../ExceptionToProducerResponseConverter.java | 2 +-
12 files changed, 1 insertion(+), 732 deletions(-)
diff --git
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
index 7a2af1646..b961bbb6c 100644
---
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
+++
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
@@ -38,11 +38,9 @@ import
org.apache.servicecomb.common.rest.locator.OperationLocator;
import org.apache.servicecomb.common.rest.locator.ServicePathManager;
import org.apache.servicecomb.config.YAMLUtil;
import org.apache.servicecomb.core.Const;
-import org.apache.servicecomb.core.Handler;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
@@ -180,11 +178,6 @@ public abstract class AbstractRestInvocation {
invocation.getInvocationStageTrace().startSchedule();
OperationMeta operationMeta = restOperationMeta.getOperationMeta();
- Holder<Boolean> qpsFlowControlReject = checkQpsFlowControl(operationMeta);
- if (qpsFlowControlReject.value) {
- return;
- }
-
try {
operationMeta.getExecutor().execute(() -> {
synchronized (this.requestEx) {
@@ -217,26 +210,6 @@ public abstract class AbstractRestInvocation {
}
}
- private Holder<Boolean> checkQpsFlowControl(OperationMeta operationMeta) {
- Holder<Boolean> qpsFlowControlReject = new Holder<>(false);
- @SuppressWarnings("deprecation")
- Handler providerQpsFlowControlHandler =
operationMeta.getProviderQpsFlowControlHandler();
- if (null != providerQpsFlowControlHandler) {
- try {
- providerQpsFlowControlHandler.handle(invocation, response -> {
- qpsFlowControlReject.value = true;
- produceProcessor =
ProduceProcessorManager.INSTANCE.findDefaultJsonProcessor();
- sendResponse(response);
- });
- } catch (Throwable e) {
- LOGGER.error("failed to execute ProviderQpsFlowControlHandler", e);
- qpsFlowControlReject.value = true;
- sendFailResponse(e);
- }
- }
- return qpsFlowControlReject;
- }
-
private boolean isInQueueTimeout() {
return System.nanoTime() - invocation.getInvocationStageTrace().getStart()
>
invocation.getOperationMeta().getConfig().getNanoRestRequestWaitInPoolTimeout();
diff --git
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
index 9404c6e39..34e2f148a 100644
---
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
+++
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
@@ -47,7 +47,6 @@ import
org.apache.servicecomb.common.rest.locator.ServicePathManager;
import org.apache.servicecomb.common.rest.locator.TestPathSchema;
import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.Const;
-import org.apache.servicecomb.core.Handler;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
@@ -59,7 +58,6 @@ import org.apache.servicecomb.core.executor.ReactiveExecutor;
import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.common.event.EventManager;
-import org.apache.servicecomb.foundation.common.http.HttpStatus;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
@@ -70,7 +68,6 @@ import
org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import
org.apache.servicecomb.foundation.vertx.http.StandardHttpServletResponseEx;
import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
@@ -873,26 +870,6 @@ public class TestAbstractRestInvocation {
Assertions.assertSame(invocation, restInvocation.invocation);
}
- @Test
- public void doInvoke() throws Throwable {
- Response response = Response.ok("ok");
- Handler handler = (invocation, asyncResp) -> asyncResp.complete(response);
- invocation.setHandlerList(Arrays.asList(handler));
-
- Holder<Response> result = new Holder<>();
- restInvocation = new AbstractRestInvocationForTest() {
- @Override
- protected void sendResponse(Response response) {
- result.value = response;
- }
- };
- restInvocation.invocation = invocation;
-
- restInvocation.doInvoke();
-
- Assertions.assertSame(response, result.value);
- }
-
@Test
public void scheduleInvocation_invocationContextDeserializeError() {
AsyncContext asyncContext = Mockito.mock(AsyncContext.class);
@@ -937,50 +914,4 @@ public class TestAbstractRestInvocation {
Assertions.assertEquals("Unexpected producer error, please check logs for
details", reasonPhrase.value);
Assertions.assertEquals(Integer.valueOf(1), endCount.value);
}
-
- @SuppressWarnings("deprecation")
- @Test
- public void scheduleInvocation_flowControlReject() {
- operationMeta = Mockito.spy(operationMeta);
- Mockito.when(operationMeta.getProviderQpsFlowControlHandler())
- .thenReturn((invocation, asyncResp) -> asyncResp.producerFail(new
InvocationException(
- new HttpStatus(429, "Too Many Requests"),
- new CommonExceptionData("rejected by qps flowcontrol"))));
- restOperation = Mockito.spy(restOperation);
- Mockito.when(restOperation.getOperationMeta()).thenReturn(operationMeta);
- Holder<Integer> status = new Holder<>();
- Holder<String> reasonPhrase = new Holder<>();
- Holder<Integer> endCount = new Holder<>(0);
- Holder<String> responseBody = new Holder<>();
- responseEx = new AbstractHttpServletResponse() {
- @SuppressWarnings("deprecation")
- @Override
- public void setStatus(int sc, String sm) {
- status.value = sc;
- reasonPhrase.value = sm;
- }
-
- @Override
- public void flushBuffer() {
- endCount.value = endCount.value + 1;
- }
-
- @Override
- public void setContentType(String type) {
- Assertions.assertEquals("application/json; charset=utf-8", type);
- }
-
- @Override
- public void setBodyBuffer(Buffer bodyBuffer) {
- responseBody.value = bodyBuffer.toString();
- }
- };
- initRestInvocation();
- restInvocation.scheduleInvocation();
-
- Assertions.assertEquals(Integer.valueOf(429), status.value);
- Assertions.assertEquals("Too Many Requests", reasonPhrase.value);
- Assertions.assertEquals("{\"message\":\"rejected by qps flowcontrol\"}",
responseBody.value);
- Assertions.assertEquals(Integer.valueOf(1), endCount.value);
- }
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/handler/AbstractHandlerManager.java
b/core/src/main/java/org/apache/servicecomb/core/handler/AbstractHandlerManager.java
deleted file mode 100644
index c823ce3e6..000000000
---
a/core/src/main/java/org/apache/servicecomb/core/handler/AbstractHandlerManager.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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.core.handler;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.core.Handler;
-import org.apache.servicecomb.core.handler.config.Config;
-import org.apache.servicecomb.foundation.common.AbstractObjectManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-import com.netflix.config.DynamicPropertyFactory;
-
-// key为microserviceName
-public abstract class AbstractHandlerManager extends
AbstractObjectManager<String, String, List<Handler>> {
-
- private static final Logger LOGGER =
LoggerFactory.getLogger(AbstractHandlerManager.class);
-
- private String defaultChainDef;
-
- private Config config;
-
- protected abstract String getName();
-
- // consumer、provider端,最后一个handler,都是由框架指定的,业务不可配置
- protected abstract Handler getLastHandler();
-
- // 内置默认值,用于业务未指定时的取值
- protected abstract String getInnerDefaultChainDef();
-
- private void loadDefaultChainDef() {
- String key = "servicecomb.handler.chain." + getName() + ".default";
-
- defaultChainDef = DynamicPropertyFactory.getInstance()
- .getStringProperty(key, getInnerDefaultChainDef())
- .get();
- }
-
- private List<Class<Handler>> convertToChainClass(String chainDef) {
- List<Class<Handler>> result = new ArrayList<>();
- if (StringUtils.isEmpty(chainDef)) {
- return result;
- }
-
- String[] handlerIds = chainDef.split(",");
- Map<String, Class<Handler>> handlerMaps = config.getHandlerClassMap();
- for (String handlerId : handlerIds) {
- if (handlerId != null) {
- handlerId = handlerId.trim();
- }
- if (StringUtils.isEmpty(handlerId)) {
- continue;
- }
-
- Class<Handler> cls = handlerMaps.get(handlerId);
- if (cls == null) {
- throw new Error("can not find handler :" + handlerId);
- }
- result.add(cls);
- }
- return result;
- }
-
- public void init(Config config) {
- this.config = config;
-
- loadDefaultChainDef();
- }
-
- private List<Handler> createHandlerChain(String chainDef) {
- List<Class<Handler>> chainClasses = convertToChainClass(chainDef);
-
- List<Handler> handlerList = new ArrayList<>();
- for (Class<Handler> cls : chainClasses) {
- try {
- handlerList.add(cls.getDeclaredConstructor().newInstance());
- } catch (Exception e) {
- // 在启动阶段直接抛异常出来
- throw new Error(e);
- }
- }
- handlerList.add(getLastHandler());
- return handlerList;
- }
-
- @Override
- protected String getKey(String microserviceName) {
- return microserviceName;
- }
-
- @Override
- protected List<Handler> create(String microserviceName) {
- String handlerChainKey = "servicecomb.handler.chain." + getName() +
".service." + microserviceName;
- String chainDef = DynamicPropertyFactory.getInstance()
- .getStringProperty(handlerChainKey,
- defaultChainDef)
- .get();
- LOGGER.info("get handler chain for [{}]: [{}]", handlerChainKey, chainDef);
- return createHandlerChain(chainDef);
- }
-}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/handler/ConsumerHandlerManager.java
b/core/src/main/java/org/apache/servicecomb/core/handler/ConsumerHandlerManager.java
deleted file mode 100644
index 34a253dae..000000000
---
a/core/src/main/java/org/apache/servicecomb/core/handler/ConsumerHandlerManager.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.core.handler;
-
-import org.apache.servicecomb.core.Handler;
-import org.apache.servicecomb.core.handler.impl.TransportClientHandler;
-
-public class ConsumerHandlerManager extends AbstractHandlerManager {
- @Override
- protected String getName() {
- return "Consumer";
- }
-
- @Override
- protected String getInnerDefaultChainDef() {
- return "simpleLB";
- }
-
- @Override
- protected Handler getLastHandler() {
- return TransportClientHandler.INSTANCE;
- }
-}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/handler/HandlerConfigUtils.java
b/core/src/main/java/org/apache/servicecomb/core/handler/HandlerConfigUtils.java
deleted file mode 100644
index 88c8dd8b8..000000000
---
a/core/src/main/java/org/apache/servicecomb/core/handler/HandlerConfigUtils.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.core.handler;
-
-import java.util.List;
-
-import org.apache.servicecomb.core.handler.config.Config;
-import org.apache.servicecomb.foundation.common.config.PaaSResourceUtils;
-import org.apache.servicecomb.foundation.common.config.impl.XmlLoaderUtils;
-import org.springframework.core.io.Resource;
-
-public final class HandlerConfigUtils {
- private HandlerConfigUtils() {
- }
-
- private static Config loadConfig() throws Exception {
- Config config = new Config();
-
- List<Resource> resList = PaaSResourceUtils.
- getResources(new String[] {"classpath*:config/*.handler.xml"});
- PaaSResourceUtils.sortResources(resList, ".handler.xml");
-
- for (Resource res : resList) {
- Config tmpConfig = XmlLoaderUtils.load(res, Config.class);
- config.mergeFrom(tmpConfig);
- }
-
- return config;
- }
-
- public static void init(ConsumerHandlerManager consumerHandlerManager,
ProducerHandlerManager producerHandlerManager)
- throws Exception {
- Config config = loadConfig();
- consumerHandlerManager.init(config);
- producerHandlerManager.init(config);
- }
-}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/handler/ProducerHandlerManager.java
b/core/src/main/java/org/apache/servicecomb/core/handler/ProducerHandlerManager.java
deleted file mode 100644
index 88c726b80..000000000
---
a/core/src/main/java/org/apache/servicecomb/core/handler/ProducerHandlerManager.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.core.handler;
-
-import org.apache.servicecomb.core.Handler;
-import org.apache.servicecomb.core.handler.impl.ProducerOperationHandler;
-
-public class ProducerHandlerManager extends AbstractHandlerManager {
- @Override
- protected String getName() {
- return "Provider";
- }
-
- @Override
- protected String getInnerDefaultChainDef() {
- return "";
- }
-
- @Override
- protected Handler getLastHandler() {
- return ProducerOperationHandler.INSTANCE;
- }
-}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
b/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
deleted file mode 100644
index c2932dc9f..000000000
---
a/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.core.handler.impl;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.core.Const;
-import org.apache.servicecomb.core.Handler;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.exception.ExceptionUtils;
-import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-import
org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.netflix.config.DynamicPropertyFactory;
-
-public class ProducerOperationHandler implements Handler {
- private static final Logger LOGGER =
LoggerFactory.getLogger(ProducerOperationHandler.class);
-
- public static final ProducerOperationHandler INSTANCE = new
ProducerOperationHandler();
-
- @Override
- public void handle(Invocation invocation, AsyncResponse asyncResp) {
- SwaggerProducerOperation producerOperation =
invocation.getOperationMeta().getSwaggerProducerOperation();
- if (producerOperation == null) {
- asyncResp.producerFail(
- ExceptionUtils.producerOperationNotExist(invocation.getSchemaId(),
- invocation.getOperationName()));
- return;
- }
- invoke(invocation, producerOperation, asyncResp);
- }
-
- private void invoke(Invocation invocation, SwaggerProducerOperation
producerOperation, AsyncResponse asyncResp) {
- if
(CompletableFuture.class.equals(producerOperation.getProducerMethod().getReturnType()))
{
- completableFutureInvoke(invocation, producerOperation, asyncResp);
- return;
- }
-
- syncInvoke(invocation, producerOperation, asyncResp);
- }
-
- public void completableFutureInvoke(Invocation invocation,
SwaggerProducerOperation producerOperation,
- AsyncResponse asyncResp) {
- ContextUtils.setInvocationContext(invocation);
- doCompletableFutureInvoke(invocation, producerOperation, asyncResp);
- ContextUtils.removeInvocationContext();
- }
-
- @SuppressWarnings("unchecked")
- public void doCompletableFutureInvoke(Invocation invocation,
SwaggerProducerOperation producerOperation,
- AsyncResponse asyncResp) {
- try {
- invocation.onBusinessMethodStart();
-
- Object[] args = invocation.toProducerArguments();
- for (ProducerInvokeExtension producerInvokeExtension :
producerOperation.getProducerInvokeExtenstionList()) {
- producerInvokeExtension.beforeMethodInvoke(invocation,
producerOperation, args);
- }
-
- Object result =
producerOperation.getProducerMethod().invoke(producerOperation.getProducerInstance(),
args);
- invocation.onBusinessMethodFinish();
-
- ((CompletableFuture<Object>) result).whenComplete((realResult, ex) -> {
- invocation.onBusinessFinish();
- if (ex == null) {
-
asyncResp.handle(producerOperation.getResponseMapper().mapResponse(invocation.getStatus(),
realResult));
- return;
- }
-
- asyncResp.handle(processException(invocation, ex));
- });
- } catch (Throwable e) {
- if (shouldPrintErrorLog(e)) {
- invocation.getTraceIdLogger().error(LOGGER, "unexpected error {},
message={}",
- invocation.getInvocationQualifiedName(),
-
org.apache.servicecomb.foundation.common.utils.ExceptionUtils.getExceptionMessageWithoutTrace(e));
- }
- invocation.onBusinessMethodFinish();
- invocation.onBusinessFinish();
- asyncResp.handle(processException(invocation, e));
- }
- }
-
- public void syncInvoke(Invocation invocation, SwaggerProducerOperation
producerOperation, AsyncResponse asyncResp) {
- ContextUtils.setInvocationContext(invocation);
- Response response = doInvoke(invocation, producerOperation);
- ContextUtils.removeInvocationContext();
- asyncResp.handle(response);
- }
-
- public Response doInvoke(Invocation invocation, SwaggerProducerOperation
producerOperation) {
- Response response;
- try {
- invocation.onBusinessMethodStart();
-
- Object[] args = invocation.toProducerArguments();
- for (ProducerInvokeExtension producerInvokeExtension :
producerOperation.getProducerInvokeExtenstionList()) {
- producerInvokeExtension.beforeMethodInvoke(invocation,
producerOperation, args);
- }
-
- Object result =
producerOperation.getProducerMethod().invoke(producerOperation.getProducerInstance(),
args);
- response =
producerOperation.getResponseMapper().mapResponse(invocation.getStatus(),
result);
-
- invocation.onBusinessMethodFinish();
- invocation.onBusinessFinish();
- } catch (Throwable e) {
- if
(DynamicPropertyFactory.getInstance().getBooleanProperty(Const.PRINT_SENSITIVE_ERROR_MESSAGE,
- false).get()) {
- invocation.getTraceIdLogger().error(LOGGER, "unexpected error
operation={}",
- invocation.getInvocationQualifiedName(), e);
- } else {
- if (shouldPrintErrorLog(e)) {
- invocation.getTraceIdLogger().error(LOGGER, "unexpected error
operation={}, message={}",
- invocation.getInvocationQualifiedName(),
-
org.apache.servicecomb.foundation.common.utils.ExceptionUtils.getExceptionMessageWithoutTrace(e));
- }
- }
- invocation.onBusinessMethodFinish();
- invocation.onBusinessFinish();
- response = processException(invocation, e);
- }
- return response;
- }
-
- protected boolean shouldPrintErrorLog(Throwable throwable) {
- if (!(throwable instanceof InvocationTargetException)) {
- return true;
- }
- Throwable targetException = ((InvocationTargetException)
throwable).getTargetException();
- return !(targetException instanceof InvocationException);
- }
-
- protected Response processException(SwaggerInvocation invocation, Throwable
e) {
- if (e instanceof InvocationTargetException) {
- e = ((InvocationTargetException) e).getTargetException();
- }
-
- return ExceptionFactory.convertExceptionToResponse(invocation, e);
- }
-}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/handler/impl/TransportClientHandler.java
b/core/src/main/java/org/apache/servicecomb/core/handler/impl/TransportClientHandler.java
deleted file mode 100644
index 2213df903..000000000
---
a/core/src/main/java/org/apache/servicecomb/core/handler/impl/TransportClientHandler.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.core.handler.impl;
-
-import org.apache.servicecomb.core.Handler;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TransportClientHandler implements Handler {
-
- private static final Logger log =
LoggerFactory.getLogger(TransportClientHandler.class);
-
- public static final TransportClientHandler INSTANCE = new
TransportClientHandler();
-
- @Override
- public void handle(Invocation invocation, AsyncResponse asyncResp) throws
Exception {
- Transport transport = invocation.getTransport();
-
- log.debug(
- "Sending request {} to {}",
- invocation.getMicroserviceQualifiedName(),
- invocation.getEndpoint().getEndpoint());
-
- transport.send(invocation, asyncResp);
- }
-}
diff --git
a/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestProducerOperationHandler.java
b/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestProducerOperationHandler.java
deleted file mode 100644
index cafb89072..000000000
---
a/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestProducerOperationHandler.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.core.handler.impl;
-
-import java.lang.reflect.InvocationTargetException;
-
-import javax.ws.rs.core.Response.Status;
-
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.junit.Test;
-
-import mockit.Mocked;
-import org.junit.jupiter.api.Assertions;
-
-// test cases copied from delete class, this test case tests
ExceptionToProducerResponseConverter
-public class TestProducerOperationHandler {
- ProducerOperationHandler handler = new ProducerOperationHandler();
-
- @Test
- public void processException_normal(@Mocked SwaggerInvocation invocation) {
- Error error = new Error("abc");
-
- Response response = handler.processException(invocation, error);
- Assertions.assertSame(Status.OK, response.getStatus());
- Assertions.assertEquals("response from error: abc", response.getResult());
- }
-
- @Test
- public void processException_InvocationTargetException(@Mocked
SwaggerInvocation invocation) {
- Error error = new Error("abc");
- InvocationTargetException targetException = new
InvocationTargetException(error);
-
- Response response = handler.processException(invocation, error);
- Assertions.assertSame(Status.OK, response.getStatus());
- Assertions.assertEquals("response from error: abc", response.getResult());
- }
-}
diff --git
a/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestServiceProviderHandler.java
b/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestServiceProviderHandler.java
deleted file mode 100644
index 74ef4fdb8..000000000
---
a/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestServiceProviderHandler.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.core.handler.impl;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.jupiter.api.Assertions;
-import org.mockito.Mockito;
-
-public class TestServiceProviderHandler {
-
- ProducerOperationHandler serviceProviderHandler = null;
-
- Invocation invocation = null;
-
- AsyncResponse asyncResp = null;
-
- OperationMeta OperationMeta = null;
-
- @Before
- public void setUp() throws Exception {
- serviceProviderHandler = new ProducerOperationHandler();
- invocation = Mockito.mock(Invocation.class);
- asyncResp = Mockito.mock(AsyncResponse.class);
- OperationMeta = Mockito.mock(OperationMeta.class);
- }
-
- @After
- public void tearDown() {
- serviceProviderHandler = null;
- invocation = null;
- asyncResp = null;
- OperationMeta = null;
- }
-
- @Test
- public void testHandle() {
- boolean status = false;
- try {
- Assertions.assertNotNull(serviceProviderHandler);
- Mockito.when(invocation.getOperationMeta()).thenReturn(OperationMeta);
- serviceProviderHandler.handle(invocation, asyncResp);
- } catch (Exception e) {
- e.printStackTrace();
- status = true;
- }
- Assertions.assertFalse(status);
- }
-}
diff --git
a/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestTransportClientHandler.java
b/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestTransportClientHandler.java
deleted file mode 100644
index 602096799..000000000
---
a/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestTransportClientHandler.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.core.handler.impl;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import org.apache.servicecomb.core.Endpoint;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestTransportClientHandler {
-
- private final Endpoint endpoint = mock(Endpoint.class);
-
- private final TransportClientHandler transportClientHandler =
TransportClientHandler.INSTANCE;
-
- private final Invocation invocation = mock(Invocation.class);
-
- private final AsyncResponse asyncResp = mock(AsyncResponse.class);
-
- private final Transport transport = mock(Transport.class);
-
- @Before
- public void setUp() throws Exception {
- when(transport.getEndpoint()).thenReturn(endpoint);
- when(endpoint.getEndpoint()).thenReturn("rest://localhost:8080");
- }
-
- @Test
- public void test() throws Exception {
- when(invocation.getTransport()).thenReturn(transport);
- when(invocation.getEndpoint()).thenReturn(endpoint);
- transportClientHandler.handle(invocation, asyncResp);
-
- verify(transport).send(invocation, asyncResp);
- }
-}
diff --git
a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToProducerResponseConverter.java
b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToProducerResponseConverter.java
index 5bb9382bb..0c1c87aa4 100644
---
a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToProducerResponseConverter.java
+++
b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToProducerResponseConverter.java
@@ -20,7 +20,7 @@ import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
/**
- * ExceptionToProducerResponseConverter are used to convert provider
Exceptions to user friendly messages.
+ * ExceptionToProducerResponseConverter are used to convert provider
Exceptions to user-friendly messages.
* They are called when :
* 1. exception happens executing business logic
* 2. exception happens in ProducerInvokeExtension.beforeMethodInvoke(e.g.
parameter validation)