diff --git a/zheng-notify/pom.xml b/zheng-notify/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..26c3ef70120c684c3afdfd24d78e2d6deb42a7b6 --- /dev/null +++ b/zheng-notify/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + + com.zheng + zheng-notify + 1.0.0 + pom + + zheng-notify + http://www.zhangshuzheng.cn + + + UTF-8 + + 1.7 + 1.7 + 1.7 + + + + zheng-notify-sdk + zheng-notify-server + + diff --git a/zheng-notify/zheng-notify-client/index.html b/zheng-notify/zheng-notify-client/index.html new file mode 100644 index 0000000000000000000000000000000000000000..ea70d7f5966b9084891dcaeecf75b452c20f4f1e --- /dev/null +++ b/zheng-notify/zheng-notify-client/index.html @@ -0,0 +1,83 @@ + + + + + + 管理监控中心 + + + +
+
+
+ + + + + + +
+
+
    +
+
+
+
+ + + + + \ No newline at end of file diff --git a/zheng-notify/zheng-notify-sdk/pom.xml b/zheng-notify/zheng-notify-sdk/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b517216a8be296e9ebbb329825a4051221cb2723 --- /dev/null +++ b/zheng-notify/zheng-notify-sdk/pom.xml @@ -0,0 +1,60 @@ + + 4.0.0 + + + com.zheng + zheng-notify + 1.0.0 + + + zheng-notify-sdk + jar + + zheng-notify-sdk + http://www.zhangshuzheng.cn + + + UTF-8 + + + + + org.apache.httpcomponents + httpclient + 4.5.5 + + + com.alibaba + fastjson + 1.2.47 + + + + + zheng-notify-sdk + + + src/main/java + + **/*.xml + + true + + + src/main/resources + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + true + true + + + + + diff --git a/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/BaseResult.java b/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/BaseResult.java new file mode 100644 index 0000000000000000000000000000000000000000..a18aadfa1376250e72f0c6d3e355d9fb64f8928c --- /dev/null +++ b/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/BaseResult.java @@ -0,0 +1,54 @@ +package com.zheng.notify.sdk; + +/** + * 统一返回结果类 + * Created by shuzheng on 2017/2/18. + */ +public class BaseResult { + + /** + * 状态码:1成功,其他为失败 + */ + public int code; + + /** + * 成功为success,其他为失败原因 + */ + public String message; + + /** + * 数据结果集 + */ + public Object data; + + public BaseResult(int code, String message, Object data) { + this.code = code; + this.message = message; + this.data = data; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + +} diff --git a/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/NotifyConstants.java b/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/NotifyConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..bf2330ac479ff874f0f6abcf6955ff35b794d576 --- /dev/null +++ b/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/NotifyConstants.java @@ -0,0 +1,18 @@ +package com.zheng.notify.sdk; + +/** + * 全局常量 + * Created by shuzheng on 2018/6/28. + */ +public class NotifyConstants { + + // 通知类型:广播 + public static final String PUBLISH_TYPE_BROADCAST = "broadcast"; + + // 通知类型:主题 + public static final String PUBLISH_TYPE_TOPICS = "topics"; + + // 通知类型:点对点 + public static final String PUBLISH_TYPE_CLIENTS = "clients"; + +} diff --git a/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/NotifyHelper.java b/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/NotifyHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..a6cb38ca690d0458d038fd1d00ae36fb58c12ee6 --- /dev/null +++ b/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/NotifyHelper.java @@ -0,0 +1,68 @@ +package com.zheng.notify.sdk; + +import com.alibaba.fastjson.JSONObject; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; + +import java.nio.charset.Charset; + +/** + * 推送工具类 + * Created by shuzheng on 2018/6/28. + */ +public class NotifyHelper { + + /** + * 推送消息 + * @param url + * @param publishDto + * @return + */ + public BaseResult publish(String url, PublishDto publishDto) { + HttpPost httpPost = null; + try { + HttpClient httpClient = new DefaultHttpClient(); + + httpPost = new HttpPost(url); + httpPost.setHeader("Content-type", "application/json; charset=utf-8"); + + HttpEntity httpEntity = new StringEntity(JSONObject.toJSONString(publishDto), "utf-8"); + httpPost.setEntity(httpEntity); + + HttpResponse httpResponse = httpClient.execute(httpPost); + int statusCode = httpResponse.getStatusLine().getStatusCode(); + if (statusCode == HttpStatus.SC_OK) { + HttpEntity resEntity = httpResponse.getEntity(); + if (resEntity != null) { + String result = EntityUtils.toString(resEntity, Charset.forName("utf-8")); + return JSONObject.parseObject(result, BaseResult.class); + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (httpPost != null) { + httpPost.releaseConnection(); + } + } + return new BaseResult(-1, "error", "publish error"); + } + + public static void main(String[] args) { + String url = "http://localhost:8881/notify/publish"; + PublishDto publishDto = new PublishDto(); + publishDto.setType(NotifyConstants.PUBLISH_TYPE_BROADCAST); + publishDto.setNamespace("/demo"); + publishDto.setAccessKey("1"); + publishDto.setPayload("hi"); + BaseResult result = new NotifyHelper().publish(url, publishDto); + System.out.println(result.message); + } + +} diff --git a/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/PublishDto.java b/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/PublishDto.java new file mode 100644 index 0000000000000000000000000000000000000000..08e8a5dadb4b73ed9132792530d5191b36813e7a --- /dev/null +++ b/zheng-notify/zheng-notify-sdk/src/main/java/com/zheng/notify/sdk/PublishDto.java @@ -0,0 +1,76 @@ +package com.zheng.notify.sdk; + + +/** + * 推送消息 + * Created by shuzheng on 2018/6/20. + */ +public class PublishDto { + + // 推送类型:"broadcast/topics/clients" <=> 广播、按主题、点对点 + private String type; + + // 推送命名空间 + private String namespace; + + // 鉴权key + private String accessKey; + + // 推送订阅主题的订阅者 + private String[] topics; + + // 推送客户端 + private String[] clients; + + // 消息体 + private Object payload; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public String[] getTopics() { + return topics; + } + + public void setTopics(String[] topics) { + this.topics = topics; + } + + public String[] getClients() { + return clients; + } + + public void setClients(String[] clients) { + this.clients = clients; + } + + public Object getPayload() { + return payload; + } + + public void setPayload(Object payload) { + this.payload = payload; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + +} diff --git a/zheng-notify/zheng-notify-server/pom.xml b/zheng-notify/zheng-notify-server/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..3067fa6507884a2dc2cb57cf93a55c6b44f456ed --- /dev/null +++ b/zheng-notify/zheng-notify-server/pom.xml @@ -0,0 +1,111 @@ + + 4.0.0 + + + com.zheng + zheng-notify + 1.0.0 + + + zheng-notify-server + jar + + zheng-notify-server + http://www.zhangshuzheng.cn + + + UTF-8 + + + + + com.zheng + zheng-common + 1.0.0 + jar + + + junit + junit + 4.12 + test + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.servlet + jstl + 1.2 + + + + + + dev + + dev + + + true + + + + test + + test + + + + prod + + prod + + + + + + zheng-notify-server + + src/main/resources/profiles/${env}.properties + + + + src/main/resources + true + + + + + + org.eclipse.jetty + jetty-maven-plugin + + 9.2.7.v20150116 + + 3 + + / + + + 8881 + + automatic + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + true + true + + + + + diff --git a/zheng-notify/zheng-notify-server/src/main/java/com/zheng/notify/server/controller/IndexController.java b/zheng-notify/zheng-notify-server/src/main/java/com/zheng/notify/server/controller/IndexController.java new file mode 100644 index 0000000000000000000000000000000000000000..4c80e5b0648c672f2565b9695fc661cd0c2dfb68 --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/java/com/zheng/notify/server/controller/IndexController.java @@ -0,0 +1,26 @@ +package com.zheng.notify.server.controller; + +import com.zheng.common.base.BaseController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * 测试controller + * Created by shuzheng on 2017/2/18. + */ +@Controller +public class IndexController extends BaseController { + + private static final Logger LOGGER = LoggerFactory.getLogger(IndexController.class); + + @RequestMapping(value = "/index", method = RequestMethod.GET) + @ResponseBody + public String index() { + return "index"; + } + +} \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/resources/config.properties b/zheng-notify/zheng-notify-server/src/main/resources/config.properties new file mode 100644 index 0000000000000000000000000000000000000000..63dd02bb5ddb461bbd49ceb335f2b57f20997f4c --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/resources/config.properties @@ -0,0 +1,3 @@ +app.name=${app.name} +env=${profile.env} +zheng.ui.path=${zheng.ui.path} \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/resources/i18n/messages_en_US.properties b/zheng-notify/zheng-notify-server/src/main/resources/i18n/messages_en_US.properties new file mode 100644 index 0000000000000000000000000000000000000000..056877f3f660fcf149a45293a2de75f54644e9ad --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/resources/i18n/messages_en_US.properties @@ -0,0 +1,4 @@ +403=Access forbidden! +404=Page not found! +500=Internal server error! +error=Server error! \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/resources/i18n/messages_zh_CN.properties b/zheng-notify/zheng-notify-server/src/main/resources/i18n/messages_zh_CN.properties new file mode 100644 index 0000000000000000000000000000000000000000..d1c6f76758186aab41c9588f2c9b68864975e162 --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/resources/i18n/messages_zh_CN.properties @@ -0,0 +1,4 @@ +403=\u6CA1\u6709\u6743\u9650\uFF01 +404=\u9875\u9762\u6CA1\u6709\u627E\u5230\uFF01 +500=\u5185\u90E8\u670D\u52A1\u5668\u9519\u8BEF\uFF01 +error=\u670D\u52A1\u5668\u53D1\u751F\u9519\u8BEF\uFF01 \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/resources/log4j.properties b/zheng-notify/zheng-notify-server/src/main/resources/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..d199d8cebf0a7193ce4bc9e7898d366282afe95c --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/resources/log4j.properties @@ -0,0 +1,30 @@ +#off/fatal/error/warn/info/debug/all +log4j.debug=false +log4j.rootLogger=info,stdout,log,errorlog + +# Console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target = System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n + +### Log ### +log4j.appender.log = org.apache.log4j.DailyRollingFileAppender +log4j.appender.log.File = ../logs/zheng-notify-server.log +log4j.appender.log.Append = true +log4j.appender.log.Threshold = DEBUG +log4j.appender.log.DatePattern='.'yyyy-MM-dd +log4j.appender.log.layout = org.apache.log4j.PatternLayout +log4j.appender.log.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %p ] [ %C{1}.java :%L(%M)] %m%n + +### Error ### +log4j.appender.errorlog = org.apache.log4j.DailyRollingFileAppender +log4j.appender.errorlog.File = ../logs/zheng-notify-server.error.log +log4j.appender.errorlog.Append = true +log4j.appender.errorlog.Threshold = ERROR +log4j.appender.errorlog.DatePattern='.'yyyy-MM-dd +log4j.appender.errorlog.layout = org.apache.log4j.PatternLayout +log4j.appender.errorlog.layout.ConversionPattern =%-d{yyyy-MM-dd HH:mm:ss} [ %p ] [ %C{1}.java :%L(%M)] %m%n + +#Spring logging configuration +log4j.category.org.springframework = warn \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/resources/profiles/dev.properties b/zheng-notify/zheng-notify-server/src/main/resources/profiles/dev.properties new file mode 100644 index 0000000000000000000000000000000000000000..f15fe569cedd5bf3913c0d91eef675f3b1e71fbe --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/resources/profiles/dev.properties @@ -0,0 +1,3 @@ +app.name=zheng-notify +profile.env=dev +zheng.ui.path=http://ui.zhangshuzheng.cn:1000/ \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/resources/profiles/prod.properties b/zheng-notify/zheng-notify-server/src/main/resources/profiles/prod.properties new file mode 100644 index 0000000000000000000000000000000000000000..1047706c22cdb4d4132d3dd980f7c5868437a421 --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/resources/profiles/prod.properties @@ -0,0 +1,3 @@ +app.name=zheng-notify +profile.env=prod +zheng.ui.path=http://ui.zhangshuzheng.cn:1000/ \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/resources/profiles/test.properties b/zheng-notify/zheng-notify-server/src/main/resources/profiles/test.properties new file mode 100644 index 0000000000000000000000000000000000000000..30d1129639a8ed7d7fd0da83f4281d598405acd7 --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/resources/profiles/test.properties @@ -0,0 +1,3 @@ +app.name=zheng-notify +profile.env=test +zheng.ui.path=http://ui.zhangshuzheng.cn:1000/ \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/resources/springMVC-servlet.xml b/zheng-notify/zheng-notify-server/src/main/resources/springMVC-servlet.xml new file mode 100644 index 0000000000000000000000000000000000000000..3f302519eef614612153bbdb063d48e42a9ec636 --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/resources/springMVC-servlet.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/zheng-notify/zheng-notify-server/src/main/webapp/WEB-INF/web.xml b/zheng-notify/zheng-notify-server/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..63bd5d0477e7d2f6ef5c09599294e96c4b6d63ca --- /dev/null +++ b/zheng-notify/zheng-notify-server/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,66 @@ + + + + + + CharacterEncodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + + CharacterEncodingFilter + /* + REQUEST + FORWARD + + + + + org.springframework.web.context.ContextLoaderListener + + + contextConfigLocation + + classpath*:applicationContext*.xml + + + + + + log4jConfigLocation + classpath:log4j.properties + + + + + springMVC + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + classpath*:springMVC-servlet.xml + + 1 + true + + + springMVC + / + + + + + 30 + + + + + index.html + + + \ No newline at end of file