wangwei 5 years ago
parent
commit
cf002903ee

+ 0 - 30
assembly.xml

@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
-	<id>distribution</id>
-	<formats>
-		<format>zip</format>
-	</formats>
-	<fileSets>
-		<fileSet>
-			<directory>${project.basedir}/src/main/resources</directory>
-			<outputDirectory>/config</outputDirectory>
-		</fileSet>
-		<fileSet>
-			<directory>${project.basedir}/shell</directory>
-			<excludes>
-				<exclude>start.args</exclude>
-				<exclude>start.vmoptions</exclude>
-			</excludes>
-			<outputDirectory>/</outputDirectory>
-			<fileMode>0777</fileMode>
-		</fileSet>
-	</fileSets>
-	<dependencySets>
-		<dependencySet>
-			<useProjectArtifact>true</useProjectArtifact>
-			<outputDirectory>lib</outputDirectory>
-			<scope>runtime</scope>
-		</dependencySet>
-	</dependencySets>
-</assembly>

+ 0 - 4
jenkins-prod.sh

@@ -1,4 +0,0 @@
-#!/bin/bash
-pwd
-
-cp examcloud-basic-starter/target/examcloud-basic-distribution.zip ~/packages

+ 0 - 18
jenkins-test.sh

@@ -1,18 +0,0 @@
-#!/bin/bash
-pwd
-
-rm -rf ~/project/examcloud/examcloud-basic-distribution.zip
-rm -rf ~/project/examcloud/examcloud-basic/lib/
-
-cp examcloud-basic-starter/target/examcloud-basic-distribution.zip ~/project/examcloud/
-
-cd  ~/project/examcloud/
-unzip -o examcloud-basic-distribution.zip
-
-cd examcloud-basic
-echo "--spring.profiles.active=test --examcloud.startup.configCenterHost=localhost" > start.args
-echo "-server -Xms512m -Xmx512m  -XX:-UseGCOverheadLimit" > start.vmoptions
-
-bash stop.sh
-BUILD_ID=DONTKILLME
-bash start.sh jenkins

+ 0 - 8
src/main/java/cn/com/qmth/examcloud/ws/config/WebSocketConfig.java

@@ -1,8 +0,0 @@
-package cn.com.qmth.examcloud.ws.config;
-
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class WebSocketConfig {
-
-}

+ 21 - 21
src/main/java/cn/com/qmth/examcloud/ws/api/controller/WebSocketController.java → src/main/java/cn/com/qmth/examcloud/ws/starter/api/controller/WebSocketController.java

@@ -1,21 +1,21 @@
-package cn.com.qmth.examcloud.ws.api.controller;
-
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
-import cn.com.qmth.examcloud.web.support.ControllerSupport;
-import cn.com.qmth.examcloud.ws.core.MessageOut;
-
-@RestController
-@RequestMapping("api/ctr/ws")
-public class WebSocketController extends ControllerSupport {
-
-	@RequestMapping(value = {"/", ""}, method = RequestMethod.POST)
-	public MessageOut post(@RequestBody MessageOut messageOut) {
-		
-		return messageOut;
-	}
-
-}
+package cn.com.qmth.examcloud.ws.starter.api.controller;
+
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import cn.com.qmth.examcloud.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.ws.starter.core.MessageOut;
+
+@RestController
+@RequestMapping("api/ctr/ws")
+public class WebSocketController extends ControllerSupport {
+
+	@RequestMapping(value = {"/", ""}, method = RequestMethod.POST)
+	public MessageOut post(@RequestBody MessageOut messageOut) {
+		
+		return messageOut;
+	}
+
+}

+ 22 - 22
src/main/java/cn/com/qmth/examcloud/ws/core/Message.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/Message.java

@@ -1,22 +1,22 @@
-package cn.com.qmth.examcloud.ws.core;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * 接口ID 注解
- *
- * @author WANGWEI
- * @date 2019年3月15日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Target({ElementType.PARAMETER})
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-public @interface Message {
-
-	String value() default "";
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 接口ID 注解
+ *
+ * @author WANGWEI
+ * @date 2019年3月15日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Target({ElementType.PARAMETER})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Message {
+
+	String value() default "";
+}

+ 22 - 22
src/main/java/cn/com/qmth/examcloud/ws/core/MessageHandler.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/MessageHandler.java

@@ -1,22 +1,22 @@
-package cn.com.qmth.examcloud.ws.core;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * 接口ID 注解
- *
- * @author WANGWEI
- * @date 2019年3月15日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Target({ElementType.METHOD, ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-public @interface MessageHandler {
-
-	String value() default "";
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 接口ID 注解
+ *
+ * @author WANGWEI
+ * @date 2019年3月15日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface MessageHandler {
+
+	String value() default "";
+}

+ 97 - 97
src/main/java/cn/com/qmth/examcloud/ws/core/MessageHandlerHolder.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/MessageHandlerHolder.java

@@ -1,97 +1,97 @@
-package cn.com.qmth.examcloud.ws.core;
-
-import java.lang.reflect.Method;
-import java.util.Map;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
-import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-
-import com.google.common.collect.Maps;
-
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
-
-/**
- * 消息处理器 管理器
- *
- * @author WANGWEI
- * @date 2019年11月22日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Component
-@Order(100)
-public class MessageHandlerHolder implements ApplicationRunner {
-
-	private static Map<String, Method> methodMap = Maps.newConcurrentMap();
-
-	private static Map<String, Object> beanMap = Maps.newConcurrentMap();
-
-	public static Method getMethod(String path) {
-		return methodMap.get(path);
-	}
-
-	public static Object getBean(String path) {
-		return beanMap.get(path);
-	}
-
-	@Override
-	public void run(ApplicationArguments args) throws Exception {
-
-		Map<String, Object> map = SpringContextHolder.getApplicationContext()
-				.getBeansWithAnnotation(MessageHandler.class);
-
-		for (Object bean : map.values()) {
-			MessageHandler messageHandlerOfClass = AnnotationUtils.findAnnotation(bean.getClass(),
-					MessageHandler.class);
-			String valueOfClass = messageHandlerOfClass.value();
-
-			Method[] methods = bean.getClass().getDeclaredMethods();
-
-			for (Method method : methods) {
-				MessageHandler messageHandlerOfMethod = method.getAnnotation(MessageHandler.class);
-				if (null == messageHandlerOfMethod) {
-					continue;
-				}
-				String valueOfMethod = messageHandlerOfMethod.value();
-
-				String path = join(valueOfClass, valueOfMethod);
-				methodMap.put(path, method);
-				beanMap.put(path, bean);
-			}
-
-		}
-
-	}
-
-	private String join(String valueOfClass, String valueOfMethod) {
-		valueOfClass = valueOfClass.trim();
-		valueOfMethod = valueOfMethod.trim();
-
-		if (valueOfClass.startsWith("/")) {
-			valueOfClass = valueOfClass.substring(1);
-		}
-		if (valueOfClass.endsWith("/")) {
-			valueOfClass = valueOfClass.substring(0, valueOfClass.length() - 1);
-		}
-		if (valueOfMethod.startsWith("/")) {
-			valueOfMethod = valueOfMethod.substring(1);
-		}
-		if (valueOfMethod.endsWith("/")) {
-			valueOfMethod = valueOfMethod.substring(0, valueOfMethod.length() - 1);
-		}
-
-		if (StringUtils.isNotEmpty(valueOfClass) && StringUtils.isNotEmpty(valueOfMethod)) {
-			return valueOfClass + "/" + valueOfMethod;
-		} else if (StringUtils.isNotEmpty(valueOfClass)) {
-			return valueOfClass;
-		} else if (StringUtils.isNotEmpty(valueOfMethod)) {
-			return valueOfMethod;
-		} else {
-			return "";
-		}
-	}
-
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import com.google.common.collect.Maps;
+
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+
+/**
+ * 消息处理器 管理器
+ *
+ * @author WANGWEI
+ * @date 2019年11月22日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Component
+@Order(100)
+public class MessageHandlerHolder implements ApplicationRunner {
+
+	private static Map<String, Method> methodMap = Maps.newConcurrentMap();
+
+	private static Map<String, Object> beanMap = Maps.newConcurrentMap();
+
+	public static Method getMethod(String path) {
+		return methodMap.get(path);
+	}
+
+	public static Object getBean(String path) {
+		return beanMap.get(path);
+	}
+
+	@Override
+	public void run(ApplicationArguments args) throws Exception {
+
+		Map<String, Object> map = SpringContextHolder.getApplicationContext()
+				.getBeansWithAnnotation(MessageHandler.class);
+
+		for (Object bean : map.values()) {
+			MessageHandler messageHandlerOfClass = AnnotationUtils.findAnnotation(bean.getClass(),
+					MessageHandler.class);
+			String valueOfClass = messageHandlerOfClass.value();
+
+			Method[] methods = bean.getClass().getDeclaredMethods();
+
+			for (Method method : methods) {
+				MessageHandler messageHandlerOfMethod = method.getAnnotation(MessageHandler.class);
+				if (null == messageHandlerOfMethod) {
+					continue;
+				}
+				String valueOfMethod = messageHandlerOfMethod.value();
+
+				String path = join(valueOfClass, valueOfMethod);
+				methodMap.put(path, method);
+				beanMap.put(path, bean);
+			}
+
+		}
+
+	}
+
+	private String join(String valueOfClass, String valueOfMethod) {
+		valueOfClass = valueOfClass.trim();
+		valueOfMethod = valueOfMethod.trim();
+
+		if (valueOfClass.startsWith("/")) {
+			valueOfClass = valueOfClass.substring(1);
+		}
+		if (valueOfClass.endsWith("/")) {
+			valueOfClass = valueOfClass.substring(0, valueOfClass.length() - 1);
+		}
+		if (valueOfMethod.startsWith("/")) {
+			valueOfMethod = valueOfMethod.substring(1);
+		}
+		if (valueOfMethod.endsWith("/")) {
+			valueOfMethod = valueOfMethod.substring(0, valueOfMethod.length() - 1);
+		}
+
+		if (StringUtils.isNotEmpty(valueOfClass) && StringUtils.isNotEmpty(valueOfMethod)) {
+			return valueOfClass + "/" + valueOfMethod;
+		} else if (StringUtils.isNotEmpty(valueOfClass)) {
+			return valueOfClass;
+		} else if (StringUtils.isNotEmpty(valueOfMethod)) {
+			return valueOfMethod;
+		} else {
+			return "";
+		}
+	}
+
+}

+ 16 - 16
src/main/java/cn/com/qmth/examcloud/ws/core/MessageIn.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/MessageIn.java

@@ -1,16 +1,16 @@
-package cn.com.qmth.examcloud.ws.core;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-/**
- * 客户端消息
- *
- * @author WANGWEI
- * @date 2019年11月22日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class MessageIn implements JsonSerializable {
-
-	private static final long serialVersionUID = -3461721988846081124L;
-
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+
+/**
+ * 客户端消息
+ *
+ * @author WANGWEI
+ * @date 2019年11月22日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class MessageIn implements JsonSerializable {
+
+	private static final long serialVersionUID = -3461721988846081124L;
+
+}

+ 76 - 76
src/main/java/cn/com/qmth/examcloud/ws/core/MessageOut.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/MessageOut.java

@@ -1,76 +1,76 @@
-package cn.com.qmth.examcloud.ws.core;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-/**
- * 服务端消息
- *
- * @author WANGWEI
- * @date 2019年11月22日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class MessageOut implements JsonSerializable {
-
-	private static final long serialVersionUID = -2255327250550304236L;
-
-	private String path;
-
-	private int status = 200;
-
-	private String statusCode;
-
-	private String statusDesc;
-
-	private String eventId;
-
-	private Object content;
-
-	public String getPath() {
-		return path;
-	}
-
-	public void setPath(String path) {
-		this.path = path;
-	}
-
-	public int getStatus() {
-		return status;
-	}
-
-	public void setStatus(int status) {
-		this.status = status;
-	}
-
-	public String getStatusCode() {
-		return statusCode;
-	}
-
-	public void setStatusCode(String statusCode) {
-		this.statusCode = statusCode;
-	}
-
-	public String getStatusDesc() {
-		return statusDesc;
-	}
-
-	public void setStatusDesc(String statusDesc) {
-		this.statusDesc = statusDesc;
-	}
-
-	public String getEventId() {
-		return eventId;
-	}
-
-	public void setEventId(String eventId) {
-		this.eventId = eventId;
-	}
-
-	public Object getContent() {
-		return content;
-	}
-
-	public void setContent(Object content) {
-		this.content = content;
-	}
-
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+
+/**
+ * 服务端消息
+ *
+ * @author WANGWEI
+ * @date 2019年11月22日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class MessageOut implements JsonSerializable {
+
+	private static final long serialVersionUID = -2255327250550304236L;
+
+	private String path;
+
+	private int status = 200;
+
+	private String statusCode;
+
+	private String statusDesc;
+
+	private String eventId;
+
+	private Object content;
+
+	public String getPath() {
+		return path;
+	}
+
+	public void setPath(String path) {
+		this.path = path;
+	}
+
+	public int getStatus() {
+		return status;
+	}
+
+	public void setStatus(int status) {
+		this.status = status;
+	}
+
+	public String getStatusCode() {
+		return statusCode;
+	}
+
+	public void setStatusCode(String statusCode) {
+		this.statusCode = statusCode;
+	}
+
+	public String getStatusDesc() {
+		return statusDesc;
+	}
+
+	public void setStatusDesc(String statusDesc) {
+		this.statusDesc = statusDesc;
+	}
+
+	public String getEventId() {
+		return eventId;
+	}
+
+	public void setEventId(String eventId) {
+		this.eventId = eventId;
+	}
+
+	public Object getContent() {
+		return content;
+	}
+
+	public void setContent(Object content) {
+		this.content = content;
+	}
+
+}

+ 108 - 108
src/main/java/cn/com/qmth/examcloud/ws/core/SessionHolder.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/SessionHolder.java

@@ -1,108 +1,108 @@
-package cn.com.qmth.examcloud.ws.core;
-
-import java.util.Map;
-
-import javax.websocket.Session;
-
-import org.apache.commons.io.IOUtils;
-
-import com.google.common.collect.Maps;
-
-/**
- * websocket session管理
- *
- * @author WANGWEI
- * @date 2019年11月22日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class SessionHolder {
-
-	private static final Map<String, Session> ID_SESESION_MAP = Maps.newConcurrentMap();
-
-	private static final Map<Session, String> SESESION_ID_MAP = Maps.newConcurrentMap();
-
-	private static final Map<Session, String> SESSION_KEY_MAP = Maps.newConcurrentMap();
-
-	private static final Map<Session, String> SESSION_TOKEN_MAP = Maps.newConcurrentMap();
-
-	/**
-	 * 重新设置session
-	 *
-	 * @author WANGWEI
-	 * @param path
-	 * @param key
-	 * @param token
-	 * @param session
-	 */
-	public static void setSession(String path, String key, String token, Session session) {
-		String sessionId = key + ":" + path;
-		Session oldSession = ID_SESESION_MAP.get(sessionId);
-		if (null != oldSession && !oldSession.equals(session)) {
-			SESESION_ID_MAP.remove(oldSession);
-			SESSION_KEY_MAP.remove(oldSession);
-			SESSION_TOKEN_MAP.remove(oldSession);
-			IOUtils.closeQuietly(oldSession);
-		}
-
-		ID_SESESION_MAP.put(sessionId, session);
-		SESESION_ID_MAP.put(session, sessionId);
-
-		SESSION_KEY_MAP.put(session, key);
-		SESSION_TOKEN_MAP.put(session, token);
-	}
-
-	/**
-	 * 删除 session
-	 *
-	 * @author WANGWEI
-	 * @param session
-	 */
-	public static void delSession(Session session) {
-		String sessionId = SESESION_ID_MAP.get(session);
-		if (null != sessionId) {
-			ID_SESESION_MAP.remove(sessionId);
-		}
-
-		SESESION_ID_MAP.remove(session);
-		SESSION_KEY_MAP.remove(session);
-		SESSION_TOKEN_MAP.remove(session);
-
-		IOUtils.closeQuietly(session);
-	}
-
-	/**
-	 * 获取 session
-	 *
-	 * @author WANGWEI
-	 * @param path
-	 * @param key
-	 * @return
-	 */
-	public Session getSession(String path, String key) {
-		String sessionId = key + ":" + path;
-		Session session = ID_SESESION_MAP.get(sessionId);
-		return session;
-	}
-
-	/**
-	 * 获取 key
-	 *
-	 * @author WANGWEI
-	 * @param session
-	 * @return
-	 */
-	public static String getKey(Session session) {
-		return SESSION_KEY_MAP.get(session);
-	}
-
-	/**
-	 * 获取 token
-	 *
-	 * @author WANGWEI
-	 * @param session
-	 * @return
-	 */
-	public static String getToken(Session session) {
-		return SESSION_TOKEN_MAP.get(session);
-	}
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+import java.util.Map;
+
+import javax.websocket.Session;
+
+import org.apache.commons.io.IOUtils;
+
+import com.google.common.collect.Maps;
+
+/**
+ * websocket session管理
+ *
+ * @author WANGWEI
+ * @date 2019年11月22日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class SessionHolder {
+
+	private static final Map<String, Session> ID_SESESION_MAP = Maps.newConcurrentMap();
+
+	private static final Map<Session, String> SESESION_ID_MAP = Maps.newConcurrentMap();
+
+	private static final Map<Session, String> SESSION_KEY_MAP = Maps.newConcurrentMap();
+
+	private static final Map<Session, String> SESSION_TOKEN_MAP = Maps.newConcurrentMap();
+
+	/**
+	 * 重新设置session
+	 *
+	 * @author WANGWEI
+	 * @param path
+	 * @param key
+	 * @param token
+	 * @param session
+	 */
+	public static void setSession(String path, String key, String token, Session session) {
+		String sessionId = key + ":" + path;
+		Session oldSession = ID_SESESION_MAP.get(sessionId);
+		if (null != oldSession && !oldSession.equals(session)) {
+			SESESION_ID_MAP.remove(oldSession);
+			SESSION_KEY_MAP.remove(oldSession);
+			SESSION_TOKEN_MAP.remove(oldSession);
+			IOUtils.closeQuietly(oldSession);
+		}
+
+		ID_SESESION_MAP.put(sessionId, session);
+		SESESION_ID_MAP.put(session, sessionId);
+
+		SESSION_KEY_MAP.put(session, key);
+		SESSION_TOKEN_MAP.put(session, token);
+	}
+
+	/**
+	 * 删除 session
+	 *
+	 * @author WANGWEI
+	 * @param session
+	 */
+	public static void delSession(Session session) {
+		String sessionId = SESESION_ID_MAP.get(session);
+		if (null != sessionId) {
+			ID_SESESION_MAP.remove(sessionId);
+		}
+
+		SESESION_ID_MAP.remove(session);
+		SESSION_KEY_MAP.remove(session);
+		SESSION_TOKEN_MAP.remove(session);
+
+		IOUtils.closeQuietly(session);
+	}
+
+	/**
+	 * 获取 session
+	 *
+	 * @author WANGWEI
+	 * @param path
+	 * @param key
+	 * @return
+	 */
+	public Session getSession(String path, String key) {
+		String sessionId = key + ":" + path;
+		Session session = ID_SESESION_MAP.get(sessionId);
+		return session;
+	}
+
+	/**
+	 * 获取 key
+	 *
+	 * @author WANGWEI
+	 * @param session
+	 * @return
+	 */
+	public static String getKey(Session session) {
+		return SESSION_KEY_MAP.get(session);
+	}
+
+	/**
+	 * 获取 token
+	 *
+	 * @author WANGWEI
+	 * @param session
+	 * @return
+	 */
+	public static String getToken(Session session) {
+		return SESSION_TOKEN_MAP.get(session);
+	}
+}

+ 17 - 17
src/main/java/cn/com/qmth/examcloud/ws/core/WebSocketConfig.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/WebSocketConfig.java

@@ -1,17 +1,17 @@
-package cn.com.qmth.examcloud.ws.core;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.socket.config.annotation.EnableWebSocket;
-import org.springframework.web.socket.server.standard.ServerEndpointExporter;
-
-@Configuration
-@EnableWebSocket
-public class WebSocketConfig {
-
-	@Bean
-	public ServerEndpointExporter serverEndpointExporter() {
-		return new ServerEndpointExporter();
-	}
-
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+@Configuration
+@EnableWebSocket
+public class WebSocketConfig {
+
+	@Bean
+	public ServerEndpointExporter serverEndpointExporter() {
+		return new ServerEndpointExporter();
+	}
+
+}

+ 12 - 12
src/main/java/cn/com/qmth/examcloud/ws/core/WebSocketHelper.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/WebSocketHelper.java

@@ -1,12 +1,12 @@
-package cn.com.qmth.examcloud.ws.core;
-
-/**
- * WebSocket helper
- *
- * @author WANGWEI
- * @date 2019年11月22日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class WebSocketHelper {
-
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+/**
+ * WebSocket helper
+ *
+ * @author WANGWEI
+ * @date 2019年11月22日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class WebSocketHelper {
+
+}

+ 249 - 249
src/main/java/cn/com/qmth/examcloud/ws/core/WebSocketServerEndpoint.java → src/main/java/cn/com/qmth/examcloud/ws/starter/core/WebSocketServerEndpoint.java

@@ -1,249 +1,249 @@
-package cn.com.qmth.examcloud.ws.core;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Map;
-
-import javax.websocket.OnClose;
-import javax.websocket.OnError;
-import javax.websocket.OnMessage;
-import javax.websocket.OnOpen;
-import javax.websocket.Session;
-import javax.websocket.server.PathParam;
-import javax.websocket.server.ServerEndpoint;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.springframework.stereotype.Component;
-
-import cn.com.qmth.examcloud.api.commons.security.bean.User;
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
-import cn.com.qmth.examcloud.commons.util.JsonUtil;
-import cn.com.qmth.examcloud.web.redis.RedisClient;
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
-
-/**
- * websocket ServerEndpoint
- *
- * @author WANGWEI
- * @date 2019年11月27日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@ServerEndpoint("/{path}")
-@Component
-public class WebSocketServerEndpoint {
-
-	private static final ExamCloudLog WS_LOG = ExamCloudLogFactory.getLog("WS_LOGGER");
-
-	private static RedisClient redisClient;
-
-	private static RedisClient getRedisClient() {
-		if (null != redisClient) {
-			return redisClient;
-		}
-		redisClient = SpringContextHolder.getBean(RedisClient.class);
-		return redisClient;
-	}
-
-	@OnOpen
-	public void onOpen(Session session, @PathParam("path") String path) {
-
-		if (WS_LOG.isDebugEnabled()) {
-			WS_LOG.debug("[onOpen]. path=" + path + "");
-		}
-
-		MessageOut out = new MessageOut();
-		out.setStatus(200);
-		out.setPath(path);
-
-		Method method = MessageHandlerHolder.getMethod(path);
-		if (null == method) {
-			out.setStatus(500);
-			out.setStatusCode("500");
-			out.setStatusDesc("path is wrong.");
-			sendText(session, path, out);
-			IOUtils.closeQuietly(session);
-			return;
-		}
-
-		String key = getRequestParameter(session, "key");
-		String token = getRequestParameter(session, "token");
-
-		if (StringUtils.isBlank(key)) {
-			WS_LOG.error("[onOpen-FAIL]. path=" + path + ". key is blank");
-			IOUtils.closeQuietly(session);
-			return;
-		}
-		if (StringUtils.isBlank(token)) {
-			WS_LOG.error("[onOpen-FAIL]. path=" + path + ". token is blank");
-			IOUtils.closeQuietly(session);
-			return;
-		}
-
-		User user = getRedisClient().get(key, User.class);
-
-		if (null == user) {
-			out.setStatus(403);
-			out.setStatusCode("403");
-			out.setStatusDesc("no login");
-			sendText(session, path, out);
-			IOUtils.closeQuietly(session);
-			return;
-		} else if (!token.equals(user.getToken())) {
-			out.setStatus(403);
-			out.setStatusCode("403");
-			out.setStatusDesc("token is wrong");
-			sendText(session, path, out);
-			IOUtils.closeQuietly(session);
-			return;
-		}
-
-		out.setStatusCode("200");
-		out.setStatusDesc("success");
-		sendText(session, path, out);
-
-		SessionHolder.setSession(path, user.getKey(), user.getToken(), session);
-	}
-
-	/**
-	 * 发送消息
-	 *
-	 * @author WANGWEI
-	 * @param session
-	 * @param path
-	 * @param message
-	 */
-	private void sendText(Session session, String path, MessageOut out) {
-		try {
-			String message = JsonUtil.toJson(out);
-			if (WS_LOG.isDebugEnabled()) {
-				WS_LOG.error("[sendText]. path=" + path + "; message=" + message);
-			}
-			session.getBasicRemote().sendText(message);
-		} catch (Exception e) {
-			WS_LOG.error("[sendText-FAIL]. path=" + path + "", e);
-			IOUtils.closeQuietly(session);
-			return;
-		}
-	}
-
-	/**
-	 * 获取请求参数
-	 *
-	 * @author WANGWEI
-	 * @param session
-	 * @param key
-	 * @return
-	 */
-	private String getRequestParameter(Session session, String key) {
-		Map<String, List<String>> params = session.getRequestParameterMap();
-		List<String> list = params.get(key);
-
-		if (CollectionUtils.isEmpty(list)) {
-			return null;
-		}
-		String value = StringUtils.join(list, ",");
-		return value;
-	}
-
-	@OnClose
-	public void onClose(Session session, @PathParam("path") String path) {
-		WS_LOG.debug("[onClose]. path=" + path);
-		SessionHolder.delSession(session);
-	}
-
-	@OnMessage
-	public void onMessage(Session session, @PathParam("path") String path, String message) {
-		WS_LOG.debug("[onMessage]. path=" + path + ". message=" + message);
-		String key = SessionHolder.getKey(session);
-		String token = SessionHolder.getToken(session);
-
-		User user = getRedisClient().get(key, User.class);
-
-		MessageOut out = new MessageOut();
-		out.setStatus(200);
-		out.setPath(path);
-
-		if (null == user) {
-			out.setStatus(403);
-			out.setStatusCode("403");
-			out.setStatusDesc("no login");
-			sendText(session, path, out);
-			IOUtils.closeQuietly(session);
-			return;
-		} else if (!token.equals(user.getToken())) {
-			out.setStatus(403);
-			out.setStatusCode("403");
-			out.setStatusDesc("token is wrong");
-			sendText(session, path, out);
-			IOUtils.closeQuietly(session);
-			return;
-		}
-
-		Object result = null;
-		try {
-
-			Method method = MessageHandlerHolder.getMethod(path);
-			Object bean = MessageHandlerHolder.getBean(path);
-
-			Annotation[][] an2 = method.getParameterAnnotations();
-
-			boolean hasMessageParam = false;
-			int messageParamIndex = 0;
-			OUTER : for (int i = 0; i < an2.length; i++) {
-				Annotation[] an1 = an2[i];
-				for (Annotation an : an1) {
-					if (an.annotationType().equals(Message.class)) {
-						hasMessageParam = true;
-						messageParamIndex = i;
-						break OUTER;
-					}
-				}
-			}
-
-			Class<?>[] parameterTypes = method.getParameterTypes();
-			Object[] args = new Object[parameterTypes.length];
-			for (int i = 0; i < parameterTypes.length; i++) {
-				Class<?> curType = parameterTypes[i];
-				if (hasMessageParam && i == messageParamIndex) {
-					args[i] = JsonUtil.fromJson(message, curType);
-					continue;
-				}
-				if (curType.equals(User.class)) {
-					args[i] = user;
-					continue;
-				}
-			}
-
-			result = method.invoke(bean, args);
-
-			out.setStatusCode("200");
-			out.setStatusDesc("success");
-			out.setContent(result);
-
-		} catch (StatusException e) {
-			WS_LOG.error("[onMessage-FAIL]. path=" + path + "", e);
-			out.setStatus(500);
-			out.setStatusCode(e.getCode());
-			out.setStatusDesc(e.getDesc());
-		} catch (Exception e) {
-			WS_LOG.error("[onMessage-FAIL]. path=" + path + "", e);
-			out.setStatus(500);
-			out.setStatusCode("500");
-			out.setStatusDesc("系统异常");
-		}
-
-		sendText(session, path, out);
-	}
-
-	@OnError
-	public void onError(Session session, @PathParam("path") String path, Throwable t) {
-		WS_LOG.error("[onError]. path=" + path, t);
-		SessionHolder.delSession(session);
-	}
-
-}
+package cn.com.qmth.examcloud.ws.starter.core;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+
+import javax.websocket.OnClose;
+import javax.websocket.OnError;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
+import javax.websocket.Session;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Component;
+
+import cn.com.qmth.examcloud.api.commons.security.bean.User;
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
+import cn.com.qmth.examcloud.web.redis.RedisClient;
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+
+/**
+ * websocket ServerEndpoint
+ *
+ * @author WANGWEI
+ * @date 2019年11月27日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@ServerEndpoint("/{path}")
+@Component
+public class WebSocketServerEndpoint {
+
+	private static final ExamCloudLog WS_LOG = ExamCloudLogFactory.getLog("WS_LOGGER");
+
+	private static RedisClient redisClient;
+
+	private static RedisClient getRedisClient() {
+		if (null != redisClient) {
+			return redisClient;
+		}
+		redisClient = SpringContextHolder.getBean(RedisClient.class);
+		return redisClient;
+	}
+
+	@OnOpen
+	public void onOpen(Session session, @PathParam("path") String path) {
+
+		if (WS_LOG.isDebugEnabled()) {
+			WS_LOG.debug("[onOpen]. path=" + path + "");
+		}
+
+		MessageOut out = new MessageOut();
+		out.setStatus(200);
+		out.setPath(path);
+
+		Method method = MessageHandlerHolder.getMethod(path);
+		if (null == method) {
+			out.setStatus(500);
+			out.setStatusCode("500");
+			out.setStatusDesc("path is wrong.");
+			sendText(session, path, out);
+			IOUtils.closeQuietly(session);
+			return;
+		}
+
+		String key = getRequestParameter(session, "key");
+		String token = getRequestParameter(session, "token");
+
+		if (StringUtils.isBlank(key)) {
+			WS_LOG.error("[onOpen-FAIL]. path=" + path + ". key is blank");
+			IOUtils.closeQuietly(session);
+			return;
+		}
+		if (StringUtils.isBlank(token)) {
+			WS_LOG.error("[onOpen-FAIL]. path=" + path + ". token is blank");
+			IOUtils.closeQuietly(session);
+			return;
+		}
+
+		User user = getRedisClient().get(key, User.class);
+
+		if (null == user) {
+			out.setStatus(403);
+			out.setStatusCode("403");
+			out.setStatusDesc("no login");
+			sendText(session, path, out);
+			IOUtils.closeQuietly(session);
+			return;
+		} else if (!token.equals(user.getToken())) {
+			out.setStatus(403);
+			out.setStatusCode("403");
+			out.setStatusDesc("token is wrong");
+			sendText(session, path, out);
+			IOUtils.closeQuietly(session);
+			return;
+		}
+
+		out.setStatusCode("200");
+		out.setStatusDesc("success");
+		sendText(session, path, out);
+
+		SessionHolder.setSession(path, user.getKey(), user.getToken(), session);
+	}
+
+	/**
+	 * 发送消息
+	 *
+	 * @author WANGWEI
+	 * @param session
+	 * @param path
+	 * @param message
+	 */
+	private void sendText(Session session, String path, MessageOut out) {
+		try {
+			String message = JsonUtil.toJson(out);
+			if (WS_LOG.isDebugEnabled()) {
+				WS_LOG.error("[sendText]. path=" + path + "; message=" + message);
+			}
+			session.getBasicRemote().sendText(message);
+		} catch (Exception e) {
+			WS_LOG.error("[sendText-FAIL]. path=" + path + "", e);
+			IOUtils.closeQuietly(session);
+			return;
+		}
+	}
+
+	/**
+	 * 获取请求参数
+	 *
+	 * @author WANGWEI
+	 * @param session
+	 * @param key
+	 * @return
+	 */
+	private String getRequestParameter(Session session, String key) {
+		Map<String, List<String>> params = session.getRequestParameterMap();
+		List<String> list = params.get(key);
+
+		if (CollectionUtils.isEmpty(list)) {
+			return null;
+		}
+		String value = StringUtils.join(list, ",");
+		return value;
+	}
+
+	@OnClose
+	public void onClose(Session session, @PathParam("path") String path) {
+		WS_LOG.debug("[onClose]. path=" + path);
+		SessionHolder.delSession(session);
+	}
+
+	@OnMessage
+	public void onMessage(Session session, @PathParam("path") String path, String message) {
+		WS_LOG.debug("[onMessage]. path=" + path + ". message=" + message);
+		String key = SessionHolder.getKey(session);
+		String token = SessionHolder.getToken(session);
+
+		User user = getRedisClient().get(key, User.class);
+
+		MessageOut out = new MessageOut();
+		out.setStatus(200);
+		out.setPath(path);
+
+		if (null == user) {
+			out.setStatus(403);
+			out.setStatusCode("403");
+			out.setStatusDesc("no login");
+			sendText(session, path, out);
+			IOUtils.closeQuietly(session);
+			return;
+		} else if (!token.equals(user.getToken())) {
+			out.setStatus(403);
+			out.setStatusCode("403");
+			out.setStatusDesc("token is wrong");
+			sendText(session, path, out);
+			IOUtils.closeQuietly(session);
+			return;
+		}
+
+		Object result = null;
+		try {
+
+			Method method = MessageHandlerHolder.getMethod(path);
+			Object bean = MessageHandlerHolder.getBean(path);
+
+			Annotation[][] an2 = method.getParameterAnnotations();
+
+			boolean hasMessageParam = false;
+			int messageParamIndex = 0;
+			OUTER : for (int i = 0; i < an2.length; i++) {
+				Annotation[] an1 = an2[i];
+				for (Annotation an : an1) {
+					if (an.annotationType().equals(Message.class)) {
+						hasMessageParam = true;
+						messageParamIndex = i;
+						break OUTER;
+					}
+				}
+			}
+
+			Class<?>[] parameterTypes = method.getParameterTypes();
+			Object[] args = new Object[parameterTypes.length];
+			for (int i = 0; i < parameterTypes.length; i++) {
+				Class<?> curType = parameterTypes[i];
+				if (hasMessageParam && i == messageParamIndex) {
+					args[i] = JsonUtil.fromJson(message, curType);
+					continue;
+				}
+				if (curType.equals(User.class)) {
+					args[i] = user;
+					continue;
+				}
+			}
+
+			result = method.invoke(bean, args);
+
+			out.setStatusCode("200");
+			out.setStatusDesc("success");
+			out.setContent(result);
+
+		} catch (StatusException e) {
+			WS_LOG.error("[onMessage-FAIL]. path=" + path + "", e);
+			out.setStatus(500);
+			out.setStatusCode(e.getCode());
+			out.setStatusDesc(e.getDesc());
+		} catch (Exception e) {
+			WS_LOG.error("[onMessage-FAIL]. path=" + path + "", e);
+			out.setStatus(500);
+			out.setStatusCode("500");
+			out.setStatusDesc("系统异常");
+		}
+
+		sendText(session, path, out);
+	}
+
+	@OnError
+	public void onError(Session session, @PathParam("path") String path, Throwable t) {
+		WS_LOG.error("[onError]. path=" + path, t);
+		SessionHolder.delSession(session);
+	}
+
+}

+ 18 - 18
src/main/java/cn/com/qmth/examcloud/ws/handler/TestHandler.java → src/main/java/cn/com/qmth/examcloud/ws/starter/handler/TestHandler.java

@@ -1,18 +1,18 @@
-package cn.com.qmth.examcloud.ws.handler;
-
-import org.springframework.stereotype.Component;
-
-import cn.com.qmth.examcloud.api.commons.security.bean.User;
-import cn.com.qmth.examcloud.ws.core.Message;
-import cn.com.qmth.examcloud.ws.core.MessageHandler;
-
-@Component
-@MessageHandler("test")
-public class TestHandler {
-
-	@MessageHandler
-	public String test(User user, @Message String message) {
-		return "fuck you";
-	}
-
-}
+package cn.com.qmth.examcloud.ws.starter.handler;
+
+import org.springframework.stereotype.Component;
+
+import cn.com.qmth.examcloud.api.commons.security.bean.User;
+import cn.com.qmth.examcloud.ws.starter.core.Message;
+import cn.com.qmth.examcloud.ws.starter.core.MessageHandler;
+
+@Component
+@MessageHandler("test")
+public class TestHandler {
+
+	@MessageHandler
+	public String test(User user, @Message String message) {
+		return "fuck you";
+	}
+
+}