Commit 9574467c by 林冲

svn 转 git

0 parents
Showing 27 changed files with 1524 additions and 0 deletions
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.com.glsx.framework</groupId>
<artifactId>framework-rop</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<groupId>cn.com.glsx.dj</groupId>
<artifactId>rop-dj-platform</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rop-dj-platform</name>
<packaging>war</packaging>
</project>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.rop.platform;
import org.oreframework.boot.main.AbsOreBootStarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
/**
* @Title: Main.java
* @Description:
* @author zhoulm
* @version V1.0
* @Company: Didihu.com.cn
* @Copyright Copyright (c) 2015
*/
@SpringBootApplication
@ServletComponentScan
public class Main extends AbsOreBootStarter {
@Override
public void run(String[] args)
{
SpringApplication.run(Main.class, args);
}
public static void main(String[] args)
{
Main main = new Main();
main.run(args);
}
}
package cn.com.glsx.dj.rop.platform.config;
import org.oreframework.boot.autoconfigure.dubbo.reference.ReferenceBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Title: DubboConfig.java
* @Description: Dubbo服务注册配置
* @author zhoulm
* @version V1.0
* @Company: Didihu.com.cn
* @Copyright Copyright (c) 2018
*/
@Configuration
public class DubboConfig {
@Autowired
private ReferenceBuilderFactory factory;
/**
* 注册远程服务(示例)
* RpcRemote为需要调用的远程服务
* @return
*/
/*@Bean
public RpcRemote rpcApiMethodRemote(){
return factory.builder(RpcRemote.class).check(false).timeout(30000).build();
}*/
}
package cn.com.glsx.dj.rop.platform.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @Title: SystemProperty.java
* @Description:
* @author zhoulm
* @version V1.0
* @Company: Didihu.com.cn
* @Copyright Copyright (c) 2017
*/
@Configuration
@ConfigurationProperties("system")
public class SystemProperty {
// 对应配置项:system.name
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package cn.com.glsx.dj.rop.platform.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.FileCopyUtils;
import cn.com.glsx.dj.rop.platform.request.example.ExampleRequest;
import cn.com.glsx.dj.rop.platform.request.example.LoginRequest;
import cn.com.glsx.dj.rop.platform.request.example.ExampleComplexRequest;
import cn.com.glsx.dj.rop.platform.request.example.UploadFileRequest;
import cn.com.glsx.dj.rop.platform.response.LoginResponse;
import cn.com.glsx.dj.rop.platform.response.ExampleResponse;
import cn.com.glsx.dj.rop.platform.response.UploadFileResponse;
import cn.com.glsx.framework.rop.response.RopResponse;
import com.rop.AbstractRopRequest;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import com.rop.session.SimpleSession;
/**
* @Title: ExampleController.java
* @Description:
* @author Alvin
* @date 2019年9月2日 下午3:27:41
* @version V2.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.NO)
@Api("示例接口")
public class ExampleController
{
/**
* logger
*/
protected final Logger logger = LoggerFactory.getLogger(getClass());
/**
* 接口例子
*
* @param req ExampleRequest
* @return Object
* @throws Exception 异常
*/
@ServiceMethod(method = "org.ore.api.example", needInSession = NeedInSessionType.NO)
@ApiOperation("get接口示例")
public RopResponse<ExampleResponse> getExample(ExampleRequest req)
throws Exception
{
ExampleResponse response = new ExampleResponse();
response.setField1("Ni Hao");
response.setField2(req.getName());
return RopResponse.success(response);
}
/**
* 复杂参数示例
* @param request
* @return
* @author Alvin
*/
@ServiceMethod(method = "org.ore.api.example.complex", needInSession = NeedInSessionType.NO)
@ApiOperation("复杂参数示例")
public RopResponse<ExampleResponse> complexExample(ExampleComplexRequest request){
ExampleResponse response = new ExampleResponse();
response.setField1(request.getName());
response.setField2(request.toString());
return RopResponse.success(response);
}
/**
* 文件上传示例
* @param request
* @return
* @author Alvin
* @throws IOException
*/
@ServiceMethod(method = "org.ore.api.example.upload", needInSession = NeedInSessionType.NO)
@ApiOperation("文件上传示例")
public RopResponse<UploadFileResponse> upload(UploadFileRequest request) throws IOException{
ClassPathResource outFile = new ClassPathResource("/");
File file = new File(outFile.getFile().getParent() + "/test." + request.getFile().getFileType());
FileCopyUtils.copy(request.getFile().getContent(), file);
UploadFileResponse response = new UploadFileResponse();
response.setFilePath(file.getPath());
return RopResponse.success(response);
}
/**
* 会话示例
* @param request
* @return
* @throws Exception
* @author Alvin
*/
@ServiceMethod(method = "org.ore.api.example.insession", needInSession = NeedInSessionType.YES)
@ApiOperation("会话示例")
public RopResponse<ExampleResponse> getExampleInSession(ExampleRequest request) throws Exception{
return getExample(request);
}
/**
* 登录示例
* @param request
* @return
* @author Alvin
*/
@ServiceMethod(method = "org.ore.api.example.login", needInSession = NeedInSessionType.NO)
@ApiOperation("登录示例")
public RopResponse<LoginResponse> login(LoginRequest request){
// 创建会话
SimpleSession session = new SimpleSession();
session.setAttribute("userName", request.getUserName());
String sessionId = UUID.randomUUID().toString();
request.getRopRequestContext().addSession(sessionId, session);
LoginResponse response = new LoginResponse();
response.setSessionId(sessionId);
return RopResponse.success(response);
}
/**
* 登出示例
* @param request
* @return
* @author Alvin
*/
@ServiceMethod(method = "org.ore.api.example.logout", needInSession = NeedInSessionType.YES)
@ApiOperation("登出示例")
public RopResponse<Boolean> logout(AbstractRopRequest request){
// 删除会话
request.getRopRequestContext().removeSession();
return RopResponse.success(true);
}
}
package cn.com.glsx.dj.rop.platform.request.example;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import javax.validation.constraints.NotEmpty;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @Title: Address.java
* @Description: 地址信息参数示例
* @author Alvin
* @date 2020年11月12日 下午3:08:28
* @version V2.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
@ApiModel("地址信息")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "address")
public class Address {
@ApiModelProperty("省份")
@NotEmpty(message = "省份不能为空")
private String province;
@ApiModelProperty("城市")
private String city;
@ApiModelProperty("区域")
private String area;
@XmlElementWrapper(name = "streets")
@XmlElement(name = "street")
private List<Street> streets;
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public List<Street> getStreets() {
return streets;
}
public void setStreets(List<Street> streets) {
this.streets = streets;
}
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
}
package cn.com.glsx.dj.rop.platform.request.example;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import javax.validation.Valid;
import org.apache.commons.lang.builder.ToStringBuilder;
import com.rop.AbstractRopRequest;
/**
* @Title: ExampleComplexRequest.java
* @Description: 复杂参数示例请求
* @author Alvin
* @date 2020年11月12日 下午2:06:55
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
public class ExampleComplexRequest extends AbstractRopRequest{
@ApiModelProperty("姓名")
private String name;
@ApiModelProperty("年龄")
private Integer age;
@ApiModelProperty("兴趣爱好")
private List<String> hobby;
@ApiModelProperty("家庭住址")
@Valid
private Address address;
@ApiModelProperty("工作经历")
@Valid
private List<WorkExperience> workExperiences;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public List<String> getHobby() {
return hobby;
}
public void setHobby(List<String> hobby) {
this.hobby = hobby;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public List<WorkExperience> getWorkExperiences() {
return workExperiences;
}
public void setWorkExperiences(List<WorkExperience> workExperiences) {
this.workExperiences = workExperiences;
}
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
}
package cn.com.glsx.dj.rop.platform.request.example;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.builder.ToStringBuilder;
import com.rop.AbstractRopRequest;
/**
* 例子参数实体类
*
* @author alvin.zengqi
* @version [版本号, 2019-09-02]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class ExampleRequest extends AbstractRopRequest
{
@ApiModelProperty("姓名")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* 得到属性字符串
* @return String 属性字符串
*/
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.rop.platform.request.example;
import javax.validation.constraints.NotNull;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.builder.ToStringBuilder;
import com.rop.AbstractRopRequest;
/**
* @Title: LoginRequest.java
* @Description: 登录请求参数示例
* @author Alvin
* @date 2019年9月22日 下午3:47:04
* @version V2.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
public class LoginRequest extends AbstractRopRequest {
/**
* 用户名
*/
@ApiModelProperty(notes = "账号", required = true)
@NotNull
private String userName;
/**
* 密码
*/
@ApiModelProperty(notes = "密码", required = true)
@NotNull
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
}
package cn.com.glsx.dj.rop.platform.request.example;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @Title: Street.java
* @Description: 街道信息参数示例
* @author Alvin
* @date 2020年11月12日 下午3:08:28
* @version V2.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "street")
public class Street {
@XmlAttribute
private String no;
@XmlAttribute
private String name;
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
}
package cn.com.glsx.dj.rop.platform.request.example;
import io.swagger.annotations.ApiModelProperty;
import com.rop.AbstractRopRequest;
import com.rop.request.UploadFile;
/**
* @Title: UploadFileRequest.java
* @Description: 上传文件请求参数示例
* @author Alvin
* @date 2020年11月11日 下午2:55:22
* @version V2.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
public class UploadFileRequest extends AbstractRopRequest {
@ApiModelProperty("上传文件")
private UploadFile file;
public UploadFile getFile() {
return file;
}
public void setFile(UploadFile file) {
this.file = file;
}
}
package cn.com.glsx.dj.rop.platform.request.example;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.format.annotation.DateTimeFormat;
/**
* @Title: WorkExperience.java
* @Description: 工作经历请求参数示例
* @author Alvin
* @date 2020年11月12日 下午3:09:00
* @version V2.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
@ApiModel("工作经历")
public class WorkExperience {
@ApiModelProperty("公司名")
private String company;
@ApiModelProperty("公司地址")
@Valid
private Address address;
@ApiModelProperty("开始时间")
@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date startTime;
@ApiModelProperty("截止时间")
@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date endTime;
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
}
package cn.com.glsx.dj.rop.platform.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* ExampleResponse
* @author alvin.zengqi
* @version [版本号, 2019-09-02]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@ApiModel(description = "响应值示例")
public class ExampleResponse
{
@ApiModelProperty(name = "field1", notes = "字段1", dataType = "string", required = true, example = "aaaaa")
private String field1 = "1";
@ApiModelProperty(name = "field2", notes = "字段2", dataType = "string", required = true, example = "bbbbb", value = "字段2")
private String field2 = "2";
public void setField1(String field1) {
this.field1 = field1;
}
public String getField2() {
return field2;
}
public void setField2(String field2) {
this.field2 = field2;
}
/**
* 得到属性字符串
*
* @return String 属性字符串
*/
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.rop.platform.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @Title: LoginResponse.java
* @Description:
* @author Alvin
* @date 2019年9月22日 下午3:48:18
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2018
*/
@ApiModel(description = "响应值示例")
public class LoginResponse {
/**
* 会话ID
*/
@ApiModelProperty(name = "sessionId", notes = "会话ID", dataType = "string", required = true, example = "asdfasdf23423432432")
private String sessionId;
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public String toString()
{
return ToStringBuilder.reflectionToString(this);
}
}
package cn.com.glsx.dj.rop.platform.response;
import io.swagger.annotations.ApiModelProperty;
/**
* @Title: UploadFileResponse.java
* @Description: 上传文件响应结果
* @author Alvin
* @date 2020年11月11日 下午2:55:51
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
public class UploadFileResponse {
@ApiModelProperty("文件存储路径")
private String filePath;
@ApiModelProperty("文件访问链接")
private String fileUrl;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getFileUrl() {
return fileUrl;
}
public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl;
}
}
# framework-archetype-rop
开放平台项目骨架
一、项目结构说明:
└─src
├─main
├─java
├─cn.com.glsx.dj.rop.platform.config 配置层
├─cn.com.glsx.dj.rop.platform.controller 控制层
├─cn.com.glsx.dj.rop.platform.request 请求实体
├─cn.com.glsx.dj.rop.platform.response 响应实体
└─cn.com.glsx.dj.rop.platform.Main.java 程序入口
├─resources 资源文件目录
├─config
└─application.properties 应用配置文件
└─logback.xml 日志配置文件
└─webapp web前端文件目录
└─WEB-INF
└─bin shell脚本文件(包含启动、停止、重启等)
└─test 测试目录
├─java
└─cn.com.glsx.dj.rop.platform 测试代码
└─resources 测试资源目录
└─pom.xml pom文件
二、使用说明:
1、运行项目前需在配置中心创建配置信息,配置内容参考三配置说明:
1.1> dataId : application.properties --> ore.diamond.dataId + ore.diamond.env
1.2> group : application.properties --> ore.diamond.group
1.3> content : 参考三配置说明
三、配置说明:
#----------------------------------------------------------------------------------------------------------
# dubbo配置(调用dubbo服务需配置)
# dubbo应用名称
ore.dubbo.application.name=rop-dj-platform
# dubbo应用所有者
ore.dubbo.application.owner=zhoulm
# dubbo服务注册地址
ore.dubbo.registry.address=zookeeper://192.168.3.206:2181
# dubbo服务注册超时时间
ore.dubbo.registry.timeout=30000
# 默认协议:dubbo
ore.dubbo.protocol.name=dubbo
# dubbo服务扫描包路径
ore.dubbo.scan=cn.com.glsx.dj.rop.platform
# dubbo服务监控
ore.dubbo.monitor.protocol=registry
# dubbo服务统计
ore.dubbo.consumer.filter=metrics
#----------------------------------------------------------------------------------------------------------
# rop 注解驱动配置
ore.rop.annotation-driven.thread-ferry-class=
ore.rop.annotation-driven.sign-enable=true
ore.rop.annotation-driven.ext-error-base-name=i18n/rop/sampleRopError
ore.rop.annotation-driven.core-pool-size=200
ore.rop.annotation-driven.max-pool-size=500
ore.rop.annotation-driven.keep-alive-seconds=300
ore.rop.annotation-driven.queue-capacity=50
ore.rop.annotation-driven.service-timeout-seconds=120
# 文件上传大小限制
ore.rop.annotation-driven.upload-file-max-size=9999999
# 文件上传支持的文件格式
ore.rop.annotation-driven.upload-file-types=png,gif,jpg
ore.rop.annotation-driven.formatting-conversion-service=
# 默认本地Map缓存会话,只支持单节点
ore.rop.annotation-driven.session-manager=
# 配置为ropSessionManager,则采用Redis缓存会话,支持集群(另外需要增加redis配置)
#ore.rop.annotation-driven.session-manager=ropSessionManager
ore.rop.annotation-driven.app-secret-manager=
ore.rop.annotation-driven.service-access-controller=
ore.rop.annotation-driven.invoke-times-controller=
# rop 系统参数配置
ore.rop.sysparams.appkey-param-name=appKey
ore.rop.sysparams.sessionid-param-name=sessionId
ore.rop.sysparams.method-param-name=method
ore.rop.sysparams.version-param-name=v
ore.rop.sysparams.format-param-name=format
ore.rop.sysparams.locale-param-name=locale
ore.rop.sysparams.sign-param-name=sign
ore.rop.sysparams.jsonp-param-name=jsonp
# 会话过期时间,默认1800秒
#rop.session.timeout=1800
# 开启跨域
ore.adapter.cross-domain=true
# 允许跨域域名,多个以英文逗号分隔
ore.adapter.allowed-origins=http://ip:port
# rop 秘钥对(appKey=secret)
48e5e13229b82c1b4e6e8c96151f0637=c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b
#----------------------------------------------------------------------------------------------------------
# redis缓存
ore.redis.hostName=192.168.0.100
ore.redis.port=6379
ore.redis.password=
ore.redis.pool.maxActive=600
ore.redis.pool.maxWait=10000
ore.redis.pool.maxTotal=300
ore.redis.pool.maxIdle=300
ore.redis.pool.minIdle=0
ore.redis.timeout=30000
# 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
ore.redis.betweenEvictionRunsMillis=30000
#----------------------------------------------------------------------------------------------------------
# rop swagger配置
# 是否启用swagger-rop,默认为true(生产环境不开启)
swagger.rop.enable=true
# rop 接口 appKey,默认48e5e13229b82c1b4e6e8c96151f0637
swagger.rop.appKey=48e5e13229b82c1b4e6e8c96151f0637
# rop 接口 secret,默认c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b
swagger.rop.secret=c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b
┌------------------------------------------------------------┐
使用说明:
1、接口方法上添加Swagger注解@ApiOperation(value = "查询**", notes = "根据**查询**", httpMethod="GET")[非必须]
2、接口参数属性添加Swagger注解@ApiModelProperty(value = "参数名称", required=true)[非必须]
└------------------------------------------------------------┘
# rop swagger api访问地址(v2版本界面)
http://localhost:11001/rop-dj-platform/swagger-ui/v2/index.html
# rop swagger api访问地址(v3版本界面)
http://localhost:11001/rop-dj-platform/swagger-ui/v3/index.html
#----------------------------------------------------------------------------------------------------------
# 分布式文件系统FastDFS配置
# tracker服务地址列表(格式ip1:host1,ip2:host2......)
ore.fastdfs.tracker-servers=common.fdfs.glsx.com:22122
# 文件访问域名
ore.fastdfs.server-url=http://qcimg01.glsx.net:7060/
┌------------------------------------------------------------┐
使用说明:
1、在pom中添加如下依赖
<dependency>
<groupId>org.oreframework.boot</groupId>
<artifactId>ore-boot-starter-fastdfs</artifactId>
</dependency>
2、注入调用客户端
@Autowired
private DefaultFastDFSClient fastDFSClient;
3、调用上传
String fastDFSClient.uploadFile(byte[] fileContent, String extName)
└------------------------------------------------------------┘
\ No newline at end of file \ No newline at end of file
server.port=11001
server.display-name=rop-dj-platform
server.servlet.context-path=/rop-dj-platform
server.servlet.application-display-name=rop-dj-platform
logging.config=classpath:logback.xml
logging.path=/data/java_log/jetty/rop-dj-platform/rop-dj-platform.log
logging.level.root=INFO
ore.starter.class-name=Main
# diamond config
ore.diamond.group=dijia
ore.diamond.dataId=rop-dj-platform
ore.diamond.env=release
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<property resource="config/application.properties" />
<property name="APP_NAME" value="${server.display-name}" />
<property name="LOG_PATH" value="${logging.path}" />
<property name="LOG_LEVEL" value="${logging.level}" />
<contextName>${APP_NAME}</contextName>
<turboFilter class="org.oreframework.boot.logging.logback.OreBootTurboFilter">
<Marker>oreframework</Marker>
</turboFilter>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="org.oreframework.commons.log.OrePatternLayout">
<pattern>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [${APP_NAME}] [%traceid] [%thread] %-5level [%logger{36}.%method %line] - %msg%n</pattern>
</pattern>
</layout>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- <Encoding> Label Old version of this label can not be used -->
<!-- <Encoding>UTF-8</Encoding> -->
<File>${LOG_PATH}</File>
<!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> -->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<FileNamePattern>${LOG_PATH}.%d{yyyy-MM-dd}.%i</FileNamePattern>
<MaxHistory>15</MaxHistory>
<maxFileSize>200MB</maxFileSize>
</rollingPolicy>
<layout class="org.oreframework.commons.log.OrePatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [${APP_NAME}] [%traceid] [%thread] %-5level [%logger{36}.%method %line] - %msg%n</pattern>
</layout>
<!-- 根据文件大小滚动,不支持 SizeBasedTriggeringPolicy 这种配置-->
<!-- <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>200MB</MaxFileSize>
</triggeringPolicy> -->
</appender>
<root level="${LOG_LEVEL}">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
\ No newline at end of file \ No newline at end of file
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/classes
SERVER_NAME=`sed '/application.name/!d;s/.*=//' classes/config/application.properties | tr -d '\r'`
#LOGS_FILE=`sed '/log4j.appender.logToFile.File/!d;s/.*=//' classes/log4j.properties | tr -d '\r'`
LOGS_FILE=`sed '/name="LOG_PATH"/!d;s/.*value="\(.*\)".*/\1/g' classes/logback.xml`
if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME does not started!"
exit 1
fi
LOGS_DIR=""
if [ -n "$LOGS_FILE" ]; then
LOGS_DIR=`dirname $LOGS_FILE`
else
LOGS_DIR=$DEPLOY_DIR/logs
fi
if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi
DUMP_DIR=$LOGS_DIR/dump
if [ ! -d $DUMP_DIR ]; then
mkdir $DUMP_DIR
fi
DUMP_DATE=`date +%Y%m%d%H%M%S`
DATE_DIR=$DUMP_DIR/$DUMP_DATE
if [ ! -d $DATE_DIR ]; then
mkdir $DATE_DIR
fi
echo -e "Dumping the $SERVER_NAME ...\c"
for PID in $PIDS ; do
jstack $PID > $DATE_DIR/jstack-$PID.dump 2>&1
echo -e ".\c"
jinfo $PID > $DATE_DIR/jinfo-$PID.dump 2>&1
echo -e ".\c"
jstat -gcutil $PID > $DATE_DIR/jstat-gcutil-$PID.dump 2>&1
echo -e ".\c"
jstat -gccapacity $PID > $DATE_DIR/jstat-gccapacity-$PID.dump 2>&1
echo -e ".\c"
jmap $PID > $DATE_DIR/jmap-$PID.dump 2>&1
echo -e ".\c"
jmap -heap $PID > $DATE_DIR/jmap-heap-$PID.dump 2>&1
echo -e ".\c"
jmap -histo $PID > $DATE_DIR/jmap-histo-$PID.dump 2>&1
echo -e ".\c"
if [ -r /usr/sbin/lsof ]; then
/usr/sbin/lsof -p $PID > $DATE_DIR/lsof-$PID.dump
echo -e ".\c"
fi
done
if [ -r /bin/netstat ]; then
/bin/netstat -an > $DATE_DIR/netstat.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/iostat ]; then
/usr/bin/iostat > $DATE_DIR/iostat.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/mpstat ]; then
/usr/bin/mpstat > $DATE_DIR/mpstat.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/vmstat ]; then
/usr/bin/vmstat > $DATE_DIR/vmstat.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/free ]; then
/usr/bin/free -t > $DATE_DIR/free.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/sar ]; then
/usr/bin/sar > $DATE_DIR/sar.dump 2>&1
echo -e ".\c"
fi
if [ -r /usr/bin/uptime ]; then
/usr/bin/uptime > $DATE_DIR/uptime.dump 2>&1
echo -e ".\c"
fi
echo "OK!"
echo "DUMP: $DATE_DIR"
#!/bin/bash
ENV=$1
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
cd `dirname $0`
./stop.sh
./start.sh $ENV
\ No newline at end of file \ No newline at end of file
#!/bin/bash
cd `dirname $0`
if [ "$1" = "start" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./start.sh $ENV
else
if [ "$1" = "stop" ]; then
./stop.sh
else
if [ "$1" = "debug" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./start.sh $ENV debug
else
if [ "$1" = "restart" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./restart.sh $ENV
else
if [ "$1" = "dump" ]; then
./dump.sh
else
echo "ERROR: Please input argument: start or stop or debug or restart or dump"
exit 1
fi
fi
fi
fi
fi
#!/bin/bash
JAVA_HOME="/app/soft/jdk1.8.0_20"
ENV=$1
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/classes
SERVER_NAME=`sed '/server.display-name/!d;s/.*=//' classes/config/application.properties | tr -d '\r'`
SERVER_PORT=`sed '/server.port/!d;s/.*=//' classes/config/application.properties | tr -d '\r'`
LOGS_FILE=`sed '/logging.path/!d;s/.*=//' classes/config/application.properties | tr -d '\r'`
if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi
echo "server name is $SERVER_NAME"
echo "server port is $SERVER_PORT"
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME already started!"
echo "PID: $PIDS"
exit 1
fi
if [ -n "$SERVER_PORT" ]; then
SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"
exit 1
fi
fi
LOGS_DIR=""
if [ -n "$LOGS_FILE" ]; then
LOGS_DIR=`dirname $LOGS_FILE`
else
LOGS_DIR=$DEPLOY_DIR/logs
fi
if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi
STDOUT_FILE=$LOGS_DIR/stdout.log
LIB_DIR=$DEPLOY_DIR/lib
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`
JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
JAVA_DEBUG_OPTS=""
if [ "$2" = "debug" ]; then
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "
fi
JAVA_JMX_OPTS=""
if [ "$2" = "jmx" ]; then
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
fi
JAVA_MEM_OPTS=""
BITS=`file $JAVA_HOME/bin/java | grep 64-bit`
if [ -n "$BITS" ]; then
JAVA_MEM_OPTS=" -server -Xmx1g -Xms1g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
else
JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
fi
echo -e "Starting the $SERVER_NAME ...\c"
nohup $JAVA_HOME/bin/java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS org.oreframework.boot.bootstrap.OreBootApplication env=$ENV > $STDOUT_FILE 2>&1 &
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
if [ -n "$SERVER_PORT" ]; then
COUNT=`netstat -an | grep $SERVER_PORT | wc -l`
else
COUNT=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`
fi
if [ $COUNT -gt 0 ]; then
break
fi
done
echo "OK!"
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS"
echo "STDOUT: $STDOUT_FILE"
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/classes
SERVER_NAME=`sed '/application.name/!d;s/.*=//' classes/config/application.properties | tr -d '\r'`
if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME does not started!"
exit 1
fi
#if [ "$1" != "skip" ]; then
#$BIN_DIR/dump.sh
#fi
echo -e "Stopping the $SERVER_NAME ...\c"
for PID in $PIDS ; do
kill $PID > /dev/null 2>&1
done
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=1
for PID in $PIDS ; do
PID_EXIST=`ps --no-heading -p $PID`
if [ -n "$PID_EXIST" ]; then
COUNT=0
break
fi
done
done
echo "OK!"
echo "PID: $PIDS"
package cn.com.glsx.dj.rop.platform;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
* @Title: IpConfiguration.java
* @Description:
* @author Alvin
* @date 2019年9月3日 上午11:05:17
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2018
*/
@Component
public class IpConfiguration implements ApplicationListener<WebServerInitializedEvent> {
private int serverPort;
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
serverPort = event.getWebServer().getPort();
}
public int getPort(){
return serverPort;
}
}
package cn.com.glsx.dj.rop.platform.controller;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilder;
import cn.com.glsx.dj.rop.platform.IpConfiguration;
import com.rop.utils.RopUtils;
/**
* @Title: BaseControllerTest.java
* @Description:
* @author Alvin
* @date 2019年9月3日 上午9:32:12
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2018
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class BaseControllerTest{
String url = "http://localhost:";
@Value("${server.servlet.context-path}")
String contextPath;
@Autowired
private IpConfiguration ip;
final String appKey = "48e5e13229b82c1b4e6e8c96151f0637";
final String secret = "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b";
@Before
public void setUp() {
url = url.concat(String.valueOf(ip.getPort())).concat(contextPath).concat("/router");
}
public String get(MultiValueMap<String, String> paramsMap) throws Exception{
return get(paramsMap, String.class);
}
public <T> T get(MultiValueMap<String, String> paramsMap, Class<T> responseType) throws Exception{
MultiValueMap<String, String> params = getSysParams();
params.putAll(paramsMap);
for(Entry<String, String> entry:params.toSingleValueMap().entrySet()){
if(StringUtils.isEmpty(entry.getValue())){
params.remove(entry.getKey());
}
}
String sign = RopUtils.sign(params.toSingleValueMap(), secret);
params.add("sign", sign);
RestTemplate rest = new RestTemplate();
RopUriTemplateHandler uriTemplateHandler = new RopUriTemplateHandler(url);
uriTemplateHandler.setDefaultUriVariables(params.toSingleValueMap());
rest.setUriTemplateHandler(uriTemplateHandler);
return rest.getForObject(url, responseType, params.toSingleValueMap());
}
public String post(MultiValueMap<String, String> paramsMap) throws Exception{
return post(paramsMap, String.class);
}
public <T> T post(MultiValueMap<String, String> paramsMap, Class<T> responseType) throws Exception{
MultiValueMap<String, String> params = getSysParams();
params.putAll(paramsMap);
for(Entry<String, String> entry:params.toSingleValueMap().entrySet()){
if(StringUtils.isEmpty(entry.getValue())){
params.remove(entry.getKey());
}
}
String sign = RopUtils.sign(params.toSingleValueMap(), secret);
params.add("sign", sign);
return new RestTemplate().postForObject(url, params, responseType);
}
public String upload(MultiValueMap<String, String> paramsMap, MultiValueMap<String, String> fileParamsMap) throws Exception{
return upload(paramsMap, fileParamsMap, String.class);
}
public <T> T upload(MultiValueMap<String, String> paramsMap, MultiValueMap<String, String> fileParamsMap, Class<T> responseType) throws Exception{
MultiValueMap<String, String> params = getSysParams();
params.putAll(paramsMap);
for(Entry<String, String> entry:params.toSingleValueMap().entrySet()){
if(StringUtils.isEmpty(entry.getValue())){
params.remove(entry.getKey());
}
}
String sign = RopUtils.sign(params.toSingleValueMap(), secret);
params.add("sign", sign);
params.putAll(fileParamsMap);
return new RestTemplate().postForObject(url, params, responseType);
}
public MultiValueMap<String, String> getSysParams(){
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(16);
params.add("appKey", appKey);
params.add("format", "json");
params.add("locale", "zh_CN");
return params;
}
class RopUriTemplateHandler extends DefaultUriBuilderFactory{
public RopUriTemplateHandler(String baseUriTemplate) {
super(baseUriTemplate);
}
@Override
public URI expand(String uriTemplate, Map<String, ?> uriVars) {
UriBuilder builder = uriString(uriTemplate);
if(uriVars != null && !uriVars.isEmpty()){
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
for(Entry<String, ?> entry:uriVars.entrySet()){
params.add(entry.getKey(), entry.getValue().toString());
}
builder.queryParams(params);
}
return builder.build(uriVars);
}
}
}
package cn.com.glsx.dj.rop.platform.controller;
import java.util.Base64;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import com.rop.request.UploadFile;
/**
* @Title: ExampleControllerTest.java
* @Description:
* @author Alvin
* @date 2019年9月3日 上午9:33:00
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2018
*/
public class ExampleControllerTest extends BaseControllerTest {
@Test
public void testGetExample() throws Exception{
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.add("v", "1.0.0");
params.add("method", "org.ore.api.example");
params.add("name", "alvin");
System.out.println(get(params));
}
@Test
public void testPostExample() throws Exception{
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.add("v", "1.0.0");
params.add("method", "org.ore.api.example");
params.add("name", "alvin");
System.out.println(post(params));
}
@Test
public void testComplexRequest() throws Exception{
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.add("v", "1.0.0");
params.add("method", "org.ore.api.example.complex");
params.add("name", "alvin");
params.add("age", "18");
params.add("hobby[0]", "编程");
params.add("hobby[1]", "打球");
params.add("address.province", "广东省");
params.add("address.city", "深圳市");
params.add("address.area", "南山区");
params.add("workExperiences[0].company", "深圳广联赛讯股份有限公司");
params.add("workExperiences[0].address.province", "广东省");
params.add("workExperiences[0].address.city", "深圳市");
params.add("workExperiences[0].address.streets[0].no", "3370号");
params.add("workExperiences[0].address.streets[0].name", "留仙大道");
params.add("workExperiences[0].startTime", "2010-11-11 00:00:00");
params.add("workExperiences[0].endTime", "2020-11-11 00:00:00");
System.out.println(post(params));
}
@Test
public void testUpload() throws Exception{
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.add("v", "1.0.0");
params.add("method", "org.ore.api.example.upload");
ClassPathResource resource = new ClassPathResource("logo.png");
UploadFile uploadFile = new UploadFile(resource.getFile());
MultiValueMap<String, String> fileParams = new LinkedMultiValueMap<String, String>(4);
fileParams.add("file", "png@" + Base64.getEncoder().encodeToString(uploadFile.getContent()));
System.out.println(upload(params, fileParams));
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!