urlMap) {
48 | this.urlMap = urlMap;
49 | }
50 |
51 | public String getContextPath() {
52 | return contextPath;
53 | }
54 |
55 | public void setContextPath(String contextPath) {
56 | this.contextPath = contextPath;
57 | }
58 |
59 | public void recordServletMap(String classname, String url) {
60 | if (urlMap == null) urlMap = new ArrayList<>();
61 | if (!__serlvetCache.containsKey(classname)) {
62 | ServletMapping servletMapping = new ServletMapping(classname, new ArrayList<>());
63 | servletMapping.addPath(url);
64 | __serlvetCache.put(classname, servletMapping);
65 | urlMap.add(servletMapping);
66 | } else {
67 | __serlvetCache.get(classname).addPath(url);
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/mapping/MiddlewareMapping.java:
--------------------------------------------------------------------------------
1 | package router.mapping;
2 |
3 | import router.type.MiddlewareType;
4 |
5 | import java.util.*;
6 |
7 | public class MiddlewareMapping {
8 |
9 | private MiddlewareType type;
10 |
11 | /**
12 | * virtual path
13 | * eg: http://127.0.0.1:8080/
14 | *
15 | * virtual path is "/"
16 | */
17 | private String virtualPath;
18 |
19 | /**
20 | * The real path of webroot in the operating system
21 | */
22 | private String physicalPath;
23 |
24 | private String version;
25 |
26 |
27 | private List servletMap;
28 |
29 |
30 | private List filtersMap;
31 |
32 | private HashMap __serlvetCache = new HashMap<>();
33 | private static Integer __filterPos = 0;
34 |
35 | public MiddlewareMapping() {
36 | version = "UNKNOWN";
37 | servletMap = new ArrayList<>();
38 | filtersMap = new ArrayList<>();
39 | }
40 |
41 |
42 | public MiddlewareType getType() {
43 | return type;
44 | }
45 |
46 | public void setType(MiddlewareType type) {
47 | this.type = type;
48 | }
49 |
50 | public String getVirtualPath() {
51 | return virtualPath;
52 | }
53 |
54 | public void setVirtualPath(String virtualPath) {
55 | this.virtualPath = virtualPath;
56 | }
57 |
58 | public String getPhysicalPath() {
59 | return physicalPath;
60 | }
61 |
62 | public void setPhysicalPath(String physicalPath) {
63 | this.physicalPath = physicalPath;
64 | }
65 |
66 | public List getServletMap() {
67 | return servletMap;
68 | }
69 |
70 | public void coverAllServlet(List servletMap) {
71 | this.servletMap = servletMap;
72 | }
73 |
74 | public List getFilterMap() {
75 | return filtersMap;
76 | }
77 |
78 | public void recordFilterMap(FilterMapping filter) {
79 | if (filtersMap == null) filtersMap = new ArrayList();
80 | filter.setPriority(__filterPos);
81 | __filterPos++;
82 | filtersMap.add(filter);
83 | }
84 |
85 | public void coverAllFilter(List filterMappings) {
86 | filtersMap = filterMappings;
87 | }
88 |
89 |
90 | public String getVersion() {
91 | return version;
92 | }
93 |
94 | public void setVersion(String version) {
95 | if (version != null) {
96 | this.version = version;
97 | }
98 | }
99 |
100 |
101 | public void recordServletMap(String classname, String url) {
102 | if (servletMap == null) servletMap = new ArrayList<>();
103 | if (!__serlvetCache.containsKey(classname)) {
104 | ServletMapping servletMapping = new ServletMapping(classname, new ArrayList<>());
105 | servletMapping.addPath(url);
106 | __serlvetCache.put(classname, servletMapping);
107 | servletMap.add(servletMapping);
108 | } else {
109 | __serlvetCache.get(classname).addPath(url);
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/mapping/ServletMapping.java:
--------------------------------------------------------------------------------
1 | package router.mapping;
2 |
3 | import java.util.List;
4 |
5 | public class ServletMapping {
6 | public String classname;
7 | public List path;
8 |
9 | public ServletMapping(String name, List path) {
10 | this.classname = name;
11 | this.path = path;
12 | }
13 |
14 | public String getClassname() {
15 | return classname;
16 | }
17 |
18 | public void setClassname(String classname) {
19 | this.classname = classname;
20 | }
21 |
22 | public List getPath() {
23 | return path;
24 | }
25 |
26 | public void setPath(List path) {
27 | this.path = path;
28 | }
29 |
30 | public void addPath(String path) {
31 | if (!this.path.contains(path)) {
32 | this.path.add(path);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/middleware/JettyMiddleware.java:
--------------------------------------------------------------------------------
1 | package router.middleware;
2 |
3 | import router.analysts.ArrayAnalysts;
4 | import router.analysts.IAnalysts;
5 | import router.context.Context;
6 | import router.mapping.FilterMapping;
7 | import router.mapping.MiddlewareMapping;
8 | import router.except.MiddleWareError;
9 | import router.handler.BreakPointHandler;
10 | import router.parse.UrlParse;
11 | import router.pipeline.FilterPipeLine;
12 | import router.pipeline.ServletPipeLine;
13 | import router.publish.EndEvent;
14 | import router.publish.EventType;
15 | import router.publish.StartEvent;
16 | import router.type.MiddlewareType;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 | public class JettyMiddleware implements BreakPointHandler {
22 | @Override
23 | public void handlerTarget(IAnalysts thisObject, Context context) throws MiddleWareError {
24 | try {
25 | MiddlewareMapping jetty = new MiddlewareMapping();
26 | jetty.setType(MiddlewareType.Jetty);
27 | // set virtual path / root path
28 | setContextPath(jetty, thisObject);
29 | setVersion(thisObject, jetty);
30 | IAnalysts servletHandlerRef = thisObject.getObjFields("_servletHandler");
31 | context.getPublish().Event(new StartEvent(EventType.MiddlewareContextCount,
32 | servletHandlerRef.getId(), getHandlerName().name(), 1));
33 |
34 | setServletMapping(servletHandlerRef, jetty, context);
35 | setFilterMapping(servletHandlerRef, jetty, context);
36 | context.pushMiddleware(jetty);
37 | context.getPublish().Event(
38 | new EndEvent(EventType.MiddlewareContextAnalystsComplete, servletHandlerRef.getId(), "jetty完成分析"));
39 | } catch (Exception e) {
40 | throw MiddleWareError.JettyError(e.getMessage());
41 | }
42 | }
43 |
44 | private void setVersion(IAnalysts thisObject, MiddlewareMapping jettyRecord) {
45 | String packageVersion = thisObject.getPackageVersion(thisObject.getClassName());
46 | jettyRecord.setVersion(packageVersion);
47 | }
48 |
49 | private void setFilterMapping(IAnalysts servletHandlerRef, MiddlewareMapping jetty, Context context) throws Exception {
50 | ArrayAnalysts filterArrayRef = new ArrayAnalysts(servletHandlerRef.getObjFields("_filterMappings"));
51 | context.getPublish().Event(new StartEvent(EventType.FilterCount, filterArrayRef.getId(), filterArrayRef.getClassName(), filterArrayRef.size()));
52 | for (IAnalysts filterMapRef : filterArrayRef) {
53 | String className = filterMapRef.getObjFields("_holder", "_className").convertToString();
54 | ArrayAnalysts pathsRef = new ArrayAnalysts(filterMapRef.getObjFields("_pathSpecs"));
55 | for (IAnalysts pathRef : pathsRef) {
56 | String path = pathRef.convertToString();
57 | IAnalysts instance = filterMapRef.getObjFields("_holder", "_filter");
58 | UrlParse urlParse = UrlParse.getMiddlewareParse(jetty.getVirtualPath(), path);
59 | FilterPipeLine.doFilter(urlParse, instance, context);
60 | jetty.recordFilterMap(new FilterMapping(className, UrlParse.concatSubPath(jetty.getVirtualPath(), path)));
61 | context.getPublish().Event(new EndEvent(EventType.FilterAnalystsComplete, filterArrayRef.getId(), className));
62 | }
63 | }
64 | }
65 |
66 | private void setContextPath(MiddlewareMapping jettyRecord, IAnalysts thisObject) throws Exception {
67 | String path = thisObject.getStrFields("_contextPath");
68 | jettyRecord.setVirtualPath(path);
69 | IAnalysts baseResourceRef = thisObject.getObjFields("_baseResource");
70 | if (baseResourceRef.getClassName().equals("org.eclipse.jetty.util.resource.PathResource")) {
71 | String rootPath = baseResourceRef.getObjFields("path", "path").convertToString();
72 | jettyRecord.setPhysicalPath(rootPath);
73 | }
74 | }
75 |
76 | private void setServletMapping(IAnalysts servletHandlerRef, MiddlewareMapping jetty, Context context) throws Exception {
77 | ArrayAnalysts servletsRef = new ArrayAnalysts(servletHandlerRef.getObjFields("_servlets"));
78 | HashMap servletMappings = getAliasHashMap(jetty, servletHandlerRef.getObjFields("_servletMappings"));
79 | context.getPublish().Event(new StartEvent(EventType.ServletCount, servletsRef.getId(), servletsRef.getClassName(), servletsRef.size()));
80 | for (IAnalysts servletHolderRef : servletsRef) {
81 | String alias = servletHolderRef.getStrFields("_name");
82 | String className = servletHolderRef.getStrFields("_className");
83 | IAnalysts servletWrapperRef = servletHolderRef.getObjFields("_servlet");
84 | if (servletWrapperRef.isObjRef()) {
85 | ServletPipeLine.initServlet(MiddlewareType.Jetty, servletHolderRef, null);
86 | servletWrapperRef = servletHolderRef.getObjFields("_servlet");
87 | }
88 | UrlParse[] urlParses = servletMappings.entrySet().stream().filter(elem -> elem.getValue().equals(alias)).map(Map.Entry::getKey).toArray(UrlParse[]::new);
89 | for (UrlParse urlParse : urlParses) {
90 | if (!servletWrapperRef.isObjRef()) {
91 | IAnalysts wrappedServletRef = servletWrapperRef.getObjFields("_wrappedServlet");
92 | IAnalysts attributesRef = servletHandlerRef.getObjFields("_servletContext", "_map", "value");
93 | ServletPipeLine.handlerServlet(urlParse, wrappedServletRef, attributesRef, context);
94 | }
95 | jetty.recordServletMap(className, urlParse.getPath());
96 | context.getPublish().Event(new EndEvent(EventType.ServletAnalystsComplete, servletsRef.getId(), className));
97 | }
98 | }
99 | }
100 |
101 |
102 | private HashMap getAliasHashMap(MiddlewareMapping middlewareMapping, IAnalysts servletMappingsRef) throws Exception {
103 | HashMap result = new HashMap<>();
104 | ArrayAnalysts servletsMapRef = new ArrayAnalysts(servletMappingsRef);
105 | for (IAnalysts servletMapRef : servletsMapRef) {
106 | IAnalysts pathSpecsRef = servletMapRef.getObjFields("_pathSpecs");
107 | String name = servletMapRef.getStrFields("_servletName");
108 | ArrayAnalysts pathsRef = new ArrayAnalysts(pathSpecsRef);
109 | for (IAnalysts pathRef : pathsRef) {
110 | String path = pathRef.convertToString();
111 | UrlParse urlRecord = UrlParse.getMiddlewareParse(middlewareMapping.getVirtualPath(), path);
112 | result.put(urlRecord, name);
113 | }
114 | }
115 | return result;
116 | }
117 |
118 | @Override
119 | public MiddlewareType getHandlerName() {
120 | return MiddlewareType.Jetty;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/parse/UrlParse.java:
--------------------------------------------------------------------------------
1 | package router.parse;
2 |
3 |
4 | import java.util.Objects;
5 |
6 | public class UrlParse {
7 | private UrlType urlType;
8 | private String virtualPath;
9 | private String basePath;
10 | public boolean frameworkMode;
11 |
12 | public UrlParse(UrlType urlType, String virtualPath, String basePath) {
13 | this.urlType = urlType;
14 | this.virtualPath = virtualPath;
15 | this.basePath = basePath;
16 | }
17 |
18 | public UrlType getUrlType() {
19 | return urlType;
20 | }
21 |
22 | public void setUrlType(UrlType urlType) {
23 | this.urlType = urlType;
24 | }
25 |
26 | public String getVirtualPath() {
27 | return virtualPath;
28 | }
29 |
30 | public void setVirtualPath(String virtualPath) {
31 | this.virtualPath = virtualPath;
32 | }
33 |
34 | public String getBasePath() {
35 | return basePath;
36 | }
37 |
38 | public void setBasePath(String basePath) {
39 | this.basePath = basePath;
40 | }
41 |
42 | public boolean isFrameworkMode() {
43 | return frameworkMode;
44 | }
45 |
46 | public void setFrameworkMode(boolean frameworkMode) {
47 | this.frameworkMode = frameworkMode;
48 | }
49 |
50 | public String getPath() {
51 | switch (urlType) {
52 | case EXACT:
53 | case WILD:
54 | return concatSubPath(virtualPath, "/", basePath );
55 | case EXT:
56 | return concatSubPath(virtualPath, "/*" + basePath);
57 | default:
58 | return "";
59 | }
60 | }
61 |
62 | public String getPathByMiddleware(String path){
63 | if (virtualPath.equals("")) {
64 | virtualPath = "/";
65 | }
66 | switch (getUrlType()) {
67 | case EXACT:
68 | return concatSubPath(getVirtualPath(), getBasePath());
69 | case EXT:
70 | return concatSubPath(getVirtualPath(), path + "." + getBasePath());
71 | case WILD:
72 | return concatSubPath(getVirtualPath(), getBasePath(), path);
73 | default:
74 | if (frameworkMode) {
75 | return concatSubPath("", path);
76 | } else {
77 | return "";
78 | }
79 | }
80 | }
81 |
82 | public static String concatSubPath(String... paths) {
83 | StringBuffer result = new StringBuffer();
84 | for (String path : paths) {
85 | result.append(path);
86 | }
87 | String goodPath = result.toString();
88 | while (goodPath.contains("\\")) {
89 | goodPath = goodPath.replaceAll("\\\\", "/");
90 | }
91 | while (goodPath.contains("//")) {
92 | goodPath = goodPath.replaceAll("//", "/");
93 | }
94 | return goodPath;
95 | }
96 |
97 | public static UrlParse getMiddlewareParse(String virtualPath, String path){
98 | if (path.contains("*")) {
99 | if (path.startsWith("*.")) {
100 | return new UrlParse(UrlType.EXT, virtualPath, path.substring(2));
101 | } else {
102 | return new UrlParse(UrlType.WILD, virtualPath, path.substring(0, path.length() - 1));
103 | }
104 | } else {
105 | return new UrlParse(UrlType.EXACT, virtualPath, path);
106 | }
107 | }
108 |
109 |
110 | @Override
111 | public boolean equals(Object o) {
112 | if (this == o) return true;
113 | if (o == null || getClass() != o.getClass()) return false;
114 | UrlParse urlRecord = (UrlParse) o;
115 | return Objects.equals(virtualPath, urlRecord.virtualPath) && Objects.equals(basePath, urlRecord.basePath);
116 | }
117 |
118 | @Override
119 | public int hashCode() {
120 | return Objects.hash(virtualPath, basePath);
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/parse/UrlType.java:
--------------------------------------------------------------------------------
1 | package router.parse;
2 |
3 | public enum UrlType {
4 | DEFAULT,
5 | EXACT,
6 | WILD,
7 | EXT
8 | }
--------------------------------------------------------------------------------
/server/core/src/main/java/router/pipeline/FilterPipeLine.java:
--------------------------------------------------------------------------------
1 | package router.pipeline;
2 |
3 | import router.analysts.IAnalysts;
4 | import router.context.Context;
5 | import router.handler.Struts2Handler;
6 | import router.parse.UrlParse;
7 |
8 | public class FilterPipeLine {
9 | public static boolean doFilter(UrlParse urlParse, IAnalysts filterRef, Context context) {
10 | if (filterRef.isInstanceof("org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter") ||
11 | filterRef.isInstanceof("org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter") ||
12 | filterRef.isInstanceof("org.apache.struts2.dispatcher.FilterDispatcher")) {
13 | new Struts2Handler().handler(urlParse, filterRef, context);
14 | }
15 | return true;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/pipeline/ServletPipeLine.java:
--------------------------------------------------------------------------------
1 | package router.pipeline;
2 |
3 | import router.analysts.IAnalysts;
4 | import router.analysts.MapAnalysts;
5 | import router.context.Context;
6 | import router.handler.*;
7 | import router.parse.UrlParse;
8 | import router.type.MiddlewareType;
9 |
10 | public class ServletPipeLine {
11 | public static IAnalysts initServlet(MiddlewareType type, IAnalysts servletWrapperRef, IAnalysts classLoader) {
12 | switch (type) {
13 | case Tomcat:
14 | try {
15 | IAnalysts currentThreadClassLoader = servletWrapperRef.getCurrentThreadClassLoader();
16 | servletWrapperRef.changeThreadClassLoader(classLoader);
17 | IAnalysts result = servletWrapperRef.invokeMethod("allocate");
18 | servletWrapperRef.invokeMethod("unload");
19 | servletWrapperRef.changeThreadClassLoader(currentThreadClassLoader);
20 | return result;
21 | }catch (Exception e){
22 | return null;
23 | }
24 | case Jetty:
25 | try {
26 | // jetty9暂时不涉及上下文加载器的问题
27 | return servletWrapperRef.invokeMethod("initServlet");
28 | }catch (Exception e){
29 | return null;
30 | }
31 | default:
32 | return null;
33 | }
34 | }
35 |
36 | public static void handlerServlet(UrlParse urlParse, IAnalysts servletRef, IAnalysts attributeRef, Context context)throws Exception {
37 | if (servletRef.isInstanceof("org.apache.struts.action.ActionServlet")) {
38 | handlerStruts1(urlParse, attributeRef, context);
39 | } else if (servletRef.isInstanceof("org.springframework.web.servlet.DispatcherServlet")) {
40 | new SpringMvcHandler().handler(urlParse, servletRef, context);
41 | } else if (servletRef.isInstanceof("org.glassfish.jersey.servlet.ServletContainer")) {
42 | new Jersey2Handler().handler(urlParse, servletRef, context);
43 | } else if (servletRef.isInstanceof("com.sun.jersey.spi.container.servlet.ServletContainer")) {
44 | new Jersey1Handler().handler(urlParse, servletRef, context);
45 | }
46 | }
47 |
48 | public static void handlerStruts1(UrlParse urlParse, IAnalysts attributeRef, Context context) throws Exception {
49 | MapAnalysts.Entry[] mapInstanceRefs = new MapAnalysts(attributeRef).getKV();
50 | for (MapAnalysts.Entry mapInstanceRef : mapInstanceRefs) {
51 | if (mapInstanceRef.getKey().convertToString().startsWith("org.apache.struts.action.MODULE")) {
52 | new Struts1Handler().handler(urlParse, mapInstanceRef.getValue(), context);
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/EndEvent.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public class EndEvent implements Event {
4 | private EventType eventType;
5 | private Long uniqId;
6 | private String message;
7 |
8 | public EndEvent(EventType eventType, Long uniqId, String message) {
9 | this.eventType = eventType;
10 | this.message = message;
11 | this.uniqId = uniqId;
12 | }
13 |
14 | public String getMessage() {
15 | return message;
16 | }
17 |
18 | public void setMessage(String message) {
19 | this.message = message;
20 | }
21 |
22 | public Long getUniqId() {
23 | return uniqId;
24 | }
25 |
26 | public void setUniqId(Long uniqId) {
27 | this.uniqId = uniqId;
28 | }
29 |
30 | public EventType getEventType() {
31 | return eventType;
32 | }
33 |
34 | public void setEventType(EventType eventType) {
35 | this.eventType = eventType;
36 | }
37 |
38 | @Override
39 | public EventType getType() {
40 | return eventType;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/Error.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public interface Error {
4 | ErrorType getType();
5 | }
6 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/ErrorEvent.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public class ErrorEvent implements Error{
4 | private ErrorType errorType;
5 | private Long uniqId;
6 | private Exception exception;
7 |
8 | public ErrorEvent(ErrorType errorType, Long uniqId, Exception exception) {
9 | this.errorType = errorType;
10 | this.uniqId = uniqId;
11 | this.exception = exception;
12 | }
13 |
14 | public ErrorType getErrorType() {
15 | return errorType;
16 | }
17 |
18 | public void setErrorType(ErrorType errorType) {
19 | this.errorType = errorType;
20 | }
21 |
22 | public Long getUniqId() {
23 | return uniqId;
24 | }
25 |
26 | public void setUniqId(Long uniqId) {
27 | this.uniqId = uniqId;
28 | }
29 |
30 | public Exception getException() {
31 | return exception;
32 | }
33 |
34 | public void setException(Exception exception) {
35 | this.exception = exception;
36 | }
37 |
38 | @Override
39 | public ErrorType getType() {
40 | return errorType;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/ErrorType.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public enum ErrorType {
4 | BreakPointError,
5 | MiddlewareError,
6 | FilterError,
7 | ServletError,
8 | FrameworkError,
9 | Struts1Error,
10 | Struts2Error,
11 | SpringError,
12 | Jersey1Error,
13 | Jersey2Error,
14 | }
15 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/Event.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public interface Event {
4 | EventType getType();
5 | }
6 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/EventType.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public enum EventType {
4 | BreakPointStart,
5 | BreakPointEnd,
6 | MiddlewareContextCount,
7 | MiddlewareContextAnalystsComplete,
8 | FilterCount,
9 | FilterAnalystsComplete,
10 | ServletCount,
11 | ServletAnalystsComplete,
12 | FrameworkContextCount,
13 | FrameworkContextAnalystsComplete,
14 | Jersey1FrameworkCount,
15 | Jersey1FrameworkAnalystsComplete,
16 | Jersey2FrameworkCount,
17 | Jersey2FrameworkAnalystsComplete,
18 | SpringFrameworkCount,
19 | SpringFrameworkAnalystsComplete,
20 | Struts1FrameworkCount,
21 | Struts1FrameworkAnalystsComplete,
22 | Struts2FrameworkCount,
23 | Struts2FrameworkAnalystsComplete,
24 | }
25 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/IPublish.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public interface IPublish {
4 | void Event(Event event);
5 |
6 | // 导致分析无法进行的错误
7 | void Error(Error event);
8 | }
9 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/StartEvent.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public class StartEvent implements Event {
4 | private EventType eventType;
5 | private Long uniqId;
6 | private String taskName;
7 | private Integer taskCount;
8 |
9 | public StartEvent(EventType eventType, Long uniqId, String taskName, Integer taskCount) {
10 | this.eventType = eventType;
11 | this.uniqId = uniqId;
12 | this.taskName = taskName;
13 | this.taskCount = taskCount;
14 | }
15 |
16 | public Long getUniqId() {
17 | return uniqId;
18 | }
19 |
20 | public void setUniqId(Long uniqId) {
21 | this.uniqId = uniqId;
22 | }
23 |
24 | public EventType getEventType() {
25 | return eventType;
26 | }
27 |
28 | public void setEventType(EventType eventType) {
29 | this.eventType = eventType;
30 | }
31 |
32 | public String getTaskName() {
33 | return taskName;
34 | }
35 |
36 | public void setTaskName(String taskName) {
37 | this.taskName = taskName;
38 | }
39 |
40 | public Integer getTaskCount() {
41 | return taskCount;
42 | }
43 |
44 | public void setTaskCount(Integer taskCount) {
45 | this.taskCount = taskCount;
46 | }
47 |
48 | @Override
49 | public EventType getType() {
50 | return eventType;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/publish/StdOutPublish.java:
--------------------------------------------------------------------------------
1 | package router.publish;
2 |
3 | public class StdOutPublish implements IPublish {
4 | public void Event(Event event) {
5 | System.out.println("Router Event[ " + event.toString() + " ]");
6 | }
7 |
8 | public void Error(Error msg) {
9 | System.out.println("Router Error Event: " + msg.toString());
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/type/HandlerType.java:
--------------------------------------------------------------------------------
1 | package router.type;
2 |
3 | public enum HandlerType {
4 | Spring,
5 | Jersey1,
6 | Jersey2,
7 | Strut1,
8 | Strut2
9 | }
--------------------------------------------------------------------------------
/server/core/src/main/java/router/type/MiddlewareType.java:
--------------------------------------------------------------------------------
1 | package router.type;
2 |
3 | public enum MiddlewareType {
4 | Tomcat,
5 | Jetty
6 | }
7 |
--------------------------------------------------------------------------------
/server/core/src/main/java/router/utils/SpringUtils.java:
--------------------------------------------------------------------------------
1 | package router.utils;
2 |
3 | import com.sun.jdi.ObjectReference;
4 | import com.sun.jdi.ThreadReference;
5 | import com.sun.jdi.Value;
6 | import router.analysts.IAnalysts;
7 | import router.analysts.InvokeUtils;
8 | import router.analysts.ObjAnalysts;
9 | import router.analysts.SetAnalysts;
10 |
11 | public class SpringUtils {
12 | /**
13 | * @param handlerRef
14 | * @return
15 | */
16 | public static SetAnalysts getPatternsRef(IAnalysts handlerRef) throws Exception{
17 | if (handlerRef.existFieldByName("mapping", "patternsCondition", "patterns")) {
18 | return new SetAnalysts(handlerRef.getObjFields("mapping", "patternsCondition", "patterns"));
19 | } else if (handlerRef.existFieldByName("mapping", "pathPatternsCondition", "patterns")) {
20 | return new SpringSetAnalysts(handlerRef.getObjFields("mapping", "pathPatternsCondition", "patterns"));
21 | } else {
22 | throw new Exception("No such handler");
23 | }
24 | }
25 |
26 | public static class SpringSetAnalysts extends SetAnalysts {
27 |
28 | public SpringSetAnalysts(IAnalysts obj) {
29 | super(obj);
30 | init(obj.getRawValue());
31 | if (isImplementOf("java.util.Set")) {
32 | return;
33 | }
34 | this.thread = obj.getThreadRawRef();
35 | this.data = InvokeUtils.getSet(thread, (ObjectReference) getRawValue())
36 | .stream()
37 | .map(elem -> new SpringPathPatternObj(ObjAnalysts.parseObject(thread, elem)))
38 | .toArray(ObjAnalysts[]::new);
39 | }
40 | }
41 |
42 | public static class SpringPathPatternObj extends ObjAnalysts {
43 | public SpringPathPatternObj(IAnalysts ref) {
44 | this.init(ref.getRawValue());
45 | this.thread = ref.getThreadRawRef();
46 | }
47 |
48 | @Override
49 | public String convertToString() {
50 | try {
51 | return getStrFields("patternString");
52 | } catch (Exception e) {
53 | return null;
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/server/core/src/test/java/Test.java:
--------------------------------------------------------------------------------
1 | import java.util.HashMap;
2 |
3 | public class Test {
4 | public static void main(String[] args) {
5 | HashMap