You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2023/08/08 09:38:08 UTC
[servicecomb-java-chassis] 01/03: [SCB-2801]remove unused code for new filter
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
commit 78105e57716217aae1abffb583bd72d6494ba30f
Author: liubao <bi...@qq.com>
AuthorDate: Tue Aug 8 14:16:08 2023 +0800
[SCB-2801]remove unused code for new filter
---
.../common/rest/filter/HttpClientFilter.java | 46 ----
.../HttpClientFilterBeforeSendRequestExecutor.java | 92 -------
.../common/rest/filter/HttpServerFilter.java | 51 ----
...HttpServerFilterBeforeSendResponseExecutor.java | 92 -------
.../rest/filter/inner/ClientRestArgsFilter.java | 62 -----
.../rest/filter/inner/ServerRestArgsFilter.java | 94 -------
...servicecomb.common.rest.filter.HttpClientFilter | 18 --
...servicecomb.common.rest.filter.HttpServerFilter | 18 --
.../rest/filter/HttpClientFilterBaseForTest.java | 41 ---
.../rest/filter/HttpServerFilterBaseForTest.java | 33 ---
.../common/rest/filter/TestHttpClientFilter.java | 33 ---
.../common/rest/filter/TestHttpServerFilter.java | 56 ----
...HttpServerFilterBeforeSendResponseExecutor.java | 71 -----
.../filter/inner/TestServerRestArgsFilter.java | 66 -----
...servicecomb.common.rest.filter.HttpServerFilter | 21 --
.../jaxrs/server/JaxrsDemoHttpServerFilter.java | 49 ----
...servicecomb.common.rest.filter.HttpServerFilter | 18 --
demo/demo-signature/pom.xml | 40 ---
.../demo/signature/ClientSignature.java | 61 -----
.../demo/signature/ServerSignature.java | 54 ----
.../servicecomb/demo/signature/SignatureUtils.java | 80 ------
...servicecomb.common.rest.filter.HttpClientFilter | 18 --
...servicecomb.common.rest.filter.HttpServerFilter | 18 --
demo/pom.xml | 1 -
.../edge/core/EdgeAddHeaderClientFilter.java | 104 --------
.../servicecomb/edge/core/EdgeAddHeaderFilter.java | 61 ++++-
...servicecomb.common.rest.filter.HttpClientFilter | 18 --
...servicecomb.common.rest.filter.HttpServerFilter | 18 --
.../rest/client/http/DefaultHttpClientFilter.java | 148 -----------
...servicecomb.common.rest.filter.HttpClientFilter | 18 --
.../client/http/TestDefaultHttpClientFilter.java | 293 ---------------------
.../rest/servlet/ServletRestDispatcher.java | 14 +-
32 files changed, 62 insertions(+), 1745 deletions(-)
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpClientFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpClientFilter.java
deleted file mode 100644
index 3ae65ff94..000000000
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpClientFilter.java
+++ /dev/null
@@ -1,46 +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.common.rest.filter;
-
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-
-public interface HttpClientFilter {
- default boolean enabled() {
- return true;
- }
-
- int getOrder();
-
- /**
- * callback method before send a client request.
- */
- default CompletableFuture<Void> beforeSendRequestAsync(Invocation invocation, HttpServletRequestEx requestEx) {
- return CompletableFuture.completedFuture(null);
- }
-
- /**
- * @return if finished, then return a none null response<br>
- * if return a null response, then sdk will call next filter.afterReceiveResponse
- */
- Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx);
-}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpClientFilterBeforeSendRequestExecutor.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpClientFilterBeforeSendRequestExecutor.java
deleted file mode 100644
index b536aeb42..000000000
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpClientFilterBeforeSendRequestExecutor.java
+++ /dev/null
@@ -1,92 +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.common.rest.filter;
-
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-
-public class HttpClientFilterBeforeSendRequestExecutor {
- private final List<HttpClientFilter> httpClientFilters;
-
- private final Invocation invocation;
-
- private final HttpServletRequestEx requestEx;
-
- private int currentIndex;
-
- private final CompletableFuture<Void> future = new CompletableFuture<>();
-
- public HttpClientFilterBeforeSendRequestExecutor(List<HttpClientFilter> httpClientFilters, Invocation invocation,
- HttpServletRequestEx requestEx) {
- this.httpClientFilters = httpClientFilters;
- this.invocation = invocation;
- this.requestEx = requestEx;
- }
-
- public CompletableFuture<Void> run() {
- doRun();
-
- return future;
- }
-
- protected CompletableFuture<Void> safeInvoke(HttpClientFilter httpClientFilter) {
- try {
- if (httpClientFilter.enabled()) {
- CompletableFuture<Void> future = httpClientFilter.beforeSendRequestAsync(invocation, requestEx);
- if (future == null) {
- future = new CompletableFuture<>();
- future.completeExceptionally(new IllegalStateException(
- "HttpClientFilter beforeSendRequestAsync can not return null. Class="
- + httpClientFilter.getClass()
- .getName()));
- }
- return future;
- } else {
- CompletableFuture<Void> eFuture = new CompletableFuture<>();
- eFuture.complete(null);
- return eFuture;
- }
- } catch (Throwable e) {
- CompletableFuture<Void> eFuture = new CompletableFuture<>();
- eFuture.completeExceptionally(e);
- return eFuture;
- }
- }
-
- protected void doRun() {
- if (currentIndex == httpClientFilters.size()) {
- future.complete(null);
- return;
- }
-
- HttpClientFilter httpServerFilter = httpClientFilters.get(currentIndex);
- currentIndex++;
-
- CompletableFuture<Void> stepFuture = safeInvoke(httpServerFilter);
- stepFuture.whenComplete((v, e) -> {
- if (e == null) {
- doRun();
- return;
- }
-
- future.completeExceptionally(e);
- });
- }
-}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpServerFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpServerFilter.java
deleted file mode 100644
index 922e90725..000000000
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpServerFilter.java
+++ /dev/null
@@ -1,51 +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.common.rest.filter;
-
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-
-public interface HttpServerFilter {
- int getOrder();
-
- default boolean enabled() {
- return true;
- }
-
- default boolean needCacheRequest(OperationMeta operationMeta) {
- return false;
- }
-
- /**
- * @return if finished, then return a none null response<br>
- * if return a null response, then sdk will call next filter.afterReceiveRequest
- */
- Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx);
-
- /**
- * callback method before send a server response.
- */
- default CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
- return CompletableFuture.completedFuture(null);
- }
-}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpServerFilterBeforeSendResponseExecutor.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpServerFilterBeforeSendResponseExecutor.java
deleted file mode 100644
index 3c3c23ef2..000000000
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/HttpServerFilterBeforeSendResponseExecutor.java
+++ /dev/null
@@ -1,92 +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.common.rest.filter;
-
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-
-public class HttpServerFilterBeforeSendResponseExecutor {
- private final List<HttpServerFilter> httpServerFilters;
-
- private final Invocation invocation;
-
- private final HttpServletResponseEx responseEx;
-
- private int currentIndex;
-
- private final CompletableFuture<Void> future = new CompletableFuture<>();
-
- public HttpServerFilterBeforeSendResponseExecutor(List<HttpServerFilter> httpServerFilters, Invocation invocation,
- HttpServletResponseEx responseEx) {
- this.httpServerFilters = httpServerFilters;
- this.invocation = invocation;
- this.responseEx = responseEx;
- }
-
- public CompletableFuture<Void> run() {
- doRun();
-
- return future;
- }
-
- protected CompletableFuture<Void> safeInvoke(HttpServerFilter httpServerFilter) {
- try {
- if (httpServerFilter.enabled()) {
- CompletableFuture<Void> future = httpServerFilter.beforeSendResponseAsync(invocation, responseEx);
- if (future == null) {
- future = new CompletableFuture<>();
- future.completeExceptionally(new IllegalStateException(
- "HttpServerFilter beforeSendResponseAsync can not return null. Class="
- + httpServerFilter.getClass()
- .getName()));
- }
- return future;
- } else {
- CompletableFuture<Void> eFuture = new CompletableFuture<>();
- eFuture.complete(null);
- return eFuture;
- }
- } catch (Throwable e) {
- CompletableFuture<Void> eFuture = new CompletableFuture<>();
- eFuture.completeExceptionally(e);
- return eFuture;
- }
- }
-
- protected void doRun() {
- if (currentIndex == httpServerFilters.size()) {
- future.complete(null);
- return;
- }
-
- HttpServerFilter httpServerFilter = httpServerFilters.get(currentIndex);
- currentIndex++;
-
- CompletableFuture<Void> stepFuture = safeInvoke(httpServerFilter);
- stepFuture.whenComplete((v, e) -> {
- if (e == null) {
- doRun();
- return;
- }
-
- future.completeExceptionally(e);
- });
- }
-}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java
deleted file mode 100644
index a53283343..000000000
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java
+++ /dev/null
@@ -1,62 +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.common.rest.filter.inner;
-
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.common.rest.RestConst;
-import org.apache.servicecomb.common.rest.codec.RestCodec;
-import org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl;
-import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
-import org.apache.servicecomb.common.rest.filter.HttpClientFilter;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-
-public class ClientRestArgsFilter implements HttpClientFilter {
-
- @Override
- public int getOrder() {
- return -100;
- }
-
- @Override
- public CompletableFuture<Void> beforeSendRequestAsync(Invocation invocation, HttpServletRequestEx requestEx) {
- CompletableFuture<Void> result = new CompletableFuture<>();
- RestClientRequestImpl restClientRequest = (RestClientRequestImpl) invocation.getHandlerContext()
- .get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
- OperationMeta operationMeta = invocation.getOperationMeta();
- RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
- try {
- RestCodec.argsToRest(invocation.getSwaggerArguments(), swaggerRestOperation,
- restClientRequest);
- requestEx.setBodyBuffer(restClientRequest.getBodyBuffer());
- result.complete(null);
- } catch (Throwable e) {
- result.completeExceptionally(e);
- }
- return result;
- }
-
- @Override
- public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx) {
- return null;
- }
-}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java
deleted file mode 100644
index 63ae8eea9..000000000
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java
+++ /dev/null
@@ -1,94 +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.common.rest.filter.inner;
-
-import static org.apache.servicecomb.common.rest.filter.inner.RestServerCodecFilter.isDownloadFileResponseType;
-
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.common.rest.RestConst;
-import org.apache.servicecomb.common.rest.codec.RestCodec;
-import org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor;
-import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
-import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.foundation.common.utils.PartUtils;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-
-import com.netflix.config.DynamicPropertyFactory;
-
-import io.netty.buffer.Unpooled;
-
-public class ServerRestArgsFilter implements HttpServerFilter {
- private static final boolean enabled = DynamicPropertyFactory.getInstance().getBooleanProperty
- ("servicecomb.http.filter.server.serverRestArgs.enabled", true).get();
-
- @Override
- public int getOrder() {
- return -100;
- }
-
- @Override
- public boolean enabled() {
- return enabled;
- }
-
- @Override
- public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
- OperationMeta operationMeta = invocation.getOperationMeta();
- RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
- Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta);
- invocation.setSwaggerArguments(swaggerArguments);
- return null;
- }
-
- @Override
- public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
- Response response = (Response) responseEx.getAttribute(RestConst.INVOCATION_HANDLER_RESPONSE);
- ProduceProcessor produceProcessor =
- (ProduceProcessor) responseEx.getAttribute(RestConst.INVOCATION_HANDLER_PROCESSOR);
- Object body = response.getResult();
- if (response.isFailed()) {
- body = ((InvocationException) body).getErrorData();
- }
-
- if (null != invocation && isDownloadFileResponseType(invocation, response)) {
- return responseEx.sendPart(PartUtils.getSinglePart(null, body));
- }
-
- responseEx.setContentType(produceProcessor.getName() + "; charset=utf-8");
-
- CompletableFuture<Void> future = new CompletableFuture<>();
- try (BufferOutputStream output = new BufferOutputStream(Unpooled.compositeBuffer())) {
- produceProcessor.encodeResponse(output, body);
-
- responseEx.setBodyBuffer(output.getBuffer());
- future.complete(null);
- } catch (Throwable e) {
- future.completeExceptionally(ExceptionFactory.convertProducerException(e));
- }
- return future;
- }
-}
diff --git a/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter b/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter
deleted file mode 100644
index 6fccbe3e6..000000000
--- a/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.servicecomb.common.rest.filter.inner.ClientRestArgsFilter
\ No newline at end of file
diff --git a/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter b/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
deleted file mode 100644
index 8b2ffebbc..000000000
--- a/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.servicecomb.common.rest.filter.inner.ServerRestArgsFilter
\ No newline at end of file
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/HttpClientFilterBaseForTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/HttpClientFilterBaseForTest.java
deleted file mode 100644
index 7903b199e..000000000
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/HttpClientFilterBaseForTest.java
+++ /dev/null
@@ -1,41 +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.common.rest.filter;
-
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-
-public class HttpClientFilterBaseForTest implements HttpClientFilter {
- @Override
- public int getOrder() {
- return 0;
- }
-
- @Override
- public CompletableFuture<Void> beforeSendRequestAsync(Invocation invocation, HttpServletRequestEx requestEx) {
- return null;
- }
-
- @Override
- public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx) {
- return null;
- }
-}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/HttpServerFilterBaseForTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/HttpServerFilterBaseForTest.java
deleted file mode 100644
index 24ccd95a8..000000000
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/HttpServerFilterBaseForTest.java
+++ /dev/null
@@ -1,33 +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.common.rest.filter;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-
-public class HttpServerFilterBaseForTest implements HttpServerFilter {
- @Override
- public int getOrder() {
- return 0;
- }
-
- @Override
- public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
- return null;
- }
-}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpClientFilter.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpClientFilter.java
deleted file mode 100644
index afc788b92..000000000
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpClientFilter.java
+++ /dev/null
@@ -1,33 +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.common.rest.filter;
-
-import java.util.Arrays;
-import java.util.concurrent.ExecutionException;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TestHttpClientFilter {
- @Test
- public void asyncFailed() {
- HttpClientFilter filter = new HttpClientFilterBaseForTest();
- HttpClientFilterBeforeSendRequestExecutor executor =
- new HttpClientFilterBeforeSendRequestExecutor(Arrays.asList(filter), null, null);
- Assertions.assertThrows(ExecutionException.class, () -> executor.run().get());
- }
-}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilter.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilter.java
deleted file mode 100644
index a27073f17..000000000
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilter.java
+++ /dev/null
@@ -1,56 +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.common.rest.filter;
-
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TestHttpServerFilter {
-
- @Test
- public void asyncSucc() throws InterruptedException, ExecutionException {
- HttpServerFilter filter = new HttpServerFilterBaseForTest();
-
- CompletableFuture<Void> future = filter.beforeSendResponseAsync(null, null);
- Assertions.assertNull(future.get());
- }
-
- @Test
- public void asyncFailed() throws InterruptedException, ExecutionException {
- HttpServerFilter filter = new HttpServerFilterBaseForTest() {
- @Override
- public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
- CompletableFuture<Void> result = new CompletableFuture<>();
- result.completeExceptionally(new RuntimeExceptionWithoutStackTrace());
- return result;
- }
- };
-
- ExecutionException exception = Assertions.assertThrows(ExecutionException.class,
- () -> {
- CompletableFuture<Void> future = filter.beforeSendResponseAsync(null, null);
- future.get();
- });
- Assertions.assertTrue(exception.getCause() instanceof RuntimeExceptionWithoutStackTrace);
- }
-}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilterBeforeSendResponseExecutor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilterBeforeSendResponseExecutor.java
deleted file mode 100644
index 169c2fda5..000000000
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilterBeforeSendResponseExecutor.java
+++ /dev/null
@@ -1,71 +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.common.rest.filter;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.junit.jupiter.api.Assertions;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mock;
-
-public class TestHttpServerFilterBeforeSendResponseExecutor {
- @Mock
- Invocation invocation;
-
- @Mock
- HttpServletResponseEx responseEx;
-
- final List<HttpServerFilter> httpServerFilters = new ArrayList<>();
-
- final HttpServerFilterBeforeSendResponseExecutor executor =
- new HttpServerFilterBeforeSendResponseExecutor(httpServerFilters, invocation, responseEx);
-
- @BeforeEach
- public void setup() {
- httpServerFilters.add(new HttpServerFilterBaseForTest());
- }
-
- @Test
- public void runSucc() throws InterruptedException, ExecutionException {
- CompletableFuture<Void> result = executor.run();
-
- Assertions.assertNull(result.get());
- }
-
- @Test
- public void runFail() throws InterruptedException, ExecutionException {
- httpServerFilters.add(new HttpServerFilterBaseForTest() {
- @Override
- public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
- throw new RuntimeExceptionWithoutStackTrace();
- }
- });
-
- CompletableFuture<Void> result = executor.run();
-
- ExecutionException exception = Assertions.assertThrows(ExecutionException.class, result::get);
- Assertions.assertTrue(exception.getCause() instanceof RuntimeExceptionWithoutStackTrace);
- }
-}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/TestServerRestArgsFilter.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/TestServerRestArgsFilter.java
deleted file mode 100644
index cdc9946ea..000000000
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/TestServerRestArgsFilter.java
+++ /dev/null
@@ -1,66 +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.common.rest.filter.inner;
-
-import jakarta.servlet.http.Part;
-
-import org.apache.servicecomb.common.rest.RestConst;
-import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.response.ResponsesMeta;
-import org.junit.jupiter.api.Assertions;
-
-import com.fasterxml.jackson.databind.type.TypeFactory;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-
-
-public class TestServerRestArgsFilter {
-
- final Invocation invocation = Mockito.mock(Invocation.class);
-
- final HttpServletResponseEx responseEx = Mockito.mock(HttpServletResponseEx.class);
-
- final Response response = Mockito.mock(Response.class);
-
- final Part part = Mockito.mock(Part.class);
-
- boolean invokedSendPart;
-
- final ServerRestArgsFilter filter = new ServerRestArgsFilter();
-
- @Test
- public void asyncBeforeSendResponse_part() {
- ResponsesMeta responsesMeta = new ResponsesMeta();
- responsesMeta.getResponseMap().put(202, RestObjectMapperFactory.getRestObjectMapper().constructType(Part.class));
-
- Mockito.when(responseEx.getAttribute(RestConst.INVOCATION_HANDLER_RESPONSE)).thenReturn(response);
- Mockito.when(response.getResult()).thenReturn(part);
- Mockito.when(response.getStatusCode()).thenReturn(202);
- Mockito.when(invocation.findResponseType(202)).thenReturn(TypeFactory.defaultInstance().constructType(Part.class));
-
- Mockito.doAnswer(invocationOnMock -> {
- invokedSendPart = true;
- return null;
- }).when(responseEx).sendPart(part);
-
- Assertions.assertNull(filter.beforeSendResponseAsync(invocation, responseEx));
- Assertions.assertTrue(invokedSendPart);
- }
-}
diff --git a/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter b/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
deleted file mode 100644
index eb91526f3..000000000
--- a/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
+++ /dev/null
@@ -1,21 +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.
-#
-
-org.apache.servicecomb.demo.edge.service.encrypt.filter.EdgeSignatureRequestFilter
-org.apache.servicecomb.demo.edge.service.encrypt.filter.DecodeBodyFilter
-org.apache.servicecomb.demo.edge.service.encrypt.filter.UserIdFilter
-org.apache.servicecomb.demo.edge.service.encrypt.filter.EdgeSignatureResponseFilter
\ No newline at end of file
diff --git a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/JaxrsDemoHttpServerFilter.java b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/JaxrsDemoHttpServerFilter.java
deleted file mode 100644
index 726a3aeed..000000000
--- a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/JaxrsDemoHttpServerFilter.java
+++ /dev/null
@@ -1,49 +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.demo.jaxrs.server;
-
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class JaxrsDemoHttpServerFilter implements HttpServerFilter {
- private static final Logger LOGGER = LoggerFactory.getLogger(JaxrsDemoHttpServerFilter.class);
-
- @Override
- public int getOrder() {
- return 0;
- }
-
- @Override
- public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
- return null;
- }
-
- @Override
- public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
- // in 404 situation, invocation is null and a NPE is thrown
- LOGGER.info("JaxrsDemoHttpServerFilter is called, operation=[{}]", invocation.getOperationName());
- return CompletableFuture.completedFuture(null);
- }
-}
diff --git a/demo/demo-jaxrs/jaxrs-server/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter b/demo/demo-jaxrs/jaxrs-server/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
deleted file mode 100644
index 5e737d86d..000000000
--- a/demo/demo-jaxrs/jaxrs-server/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.servicecomb.demo.jaxrs.server.JaxrsDemoHttpServerFilter
\ No newline at end of file
diff --git a/demo/demo-signature/pom.xml b/demo/demo-signature/pom.xml
deleted file mode 100644
index e4e35f3f8..000000000
--- a/demo/demo-signature/pom.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.servicecomb.demo</groupId>
- <artifactId>demo-parent</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- </parent>
- <artifactId>demo-signature</artifactId>
- <name>Java Chassis::Demo::Signature</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>common-rest</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>registry-service-center</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ClientSignature.java b/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ClientSignature.java
deleted file mode 100644
index 833948f76..000000000
--- a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ClientSignature.java
+++ /dev/null
@@ -1,61 +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.demo.signature;
-
-import java.util.concurrent.CompletableFuture;
-
-import jakarta.ws.rs.core.Response.Status;
-
-import org.apache.servicecomb.common.rest.filter.HttpClientFilter;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ClientSignature implements HttpClientFilter {
- private static final Logger LOGGER = LoggerFactory.getLogger(ClientSignature.class);
-
- @Override
- public int getOrder() {
- return 0;
- }
-
- @Override
- public CompletableFuture<Void> beforeSendRequestAsync(Invocation invocation, HttpServletRequestEx requestEx) {
- String signature = SignatureUtils.genSignature(requestEx);
- requestEx.setHeader("signature", signature);
- return CompletableFuture.completedFuture(null);
- }
-
- @Override
- public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx) {
- String signature = SignatureUtils.genSignature(responseEx);
- String serverSignature = responseEx.getHeader("signature");
-
- if (serverSignature != null) {
- LOGGER.debug("check response signature, client: {}, server: {}.", signature, serverSignature);
- if (!signature.equals(serverSignature)) {
- LOGGER.error("check response signature failed");
- return Response.create(Status.UNAUTHORIZED, "check response signature failed");
- }
- }
- return null;
- }
-}
diff --git a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ServerSignature.java b/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ServerSignature.java
deleted file mode 100644
index b39b60371..000000000
--- a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ServerSignature.java
+++ /dev/null
@@ -1,54 +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.demo.signature;
-
-import java.util.concurrent.CompletableFuture;
-
-import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-
-public class ServerSignature implements HttpServerFilter {
- public ServerSignature() {
- }
-
- @Override
- public int getOrder() {
- return 0;
- }
-
- @Override
- public boolean needCacheRequest(OperationMeta operationMeta) {
- return true;
- }
-
- @Override
- public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
- return null;
- }
-
- @Override
- public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
- String signature = SignatureUtils.genSignature(responseEx);
- responseEx.addHeader("signature", signature);
- return CompletableFuture.completedFuture(null);
- }
-}
diff --git a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/SignatureUtils.java b/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/SignatureUtils.java
deleted file mode 100644
index 41c334c85..000000000
--- a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/SignatureUtils.java
+++ /dev/null
@@ -1,80 +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.demo.signature;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-import jakarta.ws.rs.core.MediaType;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
-import com.netflix.config.DynamicStringListProperty;
-
-public class SignatureUtils {
- private static final DynamicStringListProperty PARAM_NAMES_PROPERTY =
- new DynamicStringListProperty("servicecomb.demo.signature.param-names", Arrays.asList("userId"));
-
- private static List<String> paramNames = PARAM_NAMES_PROPERTY.get();
-
- static {
- PARAM_NAMES_PROPERTY.addCallback(() -> {
- List<String> tmpNames = PARAM_NAMES_PROPERTY.get();
- tmpNames.sort(Comparator.naturalOrder());
- paramNames = tmpNames;
- });
- }
-
- public static String genSignature(HttpServletRequestEx requestEx) {
- Hasher hasher = Hashing.sha256().newHasher();
- hasher.putString(requestEx.getRequestURI(), StandardCharsets.UTF_8);
- for (String paramName : paramNames) {
- String paramValue = requestEx.getHeader(paramName);
- if (paramValue != null) {
- hasher.putString(paramName, StandardCharsets.UTF_8);
- hasher.putString(paramValue, StandardCharsets.UTF_8);
- System.out.printf("%s %s\n", paramName, paramValue);
- }
- }
-
- if (!StringUtils.startsWithIgnoreCase(requestEx.getContentType(), MediaType.APPLICATION_FORM_URLENCODED)) {
- byte[] bytes = requestEx.getBodyBytes();
- if (bytes != null) {
- hasher.putBytes(bytes, 0, requestEx.getBodyBytesLength());
- }
- }
-
- return hasher.hash().toString();
- }
-
- public static String genSignature(HttpServletResponseEx responseEx) {
- Hasher hasher = Hashing.sha256().newHasher();
- byte[] bytes = responseEx.getBodyBytes();
- if (bytes != null) {
- hasher.putBytes(bytes, 0, responseEx.getBodyBytesLength());
- }
-
- return hasher.hash().toString();
- }
-}
diff --git a/demo/demo-signature/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter b/demo/demo-signature/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter
deleted file mode 100644
index 9533c7956..000000000
--- a/demo/demo-signature/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.servicecomb.demo.signature.ClientSignature
diff --git a/demo/demo-signature/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter b/demo/demo-signature/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
deleted file mode 100644
index 37d767122..000000000
--- a/demo/demo-signature/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.servicecomb.demo.signature.ServerSignature
diff --git a/demo/pom.xml b/demo/pom.xml
index 7ad42adf4..06b7a9fd2 100644
--- a/demo/pom.xml
+++ b/demo/pom.xml
@@ -53,7 +53,6 @@
<module>demo-edge</module>
<module>demo-multiple</module>
<module>demo-multi-service-center</module>
- <module>demo-signature</module>
<module>demo-cse-v1</module>
<module>demo-cse-v2</module>
</modules>
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderClientFilter.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderClientFilter.java
deleted file mode 100644
index 49258fab9..000000000
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderClientFilter.java
+++ /dev/null
@@ -1,104 +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.edge.core;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.BiConsumer;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.common.rest.filter.HttpClientFilter;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.DynamicPropertyFactory;
-
-public class EdgeAddHeaderClientFilter implements HttpClientFilter {
- private static final Logger LOGGER = LoggerFactory.getLogger(EdgeAddHeaderClientFilter.class);
-
- private static final String PREFIX = "servicecomb.edge.filter.addHeader";
-
- private static final String KEY_ENABLED = PREFIX + ".enabled";
-
- private static final String KEY_HEADERS = PREFIX + ".allowedHeaders";
-
- private List<String> publicHeaders = new ArrayList<>();
-
- private boolean enabled = false;
-
- public EdgeAddHeaderClientFilter() {
- init();
- ConfigurationManager.getConfigInstance()
- .addConfigurationListener(event -> {
- if (StringUtils.startsWith(event.getPropertyName(), PREFIX)) {
- LOGGER.info("Public headers config have been changed. Event=" + event.getType());
- init();
- }
- });
- }
-
- private void init() {
- enabled = DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_ENABLED, false).get();
- String publicHeaderStr = DynamicPropertyFactory.getInstance().getStringProperty(KEY_HEADERS, "").get();
- String[] split = publicHeaderStr.split(",");
- if (split.length > 0) {
- publicHeaders = Arrays.asList(split);
- }
- }
-
- @Override
- public int getOrder() {
- return 0;
- }
-
- @Override
- public boolean enabled() {
- return enabled;
- }
-
- @Override
- public CompletableFuture<Void> beforeSendRequestAsync(Invocation invocation, HttpServletRequestEx requestEx) {
- addHeaders(invocation, requestEx::addHeader);
- return CompletableFuture.completedFuture(null);
- }
-
- public void addHeaders(Invocation invocation, BiConsumer<String, String> headerAdder) {
- if (!invocation.isEdge()) {
- return;
- }
-
- HttpServletRequestEx oldRequest = invocation.getRequestEx();
- publicHeaders.forEach(key -> {
- String value = oldRequest.getHeader(key);
- if (StringUtils.isNotEmpty(value)) {
- headerAdder.accept(key, value);
- }
- });
- }
-
- @Override
- public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx) {
- return null;
- }
-}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
index 8962ed181..333a36edf 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
@@ -16,22 +16,63 @@
*/
package org.apache.servicecomb.edge.core;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.concurrent.CompletableFuture;
+import java.util.function.BiConsumer;
import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.transport.rest.client.RestClientTransportContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.netflix.config.ConfigurationManager;
+import com.netflix.config.DynamicPropertyFactory;
public class EdgeAddHeaderFilter implements ConsumerFilter {
+ private static final Logger LOGGER = LoggerFactory.getLogger(EdgeAddHeaderFilter.class);
+
public static final String NAME = "edge-add-headers";
- private final EdgeAddHeaderClientFilter filter = new EdgeAddHeaderClientFilter();
+ private static final String PREFIX = "servicecomb.edge.filter.addHeader";
+
+ private static final String KEY_ENABLED = PREFIX + ".enabled";
+
+ private static final String KEY_HEADERS = PREFIX + ".allowedHeaders";
+
+ private List<String> publicHeaders = new ArrayList<>();
+
+ private boolean enabled = false;
+
+ public EdgeAddHeaderFilter() {
+ init();
+ ConfigurationManager.getConfigInstance()
+ .addConfigurationListener(event -> {
+ if (StringUtils.startsWith(event.getPropertyName(), PREFIX)) {
+ LOGGER.info("Public headers config have been changed. Event=" + event.getType());
+ init();
+ }
+ });
+ }
+
+ private void init() {
+ enabled = DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_ENABLED, false).get();
+ String publicHeaderStr = DynamicPropertyFactory.getInstance().getStringProperty(KEY_HEADERS, "").get();
+ String[] split = publicHeaderStr.split(",");
+ if (split.length > 0) {
+ publicHeaders = Arrays.asList(split);
+ }
+ }
@Nonnull
@Override
@@ -41,7 +82,7 @@ public class EdgeAddHeaderFilter implements ConsumerFilter {
@Override
public boolean isEnabledForTransport(String transport) {
- return filter.enabled();
+ return enabled;
}
@Override
@@ -54,10 +95,24 @@ public class EdgeAddHeaderFilter implements ConsumerFilter {
RestClientTransportContext transportContext = invocation.getTransportContext();
if (transportContext != null) {
return CompletableFuture.completedFuture(null)
- .thenAccept(v -> filter.addHeaders(invocation, transportContext.getHttpClientRequest()::putHeader))
+ .thenAccept(v -> addHeaders(invocation, transportContext.getHttpClientRequest()::putHeader))
.thenCompose(v -> nextNode.onFilter(invocation));
}
// normal consumer in edge process
return nextNode.onFilter(invocation);
}
+
+ public void addHeaders(Invocation invocation, BiConsumer<String, String> headerAdder) {
+ if (!invocation.isEdge()) {
+ return;
+ }
+
+ HttpServletRequestEx oldRequest = invocation.getRequestEx();
+ publicHeaders.forEach(key -> {
+ String value = oldRequest.getHeader(key);
+ if (StringUtils.isNotEmpty(value)) {
+ headerAdder.accept(key, value);
+ }
+ });
+ }
}
diff --git a/edge/edge-core/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter b/edge/edge-core/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter
deleted file mode 100644
index c07a4b762..000000000
--- a/edge/edge-core/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.servicecomb.edge.core.EdgeAddHeaderClientFilter
diff --git a/handlers/handler-router/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter b/handlers/handler-router/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
deleted file mode 100644
index 065e42fad..000000000
--- a/handlers/handler-router/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.servicecomb.router.custom.RouterAddHeaderFilter
\ No newline at end of file
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/DefaultHttpClientFilter.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/DefaultHttpClientFilter.java
deleted file mode 100644
index e3016022a..000000000
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/DefaultHttpClientFilter.java
+++ /dev/null
@@ -1,148 +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.http;
-
-import java.util.Collection;
-import java.util.concurrent.CompletableFuture;
-
-import jakarta.ws.rs.core.HttpHeaders;
-
-import org.apache.servicecomb.common.rest.RestConst;
-import org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor;
-import org.apache.servicecomb.common.rest.codec.produce.ProduceProcessorManager;
-import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
-import org.apache.servicecomb.common.rest.filter.HttpClientFilter;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.context.HttpStatus;
-import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.databind.JavaType;
-import com.netflix.config.DynamicPropertyFactory;
-
-public class DefaultHttpClientFilter implements HttpClientFilter {
- private static final Logger LOGGER = LoggerFactory.getLogger(DefaultHttpClientFilter.class);
-
- private static final boolean enabled = DynamicPropertyFactory.getInstance().getBooleanProperty
- ("servicecomb.http.filter.client.default.enabled", true).get();
-
- @Override
- public int getOrder() {
- return 10000;
- }
-
- @Override
- public CompletableFuture<Void> beforeSendRequestAsync(Invocation invocation, HttpServletRequestEx requestEx) {
- return CompletableFuture.completedFuture(null);
- }
-
- @Override
- public boolean enabled() {
- return enabled;
- }
-
- protected ProduceProcessor findProduceProcessor(RestOperationMeta restOperation,
- HttpServletResponseEx responseEx) {
- String contentType = responseEx.getHeader(HttpHeaders.CONTENT_TYPE);
- if (contentType == null) {
- return null;
- }
-
- String contentTypeForFind = contentType;
- int idx = contentType.indexOf(';');
- if (idx != -1) {
- contentTypeForFind = contentType.substring(0, idx);
- }
- return restOperation.findProduceProcessor(contentTypeForFind);
- }
-
- protected Response extractResponse(Invocation invocation, HttpServletResponseEx responseEx) {
- Object result = invocation.getHandlerContext().get(RestConst.READ_STREAM_PART);
- if (result != null) {
- return Response.create(responseEx.getStatusType(), result);
- }
-
- OperationMeta operationMeta = invocation.getOperationMeta();
- JavaType responseType = invocation.findResponseType(responseEx.getStatus());
- RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
- ProduceProcessor produceProcessor = findProduceProcessor(swaggerRestOperation, responseEx);
- if (produceProcessor == null) {
- // This happens outside the runtime such as Servlet filter response. Here we give a default json parser to it
- // and keep user data not get lose.
- String msg =
- String.format("method %s, path %s, statusCode %d, reasonPhrase %s, response content-type %s is not supported",
- swaggerRestOperation.getHttpMethod(),
- swaggerRestOperation.getAbsolutePath(),
- responseEx.getStatus(),
- responseEx.getStatusType().getReasonPhrase(),
- responseEx.getHeader(HttpHeaders.CONTENT_TYPE));
- LOGGER.warn(msg);
- produceProcessor = ProduceProcessorManager.INSTANCE.findDefaultProcessor();
- }
-
- try {
- result = produceProcessor.decodeResponse(responseEx.getBodyBuffer(), responseType);
- Response response = Response.create(responseEx.getStatusType(), result);
- if (response.isFailed()) {
- LOGGER.warn("invoke operation [{}] failed, status={}, msg={}", invocation.getMicroserviceQualifiedName(),
- responseEx.getStatusType().getStatusCode(), result == null ? "" : result.toString());
- }
- return response;
- } catch (Exception e) {
- LOGGER.error("failed to decode response body, exception is [{}]", e.getMessage());
- String msg =
- String.format("method %s, path %s, statusCode %d, reasonPhrase %s, response content-type %s is not supported",
- swaggerRestOperation.getHttpMethod(),
- swaggerRestOperation.getAbsolutePath(),
- responseEx.getStatus(),
- responseEx.getStatusType().getReasonPhrase(),
- responseEx.getHeader(HttpHeaders.CONTENT_TYPE));
- if (HttpStatus.isSuccess(responseEx.getStatus())) {
- return Response.createConsumerFail(
- new InvocationException(400, responseEx.getStatusType().getReasonPhrase(),
- new CommonExceptionData(msg), e));
- }
- return Response.createConsumerFail(
- new InvocationException(responseEx.getStatus(), responseEx.getStatusType().getReasonPhrase(),
- new CommonExceptionData(msg), e));
- }
- }
-
- @Override
- public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx) {
- Response response = extractResponse(invocation, responseEx);
-
- for (String headerName : responseEx.getHeaderNames()) {
- if (headerName.equals(":status")) {
- continue;
- }
- Collection<String> headerValues = responseEx.getHeaders(headerName);
- for (String headerValue : headerValues) {
- response.addHeader(headerName, headerValue);
- }
- }
-
- return response;
- }
-}
diff --git a/transports/transport-rest/transport-rest-client/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter b/transports/transport-rest/transport-rest-client/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter
deleted file mode 100644
index 8addf988d..000000000
--- a/transports/transport-rest/transport-rest-client/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpClientFilter
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.servicecomb.transport.rest.client.http.DefaultHttpClientFilter
diff --git a/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestDefaultHttpClientFilter.java b/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestDefaultHttpClientFilter.java
deleted file mode 100644
index fb687a57c..000000000
--- a/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestDefaultHttpClientFilter.java
+++ /dev/null
@@ -1,293 +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.http;
-
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.Response.Status;
-
-import org.apache.servicecomb.common.rest.RestConst;
-import org.apache.servicecomb.common.rest.codec.produce.ProduceJsonProcessor;
-import org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor;
-import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.foundation.common.utils.JsonUtils;
-import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.apache.servicecomb.foundation.vertx.http.ReadStreamPart;
-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.junit.Test;
-
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.type.SimpleType;
-
-import io.vertx.core.MultiMap;
-import io.vertx.core.buffer.Buffer;
-import io.vertx.core.buffer.impl.BufferImpl;
-import mockit.Expectations;
-import mockit.Mock;
-import mockit.MockUp;
-import mockit.Mocked;
-import org.junit.jupiter.api.Assertions;
-
-public class TestDefaultHttpClientFilter {
- private final DefaultHttpClientFilter filter = new DefaultHttpClientFilter();
-
- @Test
- public void testOrder() {
- Assertions.assertEquals(10000, filter.getOrder());
- }
-
- @Test
- public void testFindProduceProcessorNullContentType(@Mocked RestOperationMeta restOperation,
- @Mocked HttpServletResponseEx responseEx) {
- new Expectations() {
- {
- responseEx.getHeader(HttpHeaders.CONTENT_TYPE);
- result = null;
- }
- };
-
- Assertions.assertNull(filter.findProduceProcessor(restOperation, responseEx));
- }
-
- @Test
- public void testFindProduceProcessorJson(@Mocked RestOperationMeta restOperation,
- @Mocked HttpServletResponseEx responseEx, @Mocked ProduceProcessor produceProcessor) {
- new Expectations() {
- {
- responseEx.getHeader(HttpHeaders.CONTENT_TYPE);
- result = "json";
- restOperation.findProduceProcessor("json");
- result = produceProcessor;
- }
- };
-
- Assertions.assertSame(produceProcessor, filter.findProduceProcessor(restOperation, responseEx));
- }
-
- @Test
- public void testFindProduceProcessorJsonWithCharset(@Mocked RestOperationMeta restOperation,
- @Mocked HttpServletResponseEx responseEx, @Mocked ProduceProcessor produceProcessor) {
- new Expectations() {
- {
- responseEx.getHeader(HttpHeaders.CONTENT_TYPE);
- result = "json; UTF-8";
- restOperation.findProduceProcessor("json");
- result = produceProcessor;
- }
- };
-
- Assertions.assertSame(produceProcessor, filter.findProduceProcessor(restOperation, responseEx));
- }
-
- @Test
- public void extractResult_readStreamPart(@Mocked Invocation invocation, @Mocked ReadStreamPart part,
- @Mocked HttpServletResponseEx responseEx) {
- Map<String, Object> handlerContext = new HashMap<>();
- handlerContext.put(RestConst.READ_STREAM_PART, part);
- new Expectations() {
- {
- invocation.getHandlerContext();
- result = handlerContext;
- responseEx.getStatusType();
- result = Status.OK;
- }
- };
-
- Response response = filter.extractResponse(invocation, responseEx);
- Assertions.assertSame(part, response.getResult());
- Assertions.assertEquals(Status.OK, response.getStatus());
- }
-
- @Test
- public void extractResult_decodeError(@Mocked Invocation invocation, @Mocked ReadStreamPart part,
- @Mocked OperationMeta operationMeta,
- @Mocked RestOperationMeta swaggerRestOperation,
- @Mocked HttpServletResponseEx responseEx) {
- Map<String, Object> handlerContext = new HashMap<>();
- new Expectations() {
- {
- invocation.getHandlerContext();
- result = handlerContext;
- invocation.getOperationMeta();
- result = operationMeta;
- invocation.findResponseType(400);
- result = SimpleType.constructUnsafe(Date.class);
- operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
- result = swaggerRestOperation;
- responseEx.getStatus();
- result = 400;
- responseEx.getBodyBuffer();
- result = new BufferImpl().appendString("abc");
- }
- };
- new MockUp<DefaultHttpClientFilter>() {
- @Mock
- ProduceProcessor findProduceProcessor(RestOperationMeta restOperation, HttpServletResponseEx responseEx) {
- return new ProduceJsonProcessor();
- }
- };
-
- Response response = filter.extractResponse(invocation, responseEx);
- Assertions.assertEquals(400, response.getStatusCode());
- Assertions.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
- InvocationException invocationException = response.getResult();
- Assertions.assertEquals(
- "InvocationException: code=400;msg=CommonExceptionData [message=method null, path null, statusCode 400, reasonPhrase null, response content-type null is not supported]",
- invocationException.getMessage());
- Assertions.assertEquals(
- "Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n"
- + " at [Source: (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream); line: 1, column: 4]",
- invocationException.getCause().getMessage());
- Assertions.assertEquals(CommonExceptionData.class, invocationException.getErrorData().getClass());
- CommonExceptionData commonExceptionData = (CommonExceptionData) invocationException.getErrorData();
- Assertions.assertEquals(
- "method null, path null, statusCode 400, reasonPhrase null, response content-type null is not supported",
- commonExceptionData.getMessage());
- }
-
- @Test
- public void extractResult_decodeError200(@Mocked Invocation invocation, @Mocked ReadStreamPart part,
- @Mocked OperationMeta operationMeta,
- @Mocked RestOperationMeta swaggerRestOperation,
- @Mocked HttpServletResponseEx responseEx) {
- Map<String, Object> handlerContext = new HashMap<>();
- new Expectations() {
- {
- invocation.getHandlerContext();
- result = handlerContext;
- invocation.getOperationMeta();
- result = operationMeta;
- invocation.findResponseType(200);
- result = SimpleType.constructUnsafe(Date.class);
- operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
- result = swaggerRestOperation;
- responseEx.getStatus();
- result = 200;
- responseEx.getBodyBuffer();
- result = new BufferImpl().appendString("abc");
- }
- };
- new MockUp<DefaultHttpClientFilter>() {
- @Mock
- ProduceProcessor findProduceProcessor(RestOperationMeta restOperation, HttpServletResponseEx responseEx) {
- return new ProduceJsonProcessor();
- }
- };
-
- Response response = filter.extractResponse(invocation, responseEx);
- Assertions.assertEquals(400, response.getStatusCode());
- Assertions.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
- InvocationException invocationException = response.getResult();
- Assertions.assertEquals(
- "InvocationException: code=400;msg=CommonExceptionData [message=method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported]",
- invocationException.getMessage());
- Assertions.assertEquals(
- "Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n"
- + " at [Source: (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream); line: 1, column: 4]",
- invocationException.getCause().getMessage());
- Assertions.assertEquals(CommonExceptionData.class, invocationException.getErrorData().getClass());
- CommonExceptionData commonExceptionData = (CommonExceptionData) invocationException.getErrorData();
- Assertions.assertEquals(
- "method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported",
- commonExceptionData.getMessage());
- }
-
- @Test
- public void testAfterReceiveResponseNullProduceProcessor(@Mocked Invocation invocation,
- @Mocked HttpServletResponseEx responseEx,
- @Mocked OperationMeta operationMeta,
- @Mocked RestOperationMeta swaggerRestOperation) throws Exception {
- CommonExceptionData data = new CommonExceptionData("abcd");
- new Expectations() {
- {
- invocation.getOperationMeta();
- result = operationMeta;
- operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
- result = swaggerRestOperation;
- invocation.findResponseType(403);
- result = SimpleType.constructUnsafe(CommonExceptionData.class);
- responseEx.getStatus();
- result = 403;
- responseEx.getStatusType();
- result = Status.FORBIDDEN;
- responseEx.getBodyBuffer();
- result = Buffer.buffer(JsonUtils.writeValueAsString(data).getBytes());
- }
- };
-
- Response response = filter.afterReceiveResponse(invocation, responseEx);
- Assertions.assertEquals(403, response.getStatusCode());
- Assertions.assertEquals("Forbidden", response.getReasonPhrase());
- Assertions.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
- InvocationException invocationException = response.getResult();
- Assertions.assertEquals(
- 403,
- invocationException.getStatusCode());
- Assertions.assertEquals(
- "CommonExceptionData [message=abcd]",
- invocationException.getErrorData().toString());
- }
-
- @Test
- public void testAfterReceiveResponseNormal(@Mocked Invocation invocation,
- @Mocked HttpServletResponseEx responseEx,
- @Mocked Buffer bodyBuffer,
- @Mocked OperationMeta operationMeta,
- @Mocked RestOperationMeta swaggerRestOperation,
- @Mocked ProduceProcessor produceProcessor) throws Exception {
- MultiMap responseHeader = MultiMap.caseInsensitiveMultiMap();
- responseHeader.add("b", "bValue");
-
- Object decodedResult = new Object();
- new Expectations() {
- {
- responseEx.getHeader(HttpHeaders.CONTENT_TYPE);
- result = "json";
- responseEx.getHeaderNames();
- result = Arrays.asList("a", "b");
- responseEx.getHeaders("b");
- result = responseHeader.getAll("b");
- swaggerRestOperation.findProduceProcessor("json");
- result = produceProcessor;
- produceProcessor.decodeResponse(bodyBuffer, (JavaType) any);
- result = decodedResult;
-
- invocation.getOperationMeta();
- result = operationMeta;
- operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
- result = swaggerRestOperation;
-
- responseEx.getStatusType();
- result = Status.OK;
- }
- };
-
- Response response = filter.afterReceiveResponse(invocation, responseEx);
- Assertions.assertSame(decodedResult, response.getResult());
- Assertions.assertEquals(1, response.getHeaders().size());
- Assertions.assertEquals(response.getHeaders("b"), Arrays.asList("bValue"));
- }
-}
diff --git a/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/ServletRestDispatcher.java b/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/ServletRestDispatcher.java
index 09f876ab5..0abb898ed 100644
--- a/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/ServletRestDispatcher.java
+++ b/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/ServletRestDispatcher.java
@@ -17,25 +17,21 @@
package org.apache.servicecomb.transport.rest.servlet;
-import java.util.List;
-
-import jakarta.servlet.AsyncContext;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
import org.apache.servicecomb.common.rest.RestProducerInvocationFlow;
-import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.Transport;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.invocation.InvocationCreator;
-import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.StandardHttpServletResponseEx;
+import jakarta.servlet.AsyncContext;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
public class ServletRestDispatcher {
private final RestAsyncListener restAsyncListener = new RestAsyncListener();
@@ -43,8 +39,6 @@ public class ServletRestDispatcher {
private MicroserviceMeta microserviceMeta;
- private final List<HttpServerFilter> httpServerFilters = SPIServiceUtils.getSortedService(HttpServerFilter.class);
-
public void service(HttpServletRequest request, HttpServletResponse response) {
if (transport == null) {
transport = SCBEngine.getInstance().getTransportManager().findTransport(Const.RESTFUL);