You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by fe...@apache.org on 2021/09/15 02:33:52 UTC

[incubator-shenyu] branch master updated: remove websocket filter (#2074)

This is an automated email from the ASF dual-hosted git repository.

fengzhenbing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new b03603f  remove websocket filter (#2074)
b03603f is described below

commit b03603fbf863285be502e4879866de3e13d1a5b0
Author: xiaoyu <xi...@apache.org>
AuthorDate: Wed Sep 15 10:33:47 2021 +0800

    remove websocket filter (#2074)
---
 .../starter/gateway/ShenyuConfiguration.java       |  12 ---
 .../shenyu/web/filter/WebSocketParamFilter.java    |  66 -------------
 .../web/filter/WebSocketParamFilterTest.java       | 106 ---------------------
 3 files changed, 184 deletions(-)

diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/gateway/ShenyuConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/gateway/ShenyuConfiguration.java
index e5132bc..8fcf408 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/gateway/ShenyuConfiguration.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/gateway/ShenyuConfiguration.java
@@ -31,7 +31,6 @@ import org.apache.shenyu.web.filter.CrossFilter;
 import org.apache.shenyu.web.filter.ExcludeFilter;
 import org.apache.shenyu.web.filter.FileSizeFilter;
 import org.apache.shenyu.web.filter.LocalDispatcherFilter;
-import org.apache.shenyu.web.filter.WebSocketParamFilter;
 import org.apache.shenyu.web.forward.ForwardedRemoteAddressResolver;
 import org.apache.shenyu.web.handler.ShenyuWebHandler;
 import org.apache.shenyu.web.loader.ShenyuLoaderService;
@@ -210,15 +209,4 @@ public class ShenyuConfiguration {
     public ShenyuConfig shenyuConfig() {
         return new ShenyuConfig();
     }
-    
-    /**
-     * Web socket web filter web filter.
-     *
-     * @return the web filter
-     */
-    @Bean
-    @Order(4)
-    public WebFilter webSocketWebFilter() {
-        return new WebSocketParamFilter();
-    }
 }
diff --git a/shenyu-web/src/main/java/org/apache/shenyu/web/filter/WebSocketParamFilter.java b/shenyu-web/src/main/java/org/apache/shenyu/web/filter/WebSocketParamFilter.java
deleted file mode 100644
index cc7801a..0000000
--- a/shenyu-web/src/main/java/org/apache/shenyu/web/filter/WebSocketParamFilter.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.shenyu.web.filter;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shenyu.common.constant.Constants;
-import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.plugin.api.result.ShenyuResultEnum;
-import org.apache.shenyu.plugin.api.result.ShenyuResultWrap;
-import org.apache.shenyu.plugin.api.utils.WebFluxResultUtils;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilterChain;
-import reactor.core.publisher.Mono;
-
-/**
- * this is http post param verify filter.
- */
-public class WebSocketParamFilter extends AbstractWebFilter {
-
-    private static final String UPGRADE = "Upgrade";
-
-    @Override
-    protected Mono<Boolean> doFilter(final ServerWebExchange exchange, final WebFilterChain chain) {
-        ServerHttpRequest request = exchange.getRequest();
-        HttpHeaders headers = request.getHeaders();
-        String upgrade = headers.getFirst(UPGRADE);
-        if (StringUtils.isNoneBlank(upgrade) && RpcTypeEnum.WEB_SOCKET.getName().equals(upgrade)) {
-            return Mono.just(verify(request.getQueryParams()));
-        }
-        return Mono.just(true);
-    }
-
-    @Override
-    protected Mono<Void> doDenyResponse(final ServerWebExchange exchange) {
-        ServerHttpResponse response = exchange.getResponse();
-        response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
-        Object error = ShenyuResultWrap.error(ShenyuResultEnum.PARAM_ERROR.getCode(), ShenyuResultEnum.PARAM_ERROR.getMsg(), null);
-        return WebFluxResultUtils.result(exchange, error);
-    }
-
-    private Boolean verify(final MultiValueMap<String, String> queryParams) {
-        return !StringUtils.isBlank(queryParams.getFirst(Constants.MODULE))
-                && !StringUtils.isBlank(queryParams.getFirst(Constants.METHOD))
-                && !StringUtils.isBlank(queryParams.getFirst(Constants.RPC_TYPE));
-    }
-}
diff --git a/shenyu-web/src/test/java/org/apache/shenyu/web/filter/WebSocketParamFilterTest.java b/shenyu-web/src/test/java/org/apache/shenyu/web/filter/WebSocketParamFilterTest.java
deleted file mode 100644
index 5324150..0000000
--- a/shenyu-web/src/test/java/org/apache/shenyu/web/filter/WebSocketParamFilterTest.java
+++ /dev/null
@@ -1,106 +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.shenyu.web.filter;
-
-import org.apache.shenyu.common.constant.Constants;
-import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.plugin.api.result.ShenyuResult;
-import org.apache.shenyu.plugin.api.utils.SpringBeanUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
-import org.springframework.mock.web.server.MockServerWebExchange;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilterChain;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-import java.util.Collections;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-/**
- * Test cases for WebSocketParamFilter.
- */
-@RunWith(MockitoJUnitRunner.class)
-public final class WebSocketParamFilterTest<T> extends WebSocketParamFilter {
-
-    private static final String UPGRADE = "Upgrade";
-
-    @Mock
-    private ShenyuResult<T> shenyuResult;
-
-    @Mock
-    private WebFilterChain chain;
-
-    @Test
-    public void testDoFilter() {
-        MultiValueMap<String, String> headerParams = new LinkedMultiValueMap<>(1);
-        MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>(3);
-        verifyTrue(getResult(headerParams, queryParams));
-
-        headerParams.put(UPGRADE, Collections.singletonList(RpcTypeEnum.HTTP.getName()));
-        verifyTrue(getResult(headerParams, queryParams));
-
-        headerParams.put(UPGRADE, Collections.singletonList(RpcTypeEnum.WEB_SOCKET.getName()));
-        verifyFalse(getResult(headerParams, queryParams));
-
-        queryParams.put(Constants.MODULE, Collections.singletonList("module_placeholder"));
-        verifyFalse(getResult(headerParams, queryParams));
-
-        queryParams.put(Constants.METHOD, Collections.singletonList("mothod_placeholder"));
-        verifyFalse(getResult(headerParams, queryParams));
-
-        queryParams.put(Constants.RPC_TYPE, Collections.singletonList("rpc_type_palceholder"));
-        verifyTrue(getResult(headerParams, queryParams));
-    }
-
-    @Test
-    public void testDoDenyResponse() {
-        final ConfigurableApplicationContext cfgContext = mock(ConfigurableApplicationContext.class);
-        SpringBeanUtils.getInstance().setApplicationContext(cfgContext);
-        when(SpringBeanUtils.getInstance().getBean(ShenyuResult.class)).thenReturn(shenyuResult);
-        final Mono<Void> result = doDenyResponse(createExchange(new LinkedMultiValueMap<>(1), new LinkedMultiValueMap<>(1)));
-        StepVerifier.create(result).expectSubscription().verifyComplete();
-    }
-    
-    private Mono<Boolean> getResult(final MultiValueMap<String, String> headerParams, final MultiValueMap<String, String> queryParams) {
-        return doFilter(createExchange(headerParams, queryParams), chain);
-    }
-    
-    private ServerWebExchange createExchange(final MultiValueMap<String, String> headerParams, final MultiValueMap<String, String> queryParams) {
-        return MockServerWebExchange.from(MockServerHttpRequest.post("localhost")
-                .headers(headerParams)
-                .queryParams(queryParams)
-                .build());
-    }
-    
-    private void verifyTrue(final Mono<Boolean> result) {
-        StepVerifier.create(result).expectSubscription().expectNext(Boolean.TRUE).verifyComplete();
-    }
-    
-    private void verifyFalse(final Mono<Boolean> result) {
-        StepVerifier.create(result).expectSubscription().expectNext(Boolean.FALSE).verifyComplete();
-    }
-}