wujimin closed pull request #1048: [SCB-1060]revert this : edge support Exception converter and make it … URL: https://github.com/apache/servicecomb-java-chassis/pull/1048
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): 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 000000000..9c210af44 --- /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 c9027e728..e616c8e9f 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 aae0bc174..ec4c3100d 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 6b2dd7305..8af3b3adf 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 @@ protected void fail(Throwable e) { } stageTrace.finishClientFiltersResponse(); - //convert exception - asyncResp.handle(ExceptionFactory.convertExceptionToResponse(invocation, e)); + asyncResp.fail(invocation.getInvocationType(), e); } protected void setCseContext() { ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
