From dce4afa5dd007b34fbbd19fef510a8784ef7af6b Mon Sep 17 00:00:00 2001 From: liuguangrong <50402852+liuguangrong@users.noreply.github.com> Date: Mon, 21 Dec 2020 14:34:24 +0800 Subject: [PATCH 1/4] Update RestClientInvocation.java --- .../transport/rest/client/http/RestClientInvocation.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 251b27eb937..9ac565be99b 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 @@ -35,6 +35,7 @@ import org.apache.servicecomb.foundation.common.net.URIEndpointObject; import org.apache.servicecomb.foundation.common.utils.ExceptionUtils; import org.apache.servicecomb.foundation.common.utils.JsonUtils; +import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils; import org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext; import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx; import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx; @@ -47,6 +48,7 @@ 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.apache.servicecomb.transport.rest.client.HttpRestClientInvocationHook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.StringUtils; @@ -116,12 +118,17 @@ public void invoke(Invocation invocation, AsyncResponse asyncResp) throws Except filter.beforeSendRequest(invocation, requestEx); } } + List httpRestClientInvocationHooks = + SPIServiceUtils.getAllService(HttpRestClientInvocationHook.class); clientRequest.exceptionHandler(e -> { invocation.getTraceIdLogger() .error(LOGGER, "Failed to send request, alreadyFailed:{}, local:{}, remote:{}, message={}.", alreadyFailed, getLocalAddress(), ipPort.getSocketAddress(), ExceptionUtils.getExceptionMessageWithoutTrace(e)); + httpRestClientInvocationHooks.forEach(httpServerExceptionHandler -> { + httpServerExceptionHandler.handle(e); + }); throwableHandler.handle(e); }); From 118c3a5949b7916efc4567eb29136292f2881c30 Mon Sep 17 00:00:00 2001 From: liuguangrong <50402852+liuguangrong@users.noreply.github.com> Date: Mon, 21 Dec 2020 14:35:34 +0800 Subject: [PATCH 2/4] Create HttpRestClientInvocationHook --- .../rest/client/HttpRestClientInvocationHook | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook new file mode 100644 index 00000000000..f5f354a2ae0 --- /dev/null +++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook @@ -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.transport.rest.client; + +import io.vertx.core.Handler; +import org.apache.servicecomb.foundation.common.utils.SPIOrder; + +public interface HttpRestClientInvocationHook extends Handler, SPIOrder { +} From 7f2d97d69cdb4dd5322db9ce3563a90cdc2ff816 Mon Sep 17 00:00:00 2001 From: liuguangrong <50402852+liuguangrong@users.noreply.github.com> Date: Mon, 21 Dec 2020 17:56:49 +0800 Subject: [PATCH 3/4] Delete HttpRestClientInvocationHook --- .../rest/client/HttpRestClientInvocationHook | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook deleted file mode 100644 index f5f354a2ae0..00000000000 --- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook +++ /dev/null @@ -1,24 +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.transport.rest.client; - -import io.vertx.core.Handler; -import org.apache.servicecomb.foundation.common.utils.SPIOrder; - -public interface HttpRestClientInvocationHook extends Handler, SPIOrder { -} From 19b5f7f6a7b027e2b2b55505a19947ae6312eab1 Mon Sep 17 00:00:00 2001 From: liuguangrong <50402852+liuguangrong@users.noreply.github.com> Date: Mon, 21 Dec 2020 17:57:59 +0800 Subject: [PATCH 4/4] Create HttpRestClientInvocationHook.java --- .../client/HttpRestClientInvocationHook.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook.java diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook.java new file mode 100644 index 00000000000..f5f354a2ae0 --- /dev/null +++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/HttpRestClientInvocationHook.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.transport.rest.client; + +import io.vertx.core.Handler; +import org.apache.servicecomb.foundation.common.utils.SPIOrder; + +public interface HttpRestClientInvocationHook extends Handler, SPIOrder { +}