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

tanjian pushed a commit to branch webapp_refactoring
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit f81ce260d09ce9e226105cf01ad2d20faef83293
Author: JaredTan95 <[email protected]>
AuthorDate: Thu Jul 1 11:33:06 2021 +0800

    replace zuul proxy with spring cloud gateway 2.x.
---
 apm-webapp/pom.xml                                 | 53 +++++-----------
 .../skywalking/apm/webapp/ApplicationStartUp.java  |  7 +--
 .../skywalking/apm/webapp/proxy/MvcConfig.java     | 40 ------------
 .../apm/webapp/proxy/NotFoundHandler.java          | 49 ---------------
 .../apm/webapp/proxy/RewritePathFilter.java        | 71 ----------------------
 apm-webapp/src/main/resources/application.yml      | 42 ++++++-------
 .../skywalking/apm/webapp/NotFoundHandlerTest.java | 63 -------------------
 .../apache/skywalking/apm/webapp/WebAppTest.java   | 67 --------------------
 8 files changed, 36 insertions(+), 356 deletions(-)

diff --git a/apm-webapp/pom.xml b/apm-webapp/pom.xml
index b2dade8..89a29ab 100644
--- a/apm-webapp/pom.xml
+++ b/apm-webapp/pom.xml
@@ -17,7 +17,8 @@
   ~
   -->
 
-<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";>
+<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";>
     <parent>
         <artifactId>apm</artifactId>
         <groupId>org.apache.skywalking</groupId>
@@ -29,18 +30,18 @@
     <packaging>jar</packaging>
 
     <properties>
+        <java.version>1.8</java.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <spring.boot.version>1.5.22.RELEASE</spring.boot.version>
+        <spring.boot.version>2.4.8</spring.boot.version>
         <log4j.version>2.6.2</log4j.version>
         <gson.version>2.8.2</gson.version>
         <apache-httpclient.version>4.5.3</apache-httpclient.version>
-        
<spring-cloud-dependencies.version>Edgware.SR1</spring-cloud-dependencies.version>
+        
<spring-cloud-dependencies.version>2020.0.3</spring-cloud-dependencies.version>
         <frontend-maven-plugin.version>1.11.0</frontend-maven-plugin.version>
         <logback-classic.version>1.2.3</logback-classic.version>
         <jackson-version>2.12.2</jackson-version>
         <yaml.version>1.28</yaml.version>
-        <netty.version>4.1.65.Final</netty.version>
-        <tomcat.version>8.5.66</tomcat.version>
+        <tomcat.version>9.0.48</tomcat.version>
 
         <ui.path>${project.parent.basedir}/skywalking-ui</ui.path>
     </properties>
@@ -59,10 +60,15 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-            <version>${spring.boot.version}</version>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-gateway</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
         </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
@@ -81,11 +87,6 @@
             <version>${jackson-version}</version>
         </dependency>
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-configuration-processor</artifactId>
-            <version>${spring.boot.version}</version>
-        </dependency>
-        <dependency>
             <groupId>com.google.code.gson</groupId>
             <artifactId>gson</artifactId>
             <version>${gson.version}</version>
@@ -96,10 +97,6 @@
             <version>${apache-httpclient.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.springframework.cloud</groupId>
-            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
-        </dependency>
-        <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
             <version>${logback-classic.version}</version>
@@ -110,21 +107,6 @@
             <version>${yaml.version}</version>
         </dependency>
         <dependency>
-            <groupId>io.netty</groupId>
-            <artifactId>netty-handler</artifactId>
-            <version>${netty.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tomcat.embed</groupId>
-            <artifactId>tomcat-embed-core</artifactId>
-            <version>${tomcat.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tomcat.embed</groupId>
-            <artifactId>tomcat-embed-websocket</artifactId>
-            <version>${tomcat.version}</version>
-        </dependency>
-        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
             <version>${spring.boot.version}</version>
@@ -209,13 +191,6 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <version>${spring.boot.version}</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>repackage</goal>
-                        </goals>
-                    </execution>
-                </executions>
             </plugin>
         </plugins>
     </build>
diff --git 
a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/ApplicationStartUp.java
 
b/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/ApplicationStartUp.java
index 875ee13..cecf0ca 100644
--- 
a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/ApplicationStartUp.java
+++ 
b/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/ApplicationStartUp.java
@@ -20,15 +20,10 @@ package org.apache.skywalking.apm.webapp;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.support.SpringBootServletInitializer;
-import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
 
 @SpringBootApplication
-@EnableZuulProxy
-public class ApplicationStartUp extends SpringBootServletInitializer {
-
+public class ApplicationStartUp {
     public static void main(String[] args) {
         SpringApplication.run(ApplicationStartUp.class, args);
     }
-
 }
diff --git 
a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/MvcConfig.java
 
b/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/MvcConfig.java
deleted file mode 100644
index 973d750..0000000
--- 
a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/MvcConfig.java
+++ /dev/null
@@ -1,40 +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.skywalking.apm.webapp.proxy;
-
-import org.springframework.context.annotation.Configuration;
-import 
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import 
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
-
-/**
- * Additional MVC Configuration.
- */
-@Configuration
-public class MvcConfig extends WebMvcConfigurerAdapter {
-
-    @Override
-    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
-        
registry.addResourceHandler("/index.html").addResourceLocations("classpath:/public/index.html");
-        
registry.addResourceHandler("/css/**").addResourceLocations("classpath:/public/css/");
-        
registry.addResourceHandler("/img/**").addResourceLocations("classpath:/public/img/");
-        
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/public/js/");
-        
registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/public/favicon.ico");
-        
registry.addResourceHandler("/logo.png").addResourceLocations("classpath:/public/logo.png");
-    }
-}
\ No newline at end of file
diff --git 
a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/NotFoundHandler.java
 
b/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/NotFoundHandler.java
deleted file mode 100644
index 2ac55c9..0000000
--- 
a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/NotFoundHandler.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.skywalking.apm.webapp.proxy;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.util.StreamUtils;
-import org.springframework.web.bind.annotation.ControllerAdvice;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.servlet.NoHandlerFoundException;
-
-/**
- * NotFoundHandler handles the single page application url routing.
- */
-@ControllerAdvice
-public class NotFoundHandler {
-    @ExceptionHandler(NoHandlerFoundException.class)
-    public ResponseEntity<String> renderDefaultPage() {
-        try {
-            String body = StreamUtils.copyToString(new 
ClassPathResource("/public/index.html").getInputStream(), Charset
-                .defaultCharset());
-            return 
ResponseEntity.ok().contentType(MediaType.TEXT_HTML).body(body);
-        } catch (final IOException e) {
-            LoggerFactory.getLogger(NotFoundHandler.class).error("err", e);
-            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
-                                 .body("There was an error completing the 
action.");
-        }
-    }
-}
diff --git 
a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/RewritePathFilter.java
 
b/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/RewritePathFilter.java
deleted file mode 100644
index 24f0331..0000000
--- 
a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/RewritePathFilter.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.skywalking.apm.webapp.proxy;
-
-import com.netflix.zuul.ZuulFilter;
-import com.netflix.zuul.context.RequestContext;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
-
-import static 
org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER;
-
-/**
- * Rewrite url to rewritePath
- */
-@Component
-@ConfigurationProperties(prefix = "collector")
-public class RewritePathFilter extends ZuulFilter {
-
-    private static final String REQUEST_URI = "requestURI";
-
-    private static final int ORDER = PRE_DECORATION_FILTER_ORDER + 2;
-
-    private String path;
-
-    public String getPath() {
-        return path;
-    }
-
-    public void setPath(String path) {
-        this.path = path;
-    }
-
-    @Override
-    public int filterOrder() {
-        return ORDER;
-    }
-
-    @Override
-    public String filterType() {
-        return "pre";
-    }
-
-    @Override
-    public boolean shouldFilter() {
-        RequestContext ctx = RequestContext.getCurrentContext();
-        return ctx.containsKey(REQUEST_URI);
-    }
-
-    @Override
-    public Object run() {
-        RequestContext ctx = RequestContext.getCurrentContext();
-        ctx.set(REQUEST_URI, path);
-        return null;
-    }
-}
diff --git a/apm-webapp/src/main/resources/application.yml 
b/apm-webapp/src/main/resources/application.yml
index b885b48..d56ed2a 100755
--- a/apm-webapp/src/main/resources/application.yml
+++ b/apm-webapp/src/main/resources/application.yml
@@ -17,28 +17,28 @@
 server:
   port: 8080
 
-zuul:
-  ignoredServices: '*'
-  routes:
-    api:
-      path: /graphql
-      serviceId: collector
-    login:
-      path: /login/account
-      serviceId: collector
-
-collector:
-  path: /graphql
-  ribbon:
-    # Point to all backend's restHost:restPort, split by ,
-    listOfServers: 127.0.0.1:12800
-
 spring:
-  resources:
-    add-mappings: false
+  cloud:
+    gateway:
+      routes:
+        - id: oap-route
+          uri: lb://oap-service
+          predicates:
+            - Path=/graphql/**
+    discovery:
+      client:
+        simple:
+          instances:
+            oap-service:
+              - uri: http://127.0.0.1:12800
+
   mvc:
     throw-exception-if-no-handler-found: true
-      
+
+  web:
+    resources:
+      add-mappings: true
+
 management:
-  # Customizing the management endpoint paths
-  context-path: /manage
+  server:
+    base-path: /manage
diff --git 
a/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/NotFoundHandlerTest.java
 
b/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/NotFoundHandlerTest.java
deleted file mode 100644
index 8a253cd..0000000
--- 
a/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/NotFoundHandlerTest.java
+++ /dev/null
@@ -1,63 +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.skywalking.apm.webapp;
-
-import java.io.IOException;
-import org.apache.skywalking.apm.webapp.proxy.NotFoundHandler;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(value = {
-    NotFoundHandler.class,
-    ClassPathResource.class
-})
-public class NotFoundHandlerTest {
-    @Mock
-    private NotFoundHandler notFoundHandler;
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-    }
-
-    @Test
-    public void shouldInternalErrorWhenIndexPageIsMissing() throws Exception {
-        ClassPathResource mockIndexResource = mock(ClassPathResource.class);
-        when(mockIndexResource.getInputStream()).thenThrow(new IOException());
-
-        
PowerMockito.whenNew(ClassPathResource.class).withArguments("/public/index.html").thenReturn(mockIndexResource);
-
-        when(notFoundHandler.renderDefaultPage()).thenCallRealMethod();
-        ResponseEntity<String> response = notFoundHandler.renderDefaultPage();
-        
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
-    }
-}
diff --git 
a/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/WebAppTest.java 
b/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/WebAppTest.java
deleted file mode 100644
index e0b1e1d..0000000
--- a/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/WebAppTest.java
+++ /dev/null
@@ -1,67 +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.skywalking.apm.webapp;
-
-import org.apache.skywalking.apm.webapp.proxy.NotFoundHandler;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
-import org.springframework.boot.test.mock.mockito.MockBean;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.test.web.servlet.MockMvc;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.only;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static 
org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static 
org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
-import static 
org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
-import static 
org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
-@WebMvcTest
-@RunWith(SpringRunner.class)
-public class WebAppTest {
-    @Autowired
-    private MockMvc mvc;
-    @MockBean
-    private NotFoundHandler notFoundHandler;
-
-    @Test
-    public void shouldGetStaticResources() throws Exception {
-        when(notFoundHandler.renderDefaultPage()).thenCallRealMethod();
-
-        mvc.perform(get("/index.html"))
-           .andDo(print())
-           .andExpect(status().isOk())
-           
.andExpect(content().string(containsString("<title>SkyWalking</title>")));
-
-        verify(notFoundHandler, never()).renderDefaultPage();
-    }
-
-    @Test
-    public void shouldRedirectToIndexWhenResourcesIsAbsent() throws Exception {
-        when(notFoundHandler.renderDefaultPage()).thenCallRealMethod();
-
-        
mvc.perform(get("/absent.html")).andDo(print()).andExpect(status().isOk());
-
-        verify(notFoundHandler, only()).renderDefaultPage();
-    }
-}
\ No newline at end of file

Reply via email to