You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2018/12/29 10:06:53 UTC
[servicecomb-java-chassis] branch master updated: [SCB-1060]revert
this : edge support Exception converter and make it another implementation
using handler
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 6b1ec5e [SCB-1060]revert this : edge support Exception converter and make it another implementation using handler
6b1ec5e is described below
commit 6b1ec5ea506617d0ea4eef1897437479ee76edb2
Author: liubao <ba...@huawei.com>
AuthorDate: Sat Dec 29 17:38:26 2018 +0800
[SCB-1060]revert this : edge support Exception converter and make it another implementation using handler
---
.../it/edge/handler/ExceptionConvertHandler.java | 45 ++++++++++++++++++++++
.../src/main/resources/config/cse.handler.xml | 1 +
.../it-edge/src/main/resources/microservice.yaml | 4 +-
.../rest/client/http/RestClientInvocation.java | 3 +-
4 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/integration-tests/it-edge/src/main/java/org/apache/servicecomb/it/edge/handler/ExceptionConvertHandler.java b/integration-tests/it-edge/src/main/java/org/apache/servicecomb/it/edge/handler/ExceptionConvertHandler.java
new file mode 100644
index 0000000..9c210af
--- /dev/null
+++ b/integration-tests/it-edge/src/main/java/org/apache/servicecomb/it/edge/handler/ExceptionConvertHandler.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.it.edge.handler;
+
+import java.util.concurrent.TimeoutException;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.servicecomb.core.Handler;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.it.edge.converter.CustomException;
+import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+
+public class ExceptionConvertHandler implements Handler {
+ @Override
+ public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
+ invocation.next(response -> {
+ if (response.isFailed()) {
+ Throwable e = response.getResult();
+ if (response.getResult() instanceof TimeoutException) {
+ CustomException customException = new CustomException("change the response", 777);
+ InvocationException stt = new InvocationException(Status.EXPECTATION_FAILED, customException);
+ response.setResult(stt);
+ }
+ }
+ asyncResp.complete(response);
+ });
+ }
+}
diff --git a/integration-tests/it-edge/src/main/resources/config/cse.handler.xml b/integration-tests/it-edge/src/main/resources/config/cse.handler.xml
index c9027e7..e616c8e 100644
--- a/integration-tests/it-edge/src/main/resources/config/cse.handler.xml
+++ b/integration-tests/it-edge/src/main/resources/config/cse.handler.xml
@@ -17,4 +17,5 @@
<config>
<handler id="auth" class="org.apache.servicecomb.it.edge.handler.AuthHandler"/>
+ <handler id="globalExceptionHandler" class="org.apache.servicecomb.it.edge.handler.ExceptionConvertHandler"/>
</config>
diff --git a/integration-tests/it-edge/src/main/resources/microservice.yaml b/integration-tests/it-edge/src/main/resources/microservice.yaml
index aae0bc1..ec4c310 100644
--- a/integration-tests/it-edge/src/main/resources/microservice.yaml
+++ b/integration-tests/it-edge/src/main/resources/microservice.yaml
@@ -22,9 +22,9 @@ servicecomb:
handler:
chain:
Consumer:
- default: loadbalance
+ default: globalExceptionHandler,loadbalance
service:
- it-auth: loadbalance
+ it-auth: globalExceptionHandler,loadbalance
# this is not the majority, not testing this feature by default
# rest:
# parameter:
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
index 6b2dd73..8af3b3a 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
@@ -244,8 +244,7 @@ public class RestClientInvocation {
}
stageTrace.finishClientFiltersResponse();
- //convert exception
- asyncResp.handle(ExceptionFactory.convertExceptionToResponse(invocation, e));
+ asyncResp.fail(invocation.getInvocationType(), e);
}
protected void setCseContext() {