|
1
|
package com.crossoverjie.netty.action.client.controller;
|
1
|
package com.crossoverjie.netty.action.client.controller;
|
|
2
|
|
2
|
|
|
3
|
import com.crossoverjie.netty.action.client.HeartbeatClient;
|
3
|
import com.crossoverjie.netty.action.client.HeartbeatClient;
|
|
|
|
4
|
+import com.crossoverjie.netty.action.client.service.RouteRequest;
|
|
4
|
import com.crossoverjie.netty.action.client.vo.req.GoogleProtocolVO;
|
5
|
import com.crossoverjie.netty.action.client.vo.req.GoogleProtocolVO;
|
|
5
|
import com.crossoverjie.netty.action.client.vo.req.SendMsgReqVO;
|
6
|
import com.crossoverjie.netty.action.client.vo.req.SendMsgReqVO;
|
|
6
|
import com.crossoverjie.netty.action.client.vo.req.StringReqVO;
|
7
|
import com.crossoverjie.netty.action.client.vo.req.StringReqVO;
|
|
@@ -11,10 +12,6 @@ import com.crossoverjie.netty.action.common.pojo.CustomProtocol; |
|
@@ -11,10 +12,6 @@ import com.crossoverjie.netty.action.common.pojo.CustomProtocol; |
|
11
|
import com.crossoverjie.netty.action.common.res.BaseResponse;
|
12
|
import com.crossoverjie.netty.action.common.res.BaseResponse;
|
|
12
|
import com.crossoverjie.netty.action.common.res.NULLBody;
|
13
|
import com.crossoverjie.netty.action.common.res.NULLBody;
|
|
13
|
import io.swagger.annotations.ApiOperation;
|
14
|
import io.swagger.annotations.ApiOperation;
|
|
14
|
-import okhttp3.MediaType;
|
|
|
|
15
|
-import okhttp3.OkHttpClient;
|
|
|
|
16
|
-import okhttp3.Request;
|
|
|
|
17
|
-import okhttp3.Response;
|
|
|
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
19
|
import org.springframework.boot.actuate.metrics.CounterService;
|
16
|
import org.springframework.boot.actuate.metrics.CounterService;
|
|
20
|
import org.springframework.stereotype.Controller;
|
17
|
import org.springframework.stereotype.Controller;
|
|
@@ -23,8 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
@@ -23,8 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
23
|
import org.springframework.web.bind.annotation.RequestMethod;
|
20
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
24
|
import org.springframework.web.bind.annotation.ResponseBody;
|
21
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
25
|
|
22
|
|
|
26
|
-import java.io.IOException;
|
|
|
|
27
|
-
|
|
|
|
28
|
/**
|
23
|
/**
|
|
29
|
* Function:
|
24
|
* Function:
|
|
30
|
*
|
25
|
*
|
|
@@ -45,6 +40,11 @@ public class IndexController { |
|
@@ -45,6 +40,11 @@ public class IndexController { |
|
45
|
@Autowired
|
40
|
@Autowired
|
|
46
|
private HeartbeatClient heartbeatClient ;
|
41
|
private HeartbeatClient heartbeatClient ;
|
|
47
|
|
42
|
|
|
|
|
43
|
+
|
|
|
|
44
|
+
|
|
|
|
45
|
+ @Autowired
|
|
|
|
46
|
+ private RouteRequest routeRequest ;
|
|
|
|
47
|
+
|
|
48
|
/**
|
48
|
/**
|
|
49
|
* 向服务端发消息
|
49
|
* 向服务端发消息
|
|
50
|
* @param sendMsgReqVO
|
50
|
* @param sendMsgReqVO
|
|
@@ -128,39 +128,15 @@ public class IndexController { |
|
@@ -128,39 +128,15 @@ public class IndexController { |
|
128
|
@ApiOperation("群发消息")
|
128
|
@ApiOperation("群发消息")
|
|
129
|
@RequestMapping(value = "sendGroupMsg",method = RequestMethod.POST)
|
129
|
@RequestMapping(value = "sendGroupMsg",method = RequestMethod.POST)
|
|
130
|
@ResponseBody
|
130
|
@ResponseBody
|
|
131
|
- public BaseResponse<SendMsgResVO> sendGroupMsg(@RequestBody SendMsgReqVO sendMsgReqVO) throws IOException {
|
|
|
|
132
|
- BaseResponse<SendMsgResVO> res = new BaseResponse();
|
|
|
|
133
|
- OkHttpClient client = new OkHttpClient();
|
|
|
|
134
|
- MediaType MEDIA_TYPE_MARKDOWN
|
|
|
|
135
|
- = MediaType.parse("text/x-markdown; charset=utf-8");
|
|
|
|
136
|
-
|
|
|
|
137
|
- String postBody = ""
|
|
|
|
138
|
- + "Releases\n"
|
|
|
|
139
|
- + "--------\n"
|
|
|
|
140
|
- + "\n"
|
|
|
|
141
|
- + " * _1.0_ May 6, 2013\n"
|
|
|
|
142
|
- + " * _1.1_ June 15, 2013\n"
|
|
|
|
143
|
- + " * _1.2_ August 11, 2013\n";
|
|
|
|
144
|
-
|
|
|
|
145
|
- Request request = new Request.Builder()
|
|
|
|
146
|
- .url("https://api.github.com/markdown/raw")
|
|
|
|
147
|
- .post(okhttp3.RequestBody.create(MEDIA_TYPE_MARKDOWN, postBody))
|
|
|
|
148
|
- .build();
|
|
|
|
149
|
-
|
|
|
|
150
|
- Response response = client.newCall(request).execute();
|
|
|
|
151
|
- if (!response.isSuccessful()){
|
|
|
|
152
|
- throw new IOException("Unexpected code " + response);
|
|
|
|
153
|
- }
|
131
|
+ public BaseResponse sendGroupMsg(@RequestBody SendMsgReqVO sendMsgReqVO) throws Exception {
|
|
|
|
132
|
+ BaseResponse<NULLBody> res = new BaseResponse();
|
|
154
|
|
133
|
|
|
155
|
- System.out.println(response.body().string());
|
134
|
+ routeRequest.sendGroupMsg(sendMsgReqVO.getMsg()) ;
|
|
156
|
|
135
|
|
|
157
|
counterService.increment(Constants.COUNTER_SERVER_PUSH_COUNT);
|
136
|
counterService.increment(Constants.COUNTER_SERVER_PUSH_COUNT);
|
|
158
|
|
137
|
|
|
159
|
- SendMsgResVO sendMsgResVO = new SendMsgResVO() ;
|
|
|
|
160
|
- sendMsgResVO.setMsg("OK") ;
|
|
|
|
161
|
res.setCode(StatusEnum.SUCCESS.getCode()) ;
|
138
|
res.setCode(StatusEnum.SUCCESS.getCode()) ;
|
|
162
|
res.setMessage(StatusEnum.SUCCESS.getMessage()) ;
|
139
|
res.setMessage(StatusEnum.SUCCESS.getMessage()) ;
|
|
163
|
- res.setDataBody(sendMsgResVO) ;
|
|
|
|
164
|
return res ;
|
140
|
return res ;
|
|
165
|
}
|
141
|
}
|
|
166
|
} |
142
|
} |