This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-samples.git
The following commit(s) were added to refs/heads/master by this push:
new cec906e update porter to 3.0.0 (#132)
cec906e is described below
commit cec906e502608b2658d07c801ad05cfde9349c2b
Author: liubao68 <[email protected]>
AuthorDate: Thu Nov 23 16:25:29 2023 +0800
update porter to 3.0.0 (#132)
---
porter_lightweight/README.md | 131 ++-------------------
porter_lightweight/api/common/endpoint/pom.xml | 2 +-
.../samples/porter/file/api/LogEndpoint.java | 5 +-
porter_lightweight/api/common/pom.xml | 2 +-
porter_lightweight/api/common/service/pom.xml | 2 +-
.../api/file-service/endpoint/pom.xml | 2 +-
.../porter/file/api/InternalAccessEndpoint.java | 7 +-
porter_lightweight/api/file-service/pom.xml | 2 +-
.../api/file-service/service/pom.xml | 2 +-
porter_lightweight/api/pom.xml | 2 +-
.../api/user-service/endpoint/pom.xml | 2 +-
porter_lightweight/api/user-service/pom.xml | 2 +-
.../api/user-service/service/pom.xml | 2 +-
porter_lightweight/file-service/pom.xml | 2 +-
.../servicecomb/samples/porter/file/FileMain.java | 16 ++-
.../main/resources/META-INF/spring/file.bean.xml | 27 -----
.../{microservice.yaml => application.yml} | 16 +--
.../file-service/src/main/resources/log4j2.xml | 106 ++++++++++-------
porter_lightweight/gateway-service/pom.xml | 2 +-
.../samples/porter/gateway/ApiDispatcher.java | 51 +++++---
.../samples/porter/gateway/AuthHandler.java | 52 +++++---
.../samples/porter/gateway/GatewayMain.java | 16 ++-
.../porter/gateway/InternalAccessHandler.java | 29 +++--
.../porter/gateway/StaticWebpageDispatcher.java | 12 +-
.../main/resources/META-INF/spring/cse.bean.xml | 27 -----
.../{microservice.yaml => application.yml} | 25 +---
.../src/main/resources/config/cse.handler.xml | 23 ----
.../gateway-service/src/main/resources/log4j2.xml | 106 ++++++++++-------
porter_lightweight/pom.xml | 47 +++++---
porter_lightweight/user-service/pom.xml | 10 +-
.../servicecomb/samples/porter/user/UserMain.java | 14 ++-
.../samples/porter/user/dao/SessionInfoModel.java | 12 +-
.../samples/porter/user/dao/SessionMapper.java | 34 +++++-
.../samples/porter/user/dao/UserMapper.java | 24 +++-
.../porter/user/service/UserServiceImpl.java | 9 +-
.../main/resources/META-INF/spring/user.bean.xml | 53 ---------
.../{microservice.yaml => application.yml} | 21 ++--
.../src/main/resources/config/SessionMapper.xml | 57 ---------
.../src/main/resources/config/UserMapper.xml | 46 --------
.../src/main/resources/config/mybatis-config.xml | 27 -----
.../user-service/src/main/resources/log4j2.xml | 106 ++++++++++-------
41 files changed, 464 insertions(+), 669 deletions(-)
diff --git a/porter_lightweight/README.md b/porter_lightweight/README.md
index f826264..8ba61eb 100644
--- a/porter_lightweight/README.md
+++ b/porter_lightweight/README.md
@@ -1,4 +1,4 @@
-This project shows how to using java-chassis and service-center to create a
simple microservice application. It shows basic authentication and
authorization, uploading files and delete files operations.
+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)
@@ -12,20 +12,19 @@ mvn clean install
```
* run
- * create a database using mysql with user name and password(e.g. root/root)
+ * create a database using mysql with username and password(e.g. root/root)
* execute create_db_user.sql
* run user-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 >/dev/null 2>&1 &
+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
```
-Note: If startup fails, try removing "$JAVA_OPT" and ">/dev/null 2>&1 &" (same
below)
* run file-service:
```
-java $JAVA_OPT -jar porter-file-service-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &
+java $JAVA_OPT -jar porter-file-service-0.0.1-SNAPSHOT.jar
```
* run gateway-service:
@@ -35,12 +34,12 @@ gateway-service contains static web pages in resources/ui.
First copy to web roo
Is the location of its own native code).
```
-java $JAVA_OPT -Dgateway.webroot=webapp -jar
porter-gateway-service-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &
+java $JAVA_OPT -Dgateway.webroot=webapp -jar
porter-gateway-service-0.0.1-SNAPSHOT.jar
```
## Try it
-1. Using browser: http://localhost:9090/ui/login.html with user admin or guest
to login, password is test.
+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.
@@ -67,22 +66,22 @@ mvn clean install
* 启动user-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 >/dev/null 2>&1 &
+java $JAVA_OPT porter-user-service-0.0.1-SNAPSHOT.jar
```
-注意:如果启动不了,可以尝试去掉“$JAVA_OPT”和“>/dev/null 2>&1 &”(下同)
* 启动file-service:
```
-java $JAVA_OPT -jar porter-file-service-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &
+java $JAVA_OPT -jar porter-file-service-0.0.1-SNAPSHOT.jar
```
* 启动gateway-serivce:
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是自己本地代码的位置)。启动:
+
```
-java $JAVA_OPT -Dgateway.webroot=webapp -jar
porter-gateway-service-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &
+java $JAVA_OPT -Dgateway.webroot=webapp -jar
porter-gateway-service-0.0.1-SNAPSHOT.jar
```
# 使用
@@ -91,113 +90,3 @@ java $JAVA_OPT -Dgateway.webroot=webapp -jar
porter-gateway-service-0.0.1-SNAPSH
2. 选择一个文件上传,上传成功,上传成功后的文件会保存在file-service的当前目录, 文件名称是一个随机的数字,这个数字就是文件ID。
3. 删除文件:输入上一步的文件ID,点击删除。 如果是admin用户,上传成功;如果是guest用户,上传失败。
-# 接口使用说明
-ServiceComb推荐先定义接口,再定义实现的开发模式。将接口定义为一个独立项目,可以由设计者统一管控,对于接口的修改,需要设计者进行审核。先定义接口还可以让开发者培养良好的开发习惯,避免将对外接口采用内部实现数据结构(比如JsonObject)、运行平台有关的数据结构(比如HttpServletResponse、HttpServletRequest)来定义,使得以后将项目改造为其他技术框架变得复杂。采用这种方式组织的项目,用户很容易在不同的开发框架上进行迁移,比如gRPC、Spring
Cloud等。这里的接口定义代码,对于这些运行框架都是通用的,并且具备跨平台特性。
-
-## 对于接口实现者(provider)
- * 依赖api对应的jar包
-
-```
- <dependencies>
- <dependency>
- <groupId>org.apache.servicecomb.samples.porter</groupId>
- <artifactId>user-service-api-endpoint</artifactId>
- </dependency>
- </dependencies>
-```
-
- * 实现Service接口
-```
-@Service
-public class UserServiceImpl implements UserService
-```
-
-## 对于接口使用者(consumer)
- * 依赖service对应的jar包(只包含model和接口)
-
-```
- <dependencies>
- <dependency>
- <groupId>org.apache.servicecomb.samples.porter</groupId>
- <artifactId>user-service-api-service</artifactId>
- </dependency>
- </dependencies>
-```
-
- * 采用RPC方式调用
-```
- @RpcReference(microserviceName = "user-service", schemaId = "user")
- private static UserService sserService
-```
-
-# REST接口常见争议问题和处理
-
-## 查询接口参数很复杂
-
-比如:
-
-```
-public List<Goods> queryGoodsByTags(String orgId, List<GoodsTag> tags)
-```
-
-当查询参数很复杂的时候,不建议采用query参数或者path参数。主要有如下原因:
-
-* HTTP对于URL的长度有限制
-* 复杂参数可能包含特殊字符,需要客户端在拼接URL的时候,进行URL转码,客户端开发者通常会遗漏。
-* 对象无法和query参数进行合理的映射。
-* query参数或者path参数会被proxy、web server等记录到日志里面,导致日志过大,或者造成敏感信息泄露。
-
-对于复杂的查询操作,建议使用POST方法,相关复杂参数都封装为body。比如:
-
-```
-@PostMapping(path = "queryGoodsByTags")
-public List<Goods> queryGoodsByTags(@RequestParam(name = "orgId") String
orgId, @RequestBody List<GoodsTag> tags)
-```
-
-一般的,通过query传递参数的场景,尽可能要保证参数个数少,参数类型为基础类型(字符串、数字等)。参数比较多的场景采用POST来传参。
-
-本项目的处理原则是“尽可能遵循HTTP REST语义,但是不盲目,以系统可靠优先”。
-
-对于DELETE请求,也有类似的情况。在设计GET和DELETE方法时,建议都不使用body参数,尽管HTTP协议并没有强制要求不能使用body,但是由于历史因素,很多WEB服务器支持上会有问题,接口设计应该尽可能避免不必要的麻烦和陷阱。只在POST、PUT、PATCH方法中使用body参数。
-
-## REST接口的Path是否包含操作
-
-比如:下面的接口定义path是否包含deleteGoodsUnitConvertor。
-
-```
- @DeleteMapping(path = "deleteGoodsUnitConvertor")
- public ResponseBase deleteGoodsUnitConvertor(String goodsUnitConvertorId)
-```
-
-由于HTTP的方法POST/PUT/PATCH/GET/DELETE已经包含了增、改、查、删语义,path里面包含delete显得多余。不过由于项目的接口通常比较多,过多的思考接口语义反而增加了理解的难度。所以本项目path全部都包含了方法名字。包含名称有个好处,可以从URL中看出operation
id,从而很简单的将URL和契约对应起来,方便查找。此外就是上面提到的原因,并不是所有的删除操作都一定对应于DELETE操作,出于系统可靠性、安全等方面考虑,可能使用POST/PATCH等代表查询或者删除操作。
-
-## 多个对象参数
-
-由于HTTP只能有一个body,所有多个对象参数需要包装为一个参数。 比如:
-
-```
-public ResponseBase inboundOrder(InboundOrder inboundOrder,
Set<InboundOrderItem> inboundOrderItems)
-```
-
-封装为下面的REST接口定义:
-
-```
- @PostMapping(path = "inboundOrder")
- public ResponseBase inboundOrder(@RequestBody InboundOrderRequest
inboundOrderRequest) {
- return stockService.inboundOrder(inboundOrderRequest.getInboundOrder(),
inboundOrderRequest.getInboundOrderItems());
- }
-```
-
-## 敏感信息不能采用query参数
-
-Query参数可能被各种proxy、web server记录,因此对于用户敏感信息,不能使用query参数。 比如:
-
-```
-public ResponseBase rechargePrepaidCard(String cardId, double amount)
-```
-
-涉及到卡号和金额的数据,需要采用POST提交,参数存储在body。 虽然有些接口仅仅只是查询, 但也可能被设计为POST。 调整后的接口:
-
-```
-public ResponseBase rechargePrepaidCard(@RequestBody PrepaidAmountRequest
prepaidAmountRequest)
-```
diff --git a/porter_lightweight/api/common/endpoint/pom.xml
b/porter_lightweight/api/common/endpoint/pom.xml
index 27b91dd..4f3e673 100644
--- a/porter_lightweight/api/common/endpoint/pom.xml
+++ b/porter_lightweight/api/common/endpoint/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>common-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>common-api-endpoint</artifactId>
diff --git
a/porter_lightweight/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/LogEndpoint.java
b/porter_lightweight/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/LogEndpoint.java
index 8e49a6e..60e22be 100644
---
a/porter_lightweight/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/LogEndpoint.java
+++
b/porter_lightweight/api/common/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/LogEndpoint.java
@@ -22,20 +22,19 @@ import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.apache.servicecomb.samples.porter.common.api.LogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
-import com.netflix.config.DynamicPropertyFactory;
-
@RestSchema(schemaId = "log")
@RequestMapping(path = "/v1/log")
public class LogEndpoint implements LogService {
// protect your file in real applications
private static final File LOG_DIR =
- new
File(DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.samples.logdir",
".").get());
+ new
File(LegacyPropertyFactory.getStringProperty("servicecomb.samples.logdir",
"."));
private static final String FILE_POST_FIX = ".log";
diff --git a/porter_lightweight/api/common/pom.xml
b/porter_lightweight/api/common/pom.xml
index 41f0bb8..7d372bb 100644
--- a/porter_lightweight/api/common/pom.xml
+++ b/porter_lightweight/api/common/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>porter-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>common-api</artifactId>
diff --git a/porter_lightweight/api/common/service/pom.xml
b/porter_lightweight/api/common/service/pom.xml
index ce8dea5..2af9fe1 100644
--- a/porter_lightweight/api/common/service/pom.xml
+++ b/porter_lightweight/api/common/service/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>common-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>common-api-service</artifactId>
diff --git a/porter_lightweight/api/file-service/endpoint/pom.xml
b/porter_lightweight/api/file-service/endpoint/pom.xml
index d581872..f1a9bf3 100644
--- a/porter_lightweight/api/file-service/endpoint/pom.xml
+++ b/porter_lightweight/api/file-service/endpoint/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>file-service-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>file-service-api-endpoint</artifactId>
diff --git
a/porter_lightweight/api/file-service/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/InternalAccessEndpoint.java
b/porter_lightweight/api/file-service/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/InternalAccessEndpoint.java
index 1a7d94d..5840427 100644
---
a/porter_lightweight/api/file-service/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/InternalAccessEndpoint.java
+++
b/porter_lightweight/api/file-service/endpoint/src/main/java/org/apache/servicecomb/samples/porter/file/api/InternalAccessEndpoint.java
@@ -22,15 +22,16 @@ import
org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
-import io.swagger.annotations.Api;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.tags.Tag;
@RestSchema(schemaId = "InternalAccessEndpoint")
@RequestMapping(path = "/")
-@Api(tags = {"INTERNAL"})
+@OpenAPIDefinition(tags = {@Tag(name = "INTERNAL")})
public class InternalAccessEndpoint {
@Autowired
private InternalAccessService internalAccessService;
-
+
@GetMapping(path = "localAccess")
public String localAccess(String name) {
return internalAccessService.localAccess(name);
diff --git a/porter_lightweight/api/file-service/pom.xml
b/porter_lightweight/api/file-service/pom.xml
index eb9f6ce..8d00ed1 100644
--- a/porter_lightweight/api/file-service/pom.xml
+++ b/porter_lightweight/api/file-service/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>porter-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>file-service-api</artifactId>
diff --git a/porter_lightweight/api/file-service/service/pom.xml
b/porter_lightweight/api/file-service/service/pom.xml
index 326bf08..5090e69 100644
--- a/porter_lightweight/api/file-service/service/pom.xml
+++ b/porter_lightweight/api/file-service/service/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>file-service-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>file-service-api-service</artifactId>
diff --git a/porter_lightweight/api/pom.xml b/porter_lightweight/api/pom.xml
index 079cc34..87a1063 100644
--- a/porter_lightweight/api/pom.xml
+++ b/porter_lightweight/api/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>porter-application</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>porter-api</artifactId>
diff --git a/porter_lightweight/api/user-service/endpoint/pom.xml
b/porter_lightweight/api/user-service/endpoint/pom.xml
index 2feaf00..90546d0 100644
--- a/porter_lightweight/api/user-service/endpoint/pom.xml
+++ b/porter_lightweight/api/user-service/endpoint/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>user-service-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>user-service-api-endpoint</artifactId>
diff --git a/porter_lightweight/api/user-service/pom.xml
b/porter_lightweight/api/user-service/pom.xml
index 8ef9333..6d5251e 100644
--- a/porter_lightweight/api/user-service/pom.xml
+++ b/porter_lightweight/api/user-service/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>porter-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>user-service-api</artifactId>
diff --git a/porter_lightweight/api/user-service/service/pom.xml
b/porter_lightweight/api/user-service/service/pom.xml
index e1559a7..12877a6 100644
--- a/porter_lightweight/api/user-service/service/pom.xml
+++ b/porter_lightweight/api/user-service/service/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>user-service-api</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>user-service-api-service</artifactId>
diff --git a/porter_lightweight/file-service/pom.xml
b/porter_lightweight/file-service/pom.xml
index 855d094..3201813 100644
--- a/porter_lightweight/file-service/pom.xml
+++ b/porter_lightweight/file-service/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>porter-application</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>porter-file-service</artifactId>
diff --git
a/porter_lightweight/file-service/src/main/java/org/apache/servicecomb/samples/porter/file/FileMain.java
b/porter_lightweight/file-service/src/main/java/org/apache/servicecomb/samples/porter/file/FileMain.java
index ff57da5..6558ba6 100644
---
a/porter_lightweight/file-service/src/main/java/org/apache/servicecomb/samples/porter/file/FileMain.java
+++
b/porter_lightweight/file-service/src/main/java/org/apache/servicecomb/samples/porter/file/FileMain.java
@@ -17,10 +17,20 @@
package org.apache.servicecomb.samples.porter.file;
-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 FileMain {
- public static void main(String[] args) throws Exception {
- BeanUtils.init();
+ public static void main(String[] args) throws Exception {
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(FileMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
}
+ }
}
diff --git
a/porter_lightweight/file-service/src/main/resources/META-INF/spring/file.bean.xml
b/porter_lightweight/file-service/src/main/resources/META-INF/spring/file.bean.xml
deleted file mode 100644
index ca83464..0000000
---
a/porter_lightweight/file-service/src/main/resources/META-INF/spring/file.bean.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
-
- <bean id="servicecomb.samples.executor.groupThreadPool"
class="org.apache.servicecomb.core.executor.GroupExecutor"
- init-method="init"/>
-</beans>
\ No newline at end of file
diff --git
a/porter_lightweight/file-service/src/main/resources/microservice.yaml
b/porter_lightweight/file-service/src/main/resources/application.yml
similarity index 80%
rename from porter_lightweight/file-service/src/main/resources/microservice.yaml
rename to porter_lightweight/file-service/src/main/resources/application.yml
index 6416655..056ab4f 100644
--- a/porter_lightweight/file-service/src/main/resources/microservice.yaml
+++ b/porter_lightweight/file-service/src/main/resources/application.yml
@@ -24,24 +24,12 @@ servicecomb:
application: porter-application
name: file-service
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://localhost:30100
- instance:
- watch: false
rest:
address: 0.0.0.0:9091
uploads:
directory: tmp_for_upload_file
-
- samples:
- logdir: D:\code\servicecomb-samples\porter_lightweight\file-service
-
- inspector:
- enabled: false
-
- executors:
- Provider:
- log: servicecomb.samples.executor.groupThreadPool
- inspector: servicecomb.samples.executor.groupThreadPool
\ No newline at end of file
diff --git a/porter_lightweight/file-service/src/main/resources/log4j2.xml
b/porter_lightweight/file-service/src/main/resources/log4j2.xml
index 313d1fc..7f1ace8 100644
--- a/porter_lightweight/file-service/src/main/resources/log4j2.xml
+++ b/porter_lightweight/file-service/src/main/resources/log4j2.xml
@@ -1,45 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
+ 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.
+-->
+<Configuration>
+ <Properties>
+ <property name="FILE_PATH" value="./logs/file-service"/>
+ </Properties>
-<!--this is sample configuration, please modify as your wish -->
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="%d [%p][%t][%c:%L] %m%n"/>
+ </Console>
-<configuration>
- <Properties>
- <Property name="log_path">./file/log/</Property>
- </Properties>
+ <RollingFile name="AccessLog" fileName="${FILE_PATH}/access.log"
+ filePattern="${FILE_PATH}/access-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
- <Appenders>
- <Console name="Console" target="SYSTEM_OUT">
- <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n" />
- </Console>
- <RollingFile name="DailyRollingFile" fileName="${log_path}/output.log"
- filePattern="${log_path}/zcrTest%d{yyyy-MM-dd}.log">
- <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n" />
- <Policies>
- <TimeBasedTriggeringPolicy interval="1" />
- <SizeBasedTriggeringPolicy size="10 MB" />
- </Policies>
- </RollingFile>
- </Appenders>
- <Loggers>
- <Root level="info">
- <AppenderRef ref="Console" />
- <AppenderRef ref="DailyRollingFile" />
- </Root>
- </Loggers>
-</configuration>
\ No newline at end of file
+ <RollingFile name="MetricsLog" fileName="${FILE_PATH}/metrics.log"
+ filePattern="${FILE_PATH}/metrics-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
+
+ <RollingFile name="SlowLog" fileName="${FILE_PATH}/slow.log"
+ filePattern="${FILE_PATH}/slow-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
+ </Appenders>
+
+ <Loggers>
+ <AsyncLogger name="scb-access" level="INFO" additivity="false">
+ <AppenderRef ref="AccessLog"/>
+ </AsyncLogger>
+ <AsyncLogger name="scb-metrics" level="INFO" additivity="false">
+ <AppenderRef ref="MetricsLog"/>
+ </AsyncLogger>
+ <AsyncLogger name="scb-slow" level="INFO" additivity="false">
+ <AppenderRef ref="SlowLog"/>
+ </AsyncLogger>
+
+ <Root level="INFO">
+ <AppenderRef ref="Console"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/porter_lightweight/gateway-service/pom.xml
b/porter_lightweight/gateway-service/pom.xml
index db57431..a7e085a 100644
--- a/porter_lightweight/gateway-service/pom.xml
+++ b/porter_lightweight/gateway-service/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>porter-application</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>porter-gateway-service</artifactId>
diff --git
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/ApiDispatcher.java
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/ApiDispatcher.java
index c27e93c..8ab55ab 100644
---
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/ApiDispatcher.java
+++
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/ApiDispatcher.java
@@ -17,16 +17,25 @@
package org.apache.servicecomb.samples.porter.gateway;
-import java.util.Map;
-
+import org.apache.servicecomb.common.rest.RestProducerInvocationFlow;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.core.invocation.InvocationCreator;
import org.apache.servicecomb.edge.core.AbstractEdgeDispatcher;
-import org.apache.servicecomb.edge.core.EdgeInvocation;
+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;
+import
org.apache.servicecomb.foundation.vertx.http.VertxServerResponseToHttpServletResponse;
+import org.springframework.lang.Nullable;
import io.vertx.core.http.Cookie;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
public class ApiDispatcher extends AbstractEdgeDispatcher {
+ public static final String MICROSERVICE_NAME = "param0";
+
@Override
public int getOrder() {
return 10002;
@@ -40,27 +49,39 @@ public class ApiDispatcher extends AbstractEdgeDispatcher {
}
protected void onRequest(RoutingContext context) {
- Map<String, String> pathParams = context.pathParams();
- String microserviceName = pathParams.get("param0");
- String path = "/" + pathParams.get("param1");
+ String microserviceName = extractMicroserviceName(context);
+ String path = Utils.findActualPath(context.request().path(), 2);
+
+ requestByFilter(context, microserviceName, path);
+ }
+
+ @Nullable
+ private String extractMicroserviceName(RoutingContext context) {
+ return context.pathParam(MICROSERVICE_NAME);
+ }
- EdgeInvocation invoker = new EdgeInvocation() {
- // Authentication. Notice: adding context must after setContext or will
override by network
- public void setContext() throws Exception {
- super.setContext();
+ protected void requestByFilter(RoutingContext context, String
microserviceName, String path) {
+ HttpServletRequestEx requestEx = new
VertxServerRequestToHttpServletRequest(context);
+ HttpServletResponseEx responseEx = new
VertxServerResponseToHttpServletResponse(context.response());
+ InvocationCreator creator = new EdgeInvocationCreator(context, requestEx,
responseEx,
+ microserviceName, path) {
+ @Override
+ protected Invocation createInstance() {
+ Invocation invocation = super.createInstance();
// get session id from header and cookie for debug reasons
String sessionId = context.request().getHeader("session-id");
if (sessionId != null) {
- this.invocation.addContext("session-id", sessionId);
+ invocation.addContext("session-id", sessionId);
} else {
- Cookie sessionCookie = context.cookieMap().get("session-id");
+ Cookie sessionCookie = context.request().getCookie("session-id");
if (sessionCookie != null) {
- this.invocation.addContext("session-id", sessionCookie.getValue());
+ invocation.addContext("session-id", sessionCookie.getValue());
}
}
+ return invocation;
}
};
- invoker.init(microserviceName, context, path, httpServerFilters);
- invoker.edgeInvoke();
+ new RestProducerInvocationFlow(creator, requestEx, responseEx)
+ .run();
}
}
diff --git
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/AuthHandler.java
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/AuthHandler.java
index 4d1b8ec..439a379 100644
---
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/AuthHandler.java
+++
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/AuthHandler.java
@@ -20,34 +20,41 @@ package org.apache.servicecomb.samples.porter.gateway;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
-import org.apache.servicecomb.core.Handler;
import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.core.filter.AbstractFilter;
+import org.apache.servicecomb.core.filter.EdgeFilter;
+import org.apache.servicecomb.core.filter.FilterNode;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.apache.servicecomb.samples.porter.user.api.SessionInfo;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
-
-public class AuthHandler implements Handler {
- private UserServiceClient userServiceClient =
BeanUtils.getBean("UserServiceClient");
+@Component
+public class AuthHandler extends AbstractFilter implements EdgeFilter {
+ private final UserServiceClient userServiceClient;
// session expires in 10 minutes, cache for 1 seconds to get rid of
concurrent scenarios.
private Cache<String, String> sessionCache = CacheBuilder.newBuilder()
.expireAfterAccess(30, TimeUnit.SECONDS)
.build();
+ @Autowired
+ public AuthHandler(UserServiceClient userServiceClient) {
+ this.userServiceClient = userServiceClient;
+ }
+
@Override
- public void handle(Invocation invocation, AsyncResponse asyncResponse)
throws Exception {
+ public CompletableFuture<Response> onFilter(Invocation invocation,
FilterNode nextNode) {
if (invocation.getMicroserviceName().equals("user-service")
&& (invocation.getOperationName().equals("login")
- || (invocation.getOperationName().equals("getSession")))) {
+ || (invocation.getOperationName().equals("getSession")))) {
// login:return session id, set cookie by javascript
- invocation.next(asyncResponse);
+ return nextNode.onFilter(invocation);
} else {
// check session
String sessionId = invocation.getContext("session-id");
@@ -61,35 +68,42 @@ public class AuthHandler implements Handler {
// session info stored in InvocationContext. Microservices can get
it.
invocation.addContext("session-id", sessionId);
invocation.addContext("session-info", sessionInfo);
- invocation.next(asyncResponse);
+ return nextNode.onFilter(invocation);
} catch (Exception e) {
- asyncResponse.complete(Response.failResp(new
InvocationException(500, "", e.getMessage())));
+ return CompletableFuture.completedFuture(Response.failResp(new
InvocationException(500, "", e.getMessage())));
}
- return;
}
// In edge, handler is executed in reactively. Must have no blocking
logic.
CompletableFuture<SessionInfo> result =
userServiceClient.getGetSessionOperation().getSession(sessionId);
- result.whenComplete((info, e) -> {
+ return result.whenComplete((info, e) -> {
if (result.isCompletedExceptionally()) {
- asyncResponse.complete(Response.failResp(new
InvocationException(403, "", "session is not valid.")));
+ throw new InvocationException(403, "", "session is not valid.");
} else {
if (info == null) {
- asyncResponse.complete(Response.failResp(new
InvocationException(403, "", "session is not valid.")));
- return;
+ throw new InvocationException(403, "", "session is not valid.");
}
try {
// session info stored in InvocationContext. Microservices can get
it.
invocation.addContext("session-id", sessionId);
String sessionInfoStr = JsonUtils.writeValueAsString(info);
invocation.addContext("session-info", sessionInfoStr);
- invocation.next(asyncResponse);
sessionCache.put(sessionId, sessionInfoStr);
} catch (Exception ee) {
- asyncResponse.complete(Response.failResp(new
InvocationException(500, "", ee.getMessage())));
+ throw new InvocationException(500, "", ee.getMessage());
}
}
- });
+ }).thenCompose(info -> nextNode.onFilter(invocation));
}
}
+
+ @Override
+ public int getOrder() {
+ return -1890;
+ }
+
+ @Override
+ public String getName() {
+ return "edge-auth";
+ }
}
diff --git
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/GatewayMain.java
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/GatewayMain.java
index a219d2d..78b9114 100644
---
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/GatewayMain.java
+++
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/GatewayMain.java
@@ -17,10 +17,20 @@
package org.apache.servicecomb.samples.porter.gateway;
-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 GatewayMain {
- public static void main(String[] args) throws Exception {
- BeanUtils.init();
+ public static void main(String[] args) throws Exception {
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(GatewayMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
}
+ }
}
diff --git
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/InternalAccessHandler.java
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/InternalAccessHandler.java
index 0b181d8..bed3aeb 100644
---
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/InternalAccessHandler.java
+++
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/InternalAccessHandler.java
@@ -17,21 +17,34 @@
package org.apache.servicecomb.samples.porter.gateway;
-import org.apache.servicecomb.core.Handler;
+import java.util.concurrent.CompletableFuture;
+
import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.core.filter.AbstractFilter;
+import org.apache.servicecomb.core.filter.EdgeFilter;
+import org.apache.servicecomb.core.filter.FilterNode;
+import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.stereotype.Component;
-public class InternalAccessHandler implements Handler {
-
+@Component
+public class InternalAccessHandler extends AbstractFilter implements
EdgeFilter {
@Override
- public void handle(Invocation invocation, AsyncResponse asyncReponse) throws
Exception {
+ public CompletableFuture<Response> onFilter(Invocation invocation,
FilterNode nextNode) {
if (invocation.getOperationMeta().getSwaggerOperation().getTags() != null
&&
invocation.getOperationMeta().getSwaggerOperation().getTags().contains("INTERNAL"))
{
- asyncReponse.consumerFail(new InvocationException(403, "", "not
allowed"));
- return;
+ return CompletableFuture.failedFuture(new InvocationException(403, "",
"not allowed"));
}
- invocation.next(asyncReponse);
+ return nextNode.onFilter(invocation);
}
+ @Override
+ public int getOrder() {
+ return -1999;
+ }
+
+ @Override
+ public String getName() {
+ return "internal-access";
+ }
}
diff --git
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/StaticWebpageDispatcher.java
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/StaticWebpageDispatcher.java
index 791c512..9b707b3 100644
---
a/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/StaticWebpageDispatcher.java
+++
b/porter_lightweight/gateway-service/src/main/java/org/apache/servicecomb/samples/porter/gateway/StaticWebpageDispatcher.java
@@ -17,21 +17,19 @@
package org.apache.servicecomb.samples.porter.gateway;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.netflix.config.DynamicPropertyFactory;
-
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;
public class StaticWebpageDispatcher implements VertxHttpDispatcher {
private static final Logger LOGGER =
LoggerFactory.getLogger(StaticWebpageDispatcher.class);
- private static final String WEB_ROOT = DynamicPropertyFactory.getInstance()
- .getStringProperty("gateway.webroot", "/var/static")
- .get();
+ private static final String WEB_ROOT = LegacyPropertyFactory
+ .getStringProperty("gateway.webroot", "/var/static");
@Override
public int getOrder() {
@@ -41,12 +39,10 @@ public class StaticWebpageDispatcher implements
VertxHttpDispatcher {
@Override
public void init(Router router) {
String regex = "/ui/(.*)";
- StaticHandler webpageHandler = StaticHandler.create();
- webpageHandler.setWebRoot(WEB_ROOT);
+ StaticHandler webpageHandler = StaticHandler.create(WEB_ROOT);
LOGGER.info("server static web page for WEB_ROOT={}", WEB_ROOT);
router.routeWithRegex(regex).failureHandler((context) -> {
LOGGER.error("", context.failure());
}).handler(webpageHandler);
}
-
}
diff --git
a/porter_lightweight/gateway-service/src/main/resources/META-INF/spring/cse.bean.xml
b/porter_lightweight/gateway-service/src/main/resources/META-INF/spring/cse.bean.xml
deleted file mode 100644
index b5816c3..0000000
---
a/porter_lightweight/gateway-service/src/main/resources/META-INF/spring/cse.bean.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
-
- <bean id="servicecomb.samples.executor.groupThreadPool"
class="org.apache.servicecomb.core.executor.GroupExecutor"
- init-method="init"/>
-</beans>
diff --git
a/porter_lightweight/gateway-service/src/main/resources/microservice.yaml
b/porter_lightweight/gateway-service/src/main/resources/application.yml
similarity index 73%
rename from
porter_lightweight/gateway-service/src/main/resources/microservice.yaml
rename to porter_lightweight/gateway-service/src/main/resources/application.yml
index 3981921..862a6f4 100644
--- a/porter_lightweight/gateway-service/src/main/resources/microservice.yaml
+++ b/porter_lightweight/gateway-service/src/main/resources/application.yml
@@ -25,41 +25,22 @@ servicecomb:
name: gateway-service
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://localhost:30100
- instance:
- watch: false
rest:
address: 0.0.0.0:9090?sslEnabled=false
- handler:
- chain:
- Consumer:
- default: internalAccess,auth,qps-flowcontrol-consumer,loadbalance
-
uploads:
directory: tmp_for_upload_gateway
- samples:
- logdir: D:\code\servicecomb-samples\porter_lightweight\gateway-service
-
- inspector:
- enabled: false
-
- executors:
- Provider:
- log: servicecomb.samples.executor.groupThreadPool
- inspector: servicecomb.samples.executor.groupThreadPool
-
http:
dispatcher:
edge:
default:
enabled: false
- rest:
- pattern: '[/v1/log/|/inspector](.*)'
-# This is web root for windows server, change this path according to where you
put your source code
+# This is web root for Windows server, change this path according to where you
put your source code
gateway:
webroot:
/code/servicecomb-samples/porter_lightweight/gateway-service/src/main/resources
diff --git
a/porter_lightweight/gateway-service/src/main/resources/config/cse.handler.xml
b/porter_lightweight/gateway-service/src/main/resources/config/cse.handler.xml
deleted file mode 100644
index e9dd306..0000000
---
a/porter_lightweight/gateway-service/src/main/resources/config/cse.handler.xml
+++ /dev/null
@@ -1,23 +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.
- -->
-
-<config>
- <handler id="auth"
- class="org.apache.servicecomb.samples.porter.gateway.AuthHandler" />
- <handler id="internalAccess"
-
class="org.apache.servicecomb.samples.porter.gateway.InternalAccessHandler" />
-</config>
diff --git a/porter_lightweight/gateway-service/src/main/resources/log4j2.xml
b/porter_lightweight/gateway-service/src/main/resources/log4j2.xml
index e9bb265..d50e569 100644
--- a/porter_lightweight/gateway-service/src/main/resources/log4j2.xml
+++ b/porter_lightweight/gateway-service/src/main/resources/log4j2.xml
@@ -1,45 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
+ 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.
+-->
+<Configuration>
+ <Properties>
+ <property name="FILE_PATH" value="./logs/gateway-service"/>
+ </Properties>
-<!--this is sample configuration, please modify as your wish -->
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="%d [%p][%t][%c:%L] %m%n"/>
+ </Console>
-<configuration>
- <Properties>
- <Property name="log_path">./gateway/log/</Property>
- </Properties>
+ <RollingFile name="AccessLog" fileName="${FILE_PATH}/access.log"
+ filePattern="${FILE_PATH}/access-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
- <Appenders>
- <Console name="Console" target="SYSTEM_OUT">
- <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n" />
- </Console>
- <RollingFile name="DailyRollingFile" fileName="${log_path}/output.log"
- filePattern="${log_path}/zcrTest%d{yyyy-MM-dd}.log">
- <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n" />
- <Policies>
- <TimeBasedTriggeringPolicy interval="1" />
- <SizeBasedTriggeringPolicy size="10 MB" />
- </Policies>
- </RollingFile>
- </Appenders>
- <Loggers>
- <Root level="info">
- <AppenderRef ref="Console" />
- <AppenderRef ref="DailyRollingFile" />
- </Root>
- </Loggers>
-</configuration>
\ No newline at end of file
+ <RollingFile name="MetricsLog" fileName="${FILE_PATH}/metrics.log"
+ filePattern="${FILE_PATH}/metrics-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
+
+ <RollingFile name="SlowLog" fileName="${FILE_PATH}/slow.log"
+ filePattern="${FILE_PATH}/slow-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
+ </Appenders>
+
+ <Loggers>
+ <AsyncLogger name="scb-access" level="INFO" additivity="false">
+ <AppenderRef ref="AccessLog"/>
+ </AsyncLogger>
+ <AsyncLogger name="scb-metrics" level="INFO" additivity="false">
+ <AppenderRef ref="MetricsLog"/>
+ </AsyncLogger>
+ <AsyncLogger name="scb-slow" level="INFO" additivity="false">
+ <AppenderRef ref="SlowLog"/>
+ </AsyncLogger>
+
+ <Root level="INFO">
+ <AppenderRef ref="Console"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/porter_lightweight/pom.xml b/porter_lightweight/pom.xml
index 4d0e41c..b996c12 100644
--- a/porter_lightweight/pom.xml
+++ b/porter_lightweight/pom.xml
@@ -22,35 +22,33 @@
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>porter-application</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
+ <spring-boot-maven-plugin.version>3.1.3</spring-boot-maven-plugin.version>
+ <servicecomb.version>3.0.0-SNAPSHOT</servicecomb.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>3.4.5</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis-spring</artifactId>
- <version>1.3.0</version>
+ <groupId>org.mybatis.spring.boot</groupId>
+ <artifactId>mybatis-spring-boot-starter</artifactId>
+ <version>3.0.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
- <!-- need to compile lastest java-chassis code -->
+ <!-- need to compile latest java-chassis code -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>java-chassis-dependencies</artifactId>
- <version>${project.version}</version>
+ <version>${servicecomb.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -62,10 +60,19 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>solution-basic</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
+ </dependency>
+ <!-- using service-center & kie -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>registry-service-center</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>config-kie</artifactId>
+ </dependency>
<!-- using log4j2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
@@ -79,6 +86,11 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.lmax</groupId>
+ <artifactId>disruptor</artifactId>
+ <version>3.4.4</version>
+ </dependency>
</dependencies>
<modules>
@@ -94,29 +106,26 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
+ <version>${maven-compiler-plugin.version}</version>
<configuration>
- <source>1.8</source>
- <target>1.8</target>
<compilerArgument>-parameters</compilerArgument>
+ <source>17</source>
+ <target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
- <version>2.1.6.RELEASE</version>
+ <version>${spring-boot-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
- <configuration>
- <mainClass>${main.class}</mainClass>
- </configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
-</project>
\ No newline at end of file
+</project>
diff --git a/porter_lightweight/user-service/pom.xml
b/porter_lightweight/user-service/pom.xml
index a65eb11..68df4ef 100644
--- a/porter_lightweight/user-service/pom.xml
+++ b/porter_lightweight/user-service/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.servicecomb.samples.porter</groupId>
<artifactId>porter-application</artifactId>
- <version>2.8.2</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<artifactId>porter-user-service</artifactId>
@@ -45,8 +45,8 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
+ <groupId>org.mybatis.spring.boot</groupId>
+ <artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
@@ -56,10 +56,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis-spring</artifactId>
- </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
diff --git
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/UserMain.java
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/UserMain.java
index dc7b3ed..f33265c 100644
---
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/UserMain.java
+++
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/UserMain.java
@@ -17,10 +17,20 @@
package org.apache.servicecomb.samples.porter.user;
-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 UserMain {
public static void main(String[] args) throws Exception {
- BeanUtils.init();
+ try {
+ new SpringApplicationBuilder()
+ .web(WebApplicationType.NONE)
+ .sources(UserMain.class)
+ .run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionInfoModel.java
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionInfoModel.java
index fa60d33..ecbacc0 100644
---
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionInfoModel.java
+++
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionInfoModel.java
@@ -22,7 +22,7 @@ import
org.apache.servicecomb.samples.porter.user.api.SessionInfo;
public class SessionInfoModel {
private int id;
- private String sessiondId;
+ private String sessionId;
private String userName;
@@ -40,12 +40,12 @@ public class SessionInfoModel {
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() {
@@ -82,7 +82,7 @@ public class SessionInfoModel {
public static SessionInfo toSessionInfo(SessionInfoModel entity) {
SessionInfo info = new SessionInfo();
- info.setSessiondId(entity.getSessiondId());
+ info.setSessiondId(entity.getSessionId());
info.setUserName(entity.getUserName());
info.setRoleName(entity.getRoleName());
return info;
diff --git
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionMapper.java
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionMapper.java
index e09df8e..cc65595 100644
---
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionMapper.java
+++
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/SessionMapper.java
@@ -17,12 +17,38 @@
package org.apache.servicecomb.samples.porter.user.dao;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Result;
+import org.apache.ibatis.annotations.Results;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
import org.apache.servicecomb.samples.porter.user.api.SessionInfo;
+@Mapper
public interface SessionMapper {
- void createSession(SessionInfo sessionInfo);
+ @Insert("""
+ insert into T_SESSION (SESSION_ID, USER_NAME, ROLE_NAME)
+ values(#{sessiondId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
+ #{roleName,jdbcType=VARCHAR})""")
+ void createSession(SessionInfo sessionInfo);
- SessionInfoModel getSessioinInfo(String sessionId);
-
- void updateSessionInfo(String sessionId);
+ @Select("""
+ select ID, SESSION_ID, USER_NAME, ROLE_NAME, CREATION_TIME, ACTIVE_TIME
+ from T_SESSION where SESSION_ID = #{0,jdbcType=VARCHAR}""")
+ @Results({
+ @Result(property = "id", column = "ID"),
+ @Result(property = "sessionId", column = "SESSION_ID"),
+ @Result(property = "userName", column = "USER_NAME"),
+ @Result(property = "roleName", column = "ROLE_NAME"),
+ @Result(property = "creationTime", column = "CREATION_TIME"),
+ @Result(property = "activeTime", column = "ACTIVE_TIME")
+ })
+ SessionInfoModel getSessionInfo(String sessionId);
+
+ @Update("""
+ update T_SESSION set CREATION_TIME = now()
+ where SESSION_ID = #{sessionId,jdbcType=VARCHAR}
+ """)
+ void updateSessionInfo(String sessionId);
}
diff --git
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/UserMapper.java
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/UserMapper.java
index 5c2d331..1d8ffc0 100644
---
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/UserMapper.java
+++
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/dao/UserMapper.java
@@ -17,8 +17,28 @@
package org.apache.servicecomb.samples.porter.user.dao;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Result;
+import org.apache.ibatis.annotations.Results;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
public interface UserMapper {
- void createUser(UserInfo userInfo);
+ @Insert("""
+ insert into T_USER (ID, USER_NAME, PASSWORD, ROLE_NAME)
+ values(#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR},
+ #{password,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR})""")
+ void createUser(UserInfo userInfo);
- UserInfo getUserInfo(String userName);
+ @Select("""
+ select ID, USER_NAME, PASSWORD, ROLE_NAME
+ from T_USER where USER_NAME = #{userName,jdbcType=VARCHAR}""")
+ @Results({
+ @Result(property = "id", column = "ID"),
+ @Result(property = "userName", column = "USER_NAME"),
+ @Result(property = "password", column = "PASSWORD"),
+ @Result(property = "roleName", column = "ROLE_NAME")
+ })
+ UserInfo getUserInfo(String userName);
}
diff --git
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/service/UserServiceImpl.java
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/service/UserServiceImpl.java
index 5f69582..162508f 100644
---
a/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/service/UserServiceImpl.java
+++
b/porter_lightweight/user-service/src/main/java/org/apache/servicecomb/samples/porter/user/service/UserServiceImpl.java
@@ -24,6 +24,7 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.commons.codec.binary.Base64;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.samples.porter.user.api.SessionInfo;
import org.apache.servicecomb.samples.porter.user.api.UserService;
import org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel;
@@ -36,8 +37,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import com.netflix.config.DynamicPropertyFactory;
-
@Service
public class UserServiceImpl implements UserService {
private static Logger LOGGER =
LoggerFactory.getLogger(UserServiceImpl.class);
@@ -69,13 +68,13 @@ public class UserServiceImpl implements UserService {
if (sessionId == null) {
throw new InvocationException(405, "", "invalid session.");
}
- SessionInfoModel sessionInfo = sessionMapper.getSessioinInfo(sessionId);
+ SessionInfoModel sessionInfo = sessionMapper.getSessionInfo(sessionId);
if (sessionInfo != null) {
if (System.currentTimeMillis() - sessionInfo.getActiveTime().getTime() >
10 * 60 * 1000) {
LOGGER.info("user session expired.");
return null;
} else {
- sessionMapper.updateSessionInfo(sessionInfo.getSessiondId());
+ sessionMapper.updateSessionInfo(sessionInfo.getSessionId());
return SessionInfoModel.toSessionInfo(sessionInfo);
}
}
@@ -100,7 +99,7 @@ public class UserServiceImpl implements UserService {
public String ping(String message) {
- long delay =
DynamicPropertyFactory.getInstance().getLongProperty("user.ping.delay",
0).get();
+ long delay = LegacyPropertyFactory.getLongProperty("user.ping.delay", 0);
if (delay > 0) {
try {
TimeUnit.SECONDS.sleep(delay);
diff --git
a/porter_lightweight/user-service/src/main/resources/META-INF/spring/user.bean.xml
b/porter_lightweight/user-service/src/main/resources/META-INF/spring/user.bean.xml
deleted file mode 100644
index cfb2b59..0000000
---
a/porter_lightweight/user-service/src/main/resources/META-INF/spring/user.bean.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
-
- <bean id="servicecomb.samples.executor.groupThreadPool"
class="org.apache.servicecomb.core.executor.GroupExecutor"
- init-method="init"/>
-
- <bean id="dataSource"
- class="org.apache.commons.dbcp2.BasicDataSource"
- destroy-method="close">
- <property name="driverClassName"
value="${db.driverClassName:com.mysql.jdbc.Driver}" />
- <property name="url"
- value="${db.url:jdbc:mysql://localhost/porter_user_db}" />
- <property name="username" value="${db.username:root}" />
- <property name="password" value="${db.password:root}" />
- </bean>
-
- <bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="configLocation"
value="classpath:/config/mybatis-config.xml"></property>
- </bean>
-
- <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
- <property name="mapperInterface"
- value="org.apache.servicecomb.samples.porter.user.dao.UserMapper"
/>
- <property name="sqlSessionFactory" ref="sqlSessionFactory" />
- </bean>
- <bean id="sessionMapper"
class="org.mybatis.spring.mapper.MapperFactoryBean">
- <property name="mapperInterface"
-
value="org.apache.servicecomb.samples.porter.user.dao.SessionMapper" />
- <property name="sqlSessionFactory" ref="sqlSessionFactory" />
- </bean>
-</beans>
\ No newline at end of file
diff --git
a/porter_lightweight/user-service/src/main/resources/microservice.yaml
b/porter_lightweight/user-service/src/main/resources/application.yml
similarity index 79%
rename from porter_lightweight/user-service/src/main/resources/microservice.yaml
rename to porter_lightweight/user-service/src/main/resources/application.yml
index 9af2b37..eea3d1d 100644
--- a/porter_lightweight/user-service/src/main/resources/microservice.yaml
+++ b/porter_lightweight/user-service/src/main/resources/application.yml
@@ -25,21 +25,16 @@ servicecomb:
name: user-service
version: 0.0.1
- registry:
+ registry:
+ sc:
address: http://localhost:30100
- instance:
- watch: false
rest:
address: 0.0.0.0:9093
- samples:
- logdir: D:\code\servicecomb-samples\porter_lightweight\user-service
-
- inspector:
- enabled: false
-
- executors:
- Provider:
- log: servicecomb.samples.executor.groupThreadPool
- inspector: servicecomb.samples.executor.groupThreadPool
\ No newline at end of file
+spring:
+ datasource:
+ url: jdbc:mysql://localhost/porter_user_db
+ username: root
+ password: root
+ driver-class-name: com.mysql.jdbc.Driver
diff --git
a/porter_lightweight/user-service/src/main/resources/config/SessionMapper.xml
b/porter_lightweight/user-service/src/main/resources/config/SessionMapper.xml
deleted file mode 100644
index 989e786..0000000
---
a/porter_lightweight/user-service/src/main/resources/config/SessionMapper.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper
namespace="org.apache.servicecomb.samples.porter.user.dao.SessionMapper">
- <resultMap id="sessionInfo"
type="org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel">
- <result column="ID" jdbcType="INTEGER" property="id" />
- <result column="SESSION_ID" jdbcType="VARCHAR" property="sessiondId" />
- <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
- <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName" />
- <result column="CREATION_TIME" jdbcType="TIMESTAMP"
property="creationTime" />
- <result column="ACTIVE_TIME" jdbcType="TIMESTAMP"
property="activeTime" />
- </resultMap>
-
- <sql id="all_column">
- ID, SESSION_ID, USER_NAME, ROLE_NAME, CREATION_TIME, ACTIVE_TIME
- </sql>
-
- <sql id="all_column_auto">
- SESSION_ID, USER_NAME, ROLE_NAME
- </sql>
-
- <insert id="createSession"
parameterType="org.apache.servicecomb.samples.porter.user.dao.SessionInfoModel">
- insert into T_SESSION (
- <include refid="all_column_auto" />
- )
- values (#{sessiondId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
- #{roleName,jdbcType=VARCHAR})
- </insert>
-
- <select id="getSessioinInfo" parameterType="java.lang.String"
- resultMap="sessionInfo">
- select
- <include refid="all_column" />
- from T_SESSION where SESSION_ID = #{0,jdbcType=VARCHAR}
- </select>
-
- <update id="updateSessionInfo" parameterType="java.lang.String">
- update T_SESSION
- set CREATION_TIME = CREATION_TIME where SESSION_ID =
#{0,jdbcType=VARCHAR};
- </update>
-</mapper>
\ No newline at end of file
diff --git
a/porter_lightweight/user-service/src/main/resources/config/UserMapper.xml
b/porter_lightweight/user-service/src/main/resources/config/UserMapper.xml
deleted file mode 100644
index c02e60d..0000000
--- a/porter_lightweight/user-service/src/main/resources/config/UserMapper.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="org.apache.servicecomb.samples.porter.user.dao.UserMapper">
- <resultMap id="userInfo"
type="org.apache.servicecomb.samples.porter.user.dao.UserInfo">
- <result column="ID" jdbcType="INTEGER" property="id" />
- <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
- <result column="PASSWORD" jdbcType="VARCHAR" property="password" />
- <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName" />
- </resultMap>
-
- <sql id="all_column">
- ID, USER_NAME, PASSWORD, ROLE_NAME
- </sql>
-
- <insert id="createUser"
parameterType="org.apache.servicecomb.samples.porter.user.dao.UserInfo">
- insert into T_USER (
- <include refid="all_column" />
- )
- values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR},
- #{password,jdbcType=VARCHAR},#{roleName,jdbcType=VARCHAR})
- </insert>
-
- <select id="getUserInfo" parameterType="java.lang.String"
- resultMap="userInfo">
- select
- <include refid="all_column" />
- from T_USER where USER_NAME = #{0,jdbcType=VARCHAR}
- </select>
-</mapper>
\ No newline at end of file
diff --git
a/porter_lightweight/user-service/src/main/resources/config/mybatis-config.xml
b/porter_lightweight/user-service/src/main/resources/config/mybatis-config.xml
deleted file mode 100644
index 894caac..0000000
---
a/porter_lightweight/user-service/src/main/resources/config/mybatis-config.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<!DOCTYPE configuration
- PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-config.dtd">
-<configuration>
- <mappers>
- <mapper resource="config/UserMapper.xml"/>
- <mapper resource="config/SessionMapper.xml"/>
- </mappers>
-</configuration>
\ No newline at end of file
diff --git a/porter_lightweight/user-service/src/main/resources/log4j2.xml
b/porter_lightweight/user-service/src/main/resources/log4j2.xml
index 56fc9a0..f68264b 100644
--- a/porter_lightweight/user-service/src/main/resources/log4j2.xml
+++ b/porter_lightweight/user-service/src/main/resources/log4j2.xml
@@ -1,45 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
+ 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.
+-->
+<Configuration>
+ <Properties>
+ <property name="FILE_PATH" value="./logs/user-service"/>
+ </Properties>
-<!--this is sample configuration, please modify as your wish -->
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="%d [%p][%t][%c:%L] %m%n"/>
+ </Console>
-<configuration>
- <Properties>
- <Property name="log_path">./user/log/</Property>
- </Properties>
+ <RollingFile name="AccessLog" fileName="${FILE_PATH}/access.log"
+ filePattern="${FILE_PATH}/access-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
- <Appenders>
- <Console name="Console" target="SYSTEM_OUT">
- <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n" />
- </Console>
- <RollingFile name="DailyRollingFile" fileName="${log_path}/output.log"
- filePattern="${log_path}/zcrTest%d{yyyy-MM-dd}.log">
- <PatternLayout pattern="[%d][%t][%p][%c:%L] %m%n" />
- <Policies>
- <TimeBasedTriggeringPolicy interval="1" />
- <SizeBasedTriggeringPolicy size="10MB" />
- </Policies>
- </RollingFile>
- </Appenders>
- <Loggers>
- <Root level="info">
- <AppenderRef ref="Console" />
- <AppenderRef ref="DailyRollingFile" />
- </Root>
- </Loggers>
-</configuration>
\ No newline at end of file
+ <RollingFile name="MetricsLog" fileName="${FILE_PATH}/metrics.log"
+ filePattern="${FILE_PATH}/metrics-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
+
+ <RollingFile name="SlowLog" fileName="${FILE_PATH}/slow.log"
+ filePattern="${FILE_PATH}/slow-%d{yyyy-MM-dd}_%i.log.gz">
+ <PatternLayout pattern="%d [%t] %m%n"/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="20MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="100"/>
+ </RollingFile>
+ </Appenders>
+
+ <Loggers>
+ <AsyncLogger name="scb-access" level="INFO" additivity="false">
+ <AppenderRef ref="AccessLog"/>
+ </AsyncLogger>
+ <AsyncLogger name="scb-metrics" level="INFO" additivity="false">
+ <AppenderRef ref="MetricsLog"/>
+ </AsyncLogger>
+ <AsyncLogger name="scb-slow" level="INFO" additivity="false">
+ <AppenderRef ref="SlowLog"/>
+ </AsyncLogger>
+
+ <Root level="INFO">
+ <AppenderRef ref="Console"/>
+ </Root>
+ </Loggers>
+</Configuration>