diff --git a/ServiceComb-SpringMVC/src/main/java/com/huawei/servicecomb/ServicecombspringmvcApplication.java b/ServiceComb-SpringMVC/src/main/java/com/huawei/servicecomb/ServicecombspringmvcApplication.java
index b9047af3..ba73bb92 100644
--- a/ServiceComb-SpringMVC/src/main/java/com/huawei/servicecomb/ServicecombspringmvcApplication.java
+++ b/ServiceComb-SpringMVC/src/main/java/com/huawei/servicecomb/ServicecombspringmvcApplication.java
@@ -17,12 +17,10 @@
package com.huawei.servicecomb;
-import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
-@EnableServiceComb
public class ServicecombspringmvcApplication {
public static void main(String[] args) {
SpringApplication.run(ServicecombspringmvcApplication.class, args);
diff --git a/ServiceComb-SpringMVC/src/main/java/com/huawei/servicecomb/controller/ServicecombspringmvcImpl.java b/ServiceComb-SpringMVC/src/main/java/com/huawei/servicecomb/controller/ServicecombspringmvcImpl.java
index 2488dfb6..0fa0b7e8 100644
--- a/ServiceComb-SpringMVC/src/main/java/com/huawei/servicecomb/controller/ServicecombspringmvcImpl.java
+++ b/ServiceComb-SpringMVC/src/main/java/com/huawei/servicecomb/controller/ServicecombspringmvcImpl.java
@@ -18,14 +18,15 @@
package com.huawei.servicecomb.controller;
-import javax.ws.rs.core.MediaType;
+import jakarta.annotation.Generated;
+import jakarta.ws.rs.core.MediaType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.apache.servicecomb.provider.rest.common.RestSchema;
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.CseSpringDemoCodegen", date = "2019-08-02T08:06:28.094Z")
+@Generated(value = "io.swagger.codegen.languages.CseSpringDemoCodegen", date = "2019-08-02T08:06:28.094Z")
@RestSchema(schemaId = "servicecombspringmvc")
@RequestMapping(path = "/rest", produces = MediaType.APPLICATION_JSON)
diff --git a/ServiceComb-SpringMVC/src/main/resources/log4j.properties b/ServiceComb-SpringMVC/src/main/resources/log4j.properties
deleted file mode 100644
index f55f155a..00000000
--- a/ServiceComb-SpringMVC/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,28 +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.
-#
-
-# LOG4J configuration
-log4j.rootCategory=INFO,stdout,file
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
-# save logs to file
-log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.file.file=../logs/cse.log
-log4j.appender.file.DatePattern='.'yyyy-MM-dd
-log4j.appender.file.layout=org.apache.log4j.PatternLayout
-log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
\ No newline at end of file
diff --git a/ServiceComb-SpringMVC/src/main/resources/log4j2.properties b/ServiceComb-SpringMVC/src/main/resources/log4j2.properties
new file mode 100644
index 00000000..dbf50107
--- /dev/null
+++ b/ServiceComb-SpringMVC/src/main/resources/log4j2.properties
@@ -0,0 +1,41 @@
+#
+# 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.
+#
+
+# Log4j 2.x configuration
+status = error
+name = PropertiesConfig
+# Console Appender
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = [%d][%p][%t][%F][%marker]%m %l%n
+# File Appender
+appender.file.type = RollingRandomAccessFile
+appender.file.name = FILE
+appender.file.fileName = ./logs/springmvc/cse.log
+appender.file.filePattern = ./logs/springmvc/cse.%d{yyyy-MM-dd}.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = [%d][%p][%t][%F][%marker]%m %l%n
+appender.file.policies.type = Policies
+appender.file.policies.size.type = SizeBasedTriggeringPolicy
+appender.file.policies.size.size = 200MB
+appender.file.strategy.type = DefaultRolloverStrategy
+appender.file.strategy.max = 99
+# Root Logger
+rootLogger.level = info
+rootLogger.appenderRef.stdout.ref = STDOUT
+rootLogger.appenderRef.file.ref = FILE
\ No newline at end of file
diff --git a/ServiceComb-SpringMVC/src/main/resources/microservice.yaml b/ServiceComb-SpringMVC/src/main/resources/microservice.yaml
index cb2224ce..b016e695 100644
--- a/ServiceComb-SpringMVC/src/main/resources/microservice.yaml
+++ b/ServiceComb-SpringMVC/src/main/resources/microservice.yaml
@@ -23,7 +23,8 @@ servicecomb:
application: springmvc
name: servicecombspringmvc
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
instance:
watch: false
diff --git a/basic-tomcat/README.md b/basic-tomcat/README.md
index 8661955a..46d3a2de 100644
--- a/basic-tomcat/README.md
+++ b/basic-tomcat/README.md
@@ -1,78 +1,131 @@
-# Description
-This project providers sample to show working with Java Chassis Microservices.
+# basic-application(tomcat)
-* provider
-A Microserivce using Java Chassis with a REST interface. Provider is packaged as WAR and deploy in tomcat.
+## Description
-* consumer
-A Microserivce using Java Chassis with a REST interface. Consumer calls provider with RPC. Consumer is packaged as WAR and deploy in tomcat.
+This project providers sample to show working with Java Chassis Microservices.
-* gateway
-A Microserivce using Java Chassis Edge Service to forward requests to consumer. Gateway packaged as executable JAR.
+- **provider**:
+ A Microservice using Java Chassis with a REST interface.
+ Provider is packaged as WAR and deploy in tomcat.
+
+- **consumer**:
+ A Microservice using Java Chassis with a REST interface.
+ Consumer calls provider with RPC.
+ Consumer is packaged as WAR and deploy in tomcat.
+
+- **gateway**:
+ A Microservice using Java Chassis Edge Service to forward requests to consumer.
+ Gateway packaged as executable JAR.
## Precondition
+
see [Precondition](../README.md)
-# Build and Run
-* Build
+## Build and Run
+
+1. Build
- mvn clean package
+ ```bash
+ mvn clean package
+ ```
-* Run provider
+2. Run provider
- Deploy basic-provider-2.0-SNAPSHOT.war to tomcat.
+ Deploy `basic-provider-3.0-SNAPSHOT.war` to tomcat.
-* Run consumer
+3. Run consumer
- Deploy basic-consumer-2.0-SNAPSHOT.war to tomcat.
+ Deploy `basic-consumer-3.0-SNAPSHOT.war` to tomcat.
-* Run gateway
+4. Run gateway
- In ${Project}/gateway/target/
+ In `${Project}/gateway/target/`
- java -jar basic-gateway-2.0-SNAPSHOT.jar
+ ```bash
+ java -jar basic-gateway-3.0-SNAPSHOT.jar
+ ```
-* Testing
+5. Testing
-Open in browser: http://localhost:9090/sayHello?name=World
+ After starting the 3 microservices, access them through the interface:
+ 1. http://localhost:9090/sayHello?name=World
+ 2. http://localhost:9090/exampleConfig
+
+ > You can add or modify the `provider` configuration `basic.example` in the configuration center / `application.yml`,
+ > to test its priority and reading.
+> **Note:** When running `provider` and `consumer` directly via the main class, you need to configure the Spring Boot embedded Tomcat port `server.port`.
-# 项目说明
+## Call Chain
+
+```mermaid
+graph LR
+ User[User/Browser] --"1. HTTP Request"--> Gateway[Gateway]
+ Gateway --"2. Forward (Edge Service)"--> Consumer[Consumer Service]
+ Consumer --"3. RPC Call"--> Provider[Provider Service]
+ Provider --"4. Return Result"--> Consumer
+ Consumer --"5. Return Result"--> Gateway
+ Gateway --"6. HTTP Response"--> User
+```
+
+## 项目说明
这个项目提供了 Java Chassis 的简单例子,例子包括:
-* provider
-使用 Java Chassis 开发一个 REST 接口。 Provider打包为WAR在tomcat部署。
+- **provider**:
+ 使用 Java Chassis 开发一个 REST 接口。 Provider 打包为 WAR 在 tomcat 部署。
-* consumer
-使用 Java Chassis 开发一个 REST 接口, 接口实现通过 RPC 调用 provider 的接口。 Consumer打包为WAR在tomcat部署。
+- **consumer**:
+ 使用 Java Chassis 开发一个 REST 接口, 接口实现通过 RPC 调用 provider 的接口。 Consumer 打包为 WAR 在 tomcat 部署。
-* gateway
-使用 Java Chassis Edge Service 开发一个网关, 网关将所有请求转发到 consumer。 Gateway打包为可执行JAR运行。
+- **gateway**:
+ 使用 Java Chassis Edge Service 开发一个网关, 网关将所有请求转发到 consumer。 Gateway 打包为可执行 JAR 运行。
## 使用
-* 编译
+1. 编译
+
+ ```bash
+ mvn clean package
+ ```
+
+2. 启动 provider
- mvn clean package
+ 将`basic-provider-3.0-SNAPSHOT.war`部署到 Tomcat。
-* 启动 provider
+3. 启动 consumer
- 将basic-provider-2.0-SNAPSHOT.war部署到Tomcat。
+ 将`basic-consumer-3.0-SNAPSHOT.war`部署到 Tomcat。
-* 启动 consumer
+4. 启动 gateway
- 将basic-consumer-2.0-SNAPSHOT.war部署到Tomcat。
+ 进入目录 `${Project}/gateway/target/`
-* 启动 gateway
+ ```bash
+ java -jar basic-gateway-3.0-SNAPSHOT.jar
+ ```
- 进入目录 ${Project}/gateway/target/
+5. 测试
- java -jar basic-gateway-2.0-SNAPSHOT.jar
+ 启动 3 个微服务后, 然后通过界面访问:
-* 测试
+ 1. http://localhost:9090/sayHello?name=World
+ 2. http://localhost:9090/exampleConfig
+
+ > 可在配置中心/ `application.yml` 新增或修改 `provider` 的配置 `basic.example`,
+ > 测试其优先级以及读取。
-启动3个微服务后, 然后通过界面访问: http://localhost:9090/sayHello?name=World
+> 注:通过启动类直接运行 `provider` 和 `consumer` 需要配置 Spring Boot 内嵌 Tomcat 端口 `server.port`。
+## 调用链
+```mermaid
+graph LR
+ User[外部用户/浏览器] --"1. HTTP请求"--> Gateway[Gateway网关]
+ Gateway --"2. 转发 (Edge Service)"--> Consumer[Consumer服务]
+ Consumer --"3. RPC调用"--> Provider[Provider服务]
+ Provider --"4. 返回结果"--> Consumer
+ Consumer --"5. 返回结果"--> Gateway
+ Gateway --"6. HTTP响应"--> User
+```
diff --git a/basic-tomcat/consumer/pom.xml b/basic-tomcat/consumer/pom.xml
index e59c3495..846358aa 100644
--- a/basic-tomcat/consumer/pom.xml
+++ b/basic-tomcat/consumer/pom.xml
@@ -28,6 +28,10 @@
basic-consumer
war
+
+ 3.1.0
+
+
org.apache.servicecomb
@@ -55,7 +59,7 @@
org.apache.maven.plugins
maven-war-plugin
- 3.1.0
+ ${maven-war-plugin.version}
false
diff --git a/basic-tomcat/consumer/src/main/resources/log4j2.xml b/basic-tomcat/consumer/src/main/resources/log4j2.xml
index ea906df4..9553bce7 100644
--- a/basic-tomcat/consumer/src/main/resources/log4j2.xml
+++ b/basic-tomcat/consumer/src/main/resources/log4j2.xml
@@ -15,15 +15,57 @@
specific language governing permissions and limitations
under the License.
-->
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/basic-tomcat/gateway/src/main/resources/log4j2.xml b/basic-tomcat/gateway/src/main/resources/log4j2.xml
index ea906df4..67b65d20 100644
--- a/basic-tomcat/gateway/src/main/resources/log4j2.xml
+++ b/basic-tomcat/gateway/src/main/resources/log4j2.xml
@@ -15,15 +15,57 @@
specific language governing permissions and limitations
under the License.
-->
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/basic-tomcat/pom.xml b/basic-tomcat/pom.xml
index bd699855..eb2a39d0 100644
--- a/basic-tomcat/pom.xml
+++ b/basic-tomcat/pom.xml
@@ -26,8 +26,9 @@
pom
+ 17
UTF-8
- 3.0.0
+ 3.3.0
3.1.3
3.11.0
@@ -116,8 +117,8 @@
${maven-compiler-plugin.version}
-parameters
- 17
- 17
+ ${java.version}
+ ${java.version}
diff --git a/basic-tomcat/provider/pom.xml b/basic-tomcat/provider/pom.xml
index 7fe68991..83c642ab 100644
--- a/basic-tomcat/provider/pom.xml
+++ b/basic-tomcat/provider/pom.xml
@@ -30,6 +30,7 @@
war
+ 3.1.0
@@ -59,7 +60,7 @@
org.apache.maven.plugins
maven-war-plugin
- 3.1.0
+ ${maven-war-plugin.version}
false
diff --git a/basic-tomcat/provider/src/main/resources/log4j2.xml b/basic-tomcat/provider/src/main/resources/log4j2.xml
index ea906df4..169e2df5 100644
--- a/basic-tomcat/provider/src/main/resources/log4j2.xml
+++ b/basic-tomcat/provider/src/main/resources/log4j2.xml
@@ -15,15 +15,57 @@
specific language governing permissions and limitations
under the License.
-->
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/basic/README.md b/basic/README.md
index 8d1a0487..2156063a 100644
--- a/basic/README.md
+++ b/basic/README.md
@@ -1,86 +1,143 @@
-# Description
-This project providers sample to show working with Java Chassis Microservices.
+# basic-application
-* provider
-A Microserivce using Java Chassis with a REST interface.
+## Description
-* consumer
-A Microserivce using Java Chassis with a REST interface. Consumer calls provider with RPC.
+This project providers sample to show working with Java Chassis Microservices.
-* gateway
-A Microserivce using Java Chassis Edge Service to forward requests to consumer.
+- **provider**:
+ A Microservice using Java Chassis with a REST interface.
+
+- **consumer**:
+ A Microservice using Java Chassis with a REST interface. Consumer calls provider with RPC.
+
+- **gateway**:
+ A Microservice using Java Chassis Edge Service to forward requests to consumer.
## Precondition
+
see [Precondition](../README.md)
-# Build and Run
-* Build
+## Build and Run
+
+1. Build
+
+ ```bash
+ mvn clean package
+ ```
- mvn clean package
+2. Run provider
-* Run provider
+ In `${Project}/provider/target/`
- In ${Project}/provider/target/
-
- java -jar basic-provider-2.0-SNAPSHOT.jar
+ ```bash
+ java -jar basic-provider-3.0-SNAPSHOT.jar
+ ```
-* Run consumer
+3. Run consumer
- In ${Project}/consumer/target/
+ In `${Project}/consumer/target/`
- java -jar basic-consumer-2.0-SNAPSHOT.jar
+ ```bash
+ java -jar basic-consumer-3.0-SNAPSHOT.jar
+ ```
-* Run gateway
+4. Run gateway
- In ${Project}/gateway/target/
+ In `${Project}/gateway/target/`
- java -jar basic-gateway-2.0-SNAPSHOT.jar
+ ```bash
+ java -jar basic-gateway-3.0-SNAPSHOT.jar
+ ```
-* Testing
+5. Testing
-Open in browser: http://localhost:9090/sayHello?name=World
+ After starting the 3 microservices, access them through the interface:
+ 1. http://localhost:9090/sayHello?name=World
+ 2. http://localhost:9090/exampleConfig
+
+ > You can add or modify the `provider` configuration `basic.example` in the configuration center / `application.yml`,
+ > to test its priority and reading.
+## Call Chain
-# 项目说明
+```mermaid
+graph LR
+ User[User/Browser] --"1. HTTP Request"--> Gateway[Gateway]
+ Gateway --"2. Forward (Edge Service)"--> Consumer[Consumer Service]
+ Consumer --"3. RPC Call"--> Provider[Provider Service]
+ Provider --"4. Return Result"--> Consumer
+ Consumer --"5. Return Result"--> Gateway
+ Gateway --"6. HTTP Response"--> User
+```
+
+## 项目说明
这个项目提供了 Java Chassis 的简单例子,例子包括:
-* provider
-使用 Java Chassis 开发一个 REST 接口。
+- **provider**:
+ 使用 Java Chassis 开发一个 REST 接口。
+
+- **consumer**:
+ 使用 Java Chassis 开发一个 REST 接口, 接口实现通过 RPC 调用 provider 的接口。
+
+- **gateway**:
+ 使用 Java Chassis Edge Service 开发一个网关, 网关将所有请求转发到 consumer。
-* consumer
-使用 Java Chassis 开发一个 REST 接口, 接口实现通过 RPC 调用 provider 的接口。
+## 前置条件
-* gateway
-使用 Java Chassis Edge Service 开发一个网关, 网关将所有请求转发到 consumer。
+参见[前置条件](../README.md)
## 使用
-* 编译
+1. 编译
+
+ ```bash
+ mvn clean package
+ ```
+
+2. 启动 provider
- mvn clean package
+ 进入目录 `${Project}/provider/target/`
-* 启动 provider
+ ```bash
+ java -jar basic-provider-3.0-SNAPSHOT.jar
+ ```
- 进入目录 ${Project}/provider/target/
-
- java -jar basic-provider-2.0-SNAPSHOT.jar
+3. 启动 consumer
-* 启动 consumer
+ 进入目录 ${Project}/consumer/target/
- 进入目录 ${Project}/consumer/target/
+ ```bash
+ java -jar basic-consumer-3.0-SNAPSHOT.jar
+ ```
- java -jar basic-consumer-2.0-SNAPSHOT.jar
+4. 启动 gateway
-* 启动 gateway
+ 进入目录 ${Project}/gateway/target/
- 进入目录 ${Project}/gateway/target/
+ ```bash
+ java -jar basic-gateway-3.0-SNAPSHOT.jar
+ ```
- java -jar basic-gateway-2.0-SNAPSHOT.jar
+5. 测试
-* 测试
+ 启动 3 个微服务后, 然后通过界面访问:
-启动3个微服务后, 然后通过界面访问: http://localhost:9090/sayHello?name=World
+ 1. http://localhost:9090/sayHello?name=World
+ 2. http://localhost:9090/exampleConfig
+
+ > 可在配置中心/ `application.yml` 新增或修改 `provider` 的配置 `basic.example`,
+ > 测试其优先级以及读取。
+## 调用链
+```mermaid
+graph LR
+ User[外部用户/浏览器] --"1. HTTP请求"--> Gateway[Gateway网关]
+ Gateway --"2. 转发 (Edge Service)"--> Consumer[Consumer服务]
+ Consumer --"3. RPC调用"--> Provider[Provider服务]
+ Provider --"4. 返回结果"--> Consumer
+ Consumer --"5. 返回结果"--> Gateway
+ Gateway --"6. HTTP响应"--> User
+```
diff --git a/basic/consumer/pom.xml b/basic/consumer/pom.xml
index 0ed7959b..7d14ae38 100644
--- a/basic/consumer/pom.xml
+++ b/basic/consumer/pom.xml
@@ -29,10 +29,6 @@
jar
-
- org.apache.servicecomb
- java-chassis-spring-boot-starter-standalone
-
org.apache.servicecomb.samples
basic-consumer-api
diff --git a/basic/consumer/src/main/resources/log4j2.xml b/basic/consumer/src/main/resources/log4j2.xml
index 2c557a88..1a4e6611 100644
--- a/basic/consumer/src/main/resources/log4j2.xml
+++ b/basic/consumer/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/basic/gateway/pom.xml b/basic/gateway/pom.xml
index 608adf63..c56c2c81 100644
--- a/basic/gateway/pom.xml
+++ b/basic/gateway/pom.xml
@@ -29,10 +29,6 @@
jar
-
- org.apache.servicecomb
- java-chassis-spring-boot-starter-standalone
-
org.apache.servicecomb
edge-core
diff --git a/basic/gateway/src/main/resources/log4j2.xml b/basic/gateway/src/main/resources/log4j2.xml
index b24f8c50..a1011083 100644
--- a/basic/gateway/src/main/resources/log4j2.xml
+++ b/basic/gateway/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/basic/pom.xml b/basic/pom.xml
index a358be84..068da838 100644
--- a/basic/pom.xml
+++ b/basic/pom.xml
@@ -26,8 +26,9 @@
pom
+ 17
UTF-8
- 3.1.1
+ 3.3.0
3.1.3
3.11.0
@@ -49,6 +50,10 @@
org.apache.servicecomb
solution-basic
+
+ org.apache.servicecomb
+ java-chassis-spring-boot-starter-standalone
+
org.apache.logging.log4j
@@ -117,8 +122,8 @@
${maven-compiler-plugin.version}
-parameters
- 17
- 17
+ ${java.version}
+ ${java.version}
diff --git a/basic/provider/pom.xml b/basic/provider/pom.xml
index 3140127a..d3006b6e 100644
--- a/basic/provider/pom.xml
+++ b/basic/provider/pom.xml
@@ -33,10 +33,6 @@
-
- org.apache.servicecomb
- java-chassis-spring-boot-starter-standalone
-
org.apache.servicecomb.samples
basic-provider-api
diff --git a/basic/provider/src/main/resources/log4j2.xml b/basic/provider/src/main/resources/log4j2.xml
index 33482047..498a9840 100644
--- a/basic/provider/src/main/resources/log4j2.xml
+++ b/basic/provider/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/bmi/README.md b/bmi/README.md
new file mode 100644
index 00000000..8995e8fc
--- /dev/null
+++ b/bmi/README.md
@@ -0,0 +1,102 @@
+# bmi
+
+## Description
+
+This guide will introduce microservices through a simple **Body Mass Index (BMI)** application.
+BMI is mainly used to measure the degree of body fat.
+
+The application consists of two microservices:
+
+- **BMI Calculator**: Responsible for handling calculation operations.
+- **BMI Interface**: Provides user interface and gateway services.
+
+> For detailed information, please refer to the [official documentation](https://servicecomb.apache.org/references/java-chassis/zh_CN/featured-topics/application-bmi.html)
+
+## Precondition
+
+see [Precondition](../README.md)
+
+## Usage
+
+1. Modify Configuration
+
+ Before compiling, you need to modify the static resource path (refer to [issues 53](https://github.com/apache/servicecomb-samples/issues/53)):
+
+ - For Windows users, modify `gateway.webroot` to `/code/servicecomb-samples/bmi/webapp/src/main/resources/static`
+ > For absolute path, remove the drive letter. Assuming the code is saved in `D:\code\servicecomb-samples\bmi\webapp\src\main\resources\static`
+ - For Linux users, `gateway.webroot` can use relative path directly: `./bmi/webapp/src/main/resources/static`
+
+2. Compile
+
+ ```bash
+ mvn clean package
+ ```
+
+3. Start calculator
+ In `${Project}/calculator/target/`
+
+ ```bash
+ java -jar bmi-calculator-3.0.0-SNAPSHOT.jar
+ ```
+
+4. Start webapp
+ In `${Project}/webapp/target/`
+
+ ```bash
+ java -jar webapp-3.0.0-SNAPSHOT.jar
+ ```
+
+5. Test
+ After starting both microservices, access the interface through: http://localhost:8889
+
+ > You can set the configuration item `bmi.mock.error` in the `application.yml` to simulate error responses.
+
+## 项目说明
+
+本指南将以一个简单的 **体质指数(BMI)** 应用开展微服务之旅。体质指数主要用于衡量人体胖瘦程度。
+该应用主要包含两个微服务:
+
+- 体质指数计算器:负责处理运算事务。
+- 体质指数界面:提供用户界面及网关服务。
+
+> 具体信息请参[考官方文档](https://servicecomb.apache.org/references/java-chassis/zh_CN/featured-topics/application-bmi.html)
+
+## 前置条件
+
+参见[前置条件](../README.md)
+
+## 使用
+
+1. 修改配置
+
+ 编译前需要先修改静态资源路径(参考[issues 53](https://github.com/apache/servicecomb-samples/issues/53)):
+ - 如果你使用 Windows,请修改`gateway.webroot`为`/code/servicecomb-samples/bmi/webapp/src/main/resources/static` > 绝对路径去掉盘符,假设代码保存在`D:\code\servicecomb-samples\bmi\webapp\src\main\resources\static`
+ - 如果你使用 Linux,`gateway.webroot`可以直接使用相对位置:`./bmi/webapp/src/main/resources/static`
+
+2. 编译
+
+ ```bash
+ mvn clean package
+ ```
+
+3. 启动 calculator
+
+ In `${Project}/calculator/target/`
+
+ ```bash
+ java -jar bmi-calculator-3.0.0-SNAPSHOT.jar
+ ```
+
+4. 启动 webapp
+
+ In `${Project}/webapp/target/`
+
+ ```bash
+ java -jar webapp-3.0.0-SNAPSHOT.jar
+ ```
+
+5. 测试
+
+ 启动 2 个微服务后, 然后通过界面访问:http://localhost:8889
+
+ > 可在 `application.yml` 设置配置项 `bmi.mock.error` 模拟错误返回。
diff --git a/bmi/calculator/src/main/resources/log4j2.xml b/bmi/calculator/src/main/resources/log4j2.xml
index 6cc0d98d..fb8bc0e5 100644
--- a/bmi/calculator/src/main/resources/log4j2.xml
+++ b/bmi/calculator/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/bmi/pom.xml b/bmi/pom.xml
index f8dc538b..9bbff5bc 100644
--- a/bmi/pom.xml
+++ b/bmi/pom.xml
@@ -27,7 +27,7 @@
UTF-8
- 3.0.0
+ 3.3.0
3.1.3
3.11.0
17
@@ -89,8 +89,8 @@
${maven-compiler-plugin.version}
-parameters
- 17
- 17
+ ${java.version}
+ ${java.version}
diff --git a/bmi/webapp/src/main/resources/log4j2.xml b/bmi/webapp/src/main/resources/log4j2.xml
index 7bfc22e6..ff60cd0f 100644
--- a/bmi/webapp/src/main/resources/log4j2.xml
+++ b/bmi/webapp/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/java-chassis-deployment-samples/README.md b/java-chassis-deployment-samples/README.md
index 31b6edf7..79a9d483 100644
--- a/java-chassis-deployment-samples/README.md
+++ b/java-chassis-deployment-samples/README.md
@@ -1,7 +1,23 @@
+# java-chassis-deployment-samples
+
+## Description
+
This folder contains some examples of java-chassis deployments.
-* spring-boot-external-tomcat : deploy java-chassis with spring boot, but run in an external web container.
-* war-external-tomcat : deploy java-chassis into a traditional war and run in an external web container.
+- `spring-boot-external-tomcat`: deploy java-chassis with spring boot, but run in an external web container.
+- `war-external-tomcat`: deploy java-chassis into a traditional war and run in an external web container.
## Precondition
-see [Precondition](../README.md)
\ No newline at end of file
+
+see [Precondition](../README.md)
+
+## 项目说明
+
+本文件夹包含一些 java-chassis 部署的示例。
+
+- `spring-boot-external-tomcat`:使用 spring boot 部署 java-chassis,但在外部 web 容器中运行。
+- `war-external-tomcat`:将 java-chassis 部署到传统的 war 包中并在外部 web 容器中运行。
+
+## 前置条件
+
+参见[前置条件](../README.md)
diff --git a/java-chassis-deployment-samples/spring-boot-external-tomcat/README.md b/java-chassis-deployment-samples/spring-boot-external-tomcat/README.md
index d2230b36..18192fbd 100644
--- a/java-chassis-deployment-samples/spring-boot-external-tomcat/README.md
+++ b/java-chassis-deployment-samples/spring-boot-external-tomcat/README.md
@@ -1,3 +1,7 @@
+# spring-boot-external-tomcat
+
+## Description
+
This project shows how to run java-chassis with spring boot in external web container.
Following are some useful articles to run spring boot in external web container.
@@ -11,4 +15,48 @@ For java-chassis using spring boot, check following articles.
* [Working with Spring Boot](https://docs.servicecomb.io/java-chassis/zh_CN/using-java-chassis-in-spring-boot/using-java-chassis-in-spring-boot/)
## Precondition
-see [Precondition](../../README.md)
\ No newline at end of file
+
+see [Precondition](../../README.md)
+
+## Usage
+
+### Build
+
+```bash
+mvn clean package
+```
+
+After building, you will find the `springBootExternalTomcat-0.0.1.war` file in the `target` directory.
+
+### Deploy to External Tomcat
+
+1. Download and install Apache Tomcat 9.x or higher
+2. Copy the generated WAR file to Tomcat's `webapps` directory:
+
+ ```bash
+ cp target/springBootExternalTomcat-0.0.1.war /webapps/
+ ```
+
+3. Start Tomcat:
+
+ ```bash
+ cd /bin
+ ./startup.sh # On Linux/Mac
+ startup.bat # On Windows
+ ```
+
+4. Tomcat will automatically deploy the WAR file
+
+### Test the Service
+
+Once deployed and started, you can test the service using curl:
+
+```bash
+curl "http://localhost:8080/springBootExternalTomcat-0.0.1/hello?name=World"
+```
+
+Expected response:
+
+```text
+World
+```
diff --git a/java-chassis-deployment-samples/spring-boot-external-tomcat/pom.xml b/java-chassis-deployment-samples/spring-boot-external-tomcat/pom.xml
index c62c8cef..e1e1f9ac 100644
--- a/java-chassis-deployment-samples/spring-boot-external-tomcat/pom.xml
+++ b/java-chassis-deployment-samples/spring-boot-external-tomcat/pom.xml
@@ -21,9 +21,13 @@
UTF-8
- 1.8
+ 17
-Dfile.encoding=UTF-8
UTF-8
+ 3.3.0
+ 3.11.0
+
+ 2.0.16
@@ -31,10 +35,16 @@
org.apache.servicecomb
java-chassis-dependencies
- 2.6.0
+ ${servicecomb.version}
pom
import
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
@@ -66,11 +76,11 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.1
+ ${maven-compiler-plugin.version}
-parameters
- 1.8
- 1.8
+ ${java.version}
+ ${java.version}
diff --git a/java-chassis-deployment-samples/spring-boot-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/Application.java b/java-chassis-deployment-samples/spring-boot-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/Application.java
index 7e2740a5..f1f4fab0 100644
--- a/java-chassis-deployment-samples/spring-boot-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/Application.java
+++ b/java-chassis-deployment-samples/spring-boot-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/Application.java
@@ -17,14 +17,12 @@
package org.apache.servicecomb.samples.dependencyManagement;
-import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
-@EnableServiceComb
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
diff --git a/java-chassis-deployment-samples/spring-boot-external-tomcat/src/main/resources/application.yml b/java-chassis-deployment-samples/spring-boot-external-tomcat/src/main/resources/application.yml
index 76466ec9..e6e0ca6c 100644
--- a/java-chassis-deployment-samples/spring-boot-external-tomcat/src/main/resources/application.yml
+++ b/java-chassis-deployment-samples/spring-boot-external-tomcat/src/main/resources/application.yml
@@ -15,16 +15,15 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-
-APPLICATION_ID: servicecomb-samples
-
-service_description:
- version: 0.0.1
- name: spring-boot-external-tomcat
+servicecomb-config-order: 100
servicecomb:
service:
- registry:
+ application: servicecomb-samples
+ name: spring-boot-external-tomcat
+ version: 0.0.1
+ registry:
+ sc:
address: http://localhost:30100
instance:
watch: false
diff --git a/java-chassis-deployment-samples/war-external-tomcat/README.md b/java-chassis-deployment-samples/war-external-tomcat/README.md
new file mode 100644
index 00000000..4e71f388
--- /dev/null
+++ b/java-chassis-deployment-samples/war-external-tomcat/README.md
@@ -0,0 +1,62 @@
+# war-external-tomcat
+
+This project demonstrates **how to integrate ServiceComb microservice framework into an existing traditional Java Web application** and deploy it to an external Tomcat.
+
+## Project Features (Differences from spring-boot-external-tomcat)
+
+This project demonstrates a **legacy system integration scenario**:
+
+- **Traditional Servlet/Filter coexist with ServiceComb** - Traditional components configured via web.xml
+- **JSP page support** - Retaining existing JSP pages
+- **ServiceComb microservices** - Modern microservices integrated through Spring Boot
+- **Unified deployment** - All components packaged into a single WAR and deployed to external Tomcat
+
+While the `spring-boot-external-tomcat` project is a **pure Spring Boot application** without legacy components.
+
+Note:
+
+- Integrating legacy code → Not a ServiceComb feature, but a Servlet standard capability
+- This sample → Only proves ServiceComb follows standards and doesn't break legacy systems
+- ServiceComb's value → Lies in microservice governance (service discovery, load balancing, fault tolerance, etc.), not "coexisting with legacy code"
+
+This sample demonstrates that introducing ServiceComb is safe and won't break existing systems, eliminating migration concerns.
+
+### Project Structure
+
+```text
+├── LegacyServlet.java # [Legacy] Traditional Servlet (configured via web.xml)
+├── LegacyFilter.java # [Legacy] Traditional Filter (configured via web.xml)
+├── HelloEndpoint.java # [New] ServiceComb microservice interface
+├── Application.java # [New] Spring Boot bootstrap class
+├── index.jsp # [Legacy] Traditional JSP page
+└── web.xml # [Legacy] Traditional Servlet container configuration
+```
+
+### Key Configurations
+
+1. **pom.xml**: Add `java-chassis-spring-boot-starter-servlet` dependency
+2. **Application.java**: Create a bootstrap class that extends `SpringBootServletInitializer`
+3. **web.xml**: ServiceComb is auto-configured by Spring Boot; traditional components are configured normally
+4. **microservice.yaml**: ServiceComb configuration file
+
+## Deployment Steps
+
+1. Build the project: `mvn clean package`
+2. Deploy the generated WAR package to Tomcat's webapps directory
+3. Start Tomcat
+4. Access the services, after deployment you can visit:
+
+ - **Traditional JSP**: `http://localhost:8080/warExternalTomcat-0.0.1/`
+ - **Traditional Servlet**: `http://localhost:8080/warExternalTomcat-0.0.1/legacy`
+ - **ServiceComb API**: `http://localhost:8080/warExternalTomcat-0.0.1/rest/hello?name=world`
+
+## ServiceComb 3.x Adaptation Notes
+
+`ServiceComb 3.x` adopts the Spring Boot approach and no longer uses the traditional `RestServletContextListener`. WAR deployment to external Tomcat is achieved through `java-chassis-spring-boot-starter-servlet` and `SpringBootServletInitializer`.
+
+Only:
+
+- `RestServlet.class` - Servlet implementation
+- `RestAsyncListener.class` - Async listener (not `ServletContextListener`)
+
+Therefore, `2.x` version samples cannot be upgraded to `3.x` version.
diff --git a/java-chassis-deployment-samples/war-external-tomcat/pom.xml b/java-chassis-deployment-samples/war-external-tomcat/pom.xml
index cbeb2557..89e7993a 100644
--- a/java-chassis-deployment-samples/war-external-tomcat/pom.xml
+++ b/java-chassis-deployment-samples/war-external-tomcat/pom.xml
@@ -27,9 +27,14 @@
UTF-8
- 1.8
+ 17
-Dfile.encoding=UTF-8
UTF-8
+ 3.3.0
+ 3.11.0
+ 3.1.0
+
+ 2.0.16
@@ -37,10 +42,16 @@
org.apache.servicecomb
java-chassis-dependencies
- 2.6.0
+ ${servicecomb.version}
pom
import
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
@@ -48,6 +59,32 @@
org.apache.servicecomb
solution-basic
+
+
+ org.apache.logging.log4j
+ *
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+
+ org.apache.servicecomb
+ java-chassis-spring-boot-starter-servlet
+
+
+ org.springframework.boot
+ spring-boot-starter-tomcat
+
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
@@ -56,11 +93,19 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.1
+ ${maven-compiler-plugin.version}
-parameters
- 1.8
- 1.8
+ ${java.version}
+ ${java.version}
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ ${maven-war-plugin.version}
+
+ false
diff --git a/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/Application.java b/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/Application.java
new file mode 100644
index 00000000..0395dfbf
--- /dev/null
+++ b/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/Application.java
@@ -0,0 +1,42 @@
+/*
+ * 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.samples.dependencyManagement;
+
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+
+@SpringBootApplication
+public class Application extends SpringBootServletInitializer {
+ public static void main(String[] args) throws Exception {
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.SERVLET)
+ .sources(Application.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(Application.class);
+ }
+}
diff --git a/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/LegacyFilter.java b/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/LegacyFilter.java
new file mode 100644
index 00000000..939c4948
--- /dev/null
+++ b/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/LegacyFilter.java
@@ -0,0 +1,50 @@
+/*
+ * 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.samples.dependencyManagement;
+
+import java.io.IOException;
+
+import jakarta.servlet.Filter;
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.FilterConfig;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.ServletRequest;
+import jakarta.servlet.ServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+
+public class LegacyFilter implements Filter {
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ System.out.println("LegacyFilter initialized");
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws IOException, ServletException {
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+ System.out.println("LegacyFilter: Processing request to " + httpRequest.getRequestURI());
+
+ request.setAttribute("legacyFilterApplied", "true");
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void destroy() {
+ System.out.println("LegacyFilter destroyed");
+ }
+}
diff --git a/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/LegacyServlet.java b/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/LegacyServlet.java
new file mode 100644
index 00000000..140c5c3e
--- /dev/null
+++ b/java-chassis-deployment-samples/war-external-tomcat/src/main/java/org/apache/servicecomb/samples/dependencyManagement/LegacyServlet.java
@@ -0,0 +1,40 @@
+/*
+ * 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.samples.dependencyManagement;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+public class LegacyServlet extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ resp.setContentType("text/html;charset=UTF-8");
+ PrintWriter out = resp.getWriter();
+ out.println("");
+ out.println("Legacy Servlet Example
");
+ out.println("This is a traditional servlet coexisting with ServiceComb microservices.
");
+ out.println("Request URI: " + req.getRequestURI() + "
");
+ out.println("");
+ }
+}
diff --git a/java-chassis-deployment-samples/war-external-tomcat/src/main/resources/microservice.yaml b/java-chassis-deployment-samples/war-external-tomcat/src/main/resources/microservice.yaml
index 9335e113..5ec117f9 100644
--- a/java-chassis-deployment-samples/war-external-tomcat/src/main/resources/microservice.yaml
+++ b/java-chassis-deployment-samples/war-external-tomcat/src/main/resources/microservice.yaml
@@ -17,15 +17,13 @@
servicecomb-config-order: 100
-APPLICATION_ID: servicecomb-samples
-
-service_description:
- version: 0.0.1
- name: war-external-tomcat2
-
servicecomb:
service:
- registry:
+ application: servicecomb-samples
+ name: war-external-tomcat2
+ version: 0.0.1
+ registry:
+ sc:
address: http://localhost:30100
instance:
watch: false
diff --git a/java-chassis-deployment-samples/war-external-tomcat/src/main/webapp/WEB-INF/web.xml b/java-chassis-deployment-samples/war-external-tomcat/src/main/webapp/WEB-INF/web.xml
index cb2b22e5..966dc0a8 100644
--- a/java-chassis-deployment-samples/war-external-tomcat/src/main/webapp/WEB-INF/web.xml
+++ b/java-chassis-deployment-samples/war-external-tomcat/src/main/webapp/WEB-INF/web.xml
@@ -20,37 +20,33 @@
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
-
- contextConfigLocation
-
- classpath*:META-INF/spring/*.bean.xml
-
-
+
+
-
+
+
+ LegacyFilter
+ org.apache.servicecomb.samples.dependencyManagement.LegacyFilter
+
+
+ LegacyFilter
+ /legacy/*
+
-
-
- org.apache.servicecomb.transport.rest.servlet.RestServletContextListener
-
+
+
+ LegacyServlet
+ org.apache.servicecomb.samples.dependencyManagement.LegacyServlet
+ 2
+
+
+ LegacyServlet
+ /legacy
+
-
+
+
+ index.jsp
+
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java-chassis-deployment-samples/war-external-tomcat/src/main/webapp/index.jsp b/java-chassis-deployment-samples/war-external-tomcat/src/main/webapp/index.jsp
new file mode 100644
index 00000000..0416181b
--- /dev/null
+++ b/java-chassis-deployment-samples/war-external-tomcat/src/main/webapp/index.jsp
@@ -0,0 +1,59 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+ Legacy WAR with ServiceComb
+
+
+
+ 传统 WAR 包集成 ServiceComb 示例
+
+
+
遗留系统组件(Legacy Components)
+
+ - 传统 Servlet - 通过 web.xml 配置的传统 Servlet
+ - 本页面 (index.jsp) - 传统 JSP 页面
+
+
+
+
+
ServiceComb 微服务(ServiceComb Microservices)
+
+
+
+
+
特点说明
+
本项目展示了如何在已有的传统 Java Web 应用中集成 ServiceComb 微服务框架:
+
+ - 传统 Servlet/Filter 与 ServiceComb 共存
+ - JSP 页面继续正常工作
+ - ServiceComb 微服务通过 Spring Boot 方式集成
+ - 统一部署到外部 Tomcat
+
+
+
+ 部署时间: <%= new java.util.Date() %>
+
+
diff --git a/java-chassis-interoprability/README.md b/java-chassis-interoprability/README.md
index 1b963d79..f1429384 100644
--- a/java-chassis-interoprability/README.md
+++ b/java-chassis-interoprability/README.md
@@ -1,35 +1,100 @@
# About Spring Cloud and Java Chassis interoperability
-In this demo, we build a gateway using spring-cloud-gateway, a microservice `provider-java-chassis` using Java Chassis, a microservice `provider-spring-cloud` using Spring Cloud.
+## Description
-Scenario 1: User -> gateway -> provider-spring-cloud -> provider-java-chassis
+In this demo, we build:
+
+- a gateway `gateway` using spring-cloud-gateway,
+- a microservice `provider-java-chassis` using Java Chassis,
+- a microservice `provider-spring-cloud` using Spring Cloud.
+
+Both of these three microservice will be registered to `servicecomb` or `nacos`.
+
+Scenario 1: `User -> gateway -> provider-spring-cloud -> provider-java-chassis`
Request:
- `http://localhost:9090/spring-cloud/sayHello?name=World`
+```text
+http://localhost:9090/spring-cloud/sayHello?name=World
+```
Result:
- `"Hello from Java Chassis, World"`
+```text
+"Hello from Java Chassis, World"
+```
-
-Scenario 2: User -> gateway -> provider-java-chassis -> provider-spring-cloud
+Scenario 2: `User -> gateway -> provider-java-chassis -> provider-spring-cloud`
Request:
- `http://localhost:9090/java-chassis/sayHello?name=World`
+```text
+http://localhost:9090/java-chassis/sayHello?name=World
+```
Result:
- `"Hello from Spring Cloud, World"`
+```text
+"Hello from Spring Cloud, World"
+```
## Using Service Center & Kie
-Maven profile and Spring Profile using `servicecomb`.
+Maven profile and Spring Profile using `servicecomb`.
## Using Nacos
Maven profile and Spring Profile using `nacos`.
->>> Notice: Nacos 2.3.0 and above is required. Because older versions of nacos will not generate instance id for Spring Cloud applications and Java Chassis interoperability needs instance id.
+> Notice: Nacos 2.3.0 and above is required.
+> Because older versions of nacos will not generate instance id for
+> Spring Cloud applications and Java Chassis interoperability needs instance id.
+
+## 说明
+
+在本演示中,我们:
+
+- 使用 spring-cloud-gateway 构建网关 `gateway`
+- 使用 Java Chassis 构建微服务 `provider-java-chassis`
+- 使用 Spring Cloud 构建微服务 `provider-spring-cloud`
+
+以上三个服务注册到 `servicecomb` 或 `nacos`。
+
+场景 1:`用户 -> 网关 -> provider-spring-cloud -> provider-java-chassis`
+
+请求:
+
+```text
+http://localhost:9090/spring-cloud/sayHello?name=World
+```
+
+结果:
+
+```text
+"Hello from Java Chassis, World"
+```
+
+场景 2:`用户 -> 网关 -> provider-java-chassis -> provider-spring-cloud`
+
+请求:
+
+```text
+http://localhost:9090/java-chassis/sayHello?name=World
+```
+
+结果:
+
+```text
+"Hello from Spring Cloud, World"
+```
+
+## 使用 Service Center 和 Kie
+
+Maven profile 和 Spring Profile 使用 `servicecomb`。
+
+## 使用 Nacos
+
+Maven profile 和 Spring Profile 使用 `nacos`。
+> 注意:需要 Nacos 2.3.0 及以上版本。因为旧版本的 nacos 不会为 Spring Cloud 应用程序生成实例 ID,
+> 而 Java Chassis 互操作性需要实例 ID。
diff --git a/java-chassis-interoprability/java-chassis-3.0.x/pom.xml b/java-chassis-interoprability/java-chassis-3.0.x/pom.xml
index fc1bb12b..b3db3f47 100644
--- a/java-chassis-interoprability/java-chassis-3.0.x/pom.xml
+++ b/java-chassis-interoprability/java-chassis-3.0.x/pom.xml
@@ -31,7 +31,7 @@
UTF-8
- 3.0.1
+ 3.3.0
@@ -67,7 +67,7 @@
com.lmax
disruptor
- 3.4.4
+ ${disruptor.version}
diff --git a/java-chassis-interoprability/java-chassis-3.0.x/provider/src/main/resources/log4j2.xml b/java-chassis-interoprability/java-chassis-3.0.x/provider/src/main/resources/log4j2.xml
index 53ed8e90..3e50e3cb 100644
--- a/java-chassis-interoprability/java-chassis-3.0.x/provider/src/main/resources/log4j2.xml
+++ b/java-chassis-interoprability/java-chassis-3.0.x/provider/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/java-chassis-interoprability/pom.xml b/java-chassis-interoprability/pom.xml
index efc69efe..59b2e4b0 100644
--- a/java-chassis-interoprability/pom.xml
+++ b/java-chassis-interoprability/pom.xml
@@ -26,9 +26,11 @@
pom
+ 17
UTF-8
3.11.0
3.1.3
+ 3.4.4
@@ -45,8 +47,8 @@
${maven-compiler-plugin.version}
-parameters
- 17
- 17
+ ${java.version}
+ ${java.version}
diff --git a/java-chassis-interoprability/spring-cloud-2022.0.x/gateway/src/main/resources/log4j2.xml b/java-chassis-interoprability/spring-cloud-2022.0.x/gateway/src/main/resources/log4j2.xml
index 56800246..9f765e7d 100644
--- a/java-chassis-interoprability/spring-cloud-2022.0.x/gateway/src/main/resources/log4j2.xml
+++ b/java-chassis-interoprability/spring-cloud-2022.0.x/gateway/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/java-chassis-interoprability/spring-cloud-2022.0.x/pom.xml b/java-chassis-interoprability/spring-cloud-2022.0.x/pom.xml
index fa054d6f..e630067d 100644
--- a/java-chassis-interoprability/spring-cloud-2022.0.x/pom.xml
+++ b/java-chassis-interoprability/spring-cloud-2022.0.x/pom.xml
@@ -33,7 +33,7 @@
UTF-8
2022.0.2
3.0.7
- 1.11.0-2022.0.x
+ 1.11.10-2024.0.x
@@ -71,7 +71,7 @@
com.lmax
disruptor
- 3.4.4
+ ${disruptor.version}
diff --git a/java-chassis-interoprability/spring-cloud-2022.0.x/provider/src/main/resources/log4j2.xml b/java-chassis-interoprability/spring-cloud-2022.0.x/provider/src/main/resources/log4j2.xml
index 4105c13c..fd2c38d8 100644
--- a/java-chassis-interoprability/spring-cloud-2022.0.x/provider/src/main/resources/log4j2.xml
+++ b/java-chassis-interoprability/spring-cloud-2022.0.x/provider/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/java-chassis-samples/README.md b/java-chassis-samples/README.md
index 373d12d6..4824d5d9 100644
--- a/java-chassis-samples/README.md
+++ b/java-chassis-samples/README.md
@@ -1,13 +1,22 @@
# samples
It's the samples of Java chassis
-1. pojo sample
-2. jaxrs sample
-3. spring mvc sample
-4. code first sample
+
+1. apm agent sample
+2. auth sample
+3. code first sample
+4. config apollo sample
5. customer handler sample
-6. extend metrics health checker sample
-7. write metrics data into separate text files sample
+6. jaxrs sample
+7. local service registry sample
+8. spring mvc sample
+9. extend metrics health checker sample
+10. write metrics data into separate text files sample
+11. pojo sample
+12. springmvc sample
+13. trust sample
+14. use log4j2 sample
## Precondition
+
see [Precondition](../README.md)
\ No newline at end of file
diff --git a/java-chassis-samples/apm-agent/README.md b/java-chassis-samples/apm-agent/README.md
new file mode 100644
index 00000000..8be6b5f3
--- /dev/null
+++ b/java-chassis-samples/apm-agent/README.md
@@ -0,0 +1,287 @@
+# APM-Agent
+
+## Description
+
+This project is an APM (Application Performance Monitoring) sample based on Java Agent technology, demonstrating how to provide non-intrusive performance monitoring capabilities for ServiceComb microservice applications through the Java Instrumentation API.
+
+## APM Introduction
+
+APM (Application Performance Monitoring) is a practice method for monitoring and managing software application performance and availability. APM systems typically provide the following core features:
+
+- **Performance Metrics Collection**: Monitor key metrics such as response time, throughput, and error rate
+- **Distributed Tracing**: Track request call chains across multiple services in microservice architecture
+- **Business Metrics Monitoring**: Collect and analyze business-related performance data
+- **Anomaly Detection and Alerting**: Detect performance issues promptly and notify relevant personnel
+
+Common APM tools include: Zipkin, SkyWalking, Pinpoint, Jaeger, etc.
+
+## ServiceComb APM Support
+
+Apache ServiceComb provides flexible extension mechanisms to support APM integration:
+
+### 1. BootListener Mechanism
+
+ServiceComb provides extension points for application lifecycle through the `BootListener` interface, allowing custom logic to be injected at different stages of service startup:
+
+```java
+public interface BootListener {
+ void onBootEvent(BootEvent event);
+}
+```
+
+Supported event types include:
+
+- `BEFORE_FILTER`: Before filter initialization
+- `AFTER_FILTER`: After filter initialization
+- `BEFORE_PRODUCER_PROVIDER`: Before Producer Provider initialization
+- `AFTER_PRODUCER_PROVIDER`: After Producer Provider initialization
+- `BEFORE_CONSUMER_PROVIDER`: Before Consumer Provider initialization
+- `AFTER_CONSUMER_PROVIDER`: After Consumer Provider initialization
+- `BEFORE_TRANSPORT`: Before transport layer initialization
+- `AFTER_TRANSPORT`: After transport layer initialization
+- `BEFORE_REGISTRY`: Before service registration
+- `AFTER_REGISTRY`: After service registration
+- `BEFORE_CLOSE`: Before service shutdown
+- `AFTER_CLOSE`: After service shutdown
+
+### 2. EventBus Event Mechanism
+
+ServiceComb uses Guava EventBus to publish various events during microservice invocation. APM components can collect performance data by subscribing to these events:
+
+- `InvocationStartEvent`: Invocation start event
+- `InvocationStartSendRequestEvent`: Start sending request event
+- `InvocationBusinessMethodStartEvent`: Business method execution start event
+- `InvocationBusinessMethodFinishEvent`: Business method execution finish event
+- `InvocationBusinessFinishEvent`: Business logic execution complete event
+- `InvocationEncodeResponseStartEvent`: Start encoding response event
+- `InvocationFinishEvent`: Invocation finish event (contains complete performance data)
+- `InvocationTimeoutCheckEvent`: Invocation timeout check event
+- `ServerAccessLogEvent`: Server access log event
+
+**Base Event Types:**
+
+- `InvocationBaseEvent`: Base class for all invocation events
+- `InvocationWithResponseEvent`: Base class for invocation events that contain response information
+
+### 3. Invocation Context
+
+Each invocation has an independent context (`Invocation`) that supports storing local data, facilitating the transfer of APM-related information (such as TraceId, SpanId, etc.) across different stages of the invocation.
+
+## Implementation Overview
+
+### Core Components
+
+1. **AgentMain**: Java Agent entry class
+ - Injected before application startup through the `premain` method
+ - Registers Spring `ApplicationContextInitializer` to ensure APM listener is registered as a Spring Bean
+ - Uses bytecode enhancement technology to support Web container environments
+
+2. **ApmBeanRegistrar**: Spring Bean registrar
+ - Implements the `ApplicationContextInitializer` interface
+ - Dynamically registers `ApmBootListener` as a Bean during Spring container initialization
+ - Ensures ServiceComb can discover the APM listener through dependency injection
+
+3. **ApmBootListener**: APM core listener
+ - Implements ServiceComb's `BootListener` interface
+ - Subscribes to invocation-related events and collects performance metrics
+ - Generates and outputs performance monitoring reports
+
+4. **Output Generators**:
+ - `HeaderOutputGenerator`: Generates request header information
+ - `ConsumerOutputGenerator`: Generates consumer-side performance data
+ - `ProducerOutputGenerator`: Generates provider-side performance data
+ - `EdgeOutputGenerator`: Generates edge service performance data
+
+### Technical Features
+
+- **Non-intrusive**: Uses Java Agent technology, applications can integrate APM functionality without modifying any code
+- **Transparent Integration**: Automatic registration through Spring extension mechanism, completely transparent to the application
+- **Complete Call Chain**: Records timing data for each stage from request start to finish
+- **Multi-role Support**: Simultaneously supports monitoring for Consumer, Producer, Edge, and other roles
+
+## Usage
+
+### 1. Add Dependencies
+
+No dependencies need to be added to the microservice project using the APM Agent. The APM Agent is loaded as an independent JAR file through JVM parameters.
+
+### 2. Build APM Agent
+
+Execute in the `apm-agent` directory:
+
+```bash
+mvn clean install
+```
+
+After building, `apm-agent-3.0-SNAPSHOT.jar` will be generated in the `target` directory.
+
+### 3. Load Agent on Application Startup
+
+When starting a ServiceComb application, add the `-javaagent` JVM parameter:
+
+```bash
+java -javaagent:/path/to/apm-agent-3.0-SNAPSHOT.jar -jar your-application.jar
+```
+
+Or use with Maven:
+
+```bash
+mvn exec:java -Dexec.mainClass="your.main.Class" \
+ -Dexec.args="-javaagent:/path/to/apm-agent-3.0-SNAPSHOT.jar"
+```
+
+In JetBrains IDEA, you can add VM options in the run configuration:
+
+```bash
+-javaagent:/path/to/apm-agent-3.0-SNAPSHOT.jar
+```
+
+### 4. View Monitoring Output
+
+The APM Agent will output performance data for each request to the console in the following format:
+
+```text
+PROVIDER rest springmvchello.sayHi:
+ http method: GET
+ url : /springmvchello/sayhi
+ status code: 200
+ traceId : 696fe51656552b35
+ total : 9.375ms
+ prepare : 2.156ms
+ queue : 0.542ms
+ provider-decode : 0.321ms
+ provider-encode : 1.876ms
+ execute : 3.245ms
+```
+
+## Precondition
+
+See [Precondition](../../README.md)
+
+## Sample Quick Start
+
+This sample uses ServiceComb's basic example project to demonstrate APM Agent functionality.
+
+### Start the Service Center
+
+- [How to start Service Center](http://servicecomb.apache.org/docs/products/service-center/install/)
+- Make sure Service Center address is configured correctly in `microservice.yaml`
+
+```yaml
+servicecomb:
+ service:
+ registry:
+ address: http://127.0.0.1:30100 #service center address
+```
+
+### Run Sample with APM Agent
+
+Using other sample projects (such as `basic-application-sample`) as an example:
+
+1. **Build the project**
+
+ ```bash
+ # Execute in the project root directory
+ mvn clean install
+ ```
+
+2. **Start Provider service (with APM Agent)**
+
+ ```bash
+ cd java-chassis-samples/basic-application-sample/basic-provider/target
+ java -javaagent:../../../apm-agent/target/apm-agent-3.0-SNAPSHOT.jar -jar basic-provider-3.0-SNAPSHOT.jar
+ ```
+
+3. **Start Consumer service (normal startup, without APM Agent)**
+
+ ```bash
+ cd java-chassis-samples/basic-application-sample/basic-consumer/target
+ java -jar basic-consumer-3.0-SNAPSHOT.jar
+ ```
+
+### How to Verify
+
+After both Provider and Consumer services start successfully, you can see the following in the Provider's console:
+
+**Performance monitoring data**: Each service invocation will output detailed performance data, including:
+
+- HTTP method and URL
+- Response status code
+- TraceId (for distributed tracing)
+- Total time and time breakdown by stage
+
+## Output Data Description
+
+### Consumer Side Output
+
+```text
+CONSUMER rest provider.hello.sayHi:
+ http method: GET
+ url : /hello/sayhi
+ status code: 200
+ traceId : 696fe51656552b35
+ total : 17.857ms
+ prepare : 5.231ms
+ consumer-send : 8.456ms
+ consumer-decode : 2.124ms
+ consumer-after-decode : 1.046ms
+```
+
+### Provider Side Output
+
+```text
+PROVIDER rest provider.hello.sayHi:
+ http method: GET
+ url : /hello/sayhi
+ status code: 200
+ traceId : 696fe51656552b35
+ total : 9.375ms
+ prepare : 2.156ms
+ queue : 0.542ms
+ provider-decode : 0.321ms
+ provider-encode : 1.876ms
+ execute : 3.245ms
+```
+
+## Extension Development
+
+### Custom Output Format
+
+You can customize the output format by modifying or extending implementations of `AbstractOutputGenerator`:
+
+```java
+public class CustomOutputGenerator extends AbstractOutputGenerator {
+ @Override
+ public void generate(StringBuilder sb, InvocationFinishEvent event) {
+ // Custom output logic
+ }
+}
+```
+
+### Integration with External APM Systems
+
+You can add code in the `ApmBootListener.onInvocationFinish` method to send performance data to external APM systems (such as Zipkin, SkyWalking, etc.):
+
+```java
+@Subscribe
+public void onInvocationFinish(InvocationFinishEvent event) {
+ // Create Span data
+ Span span = createSpan(event);
+
+ // Send to external APM system
+ apmClient.sendSpan(span);
+}
+```
+
+## Notes
+
+1. **Performance Impact**: The APM Agent will have some impact on application performance. It is recommended to control the sampling rate in production environments
+2. **Log Output**: The current implementation outputs directly to the console. For production environments, it is recommended to use asynchronous output to files or message queues
+3. **Version Compatibility**: This sample is developed based on ServiceComb 3.0. Other versions may require adjustments
+4. **JDK Version**: Supports JDK 8 and above
+
+## References
+
+- [ServiceComb Java Chassis Official Documentation](http://servicecomb.apache.org/docs/)
+- [Java Agent Technical Documentation](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/package-summary.html)
+- [Project Implementation Details](docs/walkthrough.md)
diff --git a/java-chassis-samples/apm-agent/pom.xml b/java-chassis-samples/apm-agent/pom.xml
index f628715e..f67d2e96 100644
--- a/java-chassis-samples/apm-agent/pom.xml
+++ b/java-chassis-samples/apm-agent/pom.xml
@@ -22,42 +22,32 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
4.0.0
- org.apache.servicecomb.samples
apm-agent
- 2.1.5
Java Chassis::Samples::apm-agent
- UTF-8
- 1.8
-
- -Dfile.encoding=UTF-8
- UTF-8
+ 3.1.0
+ 2.28.0
+ org.apache.servicecomb.samples.apm.AgentMain
-
-
-
- org.apache.servicecomb
- java-chassis-dependencies
- ${project.version}
- pom
- import
-
-
-
-
org.apache.servicecomb
provider-rest-common
provided
+
+ com.google.errorprone
+ error_prone_annotations
+ ${error_prone_annotations.version}
+ provided
+
@@ -65,7 +55,7 @@
org.apache.maven.plugins
maven-jar-plugin
- 3.1.0
+ ${maven-jar-plugin.version}
default-jar
@@ -75,7 +65,7 @@
- org.apache.servicecomb.samples.apm.AgentMain
+ ${start-class}
@@ -83,10 +73,9 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.1
- 1.8
- 1.8
+ ${java.version}
+ ${java.version}
-Werror
-Xlint:all
diff --git a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/AgentMain.java b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/AgentMain.java
index 213c7900..a411e92a 100644
--- a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/AgentMain.java
+++ b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/AgentMain.java
@@ -20,6 +20,26 @@
public class AgentMain {
public static void premain(String args, Instrumentation inst) {
+ // Register Spring ApplicationContextInitializer to make ApmBootListener a Spring Bean
+ // This must be set BEFORE Spring initializes
+ String existingInitializers = System.getProperty("context.initializer.classes", "");
+ String apmInitializer = "org.apache.servicecomb.samples.apm.ApmBeanRegistrar";
+
+ if (existingInitializers.isEmpty()) {
+ System.setProperty("context.initializer.classes", apmInitializer);
+ } else {
+ System.setProperty("context.initializer.classes", existingInitializers + "," + apmInitializer);
+ }
+
+ // Inject jar to System ClassLoader immediately for JDK 9+ compatibility
+ try {
+ java.util.jar.JarFile jarFile = new java.util.jar.JarFile(
+ new java.io.File(AgentMain.class.getProtectionDomain().getCodeSource().getLocation().toURI()));
+ inst.appendToSystemClassLoaderSearch(jarFile);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
// to support web container, we can not just only inject spiJar to system classloader
// in this sample, javaAgent jar equals ServiceComb plugin jar
inst.addTransformer(
diff --git a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/ApmBeanRegistrar.java b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/ApmBeanRegistrar.java
new file mode 100644
index 00000000..a352dec3
--- /dev/null
+++ b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/ApmBeanRegistrar.java
@@ -0,0 +1,41 @@
+/*
+ * 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.samples.apm;
+
+import org.apache.servicecomb.samples.apm.impl.ApmBootListener;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+
+/**
+ * Spring ApplicationContextInitializer to dynamically register ApmBootListener as a Spring Bean.
+ * This is necessary because ServiceComb uses @Autowired to inject BootListeners,
+ * not Java's ServiceLoader mechanism.
+ */
+public class ApmBeanRegistrar implements ApplicationContextInitializer {
+ @Override
+ public void initialize(ConfigurableApplicationContext applicationContext) {
+ BeanDefinitionRegistry registry = (BeanDefinitionRegistry) applicationContext.getBeanFactory();
+
+ BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(ApmBootListener.class)
+ .getBeanDefinition();
+
+ registry.registerBeanDefinition("apmBootListener", beanDefinition);
+ }
+}
diff --git a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/SCBClassFileTransformer.java b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/SCBClassFileTransformer.java
index ae6d8cfb..7ccec757 100644
--- a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/SCBClassFileTransformer.java
+++ b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/SCBClassFileTransformer.java
@@ -49,7 +49,14 @@ private synchronized void injectSPI(ClassLoader loader) {
return;
}
+ // System ClassLoader injection is handled in premain for JDK 9+
+ if (ClassLoader.getSystemClassLoader() == loader) {
+ return;
+ }
+
try {
+ // Fallback for other classloaders (e.g. web containers) - keep legacy
+ // reflection just in case
Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addURLMethod.setAccessible(true);
addURLMethod.invoke(loader, scbSpiJar);
diff --git a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/ApmBootListener.java b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/ApmBootListener.java
index 7ad4284d..e8f15115 100644
--- a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/ApmBootListener.java
+++ b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/ApmBootListener.java
@@ -83,7 +83,7 @@ public void onInvocationFinish(InvocationFinishEvent event) {
@Override
public void onBootEvent(BootEvent event) {
- if (EventType.BEFORE_HANDLER.equals(event.getEventType())) {
+ if (EventType.BEFORE_FILTER.equals(event.getEventType())) {
event.getScbEngine().getEventBus().register(this);
}
}
diff --git a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/ConsumerOutputGenerator.java b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/ConsumerOutputGenerator.java
index 12e35ffe..1022b22e 100644
--- a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/ConsumerOutputGenerator.java
+++ b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/ConsumerOutputGenerator.java
@@ -24,17 +24,21 @@ public class ConsumerOutputGenerator extends AbstractOutputGenerator {
public void generate(StringBuilder sb, InvocationFinishEvent event) {
InvocationStageTrace stageTrace = event.getInvocation().getInvocationStageTrace();
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.HANDLERS_REQUEST, stageTrace.calcHandlersRequestTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.CLIENT_FILTERS_REQUEST,
- stageTrace.calcClientFiltersRequestTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.CONSUMER_SEND_REQUEST, stageTrace.calcSendRequestTime());
- appendTimeLine(sb, PAD6_TIME_FMT, InvocationStageTrace.CONSUMER_GET_CONNECTION, stageTrace.calcGetConnectionTime());
- appendTimeLine(sb, PAD6_TIME_FMT, InvocationStageTrace.CONSUMER_WRITE_TO_BUF, stageTrace.calcWriteToBufferTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.CONSUMER_WAIT_RESPONSE,
- stageTrace.calcReceiveResponseTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.CONSUMER_WAKE_CONSUMER, stageTrace.calcWakeConsumer());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.CLIENT_FILTERS_RESPONSE,
- stageTrace.calcClientFiltersResponseTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.HANDLERS_RESPONSE, stageTrace.calcHandlersResponseTime());
+ // 1. total: start create invocation -> all filters finished
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_TOTAL, stageTrace.calcTotal());
+ // 2. prepare: start create invocation -> finish create invocation
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PREPARE, stageTrace.calcPrepare());
+ // 3. connection: start get connection -> finish get connection
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_CONNECTION, stageTrace.calcConnection());
+ // 4. consumer-encode: start encode request -> finish encode request
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_ENCODE_REQUEST,
+ stageTrace.calcConsumerEncodeRequest());
+ // 5. consumer-send: start send request -> finish send request
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_SEND, stageTrace.calcConsumerSendRequest());
+ // 6. wait: finish send request -> start decode response
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_WAIT, stageTrace.calcWait());
+ // 7. consumer-decode: start decode response -> finish decode response
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_DECODE_RESPONSE,
+ stageTrace.calcConsumerDecodeResponse());
}
}
diff --git a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/EdgeOutputGenerator.java b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/EdgeOutputGenerator.java
index 5beb10df..541ad793 100644
--- a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/EdgeOutputGenerator.java
+++ b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/EdgeOutputGenerator.java
@@ -24,14 +24,29 @@ public class EdgeOutputGenerator extends ConsumerOutputGenerator {
public void generate(StringBuilder sb, InvocationFinishEvent event) {
InvocationStageTrace stageTrace = event.getInvocation().getInvocationStageTrace();
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.THREAD_POOL_QUEUE, stageTrace.calcThreadPoolQueueTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.SERVER_FILTERS_REQUEST,
- stageTrace.calcServerFiltersRequestTime());
-
- super.generate(sb, event);
-
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.SERVER_FILTERS_RESPONSE,
- stageTrace.calcServerFiltersResponseTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.PRODUCER_SEND_RESPONSE, stageTrace.calcSendResponseTime());
+ // 1. total: start create invocation -> all filters finished
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_TOTAL, stageTrace.calcTotal());
+ // 2. prepare: start create invocation -> finish create invocation
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PREPARE, stageTrace.calcPrepare());
+ // 4. connection: start get connection -> finish get connection
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_CONNECTION, stageTrace.calcConnection());
+ // 5. provider-decode: start decode request -> finish decode request
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PROVIDER_DECODE_REQUEST,
+ stageTrace.calcProviderDecodeRequest());
+ // 6. provider-encode: start encode response -> finish encode response
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PROVIDER_ENCODE_RESPONSE,
+ stageTrace.calcProviderEncodeResponse());
+ // 7. consumer-encode: start encode request -> finish encode request
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_ENCODE_REQUEST,
+ stageTrace.calcConsumerEncodeRequest());
+ // 8. consumer-decode: start decode response -> finish decode response
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_DECODE_RESPONSE,
+ stageTrace.calcConsumerDecodeResponse());
+ // 9. consumer-send: start send request -> finish send request
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_SEND, stageTrace.calcConsumerSendRequest());
+ // 10. provider-send: start send response -> finish send response
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PROVIDER_SEND, stageTrace.calcProviderSendResponse());
+ // 11. wait: finish send request -> start decode response
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_CONSUMER_WAIT, stageTrace.calcWait());
}
}
diff --git a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/HeaderOutputGenerator.java b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/HeaderOutputGenerator.java
index 4ee3570a..a6973363 100644
--- a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/HeaderOutputGenerator.java
+++ b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/HeaderOutputGenerator.java
@@ -20,22 +20,17 @@
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.event.InvocationFinishEvent;
-import org.apache.servicecomb.core.invocation.InvocationStageTrace;
public class HeaderOutputGenerator extends AbstractOutputGenerator {
@Override
public void generate(StringBuilder sb, InvocationFinishEvent event) {
Invocation invocation = event.getInvocation();
RestOperationMeta restOperationMeta = invocation.getOperationMeta().getExtData(RestConst.SWAGGER_REST_OPERATION);
- InvocationStageTrace stageTrace = event.getInvocation().getInvocationStageTrace();
sb.append(invocation.getInvocationQualifiedName()).append(":\n");
appendLine(sb, PAD2_KEY11_FMT, "http method", restOperationMeta.getHttpMethod());
appendLine(sb, PAD2_KEY11_FMT, "url", restOperationMeta.getAbsolutePath());
appendLine(sb, PAD2_KEY11_FMT, "status code", event.getResponse().getStatusCode());
appendLine(sb, PAD2_KEY11_FMT, "traceId", invocation.getTraceId());
-
- appendTimeLine(sb, PAD2_TIME_FMT, "total", stageTrace.calcTotalTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.PREPARE, stageTrace.calcInvocationPrepareTime());
}
}
diff --git a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/ProducerOutputGenerator.java b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/ProducerOutputGenerator.java
index 1b6250f0..2a4ee017 100644
--- a/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/ProducerOutputGenerator.java
+++ b/java-chassis-samples/apm-agent/src/main/java/org/apache/servicecomb/samples/apm/impl/output/ProducerOutputGenerator.java
@@ -26,15 +26,22 @@ public void generate(StringBuilder sb, InvocationFinishEvent event) {
Invocation invocation = event.getInvocation();
InvocationStageTrace stageTrace = invocation.getInvocationStageTrace();
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.THREAD_POOL_QUEUE, stageTrace.calcThreadPoolQueueTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.SERVER_FILTERS_REQUEST,
- stageTrace.calcServerFiltersRequestTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.HANDLERS_REQUEST, stageTrace.calcHandlersRequestTime());
- appendTimeLine(sb, PAD4_TIME_FMT, invocation.getOperationMeta().getSchemaQualifiedName(),
- stageTrace.calcBusinessTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.HANDLERS_RESPONSE, stageTrace.calcHandlersResponseTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.SERVER_FILTERS_RESPONSE,
- stageTrace.calcServerFiltersResponseTime());
- appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.PRODUCER_SEND_RESPONSE, stageTrace.calcSendResponseTime());
+ // 1. total: start create invocation -> all filters finished
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_TOTAL, stageTrace.calcTotal());
+ // 2. prepare: start create invocation -> finish create invocation
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PREPARE, stageTrace.calcPrepare());
+ // 3. queue: add in queue -> execute in thread
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PROVIDER_QUEUE, stageTrace.calcQueue());
+ // 4. provider-decode: start decode request -> finish decode request
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PROVIDER_DECODE_REQUEST,
+ stageTrace.calcProviderDecodeRequest());
+ // 5. execute: start business execute -> finish business execute
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PROVIDER_BUSINESS, stageTrace.calcBusinessExecute());
+ // 6. provider-encode: start encode response -> finish encode response
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PROVIDER_ENCODE_RESPONSE,
+ stageTrace.calcProviderEncodeResponse());
+ // 7. provider-send: start send response -> finish send response
+ appendTimeLine(sb, PAD4_TIME_FMT, InvocationStageTrace.STAGE_PROVIDER_SEND,
+ stageTrace.calcProviderSendResponse());
}
}
diff --git a/java-chassis-samples/apm-agent/src/main/resources/META-INF/services/org.apache.servicecomb.core.BootListener b/java-chassis-samples/apm-agent/src/main/resources/META-INF/services/org.apache.servicecomb.core.BootListener
deleted file mode 100644
index e0efc733..00000000
--- a/java-chassis-samples/apm-agent/src/main/resources/META-INF/services/org.apache.servicecomb.core.BootListener
+++ /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.samples.apm.impl.ApmBootListener
\ No newline at end of file
diff --git a/java-chassis-samples/auth-sample/README.md b/java-chassis-samples/auth-sample/README.md
index a84a7488..dce3f823 100644
--- a/java-chassis-samples/auth-sample/README.md
+++ b/java-chassis-samples/auth-sample/README.md
@@ -1,98 +1,126 @@
-## Auth-Sample
+# Auth-Sample
+
+## Description
To make sure the security between the interfaces of services, users can enable `RSA Authorizaiton` by simple configuration as below.
## Consumer Service
-* Add dependence in pom.xml file:
+1. Add dependence in `pom.xml` file:
-```xml
-
- org.apache.servicecomb
- handler-publickey-auth
-
-```
+ ```xml
+
+ org.apache.servicecomb
+ handler-publickey-auth
+
+ ```
-* Add handler chain in microservice.yaml:
+2. Add handler chain in `microservice.yaml`:
-```yaml
-servicecomb:
- handler:
- chain:
- Consumer:
- default: auth-consumer
-```
+ ```yaml
+ servicecomb:
+ handler:
+ chain:
+ Consumer:
+ default: auth-consumer
+ ```
## Provider Service
-* Add dependence in pom.xml file:
+1. Add dependence in `pom.xml` file:
-```xml
-
- org.apache.servicecomb
- handler-publickey-auth
-
-```
+ ```xml
+
+ org.apache.servicecomb
+ handler-publickey-auth
+
+ ```
-* Add handler chain in microservice.yaml:
+2. Add handler chain in `microservice.yaml`:
+
+ ```yaml
+ servicecomb:
+ handler:
+ chain:
+ Consumer:
+ default: auth-provider
+ ```
-```yaml
-servicecomb:
- handler:
- chain:
- Consumer:
- default: auth-provider
-```
## Precondition
+
see [Precondition](../../README.md)
## Sample Quick Start
Auth sample use `RestTemplate` to present RSA communication between provider and consumer.
-* Start the ServiceComb/Service Center
+### Start the ServiceComb/Service Center
- - [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
- - make sure service center address is configured correctly in `microservice.yaml` file
+- [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+- make sure service center address is configured correctly in `microservice.yaml` file
```yaml
servicecomb:
- service:
- registry:
- address: http://127.0.0.1:30100 #service center address
+ service:
+ registry:
+ address: http://127.0.0.1:30100 #service center address
```
-* Start the auth-provider service
+### Start the `auth-provider` service
- - Start provider service by maven
+- Start provider service by maven
- Compile the source code, and use `mvn exec` to execute the main class `AuthProviderMain`.
+ Compile the source code, and use `mvn exec` to execute the main class `AuthProviderMain`.
- ```bash
- mvn clean install
- cd auth-sample/auth-provider/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.auth.provider.AuthProviderMain"
- ```
+ ```bash
+ mvn clean install
+ cd auth-sample/auth-provider/
+ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.auth.provider.AuthProviderMain"
+ ```
- - Start provider service by IDE
+- Start provider service by IDE
- Import the project by InteliJ IDEA or Eclipse, then find `main` function `AuthProviderMain` of provider service and `RUN` it like any other Java program.
+ Import the project by InteliJ IDEA or Eclipse, then find `main` function `AuthProviderMain` of provider service and `RUN` it like any other Java program.
-* Start the auth-consumer service
+### Start the `auth-consumer` service
- Just like how to start auth-provider service. But the main class of auth-consumer service is `AuthConsumerMain`.
+Just like how to start `auth-provider` service. But the main class of auth-consumer service is `AuthConsumerMain`.
```bash
cd auth-sample/auth-consumer/
mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.auth.consumer.AuthConsumerMain"
```
-* How to verify
- On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- 1. *'swagger: 2.0 info: version: 1.0.0 ...'* means the producer generated swagger contracts
- 2. *'rest listen success. address=0.0.0.0:8080'* means the rest endpoint is listening on port 8080
-
- On the consumer side, you can see the following outputs if the consumer can invoke the producer:
- 1. *'Hello Authenticate'* means the consumer calls sayhi with name=Authenticate successfully
- 2. *'Hello person ServiceComb/Authenticate'* means the consumer calls sayhello successfully
+### How to verify
+
+On the producer side, the output should contain the following stuffs if the producer starts up successfully:
+
+1. *`swagger: 2.0 info: version: 1.0.0 ...`* means the producer generated swagger contracts
+2. *`rest listen success. address=0.0.0.0:8080`* means the rest endpoint is listening on port 8080
+
+On the consumer side, you can see the following outputs if the consumer can invoke the producer:
+
+1. *`Hello Authenticate`* means the consumer calls sayhi with name=Authenticate successfully
+2. *`Hello person ServiceComb/Authenticate`* means the consumer calls sayhello successfully
+
+Access `auth-provider` through the interface:
+
+- [GET] http://localhost:8080/springmvchello/sayhi?name=world
+- [POSt] http://localhost:8080/springmvchello/sayhello
+
+You will get:
+
+```text
+{
+ "message": "Method Not Allowed"
+}
+```
+
+Start the `auth-consumer` service, You will get on output:
+
+```text
+Hello Authenticate
+Hello person ServiceComb/Authenticate
+```
+Which means each microservice can only be accessed by the configured microservices.
diff --git a/java-chassis-samples/auth-sample/auth-consumer/pom.xml b/java-chassis-samples/auth-sample/auth-consumer/pom.xml
index 5161eed3..7f6753d0 100644
--- a/java-chassis-samples/auth-sample/auth-consumer/pom.xml
+++ b/java-chassis-samples/auth-sample/auth-consumer/pom.xml
@@ -21,46 +21,8 @@
org.apache.servicecomb.samples
auth-sample
- 2.6.0
+ 3.0-SNAPSHOT
auth-consumer
Java Chassis::Samples::Auth::Consumer
-
-
- org.apache.servicecomb
- transport-rest-vertx
-
-
- org.apache.servicecomb
- handler-loadbalance
-
-
- org.apache.servicecomb
- provider-springmvc
-
-
- org.apache.servicecomb
- provider-pojo
-
-
- org.apache.servicecomb
- handler-publickey-auth
-
-
- org.apache.logging.log4j
- log4j-slf4j-impl
-
-
- org.apache.logging.log4j
- log4j-api
-
-
- org.apache.logging.log4j
- log4j-core
-
-
- org.apache.servicecomb.samples
- common-schema
-
-
diff --git a/java-chassis-samples/auth-sample/auth-consumer/src/main/java/org/apache/servicecomb/samples/auth/consumer/AuthConsumerMain.java b/java-chassis-samples/auth-sample/auth-consumer/src/main/java/org/apache/servicecomb/samples/auth/consumer/AuthConsumerMain.java
index 2efa3e87..b55c3e2d 100644
--- a/java-chassis-samples/auth-sample/auth-consumer/src/main/java/org/apache/servicecomb/samples/auth/consumer/AuthConsumerMain.java
+++ b/java-chassis-samples/auth-sample/auth-consumer/src/main/java/org/apache/servicecomb/samples/auth/consumer/AuthConsumerMain.java
@@ -16,32 +16,45 @@
*/
package org.apache.servicecomb.samples.auth.consumer;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.samples.common.schema.models.Person;
-import org.springframework.stereotype.Component;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.web.client.RestOperations;
-@Component
+@SpringBootApplication
public class AuthConsumerMain {
- private static RestTemplate restTemplate = RestTemplateBuilder.create();
+ private static RestOperations restTemplate = RestTemplateBuilder.create();
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(AuthConsumerMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ run();
+ }
+
+ private static void run() {
+ System.out.println("RestTemplate Consumer or POJO Consumer. You can choose whatever you like.");
+ String sayHiResult = restTemplate
+ .postForObject(
+ "cse://auth-provider/springmvchello/sayhi?name=Authenticate",
+ null,
+ String.class);
+
Person person = new Person();
person.setName("ServiceComb/Authenticate");
- System.out
- .println("RestTemplate Consumer or POJO Consumer. You can choose whatever you like.");
- String sayHiResult = restTemplate
- .postForObject(
- "cse://auth-provider/springmvchello/sayhi?name=Authenticate",
- null,
- String.class);
String sayHelloResult = restTemplate.postForObject(
- "cse://auth-provider/springmvchello/sayhello",
- person,
- String.class);
+ "cse://auth-provider/springmvchello/sayhello",
+ person,
+ String.class);
System.out.println(sayHiResult);
System.out.println(sayHelloResult);
}
diff --git a/java-chassis-samples/auth-sample/auth-consumer/src/main/resources/log4j2.xml b/java-chassis-samples/auth-sample/auth-consumer/src/main/resources/log4j2.xml
index 7beef41d..f03b1fda 100644
--- a/java-chassis-samples/auth-sample/auth-consumer/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/auth-sample/auth-consumer/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/auth-sample/auth-consumer
diff --git a/java-chassis-samples/auth-sample/auth-consumer/src/main/resources/microservice.yaml b/java-chassis-samples/auth-sample/auth-consumer/src/main/resources/microservice.yaml
index 76e45f86..60a981e8 100644
--- a/java-chassis-samples/auth-sample/auth-consumer/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/auth-sample/auth-consumer/src/main/resources/microservice.yaml
@@ -18,15 +18,15 @@
servicecomb:
service:
application: auth-sample
- name: authConsumer
+ name: auth-consumer
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
- handler:
- chain:
- Consumer:
- default: auth-consumer, loadbalance
references:
auth-provider:
version-rule: 0.0.1
+ publicKey:
+ accessControl:
+ enabled: true
diff --git a/java-chassis-samples/auth-sample/auth-provider/pom.xml b/java-chassis-samples/auth-sample/auth-provider/pom.xml
index bd94b581..4bf5468b 100644
--- a/java-chassis-samples/auth-sample/auth-provider/pom.xml
+++ b/java-chassis-samples/auth-sample/auth-provider/pom.xml
@@ -21,37 +21,8 @@
org.apache.servicecomb.samples
auth-sample
- 2.6.0
+ 3.0-SNAPSHOT
auth-provider
-
-
- org.apache.servicecomb
- transport-rest-vertx
-
-
- org.apache.servicecomb
- handler-publickey-auth
-
-
- org.apache.servicecomb
- provider-springmvc
-
-
- org.apache.logging.log4j
- log4j-slf4j-impl
-
-
- org.apache.logging.log4j
- log4j-api
-
-
- org.apache.logging.log4j
- log4j-core
-
-
- org.apache.servicecomb.samples
- common-schema
-
-
+ Java Chassis::Samples::Auth::Provider
diff --git a/java-chassis-samples/auth-sample/auth-provider/src/main/java/org/apache/servicecomb/samples/auth/provider/AuthProviderMain.java b/java-chassis-samples/auth-sample/auth-provider/src/main/java/org/apache/servicecomb/samples/auth/provider/AuthProviderMain.java
index 1256f645..7256664f 100644
--- a/java-chassis-samples/auth-sample/auth-provider/src/main/java/org/apache/servicecomb/samples/auth/provider/AuthProviderMain.java
+++ b/java-chassis-samples/auth-sample/auth-provider/src/main/java/org/apache/servicecomb/samples/auth/provider/AuthProviderMain.java
@@ -17,11 +17,21 @@
package org.apache.servicecomb.samples.auth.provider;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class AuthProviderMain {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(AuthProviderMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/java-chassis-samples/auth-sample/auth-provider/src/main/java/org/apache/servicecomb/samples/auth/provider/SpringmvcHelloImpl.java b/java-chassis-samples/auth-sample/auth-provider/src/main/java/org/apache/servicecomb/samples/auth/provider/SpringmvcHelloImpl.java
index 42ef65d8..fa70f0a7 100644
--- a/java-chassis-samples/auth-sample/auth-provider/src/main/java/org/apache/servicecomb/samples/auth/provider/SpringmvcHelloImpl.java
+++ b/java-chassis-samples/auth-sample/auth-provider/src/main/java/org/apache/servicecomb/samples/auth/provider/SpringmvcHelloImpl.java
@@ -18,7 +18,7 @@
package org.apache.servicecomb.samples.auth.provider;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.MediaType;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.apache.servicecomb.samples.common.schema.Hello;
diff --git a/java-chassis-samples/auth-sample/auth-provider/src/main/resources/log4j2.xml b/java-chassis-samples/auth-sample/auth-provider/src/main/resources/log4j2.xml
index 065e1144..9962ed32 100644
--- a/java-chassis-samples/auth-sample/auth-provider/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/auth-sample/auth-provider/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/auth-sample/auth-provider
diff --git a/java-chassis-samples/auth-sample/auth-provider/src/main/resources/microservice.yaml b/java-chassis-samples/auth-sample/auth-provider/src/main/resources/microservice.yaml
index 83df4c00..8a742f23 100644
--- a/java-chassis-samples/auth-sample/auth-provider/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/auth-sample/auth-provider/src/main/resources/microservice.yaml
@@ -21,11 +21,17 @@ servicecomb:
name: auth-provider
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
- handler:
- chain:
- Provider:
- default: auth-provider
rest:
address: 0.0.0.0:8080
+
+ publicKey:
+ accessControl:
+ enabled: true
+ white:
+ list01:
+ category: property
+ propertyName: serviceName
+ rule: auth-consumer
\ No newline at end of file
diff --git a/java-chassis-samples/auth-sample/pom.xml b/java-chassis-samples/auth-sample/pom.xml
index 32e4fb23..54ad7163 100644
--- a/java-chassis-samples/auth-sample/pom.xml
+++ b/java-chassis-samples/auth-sample/pom.xml
@@ -21,17 +21,47 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
auth-sample
Java Chassis::Samples::Auth
pom
+
+
+ org.apache.servicecomb
+ solution-basic
+
org.apache.servicecomb
registry-service-center
+
+ org.apache.servicecomb
+ handler-publickey-auth
+
+
+ org.apache.servicecomb
+ java-chassis-spring-boot-starter-standalone
+
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+
+
+ org.apache.logging.log4j
+ log4j-api
+
+
+ org.apache.logging.log4j
+ log4j-core
+
+
+ org.apache.servicecomb.samples
+ common-schema
+
diff --git a/java-chassis-samples/codefirst-sample/README.md b/java-chassis-samples/codefirst-sample/README.md
index 278a671d..535c4e07 100644
--- a/java-chassis-samples/codefirst-sample/README.md
+++ b/java-chassis-samples/codefirst-sample/README.md
@@ -1,4 +1,4 @@
-## Code First Sample
+# Code First Sample
ServiceComb Java Chassis supports generating provider-service API implicitly. When the service is started, an API is automatically generated and registered to the service center.
@@ -6,81 +6,83 @@ When you develop a microservice in transparent RPC mode, the code does not show
For detail information please refer to [Doc](https://docs.servicecomb.io/java-chassis/zh_CN/build-provider/code-first/)
-
-
## Sample Quick Start
-* Start the ServiceComb/Service Center
+### Start the ServiceComb/Service Center
- - [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
- - make sure service center address is configured correctly in `microservice.yaml` file
+- [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+- make sure service center address is configured correctly in `microservice.yaml` file
```yaml
servicecomb:
service:
registry:
- address: http://127.0.0.1:30100 #service center address
+ address: http://127.0.0.1:30100 #service center address
```
-* Start the codefirst-provider service
+### Start the `codefirst-provider` service
- - Start provider service via maven
+- Start provider service via maven
- Compile the source code, and use `mvn exec` to execute the main class `CodeFirstProviderMain`.
+ Compile the source code, and use `mvn exec` to execute the main class `CodeFirstProviderMain`.
- ```bash
- mvn clean install
- cd codefirst-sample/codefirst-provider/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.provider.CodeFirstProviderMain"
- ```
+ ```bash
+ mvn clean install
+ cd codefirst-sample/codefirst-provider/
+ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.provider.CodeFirstProviderMain"
+ ```
+
+- Start provider service via gradle
+
+ Compile the source code, and use `mvn exec` to execute the main class `CodeFirstProviderMain`.
+
+ ```bash
+ cd codefirst-sample/codefirst-provider/
+
+ ```
- - Start provider service via gradle
+- Start provider service via IDE
- Compile the source code, and use `mvn exec` to execute the main class `CodeFirstProviderMain`.
+ Import the project by InteliJ IDEA or Eclipse, then find `main` function `CodeFirstProviderMain` of provider service and `RUN` it like any other Java program.
- ```bash
- cd codefirst-sample/codefirst-provider/
-
- ```
+### Start the `codefirst-consumer` service
- - Start provider service via IDE
+```bash
+mvn clean install
+cd codefirst-sample/codefirst-consumer/
+mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.consumer.CodeFirstConsumerMain"
+```
- Import the project by InteliJ IDEA or Eclipse, then find `main` function `CodeFirstProviderMain` of provider service and `RUN` it like any other Java program.
+- Start consumer service via maven
-3. Start the codefirst-consumer service
+ Just like how to start codefirst-provider service. But the main class of `codefirst-consumer` service is `CodeFirstConsumerMain`.
```bash
- mvn clean install
- cd codefirst-sample/codefirst-consumer/
mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.consumer.CodeFirstConsumerMain"
```
- - Start consumer service via maven
+- Start consumer service via gradle
- Just like how to start codefirst-provider service. But the main class of codefirst-consumer service is `CodeFirstConsumerMain`.
+ ```bash
+ gradle clean run
+ ```
- ```bash
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.consumer.CodeFirstConsumerMain"
- ```
+### How to verify
- - Start consumer service via gradle
+On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- ```bash
- gradle clean run
- ```
+1. *`swagger: 2.0 info: version: 1.0.0 ...`* means the producer generated swagger contracts
+2. *`rest listen success. address=0.0.0.0:8080`* means the rest endpoint is listening on port 8080
-4. How to verify
- On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- 1. *'swagger: 2.0 info: version: 1.0.0 ...'* means the producer generated swagger contracts
- 2. *'rest listen success. address=0.0.0.0:8080'* means the rest endpoint is listening on port 8080
-
- On the consumer side, you can see the following outputs if the consumer can invoke the producer:
- 1. *'Pojo Hello Java Chassis'* means the consumer calls sayhi successfully
- 2. *'Jaxrs Hello Java Chassis'* means the consumer calls Jaxrs sayhi successfully
- 3. *'Spring mvc Hello Java Chassis'* means the consumer calls SpringMvc sayhi successfully
- 4. *'Pojo Hello person ServiceComb/Java Chassis'* means the consumer calls sayhello successfully
- 5. *'Jaxrs Hello person ServiceComb/Java Chassis'* means the consumer calls Jaxrs sayhello successfully
- 6. *'Spring mvc Hello person ServiceComb/Java Chassis'* means the consumer calls SpringMvc sayhello successfully
+On the consumer side, you can see the following outputs if the consumer can invoke the producer:
+
+1. *`Pojo Hello Java Chassis`* means the consumer calls sayhi successfully
+2. *`Jaxrs Hello Java Chassis`* means the consumer calls Jaxrs sayhi successfully
+3. *`Spring mvc Hello Java Chassis`* means the consumer calls SpringMvc sayhi successfully
+4. *`Pojo Hello person ServiceComb/Java Chassis`* means the consumer calls sayhello successfully
+5. *`Jaxrs Hello person ServiceComb/Java Chassis`* means the consumer calls Jaxrs sayhello successfully
+6. *`Spring mvc Hello person ServiceComb/Java Chassis`* means the consumer calls SpringMvc sayhello successfully
## Precondition
+
see [Precondition](../../README.md)
\ No newline at end of file
diff --git a/java-chassis-samples/codefirst-sample/build.gradle b/java-chassis-samples/codefirst-sample/build.gradle
index f2fe0d56..755ecb51 100644
--- a/java-chassis-samples/codefirst-sample/build.gradle
+++ b/java-chassis-samples/codefirst-sample/build.gradle
@@ -16,17 +16,21 @@
*/
allprojects {
- apply plugin: 'maven'
+ apply plugin: 'maven-publish'
group = 'org.apache.servicecomb.samples'
- version = '2.0.0'
+ version = '3.0-SNAPSHOT'
}
subprojects {
apply plugin: 'java'
- sourceCompatibility = 1.8
- targetCompatibility = 1.8
+ compileJava {
+ options.compilerArgs << '-parameters'
+ }
+
+ sourceCompatibility = 17
+ targetCompatibility = 17
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
diff --git a/java-chassis-samples/codefirst-sample/codefirst-consumer/build.gradle b/java-chassis-samples/codefirst-sample/codefirst-consumer/build.gradle
index fed96248..ea469afe 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-consumer/build.gradle
+++ b/java-chassis-samples/codefirst-sample/codefirst-consumer/build.gradle
@@ -24,12 +24,12 @@ compileJava {
}
dependencies {
- compile group: 'org.apache.servicecomb', name: 'provider-pojo'
- compile group: 'org.apache.servicecomb', name: 'transport-rest-vertx'
- compile group: 'org.apache.servicecomb.samples', name: 'common-schema', version: '2.0.0'
- compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl'
- compile group: 'org.apache.logging.log4j', name: 'log4j-api'
- compile group: 'org.apache.logging.log4j', name: 'log4j-core'
+ implementation group: 'org.apache.servicecomb', name: 'solution-basic'
+ implementation group: 'org.apache.servicecomb', name: 'registry-service-center'
+ implementation group: 'org.apache.servicecomb.samples', name: 'common-schema', version: "3.0-SNAPSHOT"
+ implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl'
+ implementation group: 'org.apache.logging.log4j', name: 'log4j-api'
+ implementation group: 'org.apache.logging.log4j', name: 'log4j-core'
}
apply plugin: 'application'
@@ -53,6 +53,6 @@ apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
- mavenBom 'org.apache.servicecomb:java-chassis-dependencies:2.0.0'
+ mavenBom 'org.apache.servicecomb:java-chassis-dependencies:3.3.0'
}
}
diff --git a/java-chassis-samples/codefirst-sample/codefirst-consumer/pom.xml b/java-chassis-samples/codefirst-sample/codefirst-consumer/pom.xml
index 78537ec4..5eccd137 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-consumer/pom.xml
+++ b/java-chassis-samples/codefirst-sample/codefirst-consumer/pom.xml
@@ -21,7 +21,7 @@
org.apache.servicecomb.samples
codefirst-sample
- 2.6.0
+ 3.0-SNAPSHOT
codefirst-consumer
Java Chassis::Samples::CodeFirst::Consumer
@@ -29,17 +29,13 @@
UTF-8
-
- org.apache.servicecomb.samples
- common-schema
-
org.apache.servicecomb
- provider-pojo
+ solution-basic
- org.apache.servicecomb
- transport-rest-vertx
+ org.apache.servicecomb.samples
+ common-schema
org.apache.logging.log4j
diff --git a/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/java/org/apache/servicecomb/samples/codefirst/consumer/CodeFirstConsumerMain.java b/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/java/org/apache/servicecomb/samples/codefirst/consumer/CodeFirstConsumerMain.java
index 8866e8e9..1dff862e 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/java/org/apache/servicecomb/samples/codefirst/consumer/CodeFirstConsumerMain.java
+++ b/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/java/org/apache/servicecomb/samples/codefirst/consumer/CodeFirstConsumerMain.java
@@ -16,13 +16,14 @@
*/
package org.apache.servicecomb.samples.codefirst.consumer;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.samples.common.schema.Hello;
import org.apache.servicecomb.samples.common.schema.models.Person;
-import org.springframework.stereotype.Component;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
-@Component
+@SpringBootApplication
public class CodeFirstConsumerMain {
@RpcReference(microserviceName = "codefirst", schemaId = "codeFirstJaxrsHello")
@@ -35,7 +36,19 @@ public class CodeFirstConsumerMain {
private static Hello hello;
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(CodeFirstConsumerMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ run();
+ }
+
+ private static void run() {
System.out.println(hello.sayHi("Java Chassis"));
System.out.println(jaxrsHello.sayHi("Java Chassis"));
System.out.println(springmvcHello.sayHi("Java Chassis"));
diff --git a/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/resources/log4j2.xml b/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/resources/log4j2.xml
index 1d587110..4d807efb 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/codefirst-sample/codefirst-consumer
diff --git a/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/resources/microservice.yaml b/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/resources/microservice.yaml
index 70fa2f9e..eecaee16 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/codefirst-sample/codefirst-consumer/src/main/resources/microservice.yaml
@@ -21,11 +21,9 @@ servicecomb:
name: codefirstClient
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
- isolation:
- Consumer:
- enabled: false
references:
codefirst:
version-rule: 0.0.1
diff --git a/java-chassis-samples/codefirst-sample/codefirst-provider/build.gradle b/java-chassis-samples/codefirst-sample/codefirst-provider/build.gradle
index 003f7c1b..cbfbb218 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-provider/build.gradle
+++ b/java-chassis-samples/codefirst-sample/codefirst-provider/build.gradle
@@ -24,13 +24,12 @@ compileJava {
}
dependencies {
- compile group: 'org.apache.servicecomb', name: 'provider-pojo'
- compile group: 'org.apache.servicecomb', name: 'provider-springmvc'
- compile group: 'org.apache.servicecomb', name: 'transport-rest-vertx'
- compile group: 'org.apache.servicecomb.samples', name: 'common-schema', version: '2.0.0'
- compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl'
- compile group: 'org.apache.logging.log4j', name: 'log4j-api'
- compile group: 'org.apache.logging.log4j', name: 'log4j-core'
+ implementation group: 'org.apache.servicecomb', name: 'solution-basic'
+ implementation group: 'org.apache.servicecomb', name: 'registry-service-center'
+ implementation group: 'org.apache.servicecomb.samples', name: 'common-schema', version: "3.0-SNAPSHOT"
+ implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl'
+ implementation group: 'org.apache.logging.log4j', name: 'log4j-api'
+ implementation group: 'org.apache.logging.log4j', name: 'log4j-core'
}
apply plugin: 'application'
@@ -54,6 +53,6 @@ apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
- mavenBom 'org.apache.servicecomb:java-chassis-dependencies:2.0.0'
+ mavenBom 'org.apache.servicecomb:java-chassis-dependencies:3.3.0'
}
}
diff --git a/java-chassis-samples/codefirst-sample/codefirst-provider/pom.xml b/java-chassis-samples/codefirst-sample/codefirst-provider/pom.xml
index e9c0f11c..0870f445 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-provider/pom.xml
+++ b/java-chassis-samples/codefirst-sample/codefirst-provider/pom.xml
@@ -21,7 +21,7 @@
org.apache.servicecomb.samples
codefirst-sample
- 2.6.0
+ 3.0-SNAPSHOT
codefirst-provider
Java Chassis::Samples::CodeFirst::Provider
@@ -29,18 +29,10 @@
UTF-8
-
- org.apache.servicecomb
- provider-pojo
-
-
- org.apache.servicecomb
- provider-springmvc
-
-
- org.apache.servicecomb
- transport-rest-vertx
-
+
+ org.apache.servicecomb
+ solution-basic
+
org.apache.logging.log4j
log4j-slf4j-impl
diff --git a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstJaxrsHelloImpl.java b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstJaxrsHelloImpl.java
index d79497f3..f5c7b900 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstJaxrsHelloImpl.java
+++ b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstJaxrsHelloImpl.java
@@ -18,10 +18,10 @@
package org.apache.servicecomb.samples.codefirst.provider;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
import org.apache.servicecomb.provider.pojo.RpcSchema;
import org.apache.servicecomb.samples.common.schema.Hello;
diff --git a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstProviderMain.java b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstProviderMain.java
index 8333d8ea..73a97982 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstProviderMain.java
+++ b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstProviderMain.java
@@ -17,11 +17,21 @@
package org.apache.servicecomb.samples.codefirst.provider;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class CodeFirstProviderMain {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(CodeFirstProviderMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstSpringmvcHelloImpl.java b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstSpringmvcHelloImpl.java
index 8d0370bc..19a742fe 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstSpringmvcHelloImpl.java
+++ b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/java/org/apache/servicecomb/samples/codefirst/provider/CodeFirstSpringmvcHelloImpl.java
@@ -18,7 +18,7 @@
package org.apache.servicecomb.samples.codefirst.provider;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.MediaType;
import org.apache.servicecomb.provider.pojo.RpcSchema;
import org.apache.servicecomb.samples.common.schema.Hello;
diff --git a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/resources/log4j2.xml b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/resources/log4j2.xml
index 9302302e..f528104b 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/codefirst-sample/codefirst-provider
diff --git a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/resources/microservice.yaml b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/resources/microservice.yaml
index 3c9e1e93..7ebf7725 100644
--- a/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/codefirst-sample/codefirst-provider/src/main/resources/microservice.yaml
@@ -21,7 +21,8 @@ servicecomb:
name: codefirst
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
rest:
address: 0.0.0.0:8080
diff --git a/java-chassis-samples/codefirst-sample/pom.xml b/java-chassis-samples/codefirst-sample/pom.xml
index 2d25302f..f655eb65 100644
--- a/java-chassis-samples/codefirst-sample/pom.xml
+++ b/java-chassis-samples/codefirst-sample/pom.xml
@@ -21,15 +21,13 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
codefirst-sample
Java Chassis::Samples::CodeFirst
pom
-
- UTF-8
-
+ UTF-8
diff --git a/java-chassis-samples/common-schema/pom.xml b/java-chassis-samples/common-schema/pom.xml
index 97065bfd..ed66fc46 100644
--- a/java-chassis-samples/common-schema/pom.xml
+++ b/java-chassis-samples/common-schema/pom.xml
@@ -21,7 +21,7 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
common-schema
Java Chassis::Samples::Common Schema
diff --git a/java-chassis-samples/config-apollo-sample/README.md b/java-chassis-samples/config-apollo-sample/README.md
index eb992c87..a3b29fd6 100644
--- a/java-chassis-samples/config-apollo-sample/README.md
+++ b/java-chassis-samples/config-apollo-sample/README.md
@@ -1,59 +1,91 @@
+# config-apollo-sample
+
## Precondition
+
see [Precondition](../../README.md)
## Use Apollo as Configuration Center
To use Apollo as configuration source in ServiceComb Java Chassis services:
-* Start Apollo service and create a project to associate with Chassis service, then generate a token
+1. Start Apollo service and create a project to associate with Chassis service, then generate a token
+
+ [How to use Apollo configuration center](https://servicecomb.apache.org/references/java-chassis/zh_CN/config/general-config.html)
+
+2. Import `config-apollo` in pom:
+
+ ```xml
+
+ org.apache.servicecomb
+ config-apollo
+
+ ```
- [How to use Apollo configuration center](https://docs.servicecomb.io/java-chassis/zh_CN/config/general-config/)
+3. Configurations for Apollo itself in `microservice.yaml`, for example:
+ ```yaml
+ apollo:
+ config:
+ serverUri: http://127.0.0.1:8070 #Apollo portal server address
+ serviceName: apollo-test #service name use AppId in apollo
+ env: DEV #default value DEV
+ clusters: default #default value default
+ namespace: application #default value application
+ token: #get token from Apollo web pages
+ ```
-* Import `config-apollo` in pom:
+4. Start Chassis service and update configurations in Apollo portal service.
+ - [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
- ```xml
-
- org.apache.servicecomb
- config-apollo
-
- ```
+ Compile the source code, and use `mvn exec` to execute the main class `MainServer`.
-* Configurations for Apollo itself in `microservice.yaml`, for example:
+ ```bash
+ mvn clean install
+ cd config-apollo-sample/
+ mvn exec:java -Dexec.mainClass="MainServer"
+ ```
- ```yaml
- apollo:
- config:
- serverUri: http://127.0.0.1:8070 #Apollo portal server address
- serviceName: apollo-test #service name use AppId in apollo
- env: DEV #default value DEV
- clusters: default #default value default
- namespace: application #default value application
- token: #get token from Apollo web pages
- ```
+5. Verify configurations can be configured dynamically.
+ - Before publishing a new configuration items from apollo portal, `MainServer` will just print:
-* Start Chassis service and update configurations in Apollo portal service.
+ ```text
+ Dynamic Properties: serviceComb
+ Environment: serviceComb
+ ```
- - [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+ - After `timeout` configuration is published with value `100`, `MainServer` will print
- Compile the source code, and use `mvn exec` to execute the main class `MainServer`.
+ ```text
+ Config value cache changed: action:SET; item:[timeout]
+ Dynamic Properties: 100
+ Environment: 100
+ ```
- ```bash
- mvn clean install
- cd config-apollo-sample/
- mvn exec:java -Dexec.mainClass="MainServer"
- ```
+## Configuration tips on Apollo server
-* Verify configurations can be configured dynamically.
+ServiceComb `config-apollo` interacts with Apollo based on the **Apollo Open Platform Authorization**. You must complete the authorization on the Apollo portal before the service can successfully pull configurations.
- Before publishing a new configuration items from apollo portal, `MainServer` will just print `DynamicProperty: {name=timeout, current value=default}`
+1. Create third-party applications:
+ - Login to Apollo Portal, go to **`Admin Tools`** -> **`Open Platform Authorization Management`**.
+ - Click **`Create third-party app`**.
+ - Fill in the `Third party appId` and `Third party application name` etc. If you have already created one, skip this step.
+ - Once created, it will generate a **Token**. Copy this token for later use.
- After `timeout` configuration is published with value `100`, `MainServer` will print `DynamicProperty: {name=timeout, current value=100}`
+2. Authorization :
+ - In the **`Authorization`** section of the same page, fill `Token`, `Managed AppId`, `Managed Namespace` etc. and submit.
+3. Sync to `microservice.yaml`:
+ - Copy the generated **`Token`**, **`AppId`** etc. into your `microservice.yaml`:
+
+> **Note:** These steps are mandatory. Without Open Platform authorization, the client will not be able to fetch any data even if the network connection is correct.
+
+You can try the official Apollo test server if you can't start Apollo service by yourself. Just using `apollo.config.serverUri`: `http://81.68.181.139` (don't add port).
+And the management portal also can be access at `http://81.68.181.139/`. login info can be find on: [Apollp project](https://github.com/apolloconfig/apollo).
## More
-[Apollo Doc](https://github.com/ctripcorp/apollo/wiki)
+[Apollp project](https://github.com/apolloconfig/apollo)
-[Use Apollo In ServiceComb]((https://docs.servicecomb.io/java-chassis/zh_CN/config/general-config/))
+[Apollo Doc](https://github.com/ctripcorp/apollo/wiki)
+[Use Apollo In ServiceComb](<(https://docs.servicecomb.io/java-chassis/zh_CN/config/general-config/)>)
diff --git a/java-chassis-samples/config-apollo-sample/pom.xml b/java-chassis-samples/config-apollo-sample/pom.xml
index d983b8e0..0d236a08 100644
--- a/java-chassis-samples/config-apollo-sample/pom.xml
+++ b/java-chassis-samples/config-apollo-sample/pom.xml
@@ -22,20 +22,18 @@
samples
org.apache.servicecomb.samples
- 2.6.0
+ 3.0-SNAPSHOT
4.0.0
config-apollo-sample
+ Java Chassis::Samples::config-apollo-sample
+
org.apache.servicecomb
foundation-common
-
- com.netflix.archaius
- archaius-core
-
org.apache.servicecomb
config-apollo
diff --git a/java-chassis-samples/config-apollo-sample/src/main/java/org/apache/servicecomb/samples/apollo/MainServer.java b/java-chassis-samples/config-apollo-sample/src/main/java/org/apache/servicecomb/samples/apollo/MainServer.java
index 3b94f4ad..3957c167 100644
--- a/java-chassis-samples/config-apollo-sample/src/main/java/org/apache/servicecomb/samples/apollo/MainServer.java
+++ b/java-chassis-samples/config-apollo-sample/src/main/java/org/apache/servicecomb/samples/apollo/MainServer.java
@@ -16,16 +16,49 @@
*/
package org.apache.servicecomb.samples.apollo;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-
-import com.netflix.config.DynamicPropertyFactory;
+import org.apache.servicecomb.config.DynamicProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.Environment;
+@SpringBootApplication
public class MainServer {
+ @Autowired
+ private DynamicProperties dynamicProperties;
+
+ @Autowired
+ private Environment environment;
+
+ public String getTimeoutFromDynamic() {
+ return dynamicProperties.getStringProperty("timeout", "default");
+ }
+
+ public String getTimeoutFromEnv() {
+ return environment.getProperty("timeout","default");
+ }
+
public static void main(String[] args) throws Exception {
- BeanUtils.init();
- while (true) {
- System.out.println(DynamicPropertyFactory.getInstance().getStringProperty("timeout", "default"));
- Thread.sleep(3000);
+ ConfigurableApplicationContext context = null;
+ try {
+ context = new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(MainServer.class)
+ .run(args);
+
+ MainServer mainServer = context.getBean(MainServer.class);
+ while (true) {
+ System.out.println("Dynamic Properties: " + mainServer.getTimeoutFromDynamic());
+ System.out.println("Environment: " + mainServer.getTimeoutFromEnv());
+ Thread.sleep(3000);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ if (context != null) {
+ context.close();
+ }
}
}
}
diff --git a/java-chassis-samples/config-apollo-sample/src/main/resources/log4j2.xml b/java-chassis-samples/config-apollo-sample/src/main/resources/log4j2.xml
index 7be2ca17..1257e11b 100644
--- a/java-chassis-samples/config-apollo-sample/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/config-apollo-sample/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/config-apollo-sample
diff --git a/java-chassis-samples/config-apollo-sample/src/main/resources/microservice.yaml b/java-chassis-samples/config-apollo-sample/src/main/resources/microservice.yaml
index e843d0cc..fe22df6c 100644
--- a/java-chassis-samples/config-apollo-sample/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/config-apollo-sample/src/main/resources/microservice.yaml
@@ -16,14 +16,9 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-APPLICATION_ID: apollotest
-service_description:
- name: apollo-test
- version: 1.0.1
-
apollo:
config:
- serverUri: http://127.0.0.1:8070
+ serverUri: http://127.0.0.1:8070 #Apollo portal server address
serviceName: apollo-test #AppId in apollo
env: DEV
#default clusters name in apollo,if user create new clusters please replace this setting value
@@ -35,14 +30,14 @@ apollo:
token: #get token from Apollo web pages
servicecomb:
service:
- registry:
+ application: apollotest
+ name: apollo-test
+ version: 1.0.1
+ registry:
+ sc:
address: http://127.0.0.1:30100
rest:
address: 0.0.0.0:8080
- handler:
- chain:
- Provider:
- default: bizkeeper-provider
#executors:
#default: test
#Provider:
diff --git a/java-chassis-samples/custom-handler-sample/README.md b/java-chassis-samples/custom-handler-sample/README.md
index 85f57ada..a07a471f 100644
--- a/java-chassis-samples/custom-handler-sample/README.md
+++ b/java-chassis-samples/custom-handler-sample/README.md
@@ -1,95 +1,105 @@
-## Customized Handler Sample
-
-ServiceComb support users to define a customized handler and and invoke the handler in handler chain.
-
-* Customize a handler by implement Handler interface, for example:
-
- ```java
- public class MyHandler implements Handler {
- private static final Logger LOGGER = LoggerFactory.getLogger(MyHandler.class);
- @Override
- public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception {
- //code before
- LOGGER.info("It's my handler! \r\n");
- invocation.next(response -> {
- // code after
- asyncResponse.handle(response);
- });
+# Customized Handler Sample
+
+ServiceComb 3.X support users to define a customized filter and invoke the filter in filter chain.
+
+The new Filter-based processing chain mechanism replaces the legacy Handler-based mechanism to provide enhanced support for asynchronous processing. It unifies mechanisms such as Handler, HttpServerFilter, and HttpClientFilter, representing them all as Filters.
+
+> See:
+>
+> - [Java Chassis 3版本介绍](https://servicecomb.apache.org/references/java-chassis/zh_CN/introduce3.x.x.html)
+> - [处理链介绍](https://servicecomb.apache.org/references/java-chassis/zh_CN/references-handlers/intruduction.html#_2)
+
+1. Customize a filter by implement filter interface, for example:
+
+ ```java
+ @Component
+ public class MyFilter extends AbstractFilter implements ConsumerFilter {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(MyFilter.class);
+
+ @Override
+ public String getName() {
+ return "my-filter";
+ }
+
+ @Override
+ public int getOrder() {
+ return Filter.CONSUMER_LOAD_BALANCE_ORDER + 1;
+ }
+
+ @Override
+ public CompletableFuture onFilter(Invocation invocation, FilterNode nextNode) {
+ LOGGER.info("It's my filter! \r\n");
+ return nextNode.onFilter(invocation);
+ }
}
- }
- ```
+ ```
-* Define handler `id` and `class` in `cse.handler.xml` `config` item under `resources/config` directory
+2. Configure customized `MyFilter` in `microservice.yaml` file along with other handler together.
- ```xml
-
-
-
+ ```yaml
+ servicecomb:
+ # filters are enabled by default, configuration is optional
+ filter:
+ # Filter name
+ my-filter:
+ # Application name + Service name
+ chstest.chsClient.order: 10
+ chstest.chsClient.enabled: true
+ ```
- ```
+ > Filters are enabled by default, configuration is optional.
- ***NOTICE:*** can use a different name other than `cse.handler.xml`, e.g. `userDefined.hanlder.xml`
-
-* Configure customized `MyHandler` in `microservice.yaml` file along with other handler together
-
- ```yaml
- servicecomb:
- # other configurations omitted
- handler:
- chain:
- Consumer:
- default: bizkeeper-consumer,loadbalance, myhandler
- ```
## Precondition
-see [Precondition](../../README.md)
+see [Precondition](../../README.md)
## Sample Quick Start
-1. Start the ServiceComb/Service Center
+### Start the ServiceComb/Service Center
- - [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
- - make sure service center address is configured correctly in `microservice.yaml` file
+- [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+- make sure service center address is configured correctly in `microservice.yaml` file
```yaml
servicecomb:
- service:
- registry:
- address: http://127.0.0.1:30100 #service center address
+ service:
+ registry:
+ address: http://127.0.0.1:30100 #service center address
```
-2. Start the custom-handler-provider service
+### Start the custom-handler-provider service
- - Start provider service by maven
+- Start provider service by maven
- Compile the source code, and use `mvn exec` to execute the main class `CustomHandlerProviderMain`.
+ Compile the source code, and use `mvn exec` to execute the main class `CustomHandlerProviderMain`.
- ```bash
- mvn clean install
- cd custom-handler-sample/custom-handler-provider/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.customerhandler.provider.CustomHandlerProviderMain"
- ```
+ ```bash
+ mvn clean install
+ cd custom-handler-sample/custom-handler-provider/
+ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.customerhandler.provider.CustomHandlerProviderMain"
+ ```
+
+- Start provider service by IDE
- - Start provider service by IDE
+ Import the project by InteliJ IDEA or Eclipse, then find `main` function `CustomHandlerProviderMain` of provider service and `RUN` it like any other Java program.
- Import the project by InteliJ IDEA or Eclipse, then find `main` function `CustomHandlerProviderMain` of provider service and `RUN` it like any other Java program.
+### Start the custom-handler-consumer service
-3. Start the custom-handler-consumer service
+Just like how to start custom-handler-provider service. But the main class of custom-handler-consumer service is `CustomHandlerCustomerMain`.
+
+```bash
+cd custom-handler-sample/custom-handler-consumer
+mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.customerhandler.consumer.CustomHandlerCustomerMain"
+```
- Just like how to start custom-handler-provider service. But the main class of custom-handler-consumer service is `CustomHandlerCustomerMain`.
+### How to verify
- ```bash
- cd custom-handler-sample/custom-handler-consumer
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.customerhandler.consumer.CustomHandlerCustomerMain"
- ```
+On the producer side, the output should contain the following stuffs if the producer starts up successfully:
-4. How to verify
- On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- 1. *'swagger: 2.0 info: version: 1.0.0 ...'* means the producer generated swagger contracts
- 2. *'rest listen success. address=0.0.0.0:8080'* means the rest endpoint is listening on port 8080
-
- On the consumer side, you can see the following outputs:
- 1. *'It's my handler!'* means custom handler had take effect
+1. *`swagger: 2.0 info: version: 1.0.0 ...`* means the producer generated swagger contracts
+2. *`rest listen success. address=0.0.0.0:8080`* means the rest endpoint is listening on port 8080
+On the consumer side, you can see the following outputs:
-
\ No newline at end of file
+1. *`It's my handler!`* means custom handler had take effect
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/pom.xml b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/pom.xml
index 7683c915..590fefd8 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/pom.xml
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/pom.xml
@@ -21,31 +21,16 @@
org.apache.servicecomb.samples
custom-handler-sample
- 2.6.0
+ 3.0-SNAPSHOT
custom-handler-consumer
Java Chassis::Samples::Custom Handler::Consumer
-
org.apache.servicecomb
- provider-pojo
+ solution-basic
-
-
- org.apache.servicecomb
- transport-rest-vertx
-
-
-
- org.apache.servicecomb
- handler-bizkeeper
-
-
- org.apache.servicecomb
- handler-loadbalance
-
-
+
org.apache.logging.log4j
log4j-slf4j-impl
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/consumer/CustomHandlerCustomerMain.java b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/consumer/CustomHandlerCustomerMain.java
index ad6f8312..37d42768 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/consumer/CustomHandlerCustomerMain.java
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/consumer/CustomHandlerCustomerMain.java
@@ -16,20 +16,33 @@
*/
package org.apache.servicecomb.samples.customerhandler.consumer;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.samples.common.schema.Hello;
import org.apache.servicecomb.samples.common.schema.models.Person;
-import org.springframework.stereotype.Component;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
-@Component
+@SpringBootApplication
public class CustomHandlerCustomerMain {
@RpcReference(microserviceName = "customerhandler", schemaId = "hello")
private static Hello hello;
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(CustomHandlerCustomerMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ run();
+ }
+
+ private static void run() {
System.out.println(hello.sayHi("Java Chassis"));
Person person = new Person();
person.setName("ServiceComb/Java Chassis");
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/handlers/MyHandler.java b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/consumer/filters/MyFilter.java
similarity index 58%
rename from java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/handlers/MyHandler.java
rename to java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/consumer/filters/MyFilter.java
index da2f89ab..e2b39af9 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/handlers/MyHandler.java
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/java/org/apache/servicecomb/samples/customerhandler/consumer/filters/MyFilter.java
@@ -14,27 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.samples.customerhandler.handlers;
+package org.apache.servicecomb.samples.customerhandler.consumer.filters;
-import org.apache.servicecomb.core.Handler;
+import org.apache.servicecomb.core.filter.*;
import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.swagger.invocation.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
-public class MyHandler implements Handler {
+import java.util.concurrent.CompletableFuture;
- private static final Logger LOGGER = LoggerFactory.getLogger(MyHandler.class);
+@Component
+public class MyFilter extends AbstractFilter implements ConsumerFilter {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(MyFilter.class);
@Override
- public void handle(Invocation invocation, AsyncResponse asyncResponse) throws Exception {
- //code before
+ public String getName() {
+ return "my-filter";
+ }
- LOGGER.info("It's my handler! \r\n");
+ @Override
+ public int getOrder() {
+ return Filter.CONSUMER_LOAD_BALANCE_ORDER + 1;
+ }
- invocation.next(response -> {
- // code after
- asyncResponse.handle(response);
- });
+ @Override
+ public CompletableFuture onFilter(Invocation invocation, FilterNode nextNode) {
+ LOGGER.info("It's my filter! \r\n");
+ return nextNode.onFilter(invocation);
}
}
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/config/cse.handler.xml b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/config/cse.handler.xml
deleted file mode 100644
index 0cac14f2..00000000
--- a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/config/cse.handler.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/log4j2.xml b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/log4j2.xml
index 1d587110..1d98eb8a 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/custom-handler-sample/custom-handler-consumer
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/microservice.yaml b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/microservice.yaml
index 346a23a2..62d2ae59 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-consumer/src/main/resources/microservice.yaml
@@ -14,22 +14,23 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-
+servicecomb-config-order: 100
servicecomb:
service:
application: chstest
name: chsClient
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
- handler:
- chain:
- Consumer:
- default: bizkeeper-consumer,loadbalance, myhandler
- isolation:
- Consumer:
- enabled: false
+# # filters are enabled by default, configuration is optional
+# filter:
+# # Filter name
+# my-filter:
+# # Application name + Service name
+# chstest.chsClient.order: 10
+# chstest.chsClient.enabled: true
references:
chs:
version-rule: 0.0.1
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-provider/pom.xml b/java-chassis-samples/custom-handler-sample/custom-handler-provider/pom.xml
index 56869c93..302d2239 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-provider/pom.xml
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-provider/pom.xml
@@ -21,31 +21,16 @@
org.apache.servicecomb.samples
custom-handler-sample
- 2.6.0
+ 3.0-SNAPSHOT
custom-handler-provider
Java Chassis::Samples::Custom Handler::Provider
-
org.apache.servicecomb
- provider-pojo
+ solution-basic
-
-
- org.apache.servicecomb
- transport-rest-vertx
-
-
-
- org.apache.servicecomb
- handler-loadbalance
-
-
- org.apache.servicecomb
- handler-flowcontrol-qps
-
-
+
org.apache.logging.log4j
log4j-slf4j-impl
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/java/org/apache/servicecomb/samples/customerhandler/provider/CustomHandlerProviderMain.java b/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/java/org/apache/servicecomb/samples/customerhandler/provider/CustomHandlerProviderMain.java
index 9caa999b..80e827f7 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/java/org/apache/servicecomb/samples/customerhandler/provider/CustomHandlerProviderMain.java
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/java/org/apache/servicecomb/samples/customerhandler/provider/CustomHandlerProviderMain.java
@@ -17,11 +17,21 @@
package org.apache.servicecomb.samples.customerhandler.provider;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class CustomHandlerProviderMain {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(CustomHandlerProviderMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/resources/log4j2.xml b/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/resources/log4j2.xml
index 9302302e..4a168a1e 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/custom-handler-sample/custom-handler-provider
diff --git a/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/resources/microservice.yaml b/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/resources/microservice.yaml
index 02a2d882..99764de3 100644
--- a/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/custom-handler-sample/custom-handler-provider/src/main/resources/microservice.yaml
@@ -21,7 +21,8 @@ servicecomb:
name: customerhandler
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
rest:
address: 0.0.0.0:8080
diff --git a/java-chassis-samples/custom-handler-sample/pom.xml b/java-chassis-samples/custom-handler-sample/pom.xml
index 0b5dbd95..996dc409 100644
--- a/java-chassis-samples/custom-handler-sample/pom.xml
+++ b/java-chassis-samples/custom-handler-sample/pom.xml
@@ -21,7 +21,7 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
custom-handler-sample
Java Chassis::Samples::Custom Handler
diff --git a/java-chassis-samples/jaxrs-sample/README.md b/java-chassis-samples/jaxrs-sample/README.md
index a4911f37..3b0333a7 100644
--- a/java-chassis-samples/jaxrs-sample/README.md
+++ b/java-chassis-samples/jaxrs-sample/README.md
@@ -1,69 +1,72 @@
-## JAX-RS Sample
+# JAX-RS Sample
ServiceComb supports developers in developing services in JAX-RS mode by using JAX-RS.
-### Provider Service
+## Provider Service
* Define a service API. Compile the Java API definition based on the API definition defined before development
-* Implement the service. JAX-RS is used to describe the development of service code.
+* Implement the service. JAX-RS is used to describe the development of service code.
* Release the service. Add `@RestSchema` as the annotation of the service implementation class and specify schemaID, which indicates that the implementation is released as a schema of the current microservice.
* Create the jaxrsHello.bean.xml file in the resources/META-INF/spring directory and configure base-package that performs scanning
[Detail information please refer to Doc](https://docs.servicecomb.io/java-chassis/zh_CN/build-provider/jaxrs/)
-### Consumer Service
+## Consumer Service
To consume a provider-service, only need to decalare a member of a service API type and add the `RpcReference` annotation for the member, the microservice that depends on the declaration and the `schemaID` just like pojo consumer sample.
## Precondition
+
see [Precondition](../../README.md)
-### Sample Quick Start
+## Sample Quick Start
-1. Start the ServiceComb/Service Center
+### Start the ServiceComb/Service Center
- - [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
- - make sure service center address is configured correctly in `microservice.yaml` file
+* [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+* make sure service center address is configured correctly in `microservice.yaml` file
```yaml
servicecomb:
service:
registry:
- address: http://127.0.0.1:30100 #service center address
+ address: http://127.0.0.1:30100 #service center address
```
-2. Start the jaxrs-provider service
+### Start the `jaxrs-provider` service
- - Start provider service by maven
+* Start provider service by maven
- Compile the source code, and use `mvn exec` to execute the main class `JaxrsProviderMain`.
+ Compile the source code, and use `mvn exec` to execute the main class `JaxrsProviderMain`.
- ```bash
- mvn clean install
- cd jaxrs-sample/jaxrs-provider/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.jaxrs.provider.JaxrsProviderMain"
- ```
+ ```bash
+ mvn clean install
+ cd jaxrs-sample/jaxrs-provider/
+ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.jaxrs.provider.JaxrsProviderMain"
+ ```
- - Start provider service by IDE
+* Start provider service by IDE
- Import the project by InteliJ IDEA or Eclipse, then find `main` function `JaxrsProviderMain` of provider service and `RUN` it like any other Java Program.
+ Import the project by InteliJ IDEA or Eclipse, then find `main` function `JaxrsProviderMain` of provider service and `RUN` it like any other Java Program.
-3. Start the jaxrs-consumer service
+### Start the `jaxrs-consumer` service
- Just like how to start jaxrs-provider service. But the main class of jaxrs-consumer service is `JaxrsConsumerMain`.
+Just like how to start jaxrs-provider service. But the main class of jaxrs-consumer service is `JaxrsConsumerMain`.
- ```bash
- cd jaxrs-sample/jaxrs-consumer/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.jaxrs.consumer.JaxrsConsumerMain"
- ```
+```bash
+cd jaxrs-sample/jaxrs-consumer/
+mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.jaxrs.consumer.JaxrsConsumerMain"
+```
+
+### How to verify
+
+On the producer side, the output should contain the following stuffs if the producer starts up successfully:
+
+1. *`swagger: 2.0 info: version: 1.0.0 ...`* means the producer generated swagger contracts
+2. *`rest listen success. address=0.0.0.0:8080`* means the rest endpoint is listening on port 8080
-4. How to verify
- On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- 1. *'swagger: 2.0 info: version: 1.0.0 ...'* means the producer generated swagger contracts
- 2. *'rest listen success. address=0.0.0.0:8080'* means the rest endpoint is listening on port 8080
-
- On the consumer side, you can see the following outputs if the consumer can invoke the producer:
- 1. *'Hello Java Chassis'* means the consumer calls sayhi by RpcReference successfully
- 2. *'Hello person ServiceComb/Java Chassis'* means the consumer calls sayhello by RpcReference successfully
- 3. *'Bye !'* means the consumer calls saybye by RestTemplate successfully
+On the consumer side, you can see the following outputs if the consumer can invoke the producer:
+1. *`Hello Java Chassis`* means the consumer calls sayhi by RpcReference successfully
+2. *`Hello person ServiceComb/Java Chassis`* means the consumer calls sayhello by RpcReference successfully
+3. *`Bye !`* means the consumer calls saybye by RestTemplate successfully
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/pom.xml b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/pom.xml
index 97af4ffb..03257982 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/pom.xml
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/pom.xml
@@ -21,7 +21,7 @@
org.apache.servicecomb.samples
jaxrs-sample
- 2.6.0
+ 3.0-SNAPSHOT
jaxrs-consumer
Java Chassis::Samples::JAXRS::Consumer
@@ -30,10 +30,6 @@
org.apache.servicecomb
solution-basic
-
- org.apache.servicecomb
- servicestage-environment
-
org.apache.servicecomb.samples
common-schema
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/java/org/apache/servicecomb/samples/jaxrs/consumer/JaxrsConsumerMain.java b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/java/org/apache/servicecomb/samples/jaxrs/consumer/JaxrsConsumerMain.java
index 19344461..f41d8971 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/java/org/apache/servicecomb/samples/jaxrs/consumer/JaxrsConsumerMain.java
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/java/org/apache/servicecomb/samples/jaxrs/consumer/JaxrsConsumerMain.java
@@ -16,28 +16,41 @@
*/
package org.apache.servicecomb.samples.jaxrs.consumer;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.samples.common.schema.Hello;
import org.apache.servicecomb.samples.common.schema.models.Person;
-import org.springframework.stereotype.Component;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.web.client.RestOperations;
-@Component
+@SpringBootApplication
public class JaxrsConsumerMain {
@RpcReference(microserviceName = "jaxrs", schemaId = "jaxrsHello")
private static Hello hello;
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(JaxrsConsumerMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ run();
+ }
+
+ private static void run() {
System.out.println(hello.sayHi("Java Chassis"));
Person person = new Person();
person.setName("ServiceComb/Java Chassis");
System.out.println(hello.sayHello(person));
- RestTemplate restTemplate = RestTemplateBuilder.create();
+ RestOperations restTemplate = RestTemplateBuilder.create();
String result = restTemplate.getForObject("cse://jaxrs/jaxrshello/saybye", String.class);
System.out.println(result);
}
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/log4j2.xml b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/log4j2.xml
index 1d587110..738c4f88 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/jaxrs-sample/jaxrs-consumer
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/microservice.yaml b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/microservice.yaml
index 9e7e73d7..5b2ccd67 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/microservice.yaml
@@ -21,7 +21,8 @@ servicecomb:
name: helloClient
version: 0.0.1
- registry:
+ registry:
+ sc:
# Default using local service center
address: http://localhost:30100
# address: https://cse.cn-south-1.myhuaweicloud.com
@@ -30,13 +31,6 @@ servicecomb:
kie:
serverUri: http://localhost:30110
- handler:
- chain:
- Consumer:
- default: bizkeeper-consumer,loadbalance
- isolation:
- Consumer:
- enabled: false
references:
jaxrs:
version-rule: 0.0.1
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/microservices/hello/hello.yaml b/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/microservices/hello/hello.yaml
deleted file mode 100644
index fb9328b2..00000000
--- a/java-chassis-samples/jaxrs-sample/jaxrs-consumer/src/main/resources/microservices/hello/hello.yaml
+++ /dev/null
@@ -1,45 +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.
-## ---------------------------------------------------------------------------
-
-swagger: '2.0'
-info:
- title: hello
- version: 1.0.0
- x-java-interface: org.apache.servicecomb.samples.jaxrs.Hello
-basePath: /pojo/rest/hello
-produces:
- - application/json
-
-paths:
- /sayhi:
- post:
- operationId: sayHi
- parameters:
- - name: name
- in: body
- required: true
- schema:
- type: string
- responses:
- 200:
- description: 正确返回
- schema:
- type: string
- default:
- description: 默认返回
- schema:
- type: string
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-provider/pom.xml b/java-chassis-samples/jaxrs-sample/jaxrs-provider/pom.xml
index bcb61c4b..b9829938 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-provider/pom.xml
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-provider/pom.xml
@@ -21,7 +21,7 @@
org.apache.servicecomb.samples
jaxrs-sample
- 2.6.0
+ 3.0-SNAPSHOT
jaxrs-provider
Java Chassis::Samples::JAXRS::Provider
@@ -30,10 +30,6 @@
org.apache.servicecomb
solution-basic
-
- org.apache.servicecomb
- servicestage-environment
-
org.apache.servicecomb.samples
common-schema
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsHelloImpl.java b/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsHelloImpl.java
index f26ad062..4d62c023 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsHelloImpl.java
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsHelloImpl.java
@@ -18,11 +18,11 @@
package org.apache.servicecomb.samples.jaxrs.provider;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.apache.servicecomb.samples.common.schema.Hello;
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsProviderMain.java b/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsProviderMain.java
index e11967d3..ec531b82 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsProviderMain.java
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsProviderMain.java
@@ -17,11 +17,21 @@
package org.apache.servicecomb.samples.jaxrs.provider;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class JaxrsProviderMain {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(JaxrsProviderMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/log4j2.xml b/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/log4j2.xml
index 9302302e..12b3d35d 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/jaxrs-sample/jaxrs-provider
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/microservice.yaml b/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/microservice.yaml
index 84840144..e3a9a744 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/microservice.yaml
@@ -20,7 +20,8 @@ servicecomb:
application: jaxrstest-sample
name: jaxrs
version: 0.0.1
- registry:
+ registry:
+ sc:
# Default using local service center
address: http://localhost:30100
# address: https://cse.cn-south-1.myhuaweicloud.com
diff --git a/java-chassis-samples/jaxrs-sample/pom.xml b/java-chassis-samples/jaxrs-sample/pom.xml
index 396b528b..d2c3c33b 100644
--- a/java-chassis-samples/jaxrs-sample/pom.xml
+++ b/java-chassis-samples/jaxrs-sample/pom.xml
@@ -21,7 +21,7 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
jaxrs-sample
Java Chassis::Samples::JAXRS
diff --git a/java-chassis-samples/local-service-registry/README.md b/java-chassis-samples/local-service-registry/README.md
index d7141379..148912a2 100644
--- a/java-chassis-samples/local-service-registry/README.md
+++ b/java-chassis-samples/local-service-registry/README.md
@@ -1,4 +1,4 @@
-## Local registry
+# Local registry
User can use local registry mechanisam and can connect server endpoints without using service center.
For local registry mechanism user should provide the local registry file at consumer side.
@@ -8,46 +8,37 @@ Consumer will use local registry function and it will connect the server end poi
Please find the details as follows.
## Precondition
+
see [Precondition](../../README.md)
## Provider Side
-* run the provider with/without service center and get the schema file.
+1. run the provider with/without service center and get the schema file.
## Consumer Side changes
-* Add local registry file registry.yaml :
-
- ```yaml
- localserv:
- - id: "100"
- version: "0.0.1"
- appid: localservreg
- schemaIds:
- - localservregistry
- instances:
- - endpoints:
- - rest://localhost:8080
- ```
-
-* Add the following code at the beginning and end of the service consumer Main function
+1. Add local registry file `registry.yaml` :
-```java
- public class MyClient {
- public static void main(String[] args) {
- //"yourregistry.yaml" should be put in resource directory
- System.setProperty("local.registry.file", "yourregistry.yaml");
+ ```yaml
+ localserv:
+ - id: "100"
+ version: "0.0.1"
+ appid: localservreg
+ schemaIds:
+ - localservregistry
+ instances:
+ - endpoints:
+ - rest://localhost:8080
+ ```
- //your code
- }
- }
-```
- if file present in this path "local.registry.file" then registry mode is Local registry mode. It will not connect to service center.
+2. Add provider's schema file at below location of consumer side
-* Add provider's schema file at below location of consumer side
+ `src/main/resources/microservices/{microserviceName}/{schemaId.yaml}`
+ > here microserviceName is servers's microservice name. Like this multiple schemaId files we can put in same location.
- src/main/resources/microservices/{microserviceName}/{schemaId.yaml}
- -here microserviceName is servers's microservice name. Like this multiple schemaId files we can put in same location.
-
-* Run the consumer and verify the API's output.
+3. Run the consumer and verify the API's output.
+ ```text
+ 25
+ hello local registry test
+ ```
diff --git a/java-chassis-samples/local-service-registry/local-registry-client/pom.xml b/java-chassis-samples/local-service-registry/local-registry-client/pom.xml
index 86e4055b..9d8f767d 100644
--- a/java-chassis-samples/local-service-registry/local-registry-client/pom.xml
+++ b/java-chassis-samples/local-service-registry/local-registry-client/pom.xml
@@ -23,28 +23,17 @@
org.apache.servicecomb.samples
local-service-registry
- 2.6.0
+ 3.0-SNAPSHOT
local-registry-client
Java Chassis::Demo::LocalServiceRegistry::Client
-
- org.apache.servicecomb.samples
- common-schema
-
-
- org.apache.servicecomb
- provider-springmvc
-
org.apache.servicecomb
- transport-rest-vertx
-
-
- org.apache.servicecomb
- handler-bizkeeper
+ solution-basic
+
org.apache.logging.log4j
log4j-slf4j-impl
@@ -58,8 +47,8 @@
log4j-core
- org.apache.servicecomb
- handler-loadbalance
+ org.apache.servicecomb.samples
+ common-schema
diff --git a/java-chassis-samples/local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java b/java-chassis-samples/local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java
index 3d9346fc..471d630f 100644
--- a/java-chassis-samples/local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java
+++ b/java-chassis-samples/local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java
@@ -20,16 +20,26 @@
import java.util.HashMap;
import java.util.Map;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.samples.common.schema.models.Person;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.web.client.RestOperations;
+@SpringBootApplication
public class LocalRegistryClient {
- private static RestTemplate templateNew = RestTemplateBuilder.create();
+ private static RestOperations templateNew = RestTemplateBuilder.create();
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(LocalRegistryClient.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
run();
}
@@ -38,14 +48,14 @@ public static void run() {
testLocalRegistry(templateNew);
}
- private static void testLocalRegistry(RestTemplate template) {
+ private static void testLocalRegistry(RestOperations template) {
String microserviceName = "localserv";
String cseUrlPrefix = "cse://" + microserviceName + "/localservregistry/";
Map params = new HashMap<>();
params.put("a", "5");
params.put("b", "20");
- int result = template.postForObject(cseUrlPrefix + "add", params, Integer.class);
+ Integer result = template.postForObject(cseUrlPrefix + "add", params, Integer.class);
System.out.println(result);
Person person = new Person();
diff --git a/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/log4j2.xml b/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/log4j2.xml
index 1d587110..d2a467ac 100644
--- a/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/local-service-registry/local-registry-server
diff --git a/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/microservice.yaml b/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/microservice.yaml
index 071b4f49..8bfaec51 100644
--- a/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/microservice.yaml
@@ -20,8 +20,3 @@ servicecomb:
application: localservreg
name: localclient
version: 0.0.1
-
- handler:
- chain:
- Consumer:
- default: bizkeeper-consumer,loadbalance
diff --git a/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/microservices/localserv/hello.yaml b/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/microservices/localserv/hello.yaml
index de3c2d2d..d6d9005b 100644
--- a/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/microservices/localserv/hello.yaml
+++ b/java-chassis-samples/local-service-registry/local-registry-client/src/main/resources/microservices/localserv/hello.yaml
@@ -15,55 +15,63 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-swagger: "2.0"
+openapi: 3.0.1
info:
- version: "1.0.0"
- title: "swagger definition for org.apache.servicecomb.samples.localregistry.localregistryserver.LocalServerApi"
- x-java-interface: "cse.gen.localservreg.localserv.localservregistry.LocalServerApiIntf"
-basePath: "/localservregistry"
-consumes:
-- "application/json"
-produces:
-- "application/json"
+ title: swagger definition for org.apache.servicecomb.samples.localregistry.localregistryserver.LocalServerApi
+ version: 1.0.0
+servers:
+ - url: /localservregistry
paths:
/add:
post:
- operationId: "add"
- parameters:
- - name: "a"
- in: "formData"
- required: false
- type: "integer"
- format: "int32"
- - name: "b"
- in: "formData"
- required: false
- type: "integer"
- format: "int32"
+ operationId: add
+ requestBody:
+ content:
+ application/x-www-form-urlencoded:
+ schema:
+ type: object
+ properties:
+ a:
+ type: integer
+ format: int32
+ b:
+ type: integer
+ format: int32
responses:
- 200:
- description: "response of 200"
- schema:
- type: "integer"
- format: "int32"
+ "200":
+ description: response of 200
+ content:
+ application/json:
+ schema:
+ type: integer
+ format: int32
/sayhi:
post:
- operationId: "sayHi"
- parameters:
- - in: "body"
- name: "student"
- required: false
- schema:
- $ref: "#/definitions/Person"
+ operationId: sayHi
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Person"
+ application/protobuf:
+ schema:
+ $ref: "#/components/schemas/Person"
+ text/plain:
+ schema:
+ $ref: "#/components/schemas/Person"
+ x-name: student
responses:
- 200:
- description: "response of 200"
- schema:
- $ref: "#/definitions/Person"
-definitions:
- Person:
- type: "object"
- properties:
- name:
- type: "string"
- x-java-class: "org.apache.servicecomb.samples.common.schema.models.Person"
+ "200":
+ description: response of 200
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Person"
+components:
+ schemas:
+ Person:
+ type: object
+ properties:
+ name:
+ type: string
+ x-java-class: org.apache.servicecomb.samples.common.schema.models.Person
diff --git a/java-chassis-samples/local-service-registry/local-registry-server/pom.xml b/java-chassis-samples/local-service-registry/local-registry-server/pom.xml
index 0dc337f6..4c1561eb 100644
--- a/java-chassis-samples/local-service-registry/local-registry-server/pom.xml
+++ b/java-chassis-samples/local-service-registry/local-registry-server/pom.xml
@@ -23,26 +23,14 @@
org.apache.servicecomb.samples
local-service-registry
- 2.6.0
+ 3.0-SNAPSHOT
local-registry-server
- Java Chassis::Demo::LocalRegistry::Server
+ Java Chassis::Demo::LocalServiceRegistry::Server
-
- org.apache.servicecomb.samples
- common-schema
-
-
- org.apache.servicecomb
- provider-jaxrs
-
org.apache.servicecomb
- transport-rest-vertx
-
-
- org.apache.servicecomb
- handler-bizkeeper
+ solution-basic
@@ -57,6 +45,10 @@
org.apache.logging.log4j
log4j-core
+
+ org.apache.servicecomb.samples
+ common-schema
+
diff --git a/java-chassis-samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalRegistryServer.java b/java-chassis-samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalRegistryServer.java
index e6f06e75..ee653ad5 100644
--- a/java-chassis-samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalRegistryServer.java
+++ b/java-chassis-samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalRegistryServer.java
@@ -17,10 +17,20 @@
package org.apache.servicecomb.samples.localregistry.localregistryserver;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class LocalRegistryServer {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(LocalRegistryServer.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/java-chassis-samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalServerApi.java b/java-chassis-samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalServerApi.java
index e5fea871..66d99c8b 100644
--- a/java-chassis-samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalServerApi.java
+++ b/java-chassis-samples/local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/samples/localregistry/localregistryserver/LocalServerApi.java
@@ -17,11 +17,11 @@
package org.apache.servicecomb.samples.localregistry.localregistryserver;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.FormParam;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
import org.apache.servicecomb.samples.common.schema.models.Person;
import org.apache.servicecomb.provider.rest.common.RestSchema;
diff --git a/java-chassis-samples/local-service-registry/local-registry-server/src/main/resources/log4j2.xml b/java-chassis-samples/local-service-registry/local-registry-server/src/main/resources/log4j2.xml
index 9302302e..2857b9f6 100644
--- a/java-chassis-samples/local-service-registry/local-registry-server/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/local-service-registry/local-registry-server/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/local-service-registry/local-registry-client
diff --git a/java-chassis-samples/local-service-registry/local-registry-server/src/main/resources/microservice.yaml b/java-chassis-samples/local-service-registry/local-registry-server/src/main/resources/microservice.yaml
index 4d60b183..943d5b91 100644
--- a/java-chassis-samples/local-service-registry/local-registry-server/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/local-service-registry/local-registry-server/src/main/resources/microservice.yaml
@@ -23,7 +23,7 @@ servicecomb:
rest:
address: 0.0.0.0:8080
- handler:
- chain:
- Provider:
- default: bizkeeper-provider
+# handler:
+# chain:
+# Provider:
+# default: bizkeeper-provider
diff --git a/java-chassis-samples/local-service-registry/pom.xml b/java-chassis-samples/local-service-registry/pom.xml
index f77b486b..420320b2 100644
--- a/java-chassis-samples/local-service-registry/pom.xml
+++ b/java-chassis-samples/local-service-registry/pom.xml
@@ -22,7 +22,7 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
local-service-registry
Java Chassis::Demo::Local service registry
diff --git a/java-chassis-samples/metrics-extend-healthcheck/README.md b/java-chassis-samples/metrics-extend-healthcheck/README.md
index 1666f649..348e9ea4 100644
--- a/java-chassis-samples/metrics-extend-healthcheck/README.md
+++ b/java-chassis-samples/metrics-extend-healthcheck/README.md
@@ -1,15 +1,21 @@
# Extend Metrics Health Checker Sample
+
## What is Health Checker
+
Because micro-services is desgin by SRP(Single Responsibility Principle),one micro-service always depend on many components such as middle-ware like queue,database etc and other micro-services,so if one micro-service report failure,we want fast know what is the cause and more details to help us solve the problem.
Health check mechanism can let user write some logic to check components of micro-service dependent and return check result.
## Precondition
+
see [Precondition](../../README.md)
## How to use
+
### Add your checker implementation
-Implement *org.apache.servicecomb.foundation.metrics.health.HealthChecker* interface:
+
+Implement *`org.apache.servicecomb.foundation.metrics.health.HealthChecker`* interface:
+
```java
public interface HealthChecker {
String getName();
@@ -18,38 +24,40 @@ public interface HealthChecker {
}
```
-Then add the implementation class into **META-INF.service.org.apache.servicecomb.foundation.metrics.health.HealthChecker** by SPI(Service Provider Interface) way
+Then add the implementation class into **`META-INF.service.org.apache.servicecomb.foundation.metrics.health.HealthChecker`** by SPI(Service Provider Interface) way
In this demo,we had make two checkers :
-1. CustomHealthChecker
- always return true checker
-2. MySqlHealthChecker
- sim check mysql can connect checker
+
+1. CustomHealthChecker always return true checker
+2. MySqlHealthChecker sim check mysql can connect checker
### Add Dependency in POM
+
```xml
org.apache.servicecomb
- metrics-core
+ solution-basic
```
### Start service
+
```bash
mvn spring-boot:run
```
### Do check and get result
+
If you had config rest transport address in microservice.yaml like:
+
```yaml
servicecomb:
rest:
address: 0.0.0.0:7777
```
-Then you can invoke http://{serverip}:7777/health get summary check result : true or false.
-
-**Only all registered health checker confirm isHealthy=true,the summary check result will be true,otherwise false**
+Then you can invoke `http://{serverip}:7777/scb/health` get summary check result : true or false.
-Also can invoke http://{serverip}:7777/health/details get details of each health checker reported.
+> Only all registered health checker confirm `isHealthy=true`, the summary check result will be true, otherwise will be false
+Also can invoke `http://{serverip}:7777/scb/health/details` get details of each health checker reported.
diff --git a/java-chassis-samples/metrics-extend-healthcheck/pom.xml b/java-chassis-samples/metrics-extend-healthcheck/pom.xml
index 85da3c60..25afabd2 100644
--- a/java-chassis-samples/metrics-extend-healthcheck/pom.xml
+++ b/java-chassis-samples/metrics-extend-healthcheck/pom.xml
@@ -22,22 +22,32 @@
samples
org.apache.servicecomb.samples
- 2.6.0
+ 3.0-SNAPSHOT
4.0.0
metrics-extend-healthcheck
Java Chassis::Samples::Metrics::Health Check
+
+ 8.0.33
+
+
- org.springframework.boot
- spring-boot-starter
+ org.apache.servicecomb
+ solution-basic
org.apache.servicecomb
java-chassis-spring-boot-starter-servlet
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
@@ -46,8 +56,14 @@
- org.apache.servicecomb
- metrics-core
+ mysql
+ mysql-connector-java
+ ${mysql-connector-java.version}
+
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
@@ -56,7 +72,6 @@
org.springframework.boot
spring-boot-maven-plugin
- 2.1.2.RELEASE
diff --git a/java-chassis-samples/metrics-extend-healthcheck/src/main/java/org/apache/servicecomb/samples/metrics/extendhealthcheck/ExtendHealthCheckApplication.java b/java-chassis-samples/metrics-extend-healthcheck/src/main/java/org/apache/servicecomb/samples/metrics/extendhealthcheck/ExtendHealthCheckApplication.java
index 707a5092..8a6fa08a 100644
--- a/java-chassis-samples/metrics-extend-healthcheck/src/main/java/org/apache/servicecomb/samples/metrics/extendhealthcheck/ExtendHealthCheckApplication.java
+++ b/java-chassis-samples/metrics-extend-healthcheck/src/main/java/org/apache/servicecomb/samples/metrics/extendhealthcheck/ExtendHealthCheckApplication.java
@@ -17,12 +17,10 @@
package org.apache.servicecomb.samples.metrics.extendhealthcheck;
-import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
-@EnableServiceComb
public class ExtendHealthCheckApplication {
public static void main(String[] args) {
SpringApplication.run(ExtendHealthCheckApplication.class, args);
diff --git a/java-chassis-samples/metrics-extend-healthcheck/src/main/java/org/apache/servicecomb/samples/metrics/extendhealthcheck/MySqlHealthChecker.java b/java-chassis-samples/metrics-extend-healthcheck/src/main/java/org/apache/servicecomb/samples/metrics/extendhealthcheck/MySqlHealthChecker.java
index 6e115787..fb698ae1 100644
--- a/java-chassis-samples/metrics-extend-healthcheck/src/main/java/org/apache/servicecomb/samples/metrics/extendhealthcheck/MySqlHealthChecker.java
+++ b/java-chassis-samples/metrics-extend-healthcheck/src/main/java/org/apache/servicecomb/samples/metrics/extendhealthcheck/MySqlHealthChecker.java
@@ -27,6 +27,15 @@
//this is a demo health checker for mysql
public class MySqlHealthChecker implements HealthChecker {
+ static {
+ try {
+ // 显式加载MySQL驱动
+ Class.forName("com.mysql.cj.jdbc.Driver");
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("无法加载MySQL驱动", e);
+ }
+ }
+
@Override
public String getName() {
return "mysql";
@@ -35,21 +44,15 @@ public String getName() {
@Override
public HealthCheckResult check() {
//add your health check code here
- Connection connection = null;
- try {
- connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db?useSSL=false", "root", "pwd");
- return new HealthCheckResult(true, "local mysql health check", "");
- } catch (SQLException e) {
- e.printStackTrace();
- return new HealthCheckResult(false, "local mysql health check", e.toString());
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
+ try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db?useSSL=false&allowPublicKeyRetrieval=true", "root", "pwd")) {
+ // 验证连接是否有效
+ if (connection != null && !connection.isClosed()) {
+ return new HealthCheckResult(true, "local mysql health check", "");
+ }
+
+ return new HealthCheckResult(true, "local mysql health check", "");
+ } catch (SQLException e) {
+ return new HealthCheckResult(false, "local mysql health check", e.getMessage());
}
- }
}
}
diff --git a/java-chassis-samples/metrics-extend-healthcheck/src/main/resources/application.yml b/java-chassis-samples/metrics-extend-healthcheck/src/main/resources/application.yml
index 134f0f18..b9032a7b 100644
--- a/java-chassis-samples/metrics-extend-healthcheck/src/main/resources/application.yml
+++ b/java-chassis-samples/metrics-extend-healthcheck/src/main/resources/application.yml
@@ -20,16 +20,15 @@
server:
port: 7777
-# all interconnected microservices must belong to an application wth the same ID
-APPLICATION_ID: metrics
-
-service_description:
-# name of the declaring microservice
- name: metricsHealthCheckDemo
- version: 0.0.1
servicecomb:
service:
- registry:
+ # all interconnected microservices must belong to an application wth the same ID
+ application: metrics
+ # name of the declaring microservice
+ name: metricsHealthCheckDemo
+ version: 0.0.1
+ registry:
+ sc:
address: http://127.0.0.1:30100
rest:
address: 0.0.0.0:7777
\ No newline at end of file
diff --git a/java-chassis-samples/metrics-write-file-sample/README.md b/java-chassis-samples/metrics-write-file-sample/README.md
index 8a80e0cc..380bbd96 100644
--- a/java-chassis-samples/metrics-write-file-sample/README.md
+++ b/java-chassis-samples/metrics-write-file-sample/README.md
@@ -1,10 +1,322 @@
-# Write Metrics Data into Separate Text Files Sample
-## Purpose
-This sample show how direct get metrics data and write them into separate text files,then other monitor system can load this file in order to get run state of micro-service.
+# Metrics Write File Sample
-## What Contains
+## Description
-This module implements MetricsInitializer, to customize user defined output, see [documents](https://docs.servicecomb.io/java-chassis/zh_CN/general-development/metrics/)
+This project demonstrates how to export ServiceComb metrics data to separate text files, enabling external monitoring systems to collect runtime performance data by reading these files. It implements a custom metrics publisher that writes metrics in CloudEye-compatible JSON format to dynamically named files.
+
+## What is it for?
+
+- **Non-intrusive Monitoring**: Automatically collects and exports ServiceComb metrics without modifying application code
+- **External System Integration**: Provides a file-based interface for third-party monitoring tools (e.g., CloudEye, Prometheus exporters)
+- **Flexible Output**: Each metric is written to a separate file with dynamic naming based on metric properties
+- **Production Ready**: Uses industry-standard logging frameworks (Log4j2/Logback) for reliable file I/O
+
+## How it Works
+
+### Architecture Overview
+
+```text
+ServiceComb Application
+ ↓
+MeterRegistry (Micrometer)
+ ↓ periodic polling
+EventBus.post(PolledEvent)
+ ↓
+CloudEyeFilePublisher (@Subscribe)
+ ↓ extract metrics
+Log4j2 Routing Appender
+ ↓ dynamic file routing via MDC
+Individual .dat files
+```
+
+### Core Components
+
+1. **CloudEyeFilePublisher**: Implements `MetricsInitializer` interface
+ - Subscribes to `PolledEvent` from ServiceComb's EventBus
+ - Receives metrics snapshots periodically (controlled by `servicecomb.metrics.window_time`)
+ - Converts Micrometer meters to CloudEye JSON format
+ - Uses MDC (Mapped Diagnostic Context) for dynamic file routing
+
+2. **Log4j2 Routing Appender**: Dynamically creates log files
+ - Routes logs to different files based on `fileName` MDC variable
+ - Pattern: `${appId}.${serviceName}.${metricName}.dat`
+ - Each metric gets its own file for easy parsing by external systems
+
+3. **Spring Boot AutoConfiguration**: Zero-configuration integration
+ - Automatically registers `CloudEyeFilePublisher` as a Spring Bean
+ - Supports conditional loading via `servicecomb.metrics.write-file.enabled`
+ - Leverages Spring dependency injection for clean architecture
+
+### Output Format
+
+Each `.dat` file contains JSON lines in CloudEye format:
+
+```json
+{
+ "plugin_id": "myapp.myservice",
+ "metric": {
+ "node": "hostname",
+ "timestamp": 1706025600000,
+ "dynamicValue": { "metric.name": 123.45 }
+ }
+}
+```
+
+## Changes from ServiceComb 2.x to 3.x
+
+ServiceComb 3.x migrated from **Netflix Spectator** to **Micrometer** as its metrics API. This module has been adapted accordingly:
+
+### API Changes
+
+| Aspect | ServiceComb 2.x | ServiceComb 3.x | Status |
+| ------------------- | -------------------------- | ------------------------- | ----------- |
+| Metrics Library | Netflix Spectator | Micrometer | **Changed** |
+| Registry Type | `GlobalRegistry` | `MeterRegistry` | **Changed** |
+| Meter API | `meter.measure()` iterator | `meter.measure()` forEach | **Changed** |
+| Extension Interface | `MetricsInitializer` | `MetricsInitializer` | **Kept** |
+| Event Subscription | EventBus `@Subscribe` | EventBus `@Subscribe` | **Kept** |
+| Event Type | `PolledEvent` | `PolledEvent` | **Kept** |
+
+### Architecture Evolution
+
+| Aspect | ServiceComb 2.x | ServiceComb 3.x | Status |
+| -------------------- | ---------------------------- | ----------------------------- | ----------- |
+| Loading Mechanism | Java SPI (`ServiceLoader`) | Spring Boot AutoConfiguration | **Changed** |
+| Registration File | `META-INF/services/...` | `META-INF/spring/...imports` | **Changed** |
+| Dependency Injection | Manual `BeanUtils.getBean()` | Constructor injection | **Changed** |
+| Conditional Loading | Not supported | `@ConditionalOnProperty` | **Added** |
+| Spring Integration | Separate from Spring context | Native Spring Bean | **Changed** |
+
+### Key Improvements in 3.x
+
+✅ **Better Spring Integration**: `CloudEyeFilePublisher` is now a native Spring Bean with constructor injection
+✅ **Conditional Loading**: Can be disabled via configuration property
+✅ **Cleaner Code**: No need for `BeanUtils.getBean()` hacks
+✅ **Standard Mechanism**: Uses Spring Boot's AutoConfiguration instead of Java SPI
+
+## Usage
+
+### 1. Add Dependency
+
+Add the following dependency to your ServiceComb application's `pom.xml`:
+
+```xml
+
+ org.apache.servicecomb.samples
+ metrics-write-file
+ 3.0-SNAPSHOT
+
+```
+
+### 2. Configure Application
+
+In your `application.yml`, enable metrics collection:
+
+```yaml
+servicecomb:
+ service:
+ application: myapp
+ name: myservice
+ metrics:
+ window_time: 60000 # metrics collection interval in milliseconds, has default value
+```
+
+**Optional**: Disable this feature if needed:
+
+```yaml
+servicecomb:
+ metrics:
+ write-file:
+ enabled: false # Default is true
+```
+
+### 3. Configure Log4j2
+
+Add the Routing Appender to your application's `log4j2.xml`:
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+**Note**: Reference `sample-log4j2.xml` in the `metrics-write-file` module for a complete example.
+
+### 4. Set Log Directory (Optional)
+
+By default, metrics files are written to `logs/` directory. You can customize it:
+
+```bash
+java -DcloudEye.logDir=/custom/path/to/metrics -jar your-application.jar
+```
+
+Or in `application.yml`:
+
+```yaml
+cloudEye:
+ logDir: /custom/path/to/metrics
+```
+
+## Testing
+
+Since this is a library module, it needs to be tested with an actual ServiceComb application.
+
+### Method 1: Quick Test with Sample Project
+
+Use the `metrics-extend-healthcheck` sample:
+
+```bash
+# 1. Build and install the metrics-write-file module
+cd java-chassis-samples/metrics-write-file-sample
+mvn clean install
+
+# 2. The dependency is already configured in metrics-extend-healthcheck
+cd ../metrics-extend-healthcheck
+
+# 3. Make sure log4j2.xml includes the cloudEyeRouting appender (already configured)
+
+# 4. Run the application
+mvn spring-boot:run
+```
+
+### Method 2: Integration Test
+
+1. Add dependency to your test project
+2. Ensure Service Center is running: `http://127.0.0.1:30100`
+3. Configure `application.yml` with `servicecomb.metrics.window_time`
+4. Start your application
+5. Trigger some requests to generate metrics
+
+## How to Verify
+
+### 1. Check Startup Logs
+
+You should see the following log on application startup:
+
+```
+INFO CloudEyeFilePublisher : CloudEyeFilePublisher init() called
+INFO CloudEyeFilePublisher : CloudEyeFilePublisher filePrefix set to: myapp.myservice
+```
+
+### 2. Check Periodic Metrics Collection
+
+Every 60 seconds (or your configured `window_time`), you should see:
+
+```
+INFO CloudEyeFilePublisher : CloudEyeFilePublisher onPolledEvent() called, meters count: 45
+```
+
+### 3. Verify Metrics Files
+
+Check the `logs/` directory (or your custom `cloudEye.logDir`):
+
+```bash
+ls -l logs/
+
+# Expected output (sample):
+myapp.myservice.jvm.memory.used.area.heap.id.PS-Eden-Space.dat
+myapp.myservice.jvm.threads.live.dat
+myapp.myservice.servicecomb.invocation.count.operation.sayHello.dat
+```
+
+### 4. Inspect File Content
+
+```bash
+cat logs/myapp.myservice.jvm.memory.used.area.heap.dat
+
+# Expected JSON output:
+{"plugin_id":"myapp.myservice","metric":{"node":"hostname","timestamp":1706025600000,"dynamicValue":{"jvm.memory.used.area.heap":134217728.0}}}
+```
+
+### 5. Trigger Metrics Collection
+
+If no files appear, trigger some service invocations:
+
+```bash
+# Example: call a REST endpoint
+curl http://localhost:7777/hello
+
+# Or health check endpoint
+curl http://localhost:7777/management/health
+```
+
+Wait for the next metrics collection cycle (60 seconds by default), and files should appear.
+
+## File Naming Convention
+
+Metrics files follow the pattern: `{appId}.{serviceName}.{metricName}.{tags}.dat`
+
+Examples:
+
+- `myapp.myservice.jvm.memory.used.area.heap.id.PS-Eden-Space.dat`
+- `myapp.myservice.servicecomb.invocation.count.operation.sayHello.role.CONSUMER.dat`
+- `myapp.myservice.jvm.threads.live.dat`
+
+## Troubleshooting
+
+### No metrics files generated
+
+1. **Check log4j2.xml**: Must include the `cloudEyeRouting` appender
+
+2. **Check feature enabled**: Verify not disabled in config
+
+ ```yaml
+ servicecomb:
+ metrics:
+ write-file:
+ enabled: true # Default is true
+ ```
+
+3. **Check startup logs**: Should see "CloudEyeFilePublisher init() called"
+
+### Files created but empty
+
+1. **Trigger some traffic**: Make service calls to generate metrics
+2. **Wait for collection cycle**: Default is 60 seconds
+3. **Check EventBus logs**: Should see "onPolledEvent() called"
+
+### Permission denied errors
+
+1. **Check directory permissions**: Ensure write access to `logs/` directory
+2. **Use absolute path**: Set `cloudEye.logDir` to an absolute path
+3. **Run with proper user**: Ensure application user has write permissions
## Precondition
-see [Precondition](../../README.md)
\ No newline at end of file
+
+See [Precondition](../../README.md)
+
+## References
+
+- [ServiceComb Metrics Documentation](https://servicecomb.apache.org/references/java-chassis/en_US/general-development/metrics/)
+- [Micrometer Documentation](https://micrometer.io/docs)
+- [Log4j2 Routing Appender](https://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender)
diff --git a/java-chassis-samples/metrics-write-file-sample/metrics-write-file/pom.xml b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/pom.xml
index d34da9b4..5bca07d5 100644
--- a/java-chassis-samples/metrics-write-file-sample/metrics-write-file/pom.xml
+++ b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/pom.xml
@@ -21,7 +21,7 @@
metrics-write-file-sample
org.apache.servicecomb.samples
- 2.6.0
+ 3.0-SNAPSHOT
4.0.0
@@ -31,22 +31,15 @@
org.apache.servicecomb
- metrics-core
+ foundation-metrics
+
+
+ io.micrometer
+ micrometer-core
+
+
+ org.apache.servicecomb
+ registry-lightweight
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/java/org/apache/servicecomb/samples/mwf/CloudEyeFilePublisher.java b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/java/org/apache/servicecomb/samples/mwf/CloudEyeFilePublisher.java
index d6e6f31e..2601b6c0 100644
--- a/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/java/org/apache/servicecomb/samples/mwf/CloudEyeFilePublisher.java
+++ b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/java/org/apache/servicecomb/samples/mwf/CloudEyeFilePublisher.java
@@ -23,9 +23,8 @@
import org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig;
import org.apache.servicecomb.foundation.metrics.MetricsInitializer;
import org.apache.servicecomb.foundation.metrics.PolledEvent;
-import org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry;
import org.apache.servicecomb.registry.RegistrationManager;
-import org.apache.servicecomb.registry.api.registry.Microservice;
+import org.apache.servicecomb.registry.api.RegistrationInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@@ -33,10 +32,9 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
-import com.netflix.config.DynamicPropertyFactory;
-import com.netflix.spectator.api.Measurement;
-import com.netflix.spectator.api.Meter;
-import com.netflix.spectator.api.Tag;
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tag;
/**
* a sample for cloud eye
@@ -51,48 +49,61 @@ public class CloudEyeFilePublisher implements MetricsInitializer {
private static final Logger CLOUD_EYE_LOGGER = LoggerFactory.getLogger("cloudEyeLogger");
+ private final RegistrationManager registrationManager;
+
private String filePrefix;
private String hostName;
+ public CloudEyeFilePublisher(RegistrationManager registrationManager) {
+ this.registrationManager = registrationManager;
+ }
+
@Override
- public void init(GlobalRegistry globalRegistry, EventBus eventBus, MetricsBootstrapConfig config) {
+ public void init(MeterRegistry meterRegistry, EventBus eventBus, MetricsBootstrapConfig config) {
+ LOGGER.info("CloudEyeFilePublisher init() called");
eventBus.register(this);
- Microservice microservice = RegistrationManager.INSTANCE.getMicroservice();
- filePrefix = microservice.getAppId() + "." + microservice.getServiceName();
+ RegistrationInstance microserviceInstance = registrationManager.getPrimaryRegistration().getMicroserviceInstance();
+ filePrefix = microserviceInstance.getApplication() + "." + microserviceInstance.getServiceName();
+ LOGGER.info("CloudEyeFilePublisher filePrefix set to: {}", filePrefix);
+// // Use system properties or config to get appId and serviceName
+// String appId = System.getProperty("APPLICATION_ID", "defaultApp");
+// String serviceName = System.getProperty("service.name", "defaultService");
+// filePrefix = appId + "." + serviceName;
hostName = NetUtils.getHostName();
if (StringUtils.isEmpty(hostName)) {
hostName = NetUtils.getHostAddress();
}
- System.setProperty("cloudEye.logDir",
- DynamicPropertyFactory
- .getInstance()
- .getStringProperty("cloudEye.logDir", "logs")
- .get());
+ // Set default log directory if not already configured
+ System.setProperty("cloudEye.logDir",
+ System.getProperty("cloudEye.logDir", "logs/metrics-write-file"));
}
@Subscribe
public void onPolledEvent(PolledEvent event) {
+ LOGGER.info("CloudEyeFilePublisher onPolledEvent() called, meters count: {}", event.getMeters().size());
long now = System.currentTimeMillis();
for (Meter meter : event.getMeters()) {
- for (Measurement measurement : meter.measure()) {
- logMeasurement(measurement, now);
- }
+ meter.measure().forEach(measurement -> {
+ logMeasurement(meter, measurement.getValue(), now);
+ });
}
}
- protected void logMeasurement(Measurement measurement, long now) {
- String metricKey = generateMetricKey(measurement);
-
- MDC.put("fileName", filePrefix + "." + metricKey + ".dat");
+ protected void logMeasurement(Meter meter, double value, long now) {
+ String metricKey = generateMetricKey(meter);
+ String fileName = filePrefix + "." + metricKey + ".dat";
+
+ LOGGER.debug("Writing metric to file: {}, value: {}", fileName, value);
+ MDC.put("fileName", fileName);
CloudEyeMetricModel metricModel = new CloudEyeMetricModel();
metricModel.setNode(hostName);
metricModel.setTimestamp(now);
- metricModel.getDynamicValue().put(metricKey, String.valueOf(measurement.value()));
+ metricModel.getDynamicValue().put(metricKey, String.valueOf(value));
CloudEyeModel model = new CloudEyeModel();
model.setPlugin_id(filePrefix);
@@ -102,14 +113,16 @@ protected void logMeasurement(Measurement measurement, long now) {
CLOUD_EYE_LOGGER.info(JsonUtils.writeValueAsString(model));
} catch (JsonProcessingException e) {
LOGGER.error("Failed to write cloud eye log.", e);
+ } finally {
+ MDC.remove("fileName");
}
}
- protected String generateMetricKey(Measurement measurement) {
+ protected String generateMetricKey(Meter meter) {
StringBuilder sb = new StringBuilder();
- sb.append(measurement.id().name());
- for (Tag tag : measurement.id().tags()) {
- sb.append('.').append(tag.value());
+ sb.append(meter.getId().getName());
+ for (Tag tag : meter.getId().getTags()) {
+ sb.append('.').append(tag.getValue());
}
return sb.toString();
}
diff --git a/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/java/org/apache/servicecomb/samples/mwf/MetricsWriteFileAutoConfiguration.java b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/java/org/apache/servicecomb/samples/mwf/MetricsWriteFileAutoConfiguration.java
new file mode 100644
index 00000000..edc948b5
--- /dev/null
+++ b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/java/org/apache/servicecomb/samples/mwf/MetricsWriteFileAutoConfiguration.java
@@ -0,0 +1,33 @@
+/*
+ * 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.samples.mwf;
+
+import org.apache.servicecomb.registry.RegistrationManager;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+
+@AutoConfiguration
+@ConditionalOnProperty(value = "servicecomb.metrics.write-file.enabled", havingValue = "true", matchIfMissing = true)
+public class MetricsWriteFileAutoConfiguration {
+
+ @Bean
+ public CloudEyeFilePublisher cloudEyeFilePublisher(RegistrationManager registrationManager) {
+ return new CloudEyeFilePublisher(registrationManager);
+ }
+}
diff --git a/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/resources/META-INF/services/org.apache.servicecomb.foundation.metrics.MetricsInitializer b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/resources/META-INF/services/org.apache.servicecomb.foundation.metrics.MetricsInitializer
deleted file mode 100644
index 3a6ad61e..00000000
--- a/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/resources/META-INF/services/org.apache.servicecomb.foundation.metrics.MetricsInitializer
+++ /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.samples.mwf.CloudEyeFilePublisher
\ No newline at end of file
diff --git a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/microservices/hello/hello.yaml b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
similarity index 63%
rename from java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/microservices/hello/hello.yaml
rename to java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index fb9328b2..684821f8 100644
--- a/java-chassis-samples/jaxrs-sample/jaxrs-provider/src/main/resources/microservices/hello/hello.yaml
+++ b/java-chassis-samples/metrics-write-file-sample/metrics-write-file/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -15,31 +15,4 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-swagger: '2.0'
-info:
- title: hello
- version: 1.0.0
- x-java-interface: org.apache.servicecomb.samples.jaxrs.Hello
-basePath: /pojo/rest/hello
-produces:
- - application/json
-
-paths:
- /sayhi:
- post:
- operationId: sayHi
- parameters:
- - name: name
- in: body
- required: true
- schema:
- type: string
- responses:
- 200:
- description: 正确返回
- schema:
- type: string
- default:
- description: 默认返回
- schema:
- type: string
+org.apache.servicecomb.samples.mwf.MetricsWriteFileAutoConfiguration
diff --git a/java-chassis-samples/metrics-write-file-sample/pom.xml b/java-chassis-samples/metrics-write-file-sample/pom.xml
index db5d1ceb..a6330b00 100644
--- a/java-chassis-samples/metrics-write-file-sample/pom.xml
+++ b/java-chassis-samples/metrics-write-file-sample/pom.xml
@@ -22,7 +22,7 @@
samples
org.apache.servicecomb.samples
- 2.6.0
+ 3.0-SNAPSHOT
4.0.0
diff --git a/java-chassis-samples/pojo-sample/README.md b/java-chassis-samples/pojo-sample/README.md
index 35785749..aa77ac2a 100644
--- a/java-chassis-samples/pojo-sample/README.md
+++ b/java-chassis-samples/pojo-sample/README.md
@@ -1,16 +1,16 @@
-## POJO Sample
+# POJO Sample
POJO is also called as Transparent Remote Procedure Call (RPC), POJO development mode based on API and API implementation. The service developer does not need to use the description of Spring MVC and JAX-RS.
-### Provider Service
+## Provider Service
-The transparent RPC development mode supports two service release mode: Spring XML configuration and annotation configuration.
+The transparent RPC development mode supports two service release mode: Spring XML configuration and annotation configuration.
The Spring XML Configuration Mode:
-* Define a service API. Compile the Java API definition based on the API definition defined before development.
-* Implement the service.
-* Release the service. Create the `pojoHello.bean.xml` file in the `resources/META-INF/spring` directory and declare the schema in the file.
+* Define a service API. Compile the Java API definition based on the API definition defined before development.
+* Implement the service.
+* Release the service. Create the `pojoHello.bean.xml` file in the `resources/META-INF/spring` directory and declare the schema in the file.
The Develop Method by Configure Remarks:
@@ -20,7 +20,7 @@ The Develop Method by Configure Remarks:
[Detail information please refer to Doc](https://docs.servicecomb.io/java-chassis/zh_CN/build-provider/transparent-rpc/)
-### Consumer Service
+## Consumer Service
To call a microservice, you only need to declare a member of a service API type and add the `@RpcReference` annotation for the member, the microservice that depends on the declaration, and the `schemaID`. The sample code is as follows.
@@ -29,61 +29,65 @@ To call a microservice, you only need to declare a member of a service API type
public class CodeFirstConsumerMain {
@RpcReference(microserviceName = "codefirst", schemaId = "codeFirstHello")
private static Hello hello;
+
public static void main(String[] args) throws Exception {
- //init first
+ //init first
System.out.println(hello.sayHi("World!"));
}
}
```
+
## Precondition
+
see [Precondition](../../README.md)
-### Sample Quick Start
+## Sample Quick Start
-1. Start the ServiceComb/Service Center
+### Start the ServiceComb/Service Center
- - [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
- - make sure service center address is configured correctly in `microservice.yaml` file
+* [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+* make sure service center address is configured correctly in `microservice.yaml` file
```yaml
servicecomb:
service:
registry:
- address: http://127.0.0.1:30100 #service center address
+ address: http://127.0.0.1:30100 #service center address
```
-2. Start the pojo-provider service
+### Start the `pojo-provider` service
- - Start provider service by maven
+1. Start provider service by maven
- Compile the source code, and use `mvn exec` to execute the main class `PojoProviderMain`.
+ Compile the source code, and use `mvn exec` to execute the main class `PojoProviderMain`.
- ```bash
- mvn clean install
- cd pojo-sample/pojo-provider/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.pojo.provider.PojoProviderMain"
- ```
+ ```bash
+ mvn clean install
+ cd pojo-sample/pojo-provider/
+ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.pojo.provider.PojoProviderMain"
+ ```
- - Start provider service by IDE
+2. Start provider service by IDE
- Import the project by InteliJ IDEA or Eclipse, then find `main` function `PojoProviderMain` of provider service and `RUN` it like any other Java program.
+ Import the project by InteliJ IDEA or Eclipse, then find `main` function `PojoProviderMain` of provider service and `RUN` it like any other Java program.
-3. Start the pojo-consumer service
+### Start the `pojo-consumer` service
- Just like how to start pojo-provider service. But the main class of pojo-consumer service is `PojoConsumerMain`.
+Just like how to start `pojo-provider` service. But the main class of `pojo-consumer` service is `PojoConsumerMain`.
- ```bash
- cd pojo-sample/pojo-consumer/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.pojo.consumer.PojoConsumerMain"
- ```
+```bash
+cd pojo-sample/pojo-consumer/
+mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.pojo.consumer.PojoConsumerMain"
+```
+
+### How to verify
+
+On the producer side, the output should contain the following stuffs if the producer starts up successfully:
+
+1. *`swagger: 2.0 info: version: 1.0.0 ...`* means the producer generated swagger contracts
+2. *`rest listen success. address=0.0.0.0:8080`* means the rest endpoint is listening on port 8080
-4. How to verify
- On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- 1. *'swagger: 2.0 info: version: 1.0.0 ...'* means the producer generated swagger contracts
- 2. *'rest listen success. address=0.0.0.0:8080'* means the rest endpoint is listening on port 8080
-
- On the consumer side, you can see the following outputs if the consumer can invoke the producer:
- 1. *'Hello person ServiceComb/Java Chassis'* means the consumer calls sayHello by RpcReference successfully
- 2. *'a=1, b=2, result=3'* means the consumer calls compute.add by RpcReference successfully
-
+On the consumer side, you can see the following outputs if the consumer can invoke the producer:
+1. *`Hello person ServiceComb/Java Chassis`* means the consumer calls sayHello by RpcReference successfully
+2. *`a=1, b=2, result=3`* means the consumer calls compute.add by RpcReference successfully
diff --git a/java-chassis-samples/pojo-sample/pojo-consumer/pom.xml b/java-chassis-samples/pojo-sample/pojo-consumer/pom.xml
index f0f35760..3e556edb 100644
--- a/java-chassis-samples/pojo-sample/pojo-consumer/pom.xml
+++ b/java-chassis-samples/pojo-sample/pojo-consumer/pom.xml
@@ -21,18 +21,16 @@
org.apache.servicecomb.samples
pojo-sample
- 2.6.0
+ 3.0-SNAPSHOT
pojo-consumer
+ Java Chassis::Samples::pojo-sample::pojo-consumer
+
org.apache.servicecomb
solution-basic
-
- org.apache.servicecomb
- servicestage-environment
-
org.apache.servicecomb.samples
common-schema
diff --git a/java-chassis-samples/pojo-sample/pojo-consumer/src/main/java/org/apache/servicecomb/samples/pojo/consumer/PojoConsumerMain.java b/java-chassis-samples/pojo-sample/pojo-consumer/src/main/java/org/apache/servicecomb/samples/pojo/consumer/PojoConsumerMain.java
index ab1f6ce7..82bbda98 100644
--- a/java-chassis-samples/pojo-sample/pojo-consumer/src/main/java/org/apache/servicecomb/samples/pojo/consumer/PojoConsumerMain.java
+++ b/java-chassis-samples/pojo-sample/pojo-consumer/src/main/java/org/apache/servicecomb/samples/pojo/consumer/PojoConsumerMain.java
@@ -16,14 +16,15 @@
*/
package org.apache.servicecomb.samples.pojo.consumer;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.samples.common.schema.Hello;
import org.apache.servicecomb.samples.common.schema.models.Person;
import org.apache.servicecomb.samples.pojo.Compute;
-import org.springframework.stereotype.Component;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
-@Component
+@SpringBootApplication
public class PojoConsumerMain {
@RpcReference(microserviceName = "hello", schemaId = "hello")
@@ -33,7 +34,19 @@ public class PojoConsumerMain {
public static Compute compute;
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(PojoConsumerMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ run();
+ }
+
+ private static void run() {
System.out.println(hello.sayHi("Java Chassis"));
Person person = new Person();
person.setName("ServiceComb/Java Chassis");
diff --git a/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/log4j2.xml b/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/log4j2.xml
index 1d587110..2a8561e4 100644
--- a/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/pojo-sample/pojo-consumer
diff --git a/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/microservice.yaml b/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/microservice.yaml
index 96b93ad5..6c9343c2 100644
--- a/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/microservice.yaml
@@ -21,7 +21,8 @@ servicecomb:
name: helloClient
version: 0.0.1
- registry:
+ registry:
+ sc:
# Default using local service center
address: http://localhost:30100
# address: https://cse.cn-south-1.myhuaweicloud.com
@@ -30,13 +31,6 @@ servicecomb:
kie:
serverUri: http://localhost:30110
- handler:
- chain:
- Consumer:
- default: bizkeeper-consumer,loadbalance
- isolation:
- Consumer:
- enabled: false
references:
hello:
version-rule: 0.0.1
diff --git a/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/microservices/hello/hello.yaml b/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/microservices/hello/hello.yaml
deleted file mode 100644
index 32714e60..00000000
--- a/java-chassis-samples/pojo-sample/pojo-consumer/src/main/resources/microservices/hello/hello.yaml
+++ /dev/null
@@ -1,72 +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.
-## ---------------------------------------------------------------------------
-
-swagger: '2.0'
-info:
- title: hello
- version: 1.0.0
- x-java-interface: org.apache.servicecomb.samples.pojo.Hello
-basePath: /pojo/rest/hello
-produces:
- - application/json
-
-paths:
- /sayhi:
- post:
- operationId: sayHi
- parameters:
- - name: name
- in: body
- required: true
- schema:
- type: string
- responses:
- 200:
- description: 正确返回
- schema:
- type: string
- default:
- description: 默认返回
- schema:
- type: string
- /sayhello:
- post:
- operationId: sayHello
- parameters:
- - name: person
- in: body
- required: true
- schema:
- $ref: "#/definitions/Person"
- responses:
- 200:
- description: 正确返回
- schema:
- type: string
- default:
- description: 默认返回
- schema:
- type: string
-definitions:
- Person:
- type: "object"
- properties:
- name:
- type: "string"
- description: "person name"
- xml:
- name: "Person"
diff --git a/java-chassis-samples/pojo-sample/pojo-provider/pom.xml b/java-chassis-samples/pojo-sample/pojo-provider/pom.xml
index bd4b1d98..d892ba1e 100644
--- a/java-chassis-samples/pojo-sample/pojo-provider/pom.xml
+++ b/java-chassis-samples/pojo-sample/pojo-provider/pom.xml
@@ -21,18 +21,16 @@
org.apache.servicecomb.samples
pojo-sample
- 2.6.0
+ 3.0-SNAPSHOT
pojo-provider
+ Java Chassis::Samples::pojo-sample::pojo-provider
+
org.apache.servicecomb
solution-basic
-
- org.apache.servicecomb
- servicestage-environment
-
org.apache.servicecomb.samples
common-schema
diff --git a/java-chassis-samples/pojo-sample/pojo-provider/src/main/java/org/apache/servicecomb/samples/pojo/provider/PojoProviderMain.java b/java-chassis-samples/pojo-sample/pojo-provider/src/main/java/org/apache/servicecomb/samples/pojo/provider/PojoProviderMain.java
index ad18378e..cf763af4 100644
--- a/java-chassis-samples/pojo-sample/pojo-provider/src/main/java/org/apache/servicecomb/samples/pojo/provider/PojoProviderMain.java
+++ b/java-chassis-samples/pojo-sample/pojo-provider/src/main/java/org/apache/servicecomb/samples/pojo/provider/PojoProviderMain.java
@@ -17,11 +17,21 @@
package org.apache.servicecomb.samples.pojo.provider;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class PojoProviderMain {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(PojoProviderMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/log4j2.xml b/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/log4j2.xml
index 9302302e..89ecb8ca 100644
--- a/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/pojo-sample/pojo-provider
diff --git a/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/microservice.yaml b/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/microservice.yaml
index 6913ac34..3a137eb6 100644
--- a/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/microservice.yaml
@@ -21,7 +21,8 @@ servicecomb:
name: hello
version: 0.0.1
- registry:
+ registry:
+ sc:
# Default using local service center
address: http://localhost:30100
# address: https://cse.cn-south-1.myhuaweicloud.com
diff --git a/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/microservices/hello/hello.yaml b/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/microservices/hello/hello.yaml
deleted file mode 100644
index 32714e60..00000000
--- a/java-chassis-samples/pojo-sample/pojo-provider/src/main/resources/microservices/hello/hello.yaml
+++ /dev/null
@@ -1,72 +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.
-## ---------------------------------------------------------------------------
-
-swagger: '2.0'
-info:
- title: hello
- version: 1.0.0
- x-java-interface: org.apache.servicecomb.samples.pojo.Hello
-basePath: /pojo/rest/hello
-produces:
- - application/json
-
-paths:
- /sayhi:
- post:
- operationId: sayHi
- parameters:
- - name: name
- in: body
- required: true
- schema:
- type: string
- responses:
- 200:
- description: 正确返回
- schema:
- type: string
- default:
- description: 默认返回
- schema:
- type: string
- /sayhello:
- post:
- operationId: sayHello
- parameters:
- - name: person
- in: body
- required: true
- schema:
- $ref: "#/definitions/Person"
- responses:
- 200:
- description: 正确返回
- schema:
- type: string
- default:
- description: 默认返回
- schema:
- type: string
-definitions:
- Person:
- type: "object"
- properties:
- name:
- type: "string"
- description: "person name"
- xml:
- name: "Person"
diff --git a/java-chassis-samples/pojo-sample/pom.xml b/java-chassis-samples/pojo-sample/pom.xml
index c7a63897..0b38c8ad 100644
--- a/java-chassis-samples/pojo-sample/pom.xml
+++ b/java-chassis-samples/pojo-sample/pom.xml
@@ -21,9 +21,10 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
pojo-sample
+ Java Chassis::Samples::pojo-sample
pom
diff --git a/java-chassis-samples/pom.xml b/java-chassis-samples/pom.xml
index 8a48d887..21f25d9f 100644
--- a/java-chassis-samples/pom.xml
+++ b/java-chassis-samples/pom.xml
@@ -24,12 +24,17 @@
samples
Java Chassis::Samples
pom
- 2.6.0
+ 3.0-SNAPSHOT
UTF-8
- 1.8
+ 17
-Dfile.encoding=UTF-8
+ 3.3.0
+ 3.1.3
+ 3.11.0
+ 2.8.2
+ 0.13
@@ -54,7 +59,7 @@
org.apache.servicecomb
java-chassis-dependencies
- ${project.version}
+ ${servicecomb.version}
pom
import
@@ -67,22 +72,21 @@
-
org.apache.maven.plugins
maven-compiler-plugin
- 3.1
+ ${maven-compiler-plugin.version}
- 1.8
- 1.8
+ ${java.version}
+ ${java.version}
org.springframework.boot
spring-boot-maven-plugin
- 2.1.2.RELEASE
+ ${spring-boot-maven-plugin.version}
@@ -98,16 +102,14 @@
-
+
org.apache.maven.plugins
maven-compiler-plugin
- 3.1
-parameters
UTF-8
- 1.8
- 1.8
+ ${java.version}
-Werror
-Xlint:all
@@ -121,7 +123,7 @@
org.apache.maven.plugins
maven-deploy-plugin
- 2.8.2
+ ${maven-deploy-plugin.version}
true
@@ -129,7 +131,7 @@
org.apache.rat
apache-rat-plugin
- 0.13
+ ${apache-rat-plugin.version}
.travis.yml
diff --git a/java-chassis-samples/springmvc-sample/README.md b/java-chassis-samples/springmvc-sample/README.md
index c0c6d5d2..ddfc6aab 100644
--- a/java-chassis-samples/springmvc-sample/README.md
+++ b/java-chassis-samples/springmvc-sample/README.md
@@ -6,58 +6,62 @@
* During use of this URL format, the ServiceComb framework will perform internal microservice discovery, fallback, and fault tolerance and send the requests to the microservice providers.
## Precondition
+
see [Precondition](../../README.md)
## Sample Quick Start
-1. Start the ServiceComb/Service Center
+### Start the ServiceComb/Service Center
- - [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
- - make sure service center address is configured correctly in `microservice.yaml` file
+* [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+* make sure service center address is configured correctly in `microservice.yaml` file
```yaml
servicecomb:
service:
registry:
- address: http://127.0.0.1:30100 #service center address
+ address: http://127.0.0.1:30100 #service center address
```
-2. Start the springmvc-provider service
+### Start the springmvc-provider service
+
+* Start provider service by maven
+
+ Compile the source code, and use `mvn exec` to execute the main class `SpringmvcProviderMain`.
+
+ ```bash
+ mvn clean install
+ cd springmvc-sample/springmvc-provider/
+ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.springmvc.provider.SpringmvcProviderMain"
+ ```
- * Start provider service by maven
+* Start provider service by IDE
- Compile the source code, and use `mvn exec` to execute the main class `SpringmvcProviderMain`.
+ Import the project by InteliJ IDEA or Eclipse, then find `main` function of provider service and `RUN` it like any other Java Program.
- ```bash
- mvn clean install
- cd springmvc-sample/springmvc-provider/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.springmvc.provider.SpringmvcProviderMain"
- ```
+### Start the springmvc-consumer service
+
+Just like how to start springmvc-provider service. But the main class of springmvc-consumer service is `SpringmvcConsumerMain`.
+
+```bash
+cd springmvc-sample/springmvc-consumer/
+mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.springmvc.consumer.SpringmvcConsumerMain"
+```
- * Start provider service by IDE
+### How to verify
- Import the project by InteliJ IDEA or Eclipse, then find `main` function of provider service and `RUN` it like any other Java Program.
+On the producer side, the output should contain the following stuffs if the producer starts up successfully:
-3. Start the springmvc-consumer service
+1. *`swagger: 2.0 info: version: 1.0.0 ...`* means the producer generated swagger contracts
+2. *`rest listen success. address=0.0.0.0:8080`* means the rest endpoint is listening on port 8080
- Just like how to start springmvc-provider service. But the main class of springmvc-consumer service is `SpringmvcConsumerMain`.
+On the consumer side, you can see the following outputs if the consumer can invoke the producer:
- ```bash
- cd springmvc-sample/springmvc-consumer/
- mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.springmvc.consumer.SpringmvcConsumerMain"
- ```
+1. *`RestTemplate consumer sayhi services: Hello Java Chassis`* means the consumer calls sayhi by RestTemplate successfully
+2. *`RestTemplate consumer sayhello services: Hello person ServiceComb/Java Chassis`* means the consumer calls sayhello by RestTemplate successfully
+3. *`POJO consumer sayhi services: Hello Java Chassis`* means the consumer calls sayhi by RpcReference successfully
+4. *`POJO consumer sayhello services: Hello person ServiceComb/Java Chassis`* means the consumer calls sayhello by RpcReference successfully
-4. How to verify
- On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- 1. *'swagger: 2.0 info: version: 1.0.0 ...'* means the producer generated swagger contracts
- 2. *'rest listen success. address=0.0.0.0:8080'* means the rest endpoint is listening on port 8080
-
- On the consumer side, you can see the following outputs if the consumer can invoke the producer:
- 1. *'RestTemplate consumer sayhi services: Hello Java Chassis'* means the consumer calls sayhi by RestTemplate successfully
- 2. *'RestTemplate consumer sayhello services: Hello person ServiceComb/Java Chassis'* means the consumer calls sayhello by RestTemplate successfully
- 3. *'POJO consumer sayhi services: Hello Java Chassis'* means the consumer calls sayhi by RpcReference successfully
- 4. *'POJO consumer sayhello services: Hello person ServiceComb/Java Chassis'* means the consumer calls sayhello by RpcReference successfully
-
## More
[Develop with SpringMVC](https://docs.servicecomb.io/java-chassis/zh_CN/build-provider/springmvc/)
diff --git a/java-chassis-samples/springmvc-sample/pom.xml b/java-chassis-samples/springmvc-sample/pom.xml
index a902efa7..203aec9c 100644
--- a/java-chassis-samples/springmvc-sample/pom.xml
+++ b/java-chassis-samples/springmvc-sample/pom.xml
@@ -21,9 +21,10 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
springmvc-sample
+ Java Chassis::Samples::springmvc-sample
pom
diff --git a/java-chassis-samples/springmvc-sample/springmvc-consumer/pom.xml b/java-chassis-samples/springmvc-sample/springmvc-consumer/pom.xml
index 467c6f73..69f0ad19 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-consumer/pom.xml
+++ b/java-chassis-samples/springmvc-sample/springmvc-consumer/pom.xml
@@ -21,18 +21,16 @@
org.apache.servicecomb.samples
springmvc-sample
- 2.6.0
+ 3.0-SNAPSHOT
springmvc-consumer
+ Java Chassis::Samples::springmvc-sample::springmvc-consumer
+
org.apache.servicecomb
solution-basic
-
- org.apache.servicecomb
- servicestage-environment
-
org.apache.servicecomb.samples
common-schema
diff --git a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/HelloAync.java b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/HelloAync.java
new file mode 100644
index 00000000..f88221cf
--- /dev/null
+++ b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/HelloAync.java
@@ -0,0 +1,12 @@
+package org.apache.servicecomb.samples.springmvc.consumer;
+
+import org.apache.servicecomb.samples.common.schema.models.Person;
+
+import java.util.concurrent.CompletableFuture;
+
+
+public interface HelloAync {
+ CompletableFuture sayHi(String name);
+
+ CompletableFuture sayHello(Person person);
+}
diff --git a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcBasicClient.java b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcBasicClient.java
index 505a70a0..3dec7fc8 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcBasicClient.java
+++ b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcBasicClient.java
@@ -26,11 +26,11 @@
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.web.client.RestOperations;
@Component("SpringmvcBasicClient")
public class SpringmvcBasicClient {
- private RestTemplate restTemplateInvoker = RestTemplateBuilder.create();
+ private RestOperations restTemplateInvoker = RestTemplateBuilder.create();
@RpcReference(microserviceName = "springmvc", schemaId = "SpringmvcBasicEndpoint")
private SpringmvcBasicService rpcInoker;
diff --git a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcConsumerMain.java b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcConsumerMain.java
index 38b899f7..76120ced 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcConsumerMain.java
+++ b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcConsumerMain.java
@@ -17,11 +17,26 @@
package org.apache.servicecomb.samples.springmvc.consumer;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class SpringmvcConsumerMain {
public static void main(String[] args) throws Exception {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(SpringmvcConsumerMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ run();
+ }
+
+ private static void run() throws Exception {
SpringmvcBasicClient springmvcBasicClient = BeanUtils.getBean("SpringmvcBasicClient");
SpringmvcHelloClient springmvcHelloClient = BeanUtils.getBean("SpringmvcHelloClient");
diff --git a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcHelloClient.java b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcHelloClient.java
index 838c74fd..2b4f2922 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcHelloClient.java
+++ b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/java/org/apache/servicecomb/samples/springmvc/consumer/SpringmvcHelloClient.java
@@ -19,29 +19,30 @@
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
-import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
+//import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
import org.apache.servicecomb.samples.common.schema.Assertion;
+//import org.apache.servicecomb.samples.common.schema.Hello;
import org.apache.servicecomb.samples.common.schema.Hello;
import org.apache.servicecomb.samples.common.schema.models.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
-import org.springframework.util.concurrent.ListenableFuture;
-import org.springframework.util.concurrent.ListenableFutureCallback;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.web.client.RestOperations;
+
+import java.util.concurrent.CompletableFuture;
@Component("SpringmvcHelloClient")
public class SpringmvcHelloClient {
private static final Logger LOG = LoggerFactory.getLogger(SpringmvcHelloClient.class);
- private static RestTemplate restTemplate = RestTemplateBuilder.create();
+ private static RestOperations restTemplate = RestTemplateBuilder.create();
@RpcReference(microserviceName = "springmvc", schemaId = "springmvcHello")
private static Hello hello;
+ @RpcReference(microserviceName = "springmvc", schemaId = "springmvcHello")
+ private static HelloAync helloAync;
+
public void run() throws Exception {
Person person = new Person();
person.setName("ServiceComb/Java Chassis");
@@ -75,28 +76,16 @@ public void run() throws Exception {
//AsyncRestTemplate Consumer
// NOTICE: since 2.0.0, spring deprecated AsyncRestTemplate, user's can use CompletableFuture of RPC instead
- CseAsyncRestTemplate cseAsyncRestTemplate = new CseAsyncRestTemplate();
- ListenableFuture> responseEntityListenableFuture = cseAsyncRestTemplate
- .postForEntity("cse://springmvc/springmvchello/sayhi?name={name}", null, String.class, "Java Chassis");
- ResponseEntity responseEntity = responseEntityListenableFuture.get();
- Assertion.assertEquals("Hello Java Chassis", responseEntity.getBody());
- System.out.println("AsyncRestTemplate Consumer sayHi services: " + responseEntity.getBody());
-
- HttpEntity entity = new HttpEntity<>(person);
- ListenableFuture> listenableFuture = cseAsyncRestTemplate
- .exchange("cse://springmvc/springmvchello/sayhello", HttpMethod.POST, entity, String.class);
-
- listenableFuture.addCallback(
- new ListenableFutureCallback>() {
- @Override
- public void onFailure(Throwable ex) {
- LOG.error("AsyncResTemplate Consumer catched exception when sayHello, ", ex);
- }
-
- @Override
- public void onSuccess(ResponseEntity result) {
- System.out.println("AsyncRestTemplate Consumer sayHello services: " + result.getBody());
- }
- });
+ CompletableFuture asyncSayHi = helloAync.sayHi("Java Chassis");
+ String sayHiResp = asyncSayHi.get();
+ Assertion.assertEquals("Hello Java Chassis", sayHiResp);
+ System.out.println("Async Consumer sayHi services: " + sayHiResp);
+
+ CompletableFuture asyncSayHello = helloAync.sayHello(person);
+ asyncSayHello.thenAccept(result -> System.out.println("Async Consumer sayHello services: " + result))
+ .exceptionally(ex -> {
+ LOG.error("Async Consumer catched exception when sayHello, ", ex);
+ return null;
+ });
}
}
diff --git a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/resources/log4j2.xml b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/resources/log4j2.xml
index 1d587110..b2aedd20 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/springmvc-sample/springmvc-consumer
diff --git a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/resources/microservice.yaml b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/resources/microservice.yaml
index 81bb70a8..162d1bd1 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/springmvc-sample/springmvc-consumer/src/main/resources/microservice.yaml
@@ -21,7 +21,8 @@ servicecomb:
name: springmvcConsumer
version: 0.0.1
- registry:
+ registry:
+ sc:
# Default using local service center
address: http://localhost:30100
# address: https://cse.cn-south-1.myhuaweicloud.com
@@ -30,14 +31,6 @@ servicecomb:
kie:
serverUri: http://localhost:30110
- handler:
- chain:
- Consumer:
- default: bizkeeper-consumer,loadbalance
- isolation:
- Consumer:
- enabled: false
-
# Using Huawei Cloud Service Engine Professional Edition, AK/SK is required
# credentials:
# akskEnabled: true
diff --git a/java-chassis-samples/springmvc-sample/springmvc-provider/pom.xml b/java-chassis-samples/springmvc-sample/springmvc-provider/pom.xml
index aae73f1e..9af40269 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-provider/pom.xml
+++ b/java-chassis-samples/springmvc-sample/springmvc-provider/pom.xml
@@ -21,18 +21,16 @@
org.apache.servicecomb.samples
springmvc-sample
- 2.6.0
+ 3.0-SNAPSHOT
springmvc-provider
+ Java Chassis::Samples::springmvc-sample::springmvc-provider
+
org.apache.servicecomb
solution-basic
-
- org.apache.servicecomb
- servicestage-environment
-
org.apache.servicecomb.samples
common-schema
diff --git a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcBasicEndpoint.java b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcBasicEndpoint.java
index 91230a2a..1b1f17c9 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcBasicEndpoint.java
+++ b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcBasicEndpoint.java
@@ -20,7 +20,7 @@
import java.util.ArrayList;
import java.util.List;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.MediaType;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.springframework.web.bind.annotation.RequestBody;
diff --git a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcHelloEndpoint.java b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcHelloEndpoint.java
index 7f205f15..59368633 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcHelloEndpoint.java
+++ b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcHelloEndpoint.java
@@ -18,7 +18,7 @@
package org.apache.servicecomb.samples.springmvc.provider;
-import javax.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.MediaType;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.apache.servicecomb.samples.common.schema.Hello;
diff --git a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcProviderMain.java b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcProviderMain.java
index 1cbb2aff..fa51cc9e 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcProviderMain.java
+++ b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/java/org/apache/servicecomb/samples/springmvc/provider/SpringmvcProviderMain.java
@@ -17,11 +17,21 @@
package org.apache.servicecomb.samples.springmvc.provider;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class SpringmvcProviderMain {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(SpringmvcProviderMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/resources/log4j2.xml b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/resources/log4j2.xml
index 9302302e..a87e3cb8 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/springmvc-sample/springmvc-provider
diff --git a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/resources/microservice.yaml b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/resources/microservice.yaml
index b4078e25..3380ccaa 100644
--- a/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/springmvc-sample/springmvc-provider/src/main/resources/microservice.yaml
@@ -21,7 +21,8 @@ servicecomb:
name: springmvc
version: 0.0.1
- registry:
+ registry:
+ sc:
# Default using local service center
address: http://localhost:30100
# address: https://cse.cn-south-1.myhuaweicloud.com
@@ -32,10 +33,6 @@ servicecomb:
rest:
address: 0.0.0.0:8080
- handler:
- chain:
- Provider:
- default: bizkeeper-provider
# Using Huawei Cloud Service Engine Professional Edition, AK/SK is required
# credentials:
diff --git a/java-chassis-samples/trust-sample/README.md b/java-chassis-samples/trust-sample/README.md
index a49bcf83..33793fcc 100644
--- a/java-chassis-samples/trust-sample/README.md
+++ b/java-chassis-samples/trust-sample/README.md
@@ -1,14 +1,113 @@
-## Trust Sample
+# Trust Sample
+
This sample shows using public key mechanism to authenticate user and black/white user list. The public key mechanism security is based on Service Center, and users should first configure Service Center authentication. This sample does not show how to configure Service Center authentication.
In this sample, both customer and hacker try to access store, while store configure it's black list to deny hacker's access.
+## Provider Service
+
+1. Add dependence in `pom.xml` file:
+
+ ```xml
+
+ org.apache.servicecomb
+ handler-publickey-auth
+
+ ```
+
+2. Add publicKey accessControl rules in `microservice.yaml`:
+
+ ```yaml
+ publicKey:
+ accessControl:
+ enabled: true
+ # excludePathPatterns: '/scb/management/*'
+ # includePathPatterns: '/CodeFirstComputeImpl/*'
+ black:
+ list01:
+ category: property ## property, fixed value
+ propertyName: serviceName ## property name, e.g. serviceName, appId, environment, alias, version and so on, also support key in properties.
+ # property value match expression.
+ # if propertyName is serviceName
+ # only supports prefix match and postfix match and exactly match.
+ # e.g. hacker*, *hacker, hacker
+ rule: hacker
+ white:
+ list02:
+ category: property
+ propertyName: serviceName
+ rule: cust*
+ ```
+
+ This configuration allows serviceNames start with `cust` to access, denied serviceNames `hacker` to access.
+
+## Consumer Service
+
+1. Add dependence in `pom.xml` file:
+
+ ```xml
+
+ org.apache.servicecomb
+ handler-publickey-auth
+
+ ```
+
## Precondition
+
see [Precondition](../../README.md)
-## How to run
+## Sample Quick Start
+
+### Start the ServiceComb/Service Center
+
+* [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+* make sure service center address is configured correctly in `microservice.yaml` file
+
+### Start the `store` service
+
+* Start provider service by maven
+
+ Compile the source code, and use `mvn exec` to execute the main class `TrustMain`.
+
+ ```bash
+ mvn clean install
+ cd auth-sample/auth-provider/
+ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.trust.provider.TrustMain"
+ ```
+
+* Start provider service by IDE
+
+ Import the project by InteliJ IDEA or Eclipse, then find `main` function `TrustMain` of provider service and `RUN` it like any other Java program.
+
+### Start the `customer` service
+
+Just like how to start `store` service. But the main class of auth-consumer service is `AuthConsumerMain`.
+
+```bash
+cd auth-sample/auth-consumer/
+mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.trust.consumer.CustomerMain"
+```
+
+### Start the `hacker` service
+
+Just like how to start `store` service. But the main class of auth-consumer service is `HackerMain`.
+
+```bash
+cd auth-sample/auth-consumer/
+mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.trust.consumer.HackerMain"
+```
+
+### How to verify
+
+On the `store` side, the output should contain the following stuffs if the producer starts up successfully:
+
+1. *`swagger: 2.0 info: version: 1.0.0 ...`* means the producer generated swagger contracts
+2. *`rest listen success. address=0.0.0.0:8080`* means the rest endpoint is listening on port 8080
+
+On the `consumer` side, you can see the following outputs if the consumer can invoke the producer:
+
+* *`a=1, b=2, result=3`* means the consumer calls `add` with `a=1, b=2` successfully by rules.
-You can run the samples from your IDE. First start TrustMain in store service. And then start HackerMain in
-hacker service, the running result should be `InvocationException: code=401;msg={message=UNAUTHORIZED}`. And then
-start CustomerMain in customer service, the running result should be `a=1, b=2, result=3` .
+On the `hacker` side, you can see the following outputs if the consumer can invoke the producer:
+* *`InvocationException: code=401;msg={message=UNAUTHORIZED}`* means the consumer calls `add` been denied by rules.
diff --git a/java-chassis-samples/trust-sample/customer/pom.xml b/java-chassis-samples/trust-sample/customer/pom.xml
index 1803b85f..12e33f52 100644
--- a/java-chassis-samples/trust-sample/customer/pom.xml
+++ b/java-chassis-samples/trust-sample/customer/pom.xml
@@ -21,9 +21,11 @@
org.apache.servicecomb.samples
trust-sample
- 2.6.0
+ 3.0-SNAPSHOT
customer
+ Java Chassis::Samples::trust-sample::customer
+
org.apache.servicecomb
@@ -31,19 +33,11 @@
org.apache.servicecomb
- handler-loadbalance
+ solution-basic
org.apache.servicecomb
- transport-rest-vertx
-
-
- org.apache.servicecomb
- handler-flowcontrol-qps
-
-
- org.apache.servicecomb
- provider-pojo
+ java-chassis-spring-boot-starter-standalone
@@ -58,9 +52,5 @@
org.apache.logging.log4j
log4j-core
-
- org.apache.servicecomb.samples
- common-schema
-
diff --git a/java-chassis-samples/trust-sample/customer/src/main/java/org/apache/servicecomb/samples/trust/consumer/CustomerMain.java b/java-chassis-samples/trust-sample/customer/src/main/java/org/apache/servicecomb/samples/trust/consumer/CustomerMain.java
index 69fd5b0d..afa1f80b 100644
--- a/java-chassis-samples/trust-sample/customer/src/main/java/org/apache/servicecomb/samples/trust/consumer/CustomerMain.java
+++ b/java-chassis-samples/trust-sample/customer/src/main/java/org/apache/servicecomb/samples/trust/consumer/CustomerMain.java
@@ -16,19 +16,28 @@
*/
package org.apache.servicecomb.samples.trust.consumer;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.samples.trust.Compute;
-import org.springframework.stereotype.Component;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
-@Component
+@SpringBootApplication
public class CustomerMain {
@RpcReference(microserviceName = "store", schemaId = "codeFirstCompute")
public static Compute compute;
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(CustomerMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
System.out.println("a=1, b=2, result=" + compute.add(1, 2));
}
diff --git a/java-chassis-samples/trust-sample/customer/src/main/resources/log4j2.xml b/java-chassis-samples/trust-sample/customer/src/main/resources/log4j2.xml
index 6ad0c703..ec211ccf 100644
--- a/java-chassis-samples/trust-sample/customer/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/trust-sample/customer/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/trust-sample/customer
diff --git a/java-chassis-samples/trust-sample/customer/src/main/resources/microservice.yaml b/java-chassis-samples/trust-sample/customer/src/main/resources/microservice.yaml
index eec48359..1b6c3eb9 100644
--- a/java-chassis-samples/trust-sample/customer/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/trust-sample/customer/src/main/resources/microservice.yaml
@@ -21,17 +21,14 @@ servicecomb:
name: customer
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
- isolation:
- Consumer:
- enabled: false
references:
hello:
version-rule: 0.0.1
- handler:
- chain:
- Consumer:
- default: loadbalance,auth-consumer
- Provider:
- default: auth-provider
+ # servicecomb.filter.provider-public-key.trust-sample.customer.enabled
+ # servicecomb.filter.provider-public-key.trust-sample.customer.order
+ publicKey:
+ accessControl:
+ enabled: true
diff --git a/java-chassis-samples/trust-sample/hacker/pom.xml b/java-chassis-samples/trust-sample/hacker/pom.xml
index 0b307af6..90d3c04b 100644
--- a/java-chassis-samples/trust-sample/hacker/pom.xml
+++ b/java-chassis-samples/trust-sample/hacker/pom.xml
@@ -21,33 +21,23 @@
org.apache.servicecomb.samples
trust-sample
- 2.6.0
+ 3.0-SNAPSHOT
hacker
+ Java Chassis::Samples::trust-sample::hacker
+
org.apache.servicecomb
- handler-bizkeeper
+ solution-basic
org.apache.servicecomb
- handler-publickey-auth
-
-
- org.apache.servicecomb
- handler-loadbalance
-
-
- org.apache.servicecomb
- transport-rest-vertx
+ java-chassis-spring-boot-starter-standalone
org.apache.servicecomb
- handler-flowcontrol-qps
-
-
- org.apache.servicecomb
- provider-pojo
+ handler-publickey-auth
@@ -62,9 +52,5 @@
org.apache.logging.log4j
log4j-core
-
- org.apache.servicecomb.samples
- common-schema
-
diff --git a/java-chassis-samples/trust-sample/hacker/src/main/java/org/apache/servicecomb/samples/trust/consumer/HackerMain.java b/java-chassis-samples/trust-sample/hacker/src/main/java/org/apache/servicecomb/samples/trust/consumer/HackerMain.java
index 2ad9a786..09e53c53 100644
--- a/java-chassis-samples/trust-sample/hacker/src/main/java/org/apache/servicecomb/samples/trust/consumer/HackerMain.java
+++ b/java-chassis-samples/trust-sample/hacker/src/main/java/org/apache/servicecomb/samples/trust/consumer/HackerMain.java
@@ -16,18 +16,27 @@
*/
package org.apache.servicecomb.samples.trust.consumer;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.samples.trust.Compute;
-import org.springframework.stereotype.Component;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
-@Component
+@SpringBootApplication
public class HackerMain {
@RpcReference(microserviceName = "store", schemaId = "codeFirstCompute")
public static Compute compute;
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(HackerMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
System.out.println("a=1, b=2, result=" + compute.add(1, 2));
}
}
diff --git a/java-chassis-samples/trust-sample/hacker/src/main/resources/log4j2.xml b/java-chassis-samples/trust-sample/hacker/src/main/resources/log4j2.xml
index 9a4ae202..9dc60037 100644
--- a/java-chassis-samples/trust-sample/hacker/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/trust-sample/hacker/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/trust-sample/hacker
diff --git a/java-chassis-samples/trust-sample/hacker/src/main/resources/microservice.yaml b/java-chassis-samples/trust-sample/hacker/src/main/resources/microservice.yaml
index ad719bfe..79b55943 100644
--- a/java-chassis-samples/trust-sample/hacker/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/trust-sample/hacker/src/main/resources/microservice.yaml
@@ -21,17 +21,15 @@ servicecomb:
name: hacker
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
- isolation:
- Consumer:
- enabled: false
+
references:
hello:
version-rule: 0.0.1
- handler:
- chain:
- Consumer:
- default: loadbalance,auth-consumer
- Provider:
- default: auth-provider
+ # servicecomb.filter.provider-public-key.trust-sample.hacker.enabled
+ # servicecomb.filter.provider-public-key.trust-sample.hacker.order
+ publicKey:
+ accessControl:
+ enabled: true
\ No newline at end of file
diff --git a/java-chassis-samples/trust-sample/pom.xml b/java-chassis-samples/trust-sample/pom.xml
index 2cbd3da5..63c12c39 100644
--- a/java-chassis-samples/trust-sample/pom.xml
+++ b/java-chassis-samples/trust-sample/pom.xml
@@ -21,9 +21,10 @@
org.apache.servicecomb.samples
samples
- 2.6.0
+ 3.0-SNAPSHOT
trust-sample
+ Java Chassis::Samples::trust-sample
pom
diff --git a/java-chassis-samples/trust-sample/store/pom.xml b/java-chassis-samples/trust-sample/store/pom.xml
index 31ade65a..26d2e38c 100644
--- a/java-chassis-samples/trust-sample/store/pom.xml
+++ b/java-chassis-samples/trust-sample/store/pom.xml
@@ -21,33 +21,23 @@
org.apache.servicecomb.samples
trust-sample
- 2.6.0
+ 3.0-SNAPSHOT
store
+ Java Chassis::Samples::trust-sample::store
+
org.apache.servicecomb
- handler-bizkeeper
+ solution-basic
org.apache.servicecomb
- handler-publickey-auth
-
-
- org.apache.servicecomb
- handler-loadbalance
-
-
- org.apache.servicecomb
- transport-rest-vertx
+ java-chassis-spring-boot-starter-standalone
org.apache.servicecomb
- handler-flowcontrol-qps
-
-
- org.apache.servicecomb
- provider-pojo
+ handler-publickey-auth
@@ -62,9 +52,5 @@
org.apache.logging.log4j
log4j-core
-
- org.apache.servicecomb.samples
- common-schema
-
diff --git a/java-chassis-samples/trust-sample/store/src/main/java/org/apache/servicecomb/samples/trust/provider/TrustMain.java b/java-chassis-samples/trust-sample/store/src/main/java/org/apache/servicecomb/samples/trust/provider/TrustMain.java
index 66bca9f4..07afb9b7 100644
--- a/java-chassis-samples/trust-sample/store/src/main/java/org/apache/servicecomb/samples/trust/provider/TrustMain.java
+++ b/java-chassis-samples/trust-sample/store/src/main/java/org/apache/servicecomb/samples/trust/provider/TrustMain.java
@@ -17,11 +17,21 @@
package org.apache.servicecomb.samples.trust.provider;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class TrustMain {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(TrustMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/java-chassis-samples/trust-sample/store/src/main/resources/log4j2.xml b/java-chassis-samples/trust-sample/store/src/main/resources/log4j2.xml
index 63333c1f..17339cea 100644
--- a/java-chassis-samples/trust-sample/store/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/trust-sample/store/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/trust-sample/store
diff --git a/java-chassis-samples/trust-sample/store/src/main/resources/microservice.yaml b/java-chassis-samples/trust-sample/store/src/main/resources/microservice.yaml
index 721093f7..d13884d9 100644
--- a/java-chassis-samples/trust-sample/store/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/trust-sample/store/src/main/resources/microservice.yaml
@@ -21,24 +21,25 @@ servicecomb:
name: store
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://127.0.0.1:30100
rest:
address: 0.0.0.0:8080
- handler:
- chain:
- Consumer:
- default: loadbalance,auth-consumer
- Provider:
- default: auth-provider
publicKey:
accessControl:
+ enabled: true
+ # excludePathPatterns: '/scb/management/*'
+ # includePathPatterns: '/CodeFirstComputeImpl/*'
black:
list01:
category: property ## property, fixed value
propertyName: serviceName ## property name, e.g. serviceName, appId, environment, alias, version and so on, also support key in properties.
- rule: hacker ## property value match expression.
-##if propertyName is serviceName, only supports prefix match and postfix match and exactly match. e.g. hacker*, *hacker, hacker
+ # property value match expression.
+ # if propertyName is serviceName
+ # only supports prefix match and postfix match and exactly match.
+ # e.g. hacker*, *hacker, hacker
+ rule: hacker
white:
list02:
category: property
diff --git a/java-chassis-samples/use-log4j2-sample/README.md b/java-chassis-samples/use-log4j2-sample/README.md
new file mode 100644
index 00000000..303c157b
--- /dev/null
+++ b/java-chassis-samples/use-log4j2-sample/README.md
@@ -0,0 +1,51 @@
+# use-log4j2-sample
+
+This sample demonstrates how to use Log4j2 as the logging framework in ServiceComb Java Chassis microservices.
+
+## Overview
+
+This example shows:
+
+* Using Log4j2 instead of the default logging implementation
+* Configuring Log4j2 for console and file output
+* Implementing a simple RPC service
+
+## Preconditions
+
+* JDK 17 or higher
+* Maven 3.x
+* ServiceComb Service Center running
+
+## Start Service Center
+
+See [how to start the service center](http://servicecomb.apache.org/docs/products/service-center/install/)
+
+Make sure the Service Center address is configured correctly in the `microservice.yaml` file:
+
+```yaml
+servicecomb:
+ registry:
+ sc:
+ address: http://127.0.0.1:30100
+```
+## Log4j2 Configuration
+
+The project uses Log4j2 as the logging framework. The configuration file is located at . `src/main/resources/log4j2.xml`
+
+Key configurations:
+
+* Logs output to both console and file
+* Log file path: `./logs/use-log4j2-sample/output.log`
+* Rolling policy: Max 200MB per file, up to 99 backup files
+* Log level: INFO
+
+## How to verify
+
+* Start the Service Center
+* Build and run the sample application
+* Access the service through the interface: `http://localhost:8080/hello`
+* Check the logs in `./logs/use-log4j2-sample/output.log`
+
+## More
+* [ServiceComb Java Chassis Documentation](https://docs.servicecomb.io/java-chassis/zh_CN/)
+* [Log4j2 Official Documentation](https://logging.apache.org/log4j/2.x/)
diff --git a/java-chassis-samples/use-log4j2-sample/pom.xml b/java-chassis-samples/use-log4j2-sample/pom.xml
index a1c0a17b..711f7208 100644
--- a/java-chassis-samples/use-log4j2-sample/pom.xml
+++ b/java-chassis-samples/use-log4j2-sample/pom.xml
@@ -22,40 +22,24 @@
samples
org.apache.servicecomb.samples
- 2.6.0
+ 3.0-SNAPSHOT
4.0.0
use-log4j2-sample
+ Java Chassis::Samples::use-log4j2-sample
UTF-8
UTF-8
- 1.8
- ${project.version}
-
-
-
- org.apache.servicecomb
- java-chassis-dependencies
- ${java-chassis.version}
- pom
- import
-
-
-
-
org.apache.servicecomb
- transport-rest-vertx
-
-
- org.apache.servicecomb
- provider-pojo
+ solution-basic
+
org.apache.logging.log4j
log4j-slf4j-impl
diff --git a/java-chassis-samples/use-log4j2-sample/src/main/java/org/apache/servicecomb/samples/uselog4j2/Application.java b/java-chassis-samples/use-log4j2-sample/src/main/java/org/apache/servicecomb/samples/uselog4j2/Application.java
index af2e6745..b57ab84e 100644
--- a/java-chassis-samples/use-log4j2-sample/src/main/java/org/apache/servicecomb/samples/uselog4j2/Application.java
+++ b/java-chassis-samples/use-log4j2-sample/src/main/java/org/apache/servicecomb/samples/uselog4j2/Application.java
@@ -17,10 +17,20 @@
package org.apache.servicecomb.samples.uselog4j2;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+@SpringBootApplication
public class Application {
public static void main(String[] args) {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(Application.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
\ No newline at end of file
diff --git a/java-chassis-samples/use-log4j2-sample/src/main/java/org/apache/servicecomb/samples/uselog4j2/HelloImpl.java b/java-chassis-samples/use-log4j2-sample/src/main/java/org/apache/servicecomb/samples/uselog4j2/HelloImpl.java
index 1c9d9e4e..93f198fd 100644
--- a/java-chassis-samples/use-log4j2-sample/src/main/java/org/apache/servicecomb/samples/uselog4j2/HelloImpl.java
+++ b/java-chassis-samples/use-log4j2-sample/src/main/java/org/apache/servicecomb/samples/uselog4j2/HelloImpl.java
@@ -18,10 +18,14 @@
package org.apache.servicecomb.samples.uselog4j2;
import org.apache.servicecomb.provider.pojo.RpcSchema;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
@RpcSchema(schemaId = "hello")
+@RequestMapping(path = "/")
public class HelloImpl implements Hello {
+ @GetMapping("/hello")
public String hello() {
return "Hello World!";
}
diff --git a/java-chassis-samples/use-log4j2-sample/src/main/resources/log4j2.xml b/java-chassis-samples/use-log4j2-sample/src/main/resources/log4j2.xml
index 6e9a8e41..d04af208 100644
--- a/java-chassis-samples/use-log4j2-sample/src/main/resources/log4j2.xml
+++ b/java-chassis-samples/use-log4j2-sample/src/main/resources/log4j2.xml
@@ -18,7 +18,7 @@
- ./target/log/
+ ./logs/use-log4j2-sample
diff --git a/java-chassis-samples/use-log4j2-sample/src/main/resources/microservice.yaml b/java-chassis-samples/use-log4j2-sample/src/main/resources/microservice.yaml
index 3147b3e6..a515f757 100644
--- a/java-chassis-samples/use-log4j2-sample/src/main/resources/microservice.yaml
+++ b/java-chassis-samples/use-log4j2-sample/src/main/resources/microservice.yaml
@@ -16,13 +16,13 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-APPLICATION_ID: samples
-service_description:
- name: uselog4j2
- version: 0.0.1
servicecomb:
service:
- registry:
+ application: ssamples
+ name: uselog4j2
+ version: 0.0.1
+ registry:
+ sc:
address: http://127.0.0.1:30100
rest:
address: 0.0.0.0:8080
\ No newline at end of file
diff --git a/porter/README.md b/porter/README.md
index 8ba61eb7..5735570d 100644
--- a/porter/README.md
+++ b/porter/README.md
@@ -1,92 +1,129 @@
-This project shows how to use Java Chassis to create a simple microservice application. It shows basic authentication and authorization, uploading files and delete files operations.
+# porter-application
+
+## Description
+
+This project shows how to use Java Chassis to create a simple microservice application.
+It shows basic authentication and authorization, uploading files and delete files operations.
## Precondition
+
see [Precondition](../README.md)
## build and run
-* compile
+1. compile
+
+ ```bash
+ mvn clean install
+ ```
+
+2. before run
+
+ - create a database using mysql with username and password(e.g. root/root)
+ - execute `create_db_user.sql`
-```
-mvn clean install
-```
+3. run `user-service`:
-* run
- * create a database using mysql with username and password(e.g. root/root)
- * execute create_db_user.sql
+ ```bash
+ java $JAVA_OPT -Ddb.url="jdbc:mysql://localhost/porter_user_db?useSSL=false" -Ddb.username=root -Ddb.password=root -jar porter-user-service-3.0-SNAPSHOT.jar
+ ```
-* run user-service:
+4. run `file-service`:
-```
-java $JAVA_OPT -Ddb.url="jdbc:mysql://localhost/porter_user_db?useSSL=false" -Ddb.username=root -Ddb.password=root -jar porter-user-service-0.0.1-SNAPSHOT.jar
-```
+ ```bash
+ java $JAVA_OPT -jar porter-file-service-3.0-SNAPSHOT.jar
+ ```
-* run file-service:
+5. run `gateway-service`:
-```
-java $JAVA_OPT -jar porter-file-service-0.0.1-SNAPSHOT.jar
-```
+ The `gateway-service` contains static page files in the `resources/ui` directory.
-* run gateway-service:
+ - First, you need to copy the page files to the WEB root directory (relative path, current running directory), e.g.:
+ `webapp`.
+ - Then copy the entire ui directory to `webapp/ui` directory to start.
-gateway-service contains static web pages in resources/ui. First copy to web root folder,e.g webapp, which is relative to working directory
-(Note:"porter_lightweight/gateway-service/src/main/resources/microservice.yaml"The related configuration"gateway:webroot: /code/servicecomb-samples/porter_lightweight/gateway-service/src/main/resources"
-Is the location of its own native code).
+ Note: Related configuration in `porter_lightweight/gateway-service/src/main/resources/microservice.yaml`
+ `gateway.webroot` is your local code location
-```
-java $JAVA_OPT -Dgateway.webroot=webapp -jar porter-gateway-service-0.0.1-SNAPSHOT.jar
-```
+ Refer to [issues 53](https://github.com/apache/servicecomb-samples/issues/53):
+
+ - For Windows users, modify `gateway.webroot` to
+ `/code/servicecomb-samples/porter_lightweight/gateway-service/src/main/resources`
+ > For absolute path, remove the drive letter. Assuming the code is saved in
+ > `D:\code\servicecomb-samples\porter_lightweight\gateway-service\src\main\resources`
+ - For Linux users, `gateway.webroot` can use relative path directly:
+ `./porter_lightweight/gateway-service/src/main/resources`
+
+ ```bash
+ java $JAVA_OPT -Dgateway.webroot=webapp -jar porter-gateway-service-3.0-SNAPSHOT.jar
+ ```
## Try it
-1. Using browser: http://localhost:9090/ui/login.html with user admin or guest, password is test.
-2. Choose a file to upload. Uploaded file is stored in file-service working directory. And name is random number generated.
-3. Delete file. Input the random number generated in step 2.
+1. Using browser: http://localhost:9090/ui/login.html with user `admin` or `guest`, password is `test`.
+2. Choose a file to upload. Uploaded file is stored in `file-service` working directory.
+ And file Id is random number generated.
+3. Delete file. Input the file Id generated in step 2.
+ > Only admin account can delete files.
+
+## 说明
+这个项目帮助开发者学习如何使用 ServiceComb 开发完整的微服务。
+这个项目实现的功能非常简单,用户登录后,上传一个文件和删除一个文件,验证了没有权限的用户无法删除文件。
## 前提条件
查看 [前提条件](../README.md)
-这个项目帮助开发者学习如何使用ServiceComb开发完整的微服务。 这个项目实现的功能非常简单,用户登录后,上传一个文件和删除一个文件,验证了没有权限的用户无法删除文件。
+## 编译和运行
+
+1. 编译
+
+ ```bash
+ mvn clean install
+ ```
-# 编译和运行
+2. 运行前准备
-* 编译
+ - 安装 mysql 数据库,设置用户名密码(假设为 root/root)
+ - 执行脚本`create_db_user.sql`
-```
-mvn clean install
-```
+3. 启动`user-service`:
-* 运行
- * 安装mysql数据库,设置用户名密码(假设为root/root)
- * 执行脚本create_db_user.sql
+ ```bash
+ java $JAVA_OPT porter-user-service-3.0-SNAPSHOT.jar
+ ```
+4. 启动`file-service`:
-* 启动user-service:
+ ```bash
+ java $JAVA_OPT -jar porter-file-service-3.0-SNAPSHOT.jar
+ ```
-```
-java $JAVA_OPT porter-user-service-0.0.1-SNAPSHOT.jar
-```
+5. 启动`gateway-serivce`:
-* 启动file-service:
+ `gateway-service`包含了静态页面文件,在`resources/ui`目录。
-```
-java $JAVA_OPT -jar porter-file-service-0.0.1-SNAPSHOT.jar
-```
+ - 首先需要将页面文件拷贝到 WEB 主目录(相对路径,当前运行目录),比如:`webapp`。
+ - 然后将 ui 目录整体拷贝到`webapp/ui`目录启动。
-* 启动gateway-serivce:
+ 注意:`porter_lightweight/gateway-service/src/main/resources/microservice.yaml`中的相关配置
+ `gateway.webroot`是自己本地代码的位置
-gateway-service包含了静态页面文件,在resources/ui目录。首先需要将页面文件拷贝到WEB主目录(相对路径,当前运行目录),比如: webapp,然后将ui目录整体拷贝到webapp/ui目录(注意:porter_lightweight/gateway-service/src/main/resources/microservice.yaml中的相关配置
-gateway:webroot: /code/servicecomb-samples/porter_lightweight/gateway-service/src/main/resources是自己本地代码的位置)。启动:
+ 参考[issues 53](https://github.com/apache/servicecomb-samples/issues/53):
-```
-java $JAVA_OPT -Dgateway.webroot=webapp -jar porter-gateway-service-0.0.1-SNAPSHOT.jar
-```
+ - 如果你使用 Windows,请修改`gateway.webroot`为
+ `/code/servicecomb-samples/porter_lightweight/gateway-service/src/main/resources`
+ > 绝对路径去掉盘符,假设代码保存在`D:\code\servicecomb-samples\porter_lightweight\gateway-service\src\main\resources`
+ - 如果你使用 Linux,`gateway.webroot`可以直接使用相对位置:`./porter_lightweight/gateway-service/src/main/resources`
-# 使用
+ ```bash
+ java $JAVA_OPT -Dgateway.webroot=webapp -jar porter-gateway-service-3.0-SNAPSHOT.jar
+ ```
-1. 输入: http://localhost:9090/ui/login.html 使用admin或者guest登陆,密码为test。
-2. 选择一个文件上传,上传成功,上传成功后的文件会保存在file-service的当前目录, 文件名称是一个随机的数字,这个数字就是文件ID。
-3. 删除文件:输入上一步的文件ID,点击删除。 如果是admin用户,上传成功;如果是guest用户,上传失败。
+## 使用
+1. 输入: http://localhost:9090/ui/login.html 使用 `admin` 或者 `guest` 登陆,密码为 `test`。
+2. 选择一个文件上传,上传成功,上传成功后的文件会保存在`file-service`的当前目录, 文件名称是一个随机的数字,这个数字就是文件 ID。
+3. 删除文件:输入上一步的文件 ID,点击删除。
+ > 只有 admin 账户可以删除文件。
diff --git a/porter/file-service/src/main/java/org/apache/servicecomb/samples/porter/file/service/SessionInfo.java b/porter/file-service/src/main/java/org/apache/servicecomb/samples/porter/file/service/SessionInfo.java
index eeff2267..edfbc798 100644
--- a/porter/file-service/src/main/java/org/apache/servicecomb/samples/porter/file/service/SessionInfo.java
+++ b/porter/file-service/src/main/java/org/apache/servicecomb/samples/porter/file/service/SessionInfo.java
@@ -20,7 +20,7 @@
public class SessionInfo {
private int id;
- private String sessiondId;
+ private String sessionId;
private String userName;
@@ -38,12 +38,12 @@ public void setId(int id) {
this.id = id;
}
- public String getSessiondId() {
- return sessiondId;
+ public String getSessionId() {
+ return sessionId;
}
- public void setSessiondId(String sessiondId) {
- this.sessiondId = sessiondId;
+ public void setSessionId(String sessionId) {
+ this.sessionId = sessionId;
}
public String getUserName() {
diff --git a/porter/file-service/src/main/resources/application.yml b/porter/file-service/src/main/resources/application.yml
index 056ab4f9..1a9c194f 100644
--- a/porter/file-service/src/main/resources/application.yml
+++ b/porter/file-service/src/main/resources/application.yml
@@ -28,6 +28,9 @@ servicecomb:
sc:
address: http://localhost:30100
+ kie:
+ serverUri: http://localhost:30110
+
rest:
address: 0.0.0.0:9091
diff --git a/porter/file-service/src/main/resources/log4j2.xml b/porter/file-service/src/main/resources/log4j2.xml
index 7f1ace89..c6d256c0 100644
--- a/porter/file-service/src/main/resources/log4j2.xml
+++ b/porter/file-service/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/porter/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/ext/ApiDispatcher.java b/porter/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/ext/ApiDispatcher.java
index a488d602..a5d1afcf 100644
--- a/porter/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/ext/ApiDispatcher.java
+++ b/porter/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/ext/ApiDispatcher.java
@@ -22,7 +22,6 @@
import org.apache.servicecomb.core.invocation.InvocationCreator;
import org.apache.servicecomb.edge.core.AbstractEdgeDispatcher;
import org.apache.servicecomb.edge.core.EdgeInvocationCreator;
-import org.apache.servicecomb.edge.core.Utils;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
@@ -50,7 +49,7 @@ public void init(Router router) {
protected void onRequest(RoutingContext context) {
String microserviceName = extractMicroserviceName(context);
- String path = Utils.findActualPath(context.request().path(), 2);
+ String path = findActualPath(context.request().path(), 2);
requestByFilter(context, microserviceName, path);
}
@@ -84,4 +83,23 @@ protected Invocation createInstance() {
new RestProducerInvocationFlow(creator, requestEx, responseEx)
.run();
}
+
+ public String findActualPath(String path, int pathIndex) {
+ if (pathIndex <= 0) {
+ return path;
+ }
+
+ int fromIndex = 0;
+ int counter = pathIndex;
+ char[] chars = path.toCharArray();
+ for (int i = 0; i < chars.length; i++) {
+ if (chars[i] == '/') {
+ if (--counter < 0) {
+ fromIndex = i;
+ break;
+ }
+ }
+ }
+ return fromIndex > 0 ? path.substring(fromIndex) : "";
+ }
}
diff --git a/porter/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/user/api/SessionInfo.java b/porter/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/user/api/SessionInfo.java
index 63581045..3e0e42a7 100644
--- a/porter/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/user/api/SessionInfo.java
+++ b/porter/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/user/api/SessionInfo.java
@@ -18,18 +18,18 @@
package org.apache.servicecomb.samples.porter.user.api;
public class SessionInfo {
- private String sessiondId;
+ private String sessionId;
private String userName;
private String roleName;
- public String getSessiondId() {
- return sessiondId;
+ public String getSessionId() {
+ return sessionId;
}
- public void setSessiondId(String sessiondId) {
- this.sessiondId = sessiondId;
+ public void setSessionId(String sessionId) {
+ this.sessionId = sessionId;
}
public String getUserName() {
diff --git a/porter/gateway-service/src/main/resources/application.yml b/porter/gateway-service/src/main/resources/application.yml
index 862a6f48..6d7cd5a5 100644
--- a/porter/gateway-service/src/main/resources/application.yml
+++ b/porter/gateway-service/src/main/resources/application.yml
@@ -29,6 +29,9 @@ servicecomb:
sc:
address: http://localhost:30100
+ kie:
+ serverUri: http://localhost:30110
+
rest:
address: 0.0.0.0:9090?sslEnabled=false
diff --git a/porter/gateway-service/src/main/resources/log4j2.xml b/porter/gateway-service/src/main/resources/log4j2.xml
index d50e5697..44c2a64e 100644
--- a/porter/gateway-service/src/main/resources/log4j2.xml
+++ b/porter/gateway-service/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+
diff --git a/porter/gateway-service/src/main/resources/ui/js/login.js b/porter/gateway-service/src/main/resources/ui/js/login.js
index c7e7c8e9..46dd6c1d 100644
--- a/porter/gateway-service/src/main/resources/ui/js/login.js
+++ b/porter/gateway-service/src/main/resources/ui/js/login.js
@@ -17,7 +17,7 @@
function loginAction() {
var username = document.getElementById("username").value;
- var password = document.getElementById("paasword").value;
+ var password = document.getElementById("password").value;
var formData = {};
formData.userName = username;
formData.password = password;
@@ -28,7 +28,7 @@ function loginAction() {
data: formData,
success: function (data) {
console.log(data);
- setCookie("session-id", data.sessiondId, 1);
+ setCookie("session-id", data.sessionId, 1);
window.location = "/ui/upload.html";
},
error: function(data) {
diff --git a/porter/gateway-service/src/main/resources/ui/login.html b/porter/gateway-service/src/main/resources/ui/login.html
index c8b45fb1..5cf09f33 100644
--- a/porter/gateway-service/src/main/resources/ui/login.html
+++ b/porter/gateway-service/src/main/resources/ui/login.html
@@ -33,7 +33,7 @@ Login
diff --git a/porter/pom.xml b/porter/pom.xml
index fd745648..b77ac599 100644
--- a/porter/pom.xml
+++ b/porter/pom.xml
@@ -26,10 +26,15 @@
pom
+ 17
UTF-8
3.11.0
3.1.3
- 3.0.0
+ 3.3.0
+ 3.0.3
+ 5.1.46
+ 8.0.33
+ 3.4.4
@@ -37,12 +42,13 @@
org.mybatis.spring.boot
mybatis-spring-boot-starter
- 3.0.2
+ ${mybatis-spring-boot-starter.version}
- mysql
- mysql-connector-java
- 5.1.46
+ com.mysql
+ mysql-connector-j
+ ${mysql-connector-j.version}
+ runtime
@@ -89,7 +95,7 @@
com.lmax
disruptor
- 3.4.4
+ ${disruptor.version}
@@ -108,8 +114,8 @@
${maven-compiler-plugin.version}
-parameters
- 17
- 17
+ ${java.version}
+ ${java.version}
diff --git a/porter/user-service/pom.xml b/porter/user-service/pom.xml
index 0ebec902..0212acbd 100644
--- a/porter/user-service/pom.xml
+++ b/porter/user-service/pom.xml
@@ -45,29 +45,9 @@
- mysql
- mysql-connector-java
-
-
- org.apache.commons
- commons-dbcp2
-
-
- org.springframework
- spring-jdbc
- compile
-
-
- org.springframework
- spring-aop
-
-
- org.springframework
- spring-context-support
-
-
- org.springframework
- spring-tx
+ com.mysql
+ mysql-connector-j
+ runtime
diff --git a/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/api/SessionInfo.java b/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/api/SessionInfo.java
index 63581045..3e0e42a7 100644
--- a/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/api/SessionInfo.java
+++ b/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/api/SessionInfo.java
@@ -18,18 +18,18 @@
package org.apache.servicecomb.samples.porter.user.api;
public class SessionInfo {
- private String sessiondId;
+ private String sessionId;
private String userName;
private String roleName;
- public String getSessiondId() {
- return sessiondId;
+ public String getSessionId() {
+ return sessionId;
}
- public void setSessiondId(String sessiondId) {
- this.sessiondId = sessiondId;
+ public void setSessionId(String sessionId) {
+ this.sessionId = sessionId;
}
public String getUserName() {
diff --git a/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionInfoModel.java b/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionInfoModel.java
index ecbacc00..f31c99d6 100644
--- a/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionInfoModel.java
+++ b/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionInfoModel.java
@@ -82,7 +82,7 @@ public void setActiveTime(java.sql.Timestamp activeTime) {
public static SessionInfo toSessionInfo(SessionInfoModel entity) {
SessionInfo info = new SessionInfo();
- info.setSessiondId(entity.getSessionId());
+ info.setSessionId(entity.getSessionId());
info.setUserName(entity.getUserName());
info.setRoleName(entity.getRoleName());
return info;
diff --git a/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionMapper.java b/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionMapper.java
index cc655951..62dd8e3e 100644
--- a/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionMapper.java
+++ b/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionMapper.java
@@ -29,7 +29,7 @@
public interface SessionMapper {
@Insert("""
insert into T_SESSION (SESSION_ID, USER_NAME, ROLE_NAME)
- values(#{sessiondId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
+ values(#{sessionId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
#{roleName,jdbcType=VARCHAR})""")
void createSession(SessionInfo sessionInfo);
diff --git a/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/service/UserServiceImpl.java b/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/service/UserServiceImpl.java
index 162508fd..2dcf60f4 100644
--- a/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/service/UserServiceImpl.java
+++ b/porter/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/service/UserServiceImpl.java
@@ -54,7 +54,7 @@ public SessionInfo login(String userName,
if (userInfo != null) {
if (validatePassword(password, userInfo.getPassword())) {
SessionInfo sessionInfo = new SessionInfo();
- sessionInfo.setSessiondId(UUID.randomUUID().toString());
+ sessionInfo.setSessionId(UUID.randomUUID().toString());
sessionInfo.setUserName(userInfo.getUserName());
sessionInfo.setRoleName(userInfo.getRoleName());
sessionMapper.createSession(sessionInfo);
diff --git a/porter/user-service/src/main/resources/application.yml b/porter/user-service/src/main/resources/application.yml
index eea3d1db..66c3aee2 100644
--- a/porter/user-service/src/main/resources/application.yml
+++ b/porter/user-service/src/main/resources/application.yml
@@ -29,6 +29,9 @@ servicecomb:
sc:
address: http://localhost:30100
+ kie:
+ serverUri: http://localhost:30110
+
rest:
address: 0.0.0.0:9093
@@ -37,4 +40,4 @@ spring:
url: jdbc:mysql://localhost/porter_user_db
username: root
password: root
- driver-class-name: com.mysql.jdbc.Driver
+ driver-class-name: com.mysql.cj.jdbc.Driver
diff --git a/porter/user-service/src/main/resources/log4j2.xml b/porter/user-service/src/main/resources/log4j2.xml
index f68264bb..6c10156a 100644
--- a/porter/user-service/src/main/resources/log4j2.xml
+++ b/porter/user-service/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
-->
-
+