├── rop-war
├── .gitignore
├── src
│ └── main
│ │ ├── webapp
│ │ ├── index.jsp
│ │ └── WEB-INF
│ │ │ └── web.xml
│ │ ├── resources
│ │ ├── properties
│ │ │ ├── init.properties
│ │ │ └── log4j.properties
│ │ ├── mapper
│ │ │ └── mybatis-config.xml
│ │ ├── servlet
│ │ │ └── spring-hessian-service.xml
│ │ ├── struts.xml
│ │ └── context
│ │ │ └── applicationContext.xml
│ │ └── java
│ │ └── com
│ │ └── prowo
│ │ ├── db
│ │ └── mysql
│ │ │ ├── dialet
│ │ │ ├── OracleDialect.java
│ │ │ ├── MySQLDialect.java
│ │ │ └── Dialect.java
│ │ │ ├── util
│ │ │ └── ReflectUtil.java
│ │ │ └── interceptor
│ │ │ └── Page.java
│ │ ├── system
│ │ └── SystemInitListener.java
│ │ └── rop
│ │ ├── context
│ │ ├── RopContext.java
│ │ ├── SpringContextHandler.java
│ │ └── RopServiceHandler.java
│ │ ├── web
│ │ ├── BaseAction.java
│ │ └── Router.java
│ │ ├── filter
│ │ └── BaseAccessFilter.java
│ │ ├── intercept
│ │ ├── LogInterceptor.java
│ │ ├── CacheInterceptor.java
│ │ └── RopContextIntercept.java
│ │ └── memcached
│ │ ├── MemcachedCalendarUtil.java
│ │ └── MemcachedUtil.java
└── pom.xml
├── .gitignore
├── README.md
├── rop-service
├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── prowo
│ │ │ └── App.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── prowo
│ │ └── AppTest.java
├── pom.xml
└── rop-service.iml
├── rop-common
├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── prowo
│ │ │ ├── rop
│ │ │ ├── exception
│ │ │ │ ├── RedefinedException.java
│ │ │ │ └── RopException.java
│ │ │ ├── utils
│ │ │ │ ├── Representation.java
│ │ │ │ ├── Metadata.java
│ │ │ │ ├── ServiceMethodHandler.java
│ │ │ │ ├── MediaType.java
│ │ │ │ └── ServiceConstants.java
│ │ │ ├── annotation
│ │ │ │ └── ApiMethod.java
│ │ │ └── log
│ │ │ │ ├── LogStack.java
│ │ │ │ └── LogUtils.java
│ │ │ └── common
│ │ │ ├── enums
│ │ │ └── ResultCode.java
│ │ │ ├── exception
│ │ │ └── BussinessException.java
│ │ │ └── utils
│ │ │ ├── DateConverter.java
│ │ │ ├── HttpUtils.java
│ │ │ └── ZipUtils.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── prowo
│ │ └── AppTest.java
├── pom.xml
└── rop-common.iml
├── rop-api
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── prowo
│ │ ├── test
│ │ ├── handle
│ │ │ └── IHelloWorld.java
│ │ ├── response
│ │ │ └── RopHelloWorldResponse.java
│ │ └── request
│ │ │ └── RopHelloWorldRequest.java
│ │ └── common
│ │ ├── annotation
│ │ └── SpVersion.java
│ │ ├── rop
│ │ ├── RopRequestBody.java
│ │ ├── RopResponse.java
│ │ └── RopRequest.java
│ │ └── util
│ │ ├── PageElementModel.java
│ │ ├── ClientMemCacheConstants.java
│ │ ├── InternetProtocol.java
│ │ ├── MD5.java
│ │ └── FastJsonUtils.java
├── pom.xml
└── rop-api.iml
├── rop-persistence
├── pom.xml
├── src
│ └── test
│ │ └── java
│ │ └── com
│ │ └── prowo
│ │ └── AppTest.java
└── rop-persistence.iml
├── rop-core
├── pom.xml
├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── prowo
│ │ │ └── handler
│ │ │ └── HelloWorldHandler.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── prowo
│ │ └── test
│ │ └── HelloWorldTest.java
└── rop-core.iml
├── pom.xml
└── rop.iml
/rop-war/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 |
--------------------------------------------------------------------------------
/rop-war/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World!
4 |
5 |
6 |
--------------------------------------------------------------------------------
/rop-war/src/main/resources/properties/init.properties:
--------------------------------------------------------------------------------
1 | pointsPath=D:/data/froadpoints/
2 | #pointsPath=D:/workspace/local_config/points/
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/db/mysql/dialet/OracleDialect.java:
--------------------------------------------------------------------------------
1 | package com.prowo.db.mysql.dialet;
2 |
3 | public class OracleDialect extends Dialect {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | rop-common/target/
3 | rop-core/target/
4 | rop-service/target/
5 | rop-api/target/
6 | rop-persistence/target/
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rop
2 | Rop(Rapid Open Platform)是借鉴淘宝开发平台(TOP:Taobal Open Platform)实现的全功能Rest Web Service 开源框架(Full-Stack)。 它高于CXF,Aixs等一般的纯技术Web Service框架,提供了请求/响应序列化、数据检验、会话管理、安全管理等高级主题的东西。最值得一提的是其参考TOP,提供了一个可扩展的错误处理模型,使开发平台级的Web Service的难度大大降低。
3 |
--------------------------------------------------------------------------------
/rop-service/src/main/java/com/prowo/App.java:
--------------------------------------------------------------------------------
1 | package com.prowo;
2 |
3 | /**
4 | * Hello world!
5 | *
6 | */
7 | public class App
8 | {
9 | public static void main( String[] args )
10 | {
11 | System.out.println( "Hello World!" );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/rop/exception/RedefinedException.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.exception;
2 |
3 | /**
4 | * 重复定义的method 和 version
5 | * @author dengcheng
6 | *
7 | */
8 | public class RedefinedException extends RopException{
9 | /**
10 | *
11 | */
12 | private static final long serialVersionUID = 8768155790007183873L;
13 |
14 | public RedefinedException(){
15 | super("重复定义 method 以及版本");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/rop-api/src/main/java/com/prowo/test/handle/IHelloWorld.java:
--------------------------------------------------------------------------------
1 | package com.prowo.test.handle;
2 |
3 | import com.prowo.common.rop.RopRequestBody;
4 | import com.prowo.common.rop.RopResponse;
5 | import com.prowo.test.request.RopHelloWorldRequest;
6 | import com.prowo.test.response.RopHelloWorldResponse;
7 |
8 | public interface IHelloWorld {
9 | public RopResponse sayHello(RopRequestBody request);
10 | }
11 |
--------------------------------------------------------------------------------
/rop-api/src/main/java/com/prowo/common/annotation/SpVersion.java:
--------------------------------------------------------------------------------
1 | package com.prowo.common.annotation;
2 |
3 | import java.lang.annotation.*;
4 |
5 | @Inherited
6 | @Target({ElementType.FIELD, ElementType.METHOD})
7 | @Retention(RetentionPolicy.RUNTIME)
8 | @Documented
9 | public @interface SpVersion {
10 |
11 | /**
12 | * 用于属性过滤 json输出的时候
13 | *
14 | * @return
15 | */
16 | int gt() default 0;
17 |
18 | int ipadGt() default 0;
19 | }
20 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/rop/utils/Representation.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.utils;
2 |
3 | import javax.servlet.http.HttpServletResponse;
4 |
5 | public abstract class Representation {
6 | private MediaType mediaType;
7 |
8 | public MediaType getMediaType() {
9 | return mediaType;
10 | }
11 |
12 | public void setMediaType(MediaType mediaType) {
13 | this.mediaType = mediaType;
14 | }
15 |
16 | public void outPut(HttpServletResponse response) {
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/rop-api/src/main/java/com/prowo/common/rop/RopRequestBody.java:
--------------------------------------------------------------------------------
1 | package com.prowo.common.rop;
2 |
3 | import com.alibaba.fastjson.annotation.JSONField;
4 |
5 | import java.io.Serializable;
6 |
7 |
8 | public class RopRequestBody implements Serializable {
9 | /**
10 | *
11 | */
12 | private static final long serialVersionUID = -589833629810101948L;
13 | @JSONField(serialize = false)
14 | private T t;
15 |
16 | public T getT() {
17 | return t;
18 | }
19 |
20 | public void setT(T t) {
21 | this.t = t;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/rop/exception/RopException.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.exception;
2 |
3 | /**
4 | * 自定义rop异常
5 | */
6 | public class RopException extends RuntimeException {
7 | /**
8 | *
9 | */
10 | private static final long serialVersionUID = 7115081616648590439L;
11 |
12 | public RopException() {
13 | }
14 |
15 | public RopException(String message) {
16 | super(message);
17 | }
18 |
19 | public RopException(String message, Throwable cause) {
20 | super(message, cause);
21 | }
22 |
23 | public RopException(Throwable cause) {
24 | super(cause);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/db/mysql/dialet/MySQLDialect.java:
--------------------------------------------------------------------------------
1 | package com.prowo.db.mysql.dialet;
2 |
3 | public class MySQLDialect extends Dialect {
4 |
5 | public boolean supportsLimitOffset() {
6 | return true;
7 | }
8 |
9 | public boolean supportsLimit() {
10 | return true;
11 | }
12 |
13 | public String getLimitString(String sql, int offset,
14 | String offsetPlaceholder, int limit, String limitPlaceholder) {
15 | if (offset > 0) {
16 | return sql + " limit " + offsetPlaceholder + "," + limitPlaceholder;
17 | } else {
18 | return sql + " limit " + limitPlaceholder;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/rop-api/src/main/java/com/prowo/common/util/PageElementModel.java:
--------------------------------------------------------------------------------
1 | package com.prowo.common.util;
2 |
3 | public class PageElementModel {
4 | private String elementCode;
5 | private String elementValue;
6 |
7 | public String getElementCode() {
8 | return elementCode;
9 | }
10 |
11 | public void setElementCode(String elementCode) {
12 | this.elementCode = elementCode;
13 | }
14 |
15 | public String getElementValue() {
16 | return elementValue;
17 | }
18 |
19 | public void setElementValue(String elementValue) {
20 | this.elementValue = elementValue;
21 | }
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/rop/utils/Metadata.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.utils;
2 |
3 | public abstract class Metadata {
4 | private String name;
5 | private String description;
6 |
7 | public Metadata(String name, String description) {
8 | this.name = name;
9 | this.description = description;
10 | }
11 |
12 | public String getName() {
13 | return name;
14 | }
15 |
16 | public void setName(String name) {
17 | this.name = name;
18 | }
19 |
20 | public String getDescription() {
21 | return description;
22 | }
23 |
24 | public void setDescription(String description) {
25 | this.description = description;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/rop-api/src/main/java/com/prowo/test/response/RopHelloWorldResponse.java:
--------------------------------------------------------------------------------
1 | package com.prowo.test.response;
2 |
3 | import java.io.Serializable;
4 |
5 | public class RopHelloWorldResponse implements Serializable {
6 |
7 | private static final long serialVersionUID = 1723808150716676068L;
8 |
9 | private String content;
10 |
11 | public String getContent() {
12 | return content;
13 | }
14 |
15 | public void setContent(String content) {
16 | this.content = content;
17 | }
18 |
19 | @Override
20 | public String toString() {
21 | return "RopHelloWorldResponse{" +
22 | "content='" + content + '\'' +
23 | '}';
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/rop-war/src/main/resources/mapper/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/rop-api/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | rop-root
5 | com.prowo
6 | 1.0-SNAPSHOT
7 |
8 | 4.0.0
9 |
10 | rop-api
11 | jar
12 |
13 | rop-api
14 | http://maven.apache.org
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/rop-common/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | rop-root
5 | com.prowo
6 | 1.0-SNAPSHOT
7 |
8 | 4.0.0
9 |
10 | rop-common
11 | jar
12 |
13 | rop-common
14 | http://maven.apache.org
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/common/enums/ResultCode.java:
--------------------------------------------------------------------------------
1 | package com.prowo.common.enums;
2 |
3 | /**
4 | * @author linan
5 | * 响应码
6 | */
7 | public enum ResultCode {
8 |
9 | // 系统响应码
10 | SYS_SUCCESS("0000", "成功"),
11 | SYS_FAILED("9999", "失败"),
12 | SYS_UNKNOWN_EXCEPTION("0099", "系统未知异常"),
13 | SYS_TIMEOUT("0002", "超时"),
14 | SYS_REQUEST_CONCURRENCY("0098", "并发请求"),;
15 | private String code;
16 |
17 | private String msg;
18 |
19 | private ResultCode(String code, String msg) {
20 | this.code = code;
21 | this.msg = msg;
22 | }
23 |
24 | public String getCode() {
25 | return code;
26 | }
27 |
28 | public String getMsg() {
29 | return msg;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/rop-persistence/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | rop-root
5 | com.prowo
6 | 1.0-SNAPSHOT
7 |
8 | 4.0.0
9 |
10 | rop-persistence
11 | jar
12 |
13 | rop-persistence
14 | http://maven.apache.org
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/rop-common/src/test/java/com/prowo/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.prowo;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/rop-service/src/test/java/com/prowo/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.prowo;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/rop-persistence/src/test/java/com/prowo/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.prowo;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/rop-war/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.prowo
8 | rop-root
9 | 1.0-SNAPSHOT
10 |
11 | rop-war
12 | war
13 | rop-war Maven Webapp
14 | http://maven.apache.org
15 |
16 |
17 | com.prowo
18 | rop-core
19 | 1.0-SNAPSHOT
20 |
21 |
22 |
23 | rop-war
24 |
25 |
26 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/system/SystemInitListener.java:
--------------------------------------------------------------------------------
1 | package com.prowo.system;
2 |
3 | import javax.servlet.ServletContextEvent;
4 | import javax.servlet.ServletContextListener;
5 |
6 | import org.apache.commons.configuration.Configuration;
7 | import org.apache.commons.configuration.ConfigurationException;
8 | import org.apache.commons.configuration.PropertiesConfiguration;
9 |
10 | public class SystemInitListener implements ServletContextListener {
11 |
12 | @Override
13 | public void contextDestroyed(ServletContextEvent arg0) {
14 | System.clearProperty("pointsPath");
15 |
16 | }
17 |
18 | @Override
19 | public void contextInitialized(ServletContextEvent arg0) {
20 | Configuration config = null;
21 | try {
22 | config = new PropertiesConfiguration("properties/init.properties");
23 | } catch (ConfigurationException e) {
24 |
25 | }
26 | //设置配置文件根路径
27 | System.setProperty("pointsPath", config.getString("pointsPath"));
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/common/exception/BussinessException.java:
--------------------------------------------------------------------------------
1 | package com.prowo.common.exception;
2 |
3 | public class BussinessException extends RuntimeException {
4 |
5 | /**
6 | *
7 | */
8 | private static final long serialVersionUID = -5609021297595863252L;
9 |
10 | private String code;
11 | private String message;
12 |
13 | public BussinessException() {
14 | }
15 |
16 | public BussinessException(String code, String message) {
17 | super(message);
18 | this.code = code;
19 | this.message = message;
20 | }
21 |
22 | public BussinessException(String code, String message, Throwable cause) {
23 | super(message, cause);
24 | this.code = code;
25 | this.message = message;
26 | }
27 |
28 | public BussinessException(Throwable cause) {
29 | super(cause);
30 | }
31 |
32 | public String getCode() {
33 | return code;
34 | }
35 |
36 | public String getMessage() {
37 | return message;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/rop/utils/ServiceMethodHandler.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.utils;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | /**
6 | * 处理请求的服务相关信息
7 | *
8 | */
9 | public class ServiceMethodHandler {
10 | // 处理器对象
11 | private Object handler;
12 |
13 | // 处理器的处理方法
14 | private Method handlerMethod;
15 |
16 | private String version;
17 | /**
18 | * 是否缓存结果集
19 | */
20 | private boolean cached;
21 |
22 | public boolean isCached() {
23 | return cached;
24 | }
25 |
26 | public void setCached(boolean cached) {
27 | this.cached = cached;
28 | }
29 |
30 | public Object getHandler() {
31 | return handler;
32 | }
33 |
34 | public void setHandler(Object handler) {
35 | this.handler = handler;
36 | }
37 |
38 | public Method getHandlerMethod() {
39 | return handlerMethod;
40 | }
41 |
42 | public void setHandlerMethod(Method handlerMethod) {
43 | this.handlerMethod = handlerMethod;
44 | }
45 |
46 | public String getVersion() {
47 | return version;
48 | }
49 |
50 | public void setVersion(String version) {
51 | this.version = version;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/rop-api/src/main/java/com/prowo/test/request/RopHelloWorldRequest.java:
--------------------------------------------------------------------------------
1 | package com.prowo.test.request;
2 |
3 | import com.prowo.common.rop.RopRequest;
4 | import com.prowo.common.util.ClientMemCacheConstants;
5 | import org.apache.commons.lang3.StringUtils;
6 |
7 | public class RopHelloWorldRequest extends RopRequest {
8 |
9 | private static final long serialVersionUID = 7683393066124643022L;
10 |
11 | private String username;
12 |
13 | public String getUsername() {
14 | return username;
15 | }
16 |
17 | public void setUsername(String username) {
18 | this.username = username;
19 | }
20 |
21 | public String getCacheKey() {
22 | return StringUtils.join(ClientMemCacheConstants.ANNOTATION_CACHEKEY_CONSTANTS.HELLO_WORLD.getCacheKey(), this.username);
23 | }
24 |
25 | public int getCacheSecends() {
26 | return ClientMemCacheConstants.ANNOTATION_CACHEKEY_CONSTANTS.HELLO_WORLD.getCacheSecends();
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "RopHelloWorldRequest{" +
32 | "username='" + username + '\'' +
33 | '}';
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/rop-core/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | rop-root
5 | com.prowo
6 | 1.0-SNAPSHOT
7 |
8 | 4.0.0
9 |
10 | rop-core
11 | jar
12 |
13 | rop-core
14 | http://maven.apache.org
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
22 | com.prowo
23 | rop-api
24 | 1.0-SNAPSHOT
25 |
26 |
27 | com.prowo
28 | rop-service
29 | 1.0-SNAPSHOT
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/common/utils/DateConverter.java:
--------------------------------------------------------------------------------
1 | package com.prowo.common.utils;
2 |
3 | import java.text.ParseException;
4 | import java.util.Date;
5 |
6 | import org.apache.commons.beanutils.Converter;
7 | import org.apache.commons.lang3.StringUtils;
8 | import org.apache.commons.lang3.time.DateUtils;
9 |
10 | public class DateConverter implements Converter {
11 |
12 | public Object convert(Class type, Object value) {
13 | if (value == null) {
14 | return null;
15 | }
16 | if (value instanceof Date) {
17 | return value;
18 | }
19 | if (value instanceof Long) {
20 | Long longValue = (Long) value;
21 | return new Date(longValue.longValue());
22 | }
23 | if (value instanceof String) {
24 | String dateStr = (String) value;
25 | if (StringUtils.isEmpty(dateStr)) {
26 | return null;
27 | }
28 | Date date = null;
29 | try {
30 | date = DateUtils.parseDate(value.toString(), new String[] {
31 | "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss",
32 | "yyyy-MM-dd HH:mm", "yyyy-MM-dd" });
33 | } catch (ParseException e) {
34 | e.printStackTrace();
35 | }
36 | return date;
37 | }
38 | return null;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/rop-service/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | rop-root
5 | com.prowo
6 | 1.0-SNAPSHOT
7 |
8 | 4.0.0
9 |
10 | rop-service
11 | jar
12 |
13 | rop-service
14 | http://maven.apache.org
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
22 | com.prowo
23 | rop-persistence
24 | 1.0-SNAPSHOT
25 |
26 |
27 | com.prowo
28 | rop-common
29 | 1.0-SNAPSHOT
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/rop/annotation/ApiMethod.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.annotation;
2 |
3 | import java.lang.annotation.*;
4 |
5 | @Inherited
6 | @Target({ElementType.METHOD})
7 | @Retention(RetentionPolicy.RUNTIME)
8 | @Documented
9 | public @interface ApiMethod {
10 |
11 | /**
12 | * 映射的方法
13 | *
14 | * @return
15 | */
16 | String method() default "";
17 |
18 | /**
19 | * 支持的api版本
20 | *
21 | * @return
22 | */
23 | String version() default "ALL";
24 |
25 | /**
26 | * 是否缓存结果
27 | * 缓存时间2分钟
28 | * 会根据method 为memcached 的key 来缓存。
29 | * 请谨慎使用
30 | *
31 | * @return
32 | */
33 | boolean cached() default false;
34 |
35 | /**
36 | * aop arround 环绕处理class
37 | *
38 | * @return
39 | */
40 | String[] InterceptorRef() default {};
41 |
42 | /**
43 | * 每分钟访问限制 默认
44 | */
45 | int limitCount() default 999999999;
46 |
47 | /**
48 | * 访问限制
49 | * internal 表示内网
50 | *
51 | * @return
52 | */
53 | String accessRole() default "";
54 |
55 | /**
56 | * @Description: 默认不忽略次图片验证拦截器
57 | */
58 | boolean ignoreValidateInterceptor() default false;
59 | }
60 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/db/mysql/dialet/Dialect.java:
--------------------------------------------------------------------------------
1 | package com.prowo.db.mysql.dialet;
2 |
3 | /**
4 | * 类似hibernate的 Dialect
5 | * @author "linan"
6 | *
7 | */
8 | public abstract class Dialect {
9 |
10 | public boolean supportsLimit() {
11 | return false;
12 | }
13 |
14 | public boolean supportsLimitOffset() {
15 | return supportsLimit();
16 | }
17 |
18 | /**
19 | * 将sql变成分页sql语句,直接使用offset,limit的值作为占位符. 源代码为:
20 | * getLimitString(sql,offset
21 | * ,String.valueOf(offset),limit,String.valueOf(limit))
22 | */
23 | public String getLimitString(String sql, int offset, int limit) {
24 | return getLimitString(sql, offset, Integer.toString(offset), limit,
25 | Integer.toString(limit));
26 | }
27 |
28 | /**
29 | * 将sql变成分页sql语句,提供将offset及limit使用占位符(placeholder)替换.
30 | *
31 | *
32 | * 如mysql
33 | * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
34 | * select * from user limit :offset,:limit
35 | *
36 | *
37 | * @return 包含占位符的分页sql
38 | */
39 | public String getLimitString(String sql, int offset,
40 | String offsetPlaceholder, int limit, String limitPlaceholder) {
41 | throw new UnsupportedOperationException("paged queries not supported");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/rop/context/RopContext.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.context;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 |
6 | import com.prowo.common.rop.RopRequestBody;
7 | import com.prowo.rop.utils.ServiceMethodHandler;
8 |
9 | public class RopContext {
10 | private RopRequestBody> requestData;
11 | private ServiceMethodHandler serviceHandler;
12 | private HttpServletRequest request;
13 | private HttpServletResponse response;
14 |
15 | public HttpServletRequest getRequest() {
16 | return request;
17 | }
18 |
19 | public void setRequest(HttpServletRequest request) {
20 | this.request = request;
21 | }
22 |
23 | public HttpServletResponse getResponse() {
24 | return response;
25 | }
26 |
27 | public void setResponse(HttpServletResponse response) {
28 | this.response = response;
29 | }
30 |
31 | public ServiceMethodHandler getServiceHandler() {
32 | return serviceHandler;
33 | }
34 |
35 | public void setServiceHandler(ServiceMethodHandler serviceHandler) {
36 | this.serviceHandler = serviceHandler;
37 | }
38 |
39 | public RopRequestBody> getRequestData() {
40 | return requestData;
41 | }
42 |
43 | public void setRequestData(RopRequestBody> requestData) {
44 | this.requestData = requestData;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/rop/context/SpringContextHandler.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.context;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.ApplicationContextAware;
5 | import org.springframework.stereotype.Component;
6 |
7 | @Component
8 | public class SpringContextHandler implements ApplicationContextAware {
9 |
10 | private static ApplicationContext applicationContext;
11 |
12 | public void setApplicationContext(ApplicationContext applicationContext) {
13 | SpringContextHandler.applicationContext = applicationContext;
14 | }
15 |
16 | public static ApplicationContext getApplicationContext() {
17 | checkApplicationContext();
18 | return applicationContext;
19 | }
20 |
21 | public static T getBean(String name) {
22 | checkApplicationContext();
23 | return (T) applicationContext.getBean(name);
24 | }
25 |
26 | public static T getBean(Class clazz) {
27 | checkApplicationContext();
28 | return (T) applicationContext.getBeansOfType(clazz);
29 | }
30 |
31 | private static void checkApplicationContext() {
32 | if (applicationContext == null)
33 | throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextUtil");
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/rop/web/BaseAction.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.web;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | import org.apache.struts2.ServletActionContext;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 |
13 | import com.opensymphony.xwork2.ActionSupport;
14 |
15 | public class BaseAction extends ActionSupport{
16 |
17 | /**
18 | *
19 | */
20 | private static final long serialVersionUID = 1L;
21 |
22 | @Autowired
23 |
24 |
25 | public BaseAction() {
26 | //this.meta = metaService.getMeta(this.getRequest());
27 | }
28 |
29 |
30 | /**
31 | * 发送Ajax请求结果json
32 | *
33 | * @throws ServletException
34 | * @throws IOException
35 | */
36 | public void sendAjaxResultByJson(String json) {
37 | this.getResponse().setContentType("application/json;charset=UTF-8");
38 | this.getResponse().setCharacterEncoding("UTF-8");
39 | try {
40 | PrintWriter out = this.getResponse().getWriter();
41 | out.write(json);
42 | out.flush();
43 | out.close();
44 | } catch (Exception e) {
45 | e.printStackTrace();
46 | }
47 | }
48 |
49 |
50 | protected HttpServletResponse getResponse() {
51 | return ServletActionContext.getResponse();
52 | }
53 |
54 | protected HttpServletRequest getRequest() {
55 | return ServletActionContext.getRequest();
56 | }
57 |
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/rop-core/src/main/java/com/prowo/handler/HelloWorldHandler.java:
--------------------------------------------------------------------------------
1 | package com.prowo.handler;
2 |
3 | import org.apache.log4j.Logger;
4 | import org.springframework.stereotype.Component;
5 |
6 | import com.prowo.common.rop.RopRequestBody;
7 | import com.prowo.common.rop.RopResponse;
8 | import com.prowo.rop.annotation.ApiMethod;
9 | import com.prowo.rop.log.LogUtils;
10 | import com.prowo.test.handle.IHelloWorld;
11 | import com.prowo.test.request.RopHelloWorldRequest;
12 | import com.prowo.test.response.RopHelloWorldResponse;
13 |
14 | @Component
15 | public class HelloWorldHandler implements IHelloWorld {
16 | private final Logger logger = Logger.getLogger(this.getClass());
17 |
18 | @Override
19 | @ApiMethod(method = "api.com.test.sayHello", version = "1.0.0", cached = false)
20 | public RopResponse sayHello(
21 | RopRequestBody request) {
22 | logger.info("start sayHello api, request parms: " + request.getT().toString());
23 |
24 | RopResponse response = new RopResponse();
25 | RopHelloWorldResponse responseData = new RopHelloWorldResponse();
26 | RopHelloWorldRequest helloWorld = request.getT();
27 | LogUtils.startLogWeb("测试api的debug日志功能");
28 | LogUtils.appendLogWeb("测试debug日志");
29 | responseData.setContent("hello ! " + helloWorld.getUsername());
30 | response.setData(responseData);
31 | LogUtils.endLogWeb();
32 |
33 | logger.info("end sayHello api, response parms: " + responseData.toString());
34 | return response;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/rop-war/src/main/resources/servlet/spring-hessian-service.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/rop/filter/BaseAccessFilter.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.filter;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.servlet.Filter;
6 | import javax.servlet.FilterChain;
7 | import javax.servlet.FilterConfig;
8 | import javax.servlet.ServletException;
9 | import javax.servlet.ServletRequest;
10 | import javax.servlet.ServletResponse;
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpServletResponse;
13 |
14 | import org.apache.commons.logging.Log;
15 | import org.apache.commons.logging.LogFactory;
16 | import org.springframework.stereotype.Component;
17 |
18 | /**
19 | * 访问控制Filter
20 | */
21 | @Component
22 | public class BaseAccessFilter implements Filter {
23 | private Log log = LogFactory.getLog(BaseAccessFilter.class);
24 |
25 | public void init(FilterConfig filterConfig) throws ServletException {
26 |
27 | }
28 |
29 | public void doFilter(ServletRequest request, ServletResponse response,
30 | FilterChain chain) throws IOException, ServletException {
31 | HttpServletRequest req = (HttpServletRequest) request;
32 | HttpServletResponse res = (HttpServletResponse) response;
33 | // AccessMeta am = metaService.getMeta(req);
34 | // am.getRouter().go(am, res);
35 | // req.getRequestDispatcher("").forward(req, res);
36 | log.info("in BaseAccessFilter.....");
37 | try {
38 | chain.doFilter(request, response);
39 | } catch (Exception ex) {
40 | ex.printStackTrace();
41 | log.error("Captured Exception Exception URL: " + req.toString());
42 | } catch (Throwable e) {
43 | e.printStackTrace();
44 | log.error("Captured Throwable Exception URL: " + req.toString());
45 | log.error(this.getClass(), e);
46 | }
47 | }
48 |
49 | public void destroy() {
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/rop-api/src/main/java/com/prowo/common/util/ClientMemCacheConstants.java:
--------------------------------------------------------------------------------
1 | package com.prowo.common.util;
2 |
3 |
4 | public class ClientMemCacheConstants {
5 |
6 | //1分钟
7 | private static final int CACHE_ONE_MINS = 60;
8 | //5分钟
9 | private static final int CACHE_FIVE_MINS = 5 * 60;
10 | //10分钟
11 | private static final int CACHE_TEN_MINS = 10 * 60;
12 | //15分钟
13 | private static final int CACHE_FIVTEEN_MINS = 15 * 60;
14 | //半小时
15 | private static final int CACHE_HALF_HOUR = 30 * 60;
16 | //一小时
17 | private static final int CACHE_ONE_HOURS = 1 * 60 * 60;
18 | //两小时
19 | private static final int CACHE_TOW_HOURS = 2 * 60 * 60;
20 | //一个星期
21 | private static final int CACHE_ONE_WEEK = 24 * 7 * 60 * 60;
22 |
23 |
24 | /**
25 | * ANNOTATION注解方式缓存key和secends
26 | * 组装格式:模块_(方法名+版本号)(cacheKey, cacheSecends�?
27 | * cacheKey只是前缀,后面可自己添加参数拼装
28 | */
29 | public static enum ANNOTATION_CACHEKEY_CONSTANTS {
30 |
31 | HELLO_WORLD("API_ANNOTATION_HELLO_WORLD_", CACHE_ONE_MINS);
32 |
33 | private String cacheKey;
34 | private int cacheSecends;
35 |
36 | private ANNOTATION_CACHEKEY_CONSTANTS(String cacheKey, int cacheSecends) {
37 | this.cacheKey = cacheKey;
38 | this.cacheSecends = cacheSecends;
39 | }
40 |
41 | public String getCacheKey() {
42 | return cacheKey;
43 | }
44 |
45 | public void setCacheKey(String cacheKey) {
46 | this.cacheKey = cacheKey;
47 | }
48 |
49 | public int getCacheSecends() {
50 | return cacheSecends;
51 | }
52 |
53 | public void setCacheSecends(int cacheSecends) {
54 | this.cacheSecends = cacheSecends;
55 | }
56 |
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/rop-war/src/main/resources/properties/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=info,stdout,R,E,default
2 |
3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5 | log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n
6 | log4j.appender.stdout.Threshold=DEBUG
7 | log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
8 | log4j.appender.R.File=/var/log/applogs/rop/infos.log
9 | log4j.appender.R.DatePattern='.'yyyy-MM-dd
10 | log4j.appender.R.layout=org.apache.log4j.PatternLayout
11 | log4j.appender.R.layout.ConversionPattern=%-5r [%t][%d{ISO8601}]-[%5p]%x-[%m]%n
12 | log4j.appender.R.Threshold=INFO
13 |
14 | log4j.appender.E=org.apache.log4j.DailyRollingFileAppender
15 | log4j.appender.E.File=/var/log/applogs/rop/error.log
16 | log4j.appender.E.DatePattern='.'yyyy-MM-dd
17 | log4j.appender.E.layout=org.apache.log4j.PatternLayout
18 | log4j.appender.E.layout.ConversionPattern=%-5r [%t][%d{ISO8601}]-[%5p]%x-[%m]%n
19 | log4j.appender.E.Threshold=ERROR
20 |
21 | log4j.appender.default=org.apache.log4j.DailyRollingFileAppender
22 | log4j.appender.default.File=/var/log/applogs/rop/default.log
23 | log4j.appender.default.DatePattern='.'yyyy-MM-dd
24 | log4j.appender.default.layout=org.apache.log4j.PatternLayout
25 | log4j.appender.default.layout.ConversionPattern=%-5r [%t][%d{ISO8601}]-[%5p]%x-[%m]%n
26 | log4j.appender.default.Threshold=INFO
27 |
28 | ##\u663e\u793aSQL\u8bed\u53e5\u90e8\u5206
29 | log4j.logger.com.ibatis=DEBUG
30 | log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
31 | log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
32 | log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
33 | log4j.logger.java.sql.Connection=DEBUG
34 | log4j.logger.java.sql.Statement=DEBUG
35 | log4j.logger.java.sql.PreparedStatement=DEBUG
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/db/mysql/util/ReflectUtil.java:
--------------------------------------------------------------------------------
1 | package com.prowo.db.mysql.util;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | /**
6 | * @Description 反射工具
7 | */
8 |
9 | public class ReflectUtil {
10 |
11 | /**
12 | * 利用反射获取指定对象的指定属性值
13 | *
14 | * @param obj
15 | * 目标对象
16 | * @param fieldName
17 | * 目标属性
18 | * @return 目标属性的值
19 | */
20 | public static Object getFieldValue(Object obj, String fieldName) {
21 | Object result = null;
22 | Field field = ReflectUtil.getField(obj, fieldName);
23 | if (field != null) {
24 | // 取消 Java 语言访问检查
25 | field.setAccessible(true);
26 | try {
27 | result = field.get(obj);
28 | } catch (IllegalArgumentException e) {
29 | e.printStackTrace();
30 | } catch (IllegalAccessException e) {
31 | e.printStackTrace();
32 | }
33 | }
34 | return result;
35 | }
36 |
37 | /**
38 | * 利用反射获取指定对象里面的指定属性
39 | *
40 | * @param obj
41 | * 目标对象
42 | * @param fieldName
43 | * 目标属性
44 | * @return 目标字段
45 | */
46 | public static Field getField(Object obj, String fieldName) {
47 | Field field = null;
48 | for (Class> clazz = obj.getClass(); clazz != Object.class; clazz = clazz
49 | .getSuperclass()) {
50 | try {
51 | field = clazz.getDeclaredField(fieldName);
52 | break;
53 | } catch (NoSuchFieldException e) {
54 | // 这里不用做处理,子类没有该字段可能对应的父类有,都没有就返回null
55 | }
56 | }
57 | return field;
58 | }
59 |
60 | /**
61 | * 利用反射设置指定对象的指定属性为指定的值
62 | *
63 | * @param obj
64 | * 目标对象
65 | * @param fieldName
66 | * 目标属性
67 | * @param fieldValue
68 | * 目标值
69 | */
70 | public static void setFieldValue(Object obj, String fieldName,
71 | Object fieldValue) {
72 | Field field = ReflectUtil.getField(obj, fieldName);
73 | if (field != null) {
74 | try {
75 | field.setAccessible(true);
76 | field.set(obj, fieldValue);
77 | } catch (IllegalArgumentException e) {
78 | e.printStackTrace();
79 | } catch (IllegalAccessException e) {
80 | e.printStackTrace();
81 | }
82 | }
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/rop/intercept/LogInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.intercept;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | import org.apache.commons.lang3.StringUtils;
6 | import org.apache.struts2.ServletActionContext;
7 |
8 | import com.opensymphony.xwork2.ActionInvocation;
9 | import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
10 | import com.prowo.common.rop.RopResponse;
11 | import com.prowo.rop.log.LogStack;
12 | import com.prowo.rop.log.LogUtils;
13 |
14 | public class LogInterceptor extends AbstractInterceptor {
15 |
16 | public static final String IS_DEBUG = "IS_DEBUG";
17 |
18 | @Override
19 | public String intercept(ActionInvocation invocation) throws Exception {
20 | HttpServletRequest request = ServletActionContext.getRequest();
21 | if (!isDebug(request)) {
22 | return invocation.invoke();
23 | }
24 |
25 | String method = request.getParameter("method");
26 | String version = request.getParameter("version");
27 | if (StringUtils.isEmpty(method) || StringUtils.isEmpty(version)) {
28 | return invocation.invoke();
29 | }
30 |
31 | request.setAttribute(LogUtils.DEBUG_LOG,
32 | LogUtils.initLog(method + ' ' + version));
33 | return invocation.invoke();
34 | }
35 |
36 | /**
37 | * 是否是BUG模式
38 | *
39 | * @param request
40 | * 请求
41 | * @return 是否是BUG模式
42 | */
43 | public static boolean isDebug(HttpServletRequest request) {
44 | String isDebug = request.getParameter(IS_DEBUG);
45 | return "1".equals(isDebug);
46 | }
47 |
48 | /**
49 | * 在response中设置debug的信息
50 | *
51 | * @param request
52 | * http请求
53 | * @param response
54 | * 结构化response
55 | */
56 | public static void setDebugMsg(HttpServletRequest request, Object response) {
57 | if (request == null || response == null
58 | || !(response instanceof RopResponse)) {
59 | return;
60 | }
61 | if (isDebug(request)) {
62 | RopResponse> ropResponse = (RopResponse>) response;
63 | LogStack root = LogUtils.getRootLog();
64 | if (root == null)
65 | return;
66 | LogUtils.endLog(root);
67 | ropResponse.setDebugMsg(root.toString());
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/rop-war/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | Archetype Created Web Application
7 |
8 | contextConfigLocation
9 | classpath:/context/*.xml
10 |
11 |
12 | log4jConfigLocation
13 |
14 | classpath:/properties/log4j.properties
15 |
16 |
17 |
18 | com.prowo.system.SystemInitListener
19 |
20 |
21 | org.springframework.web.context.ContextLoaderListener
22 |
23 |
24 | org.springframework.web.util.Log4jConfigListener
25 |
26 |
27 | encodingFilter
28 | org.springframework.web.filter.CharacterEncodingFilter
29 |
30 | encoding
31 | UTF-8
32 |
33 |
34 | forceEncoding
35 | true
36 |
37 |
38 |
39 | struts2
40 | org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
41 |
42 |
43 | struts2
44 | *.do
45 | REQUEST
46 | FORWARD
47 |
48 |
49 | baseAccessFilter
50 | org.springframework.web.filter.DelegatingFilterProxy
51 |
52 |
53 | baseAccessFilter
54 | /*
55 |
56 |
57 |
58 | remote
59 | org.springframework.web.servlet.DispatcherServlet
60 |
61 | contextConfigLocation
62 | classpath:servlet/*.xml
63 |
64 | 1
65 |
66 |
67 | remote
68 | /remote/*
69 |
70 |
71 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/rop/utils/MediaType.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.utils;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public final class MediaType extends Metadata {
7 |
8 | public MediaType(String name, String description) {
9 | super(name, description);
10 | }
11 |
12 | private static volatile Map _types = null;
13 |
14 | public static final MediaType APPLICATION_ALL_XML = register(
15 | "application/*+xml", "All application/*+xml documents");
16 |
17 | public static final MediaType APPLICATION_JSON = register(
18 | "application/json", "JavaScript Object Notation document");
19 |
20 | public static final MediaType IMAGE_BMP = register("image/bmp",
21 | "Windows bitmap");
22 |
23 | public static final MediaType IMAGE_GIF = register("image/gif", "GIF image");
24 |
25 | public static final MediaType IMAGE_ICON = register("image/x-icon",
26 | "Windows icon (Favicon)");
27 |
28 | public static final MediaType IMAGE_JPEG = register("image/jpeg",
29 | "JPEG image");
30 |
31 | public static final MediaType IMAGE_PNG = register("image/png", "PNG image");
32 |
33 | public static final MediaType TEXT_HTML = register("text/html",
34 | "HTML document");
35 |
36 | public static final MediaType TEXT_PLAIN = register("text/plain",
37 | "Plain text");
38 |
39 | public static final MediaType TEXT_XML = register("text/xml", "XML text");
40 |
41 | /**
42 | * Returns the known media types map.
43 | *
44 | * @return the known media types map.
45 | */
46 | private static Map getTypes() {
47 | if (_types == null) {
48 | _types = new HashMap();
49 | }
50 | return _types;
51 | }
52 |
53 | public static synchronized MediaType register(String name,
54 | String description) {
55 |
56 | if (!getTypes().containsKey(name)) {
57 | final MediaType type = new MediaType(name, description);
58 | getTypes().put(name, type);
59 | }
60 |
61 | return getTypes().get(name);
62 | }
63 |
64 | public static MediaType valueOf(String name) {
65 | MediaType result = null;
66 |
67 | if ((name != null) && !name.equals("")) {
68 | result = getTypes().get(name);
69 | if (result == null) {
70 | return APPLICATION_JSON;
71 | }
72 | }
73 |
74 | return result;
75 | }
76 |
77 | /**
78 | * Returns the main type.
79 | *
80 | * @return The main type.
81 | */
82 | public String getMainType() {
83 | String result = null;
84 |
85 | if (getName() != null) {
86 | int index = getName().indexOf('/');
87 |
88 | // Some clients appear to use name types without subtypes
89 | if (index == -1) {
90 | index = getName().indexOf(';');
91 | }
92 |
93 | if (index == -1) {
94 | result = getName();
95 | } else {
96 | result = getName().substring(0, index);
97 | }
98 | }
99 |
100 | return result;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/db/mysql/interceptor/Page.java:
--------------------------------------------------------------------------------
1 | package com.prowo.db.mysql.interceptor;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import com.alibaba.fastjson.JSON;
8 |
9 | /**
10 | * @Description 分页
11 | * @author FQ
12 | * @date 2014年9月15日 下午4:44:58
13 | * @version 1.0
14 | */
15 |
16 | public class Page implements Serializable {
17 |
18 | public static final int MAX_PAGE_SIZE = 20000;// 每页最大记录数限制
19 |
20 | private int pageNumber = 1;// 当前页码
21 | private int pageSize = 20;// 每页记录数
22 | private int totalCount = 0;// 总记录数
23 | private int pageCount = 0;// 总页数
24 | private Long begDate; // 开始时间
25 | private Long endDate; // 接收时间
26 |
27 | private List resultsContent = new ArrayList();// 对应的当前页记录
28 |
29 |
30 | public Integer getPageNumber() {
31 | return pageNumber;
32 | }
33 |
34 | public void setPageNumber(Integer pageNumber) {
35 | if (pageNumber < 1)
36 | this.pageNumber = 1;
37 | else
38 | this.pageNumber = pageNumber;
39 | }
40 |
41 | public Integer getPageSize() {
42 | return pageSize;
43 | }
44 |
45 | public void setPageSize(Integer pageSize) {
46 | if (pageSize < 1) {
47 | pageSize = 1;
48 | } else if (pageSize > MAX_PAGE_SIZE) {
49 | pageSize = MAX_PAGE_SIZE;
50 | }
51 | this.pageSize = pageSize;
52 | }
53 |
54 | public Integer getTotalCount() {
55 | return totalCount;
56 | }
57 |
58 | public void setTotalCount(Integer totalCount) {
59 |
60 | this.totalCount = totalCount;
61 |
62 | // 设置总页数的时候计算出对应的总页数,在下面的三目运算中加法拥有更高的优先级,所以最后可以不加括号。
63 | int pageCount = totalCount % pageSize == 0 ? totalCount / pageSize
64 | : totalCount / pageSize + 1;
65 | this.setPageCount(pageCount);
66 | }
67 |
68 | public Integer getPageCount() {
69 | return pageCount;
70 | }
71 |
72 | public void setPageCount(Integer pageCount) {
73 | this.pageCount = pageCount;
74 | }
75 |
76 | public List getResultsContent() {
77 | return resultsContent;
78 | }
79 |
80 | public void setResultsContent(List resultsContent) {
81 | this.resultsContent = resultsContent;
82 | }
83 |
84 | public Long getBegDate() {
85 | return begDate;
86 | }
87 |
88 | public void setBegDate(Long begDate) {
89 | this.begDate = begDate;
90 | }
91 |
92 | public Long getEndDate() {
93 | return endDate;
94 | }
95 |
96 | public void setEndDate(Long endDate) {
97 | this.endDate = endDate;
98 | }
99 |
100 | @Override
101 | public String toString() {
102 | StringBuilder builder = new StringBuilder();
103 | builder.append("Page [pageNumber=").append(pageNumber)
104 | .append(", pageSize=").append(pageSize)
105 | .append(", resultsContent=").append(JSON.toJSONString(resultsContent))
106 | .append(", pageCount=").append(pageCount)
107 | .append(", totalCount=").append(totalCount).append("]");
108 | return builder.toString();
109 | }
110 | }
111 |
112 |
113 |
--------------------------------------------------------------------------------
/rop-api/src/main/java/com/prowo/common/rop/RopResponse.java:
--------------------------------------------------------------------------------
1 | package com.prowo.common.rop;
2 |
3 | import com.alibaba.fastjson.annotation.JSONField;
4 | import com.prowo.common.util.Constant;
5 | import com.prowo.common.util.FastJsonUtils;
6 | import com.prowo.common.util.MD5;
7 |
8 | import java.io.Serializable;
9 | import java.security.NoSuchAlgorithmException;
10 |
11 | public class RopResponse implements Serializable {
12 |
13 | /**
14 | *
15 | */
16 | private static final long serialVersionUID = -6939909168205094440L;
17 |
18 | String code = "";
19 | String message = "";
20 | String errorMessage = "";
21 | String version;
22 | String debugMsg;
23 |
24 | private T data;
25 |
26 | public RopResponse() {
27 |
28 | }
29 |
30 | public RopResponse(String code, String message, String errorMessage) {
31 | // TODO Auto-generated constructor stub
32 | this.code = code;
33 | this.message = message;
34 | this.errorMessage = errorMessage;
35 | }
36 |
37 |
38 | // public String toJson(){
39 | // return "";
40 | // }
41 | public String toString() {
42 | return "";
43 | }
44 |
45 |
46 | public T getData() {
47 | return data;
48 | }
49 |
50 |
51 | public void setData(T data) {
52 | this.data = data;
53 | }
54 |
55 | public String getCode() {
56 | return code;
57 | }
58 |
59 |
60 | public void setCode(String code) {
61 | this.code = code;
62 | }
63 |
64 |
65 | public String getMessage() {
66 | return message;
67 | }
68 |
69 |
70 | public void setMessage(String message) {
71 | this.message = message;
72 | }
73 |
74 |
75 | public String getErrorMessage() {
76 | return errorMessage;
77 | }
78 |
79 |
80 | public void setErrorMessage(String errorMessage) {
81 | this.errorMessage = errorMessage;
82 | }
83 |
84 |
85 | public String getVersion() {
86 | if (getData() != null) {
87 |
88 | Object jsonObjTargetStr = FastJsonUtils.toJson(getData());
89 | String version = "";
90 | try {
91 | version = MD5.encode(jsonObjTargetStr.toString());
92 | this.version = version;
93 | } catch (NoSuchAlgorithmException e) {
94 | // TODO Auto-generated catch block
95 | e.printStackTrace();
96 | }
97 | }
98 | return version;
99 | }
100 |
101 | @JSONField(serialize = false)
102 | public boolean isOk() {
103 | return Constant.CLIENT_ERROR_CODE.OK.getCnName().equals(code);
104 | }
105 |
106 | public void setVersion(String version) {
107 | this.version = version;
108 | }
109 |
110 | public String getDebugMsg() {
111 | return debugMsg;
112 | }
113 |
114 | public void setDebugMsg(String debugMsg) {
115 | this.debugMsg = debugMsg;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/rop-war/src/main/java/com/prowo/rop/intercept/CacheInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.intercept;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.http.HttpServletResponse;
8 |
9 | import org.apache.commons.lang3.StringUtils;
10 | import org.apache.commons.logging.Log;
11 | import org.apache.commons.logging.LogFactory;
12 | import org.apache.struts2.ServletActionContext;
13 |
14 | import com.opensymphony.xwork2.ActionInvocation;
15 | import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
16 | import com.prowo.common.rop.RopRequest;
17 | import com.prowo.common.utils.ZipUtils;
18 | import com.prowo.rop.context.RopContext;
19 | import com.prowo.rop.memcached.MemcachedUtil;
20 | import com.prowo.rop.utils.ServiceMethodHandler;
21 |
22 | /**
23 | * 类描述:缓存
24 | */
25 | public class CacheInterceptor extends AbstractInterceptor {
26 |
27 | private static final long serialVersionUID = 8674873127319932933L;
28 | private static final Log logger = LogFactory.getLog(CacheInterceptor.class);
29 |
30 | public String intercept(ActionInvocation invocation) throws Exception {
31 | try {
32 | RopContext ropContext = (RopContext) invocation
33 | .getInvocationContext().getParameters().get("ropContext");
34 | ServiceMethodHandler handler = ropContext.getServiceHandler();
35 | RopRequest baseRequest = (RopRequest) ropContext.getRequestData()
36 | .getT();
37 | if (handler.isCached() && baseRequest != null
38 | && !baseRequest.isCheckVersion()) {
39 | String cacheKey = baseRequest.getCacheKey();
40 | if (StringUtils.isNotBlank(cacheKey)) {
41 | logger.info("从缓存中取�??...........");
42 | MemcachedUtil memcachedUtil = MemcachedUtil.getInstance();
43 | Object obj = memcachedUtil.get(cacheKey);
44 | if (obj != null) {
45 | String compressedStr = (String) obj;
46 | String dataStr = ZipUtils.gunzip(compressedStr);
47 | if (StringUtils.isNotBlank(dataStr)) {
48 | logger.info("get data from cache success.........");
49 | this.sendAjaxResultByJson(dataStr);
50 | return null;
51 | }
52 | logger.info("缓存失效,有key但没value.........");
53 | }
54 | logger.info("缓存失效............");
55 | }
56 | }
57 | } catch (Exception e) {
58 | logger.info("从缓存中取�?�失�?...........");
59 | return invocation.invoke();
60 | }
61 | return invocation.invoke();
62 | }
63 |
64 | /**
65 | * 发�?�Ajax请求结果json
66 | *
67 | * @throws ServletException
68 | * @throws IOException
69 | */
70 | private void sendAjaxResultByJson(String json) {
71 | this.getResponse().setContentType("application/json;charset=UTF-8");
72 | this.getResponse().setCharacterEncoding("UTF-8");
73 | try {
74 | PrintWriter out = this.getResponse().getWriter();
75 | out.write(json);
76 | out.flush();
77 | out.close();
78 | } catch (Exception e) {
79 | e.printStackTrace();
80 | }
81 | }
82 |
83 | private HttpServletResponse getResponse() {
84 | return ServletActionContext.getResponse();
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/rop-core/src/test/java/com/prowo/test/HelloWorldTest.java:
--------------------------------------------------------------------------------
1 | package com.prowo.test;
2 |
3 | import com.caucho.hessian.client.HessianProxyFactory;
4 | import com.prowo.common.rop.RopRequestBody;
5 | import com.prowo.common.rop.RopResponse;
6 | import com.prowo.common.utils.HttpUtils;
7 | import com.prowo.test.handle.IHelloWorld;
8 | import com.prowo.test.request.RopHelloWorldRequest;
9 | import com.prowo.test.response.RopHelloWorldResponse;
10 |
11 | import java.net.MalformedURLException;
12 | import java.util.HashMap;
13 | import java.util.Map;
14 |
15 | import org.junit.Test;
16 |
17 | public class HelloWorldTest {
18 |
19 | @Test
20 | public void sayHelloTest() {
21 | String url = "http://localhost:8080/rop-war/router/rest.do";
22 |
23 | Map requestMap = new HashMap();
24 | requestMap.put("method", "api.com.test.sayHello");
25 | requestMap.put("version", "1.0.0");
26 | requestMap.put("username", "linan");
27 |
28 | String result = HttpUtils.post(url, requestMap);
29 | System.out.println(result);
30 | }
31 |
32 | @Test
33 | public void sayHelloTest2() throws MalformedURLException {
34 | String url = "http://localhost:8080/rop-war/remote/helloWorldHandler";
35 |
36 | HessianProxyFactory factory = new HessianProxyFactory();
37 | IHelloWorld hello = (IHelloWorld) factory.create(IHelloWorld.class, url);
38 |
39 | RopHelloWorldRequest requestBean = new RopHelloWorldRequest();
40 | requestBean.setUsername("linan");
41 | requestBean.setApiVersion("1.0.0");
42 | requestBean.setMethod("api.com.test.sayHello");
43 |
44 | RopRequestBody request = new RopRequestBody();
45 | request.setT(requestBean);
46 |
47 | RopResponse response = hello.sayHello(request);
48 | System.out.println(response.getData().toString());
49 |
50 | }
51 |
52 | public static void main2() throws MalformedURLException {
53 | // String url =
54 | // "http://10.43.1.138:9990/new-points-war/remote/helloWorldImpl";
55 | HessianProxyFactory factory = new HessianProxyFactory();
56 | // IHelloWorld hello =
57 | // (IHelloWorld)factory.create(IHelloWorld.class,url);
58 | // RopHelloWorldRequest requestBean = new RopHelloWorldRequest();
59 | // RopRequestBody request = new
60 | // RopRequestBody();
61 | // requestBean.setUsername("linan");
62 | // request.setT(requestBean);
63 |
64 | // RopResponse response =hello.sayHello(request);
65 | // System.out.println(response.getData().getContent());
66 |
67 | // HessianProxyFactory factory = new HessianProxyFactory();
68 | // //String url1 =
69 | // "http://10.43.1.138:9990/new-points-war/remote/queryPointsServiceImpl";
70 | // String url1 =
71 | // "http://localhost:8080/new-points-war/remote/queryPointsServiceImpl";
72 | // IQueryPointsService queryPointsService =
73 | // (IQueryPointsService)factory.create(IQueryPointsService.class,url1);
74 | // QueryPointsRopRequest requestBean1 = new QueryPointsRopRequest();
75 | // RopRequestBody request1 = new
76 | // RopRequestBody();
77 | // request1.setT(requestBean1);
78 | // RopResponse response1 =
79 | // queryPointsService.queryPoints(request1);
80 | // System.out.println(response1.getData().toString());
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/rop-common/src/main/java/com/prowo/rop/log/LogStack.java:
--------------------------------------------------------------------------------
1 | package com.prowo.rop.log;
2 |
3 | import org.apache.commons.collections.CollectionUtils;
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class LogStack {
10 |
11 | public enum LogStackType {
12 | PROCEED, END
13 | }
14 |
15 | private Long startTime;
16 |
17 | private Long endTime;
18 |
19 | private String tag;
20 |
21 | private int deep = 1;
22 |
23 | private List texts = new ArrayList();
24 |
25 | private List subLogs;
26 |
27 | private List