|
|
|
package com.crossoverjie.netty.action.client.controller;
|
|
|
|
|
|
|
|
import com.crossoverjie.netty.action.client.HeartbeatClient;
|
|
|
|
import com.crossoverjie.netty.action.client.service.RouteRequest;
|
|
|
|
import com.crossoverjie.netty.action.client.vo.req.GoogleProtocolVO;
|
|
|
|
import com.crossoverjie.netty.action.client.vo.req.SendMsgReqVO;
|
|
|
|
import com.crossoverjie.netty.action.client.vo.req.StringReqVO;
|
|
...
|
...
|
@@ -11,10 +12,6 @@ import com.crossoverjie.netty.action.common.pojo.CustomProtocol; |
|
|
|
import com.crossoverjie.netty.action.common.res.BaseResponse;
|
|
|
|
import com.crossoverjie.netty.action.common.res.NULLBody;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import okhttp3.MediaType;
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
import okhttp3.Request;
|
|
|
|
import okhttp3.Response;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.actuate.metrics.CounterService;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
...
|
...
|
@@ -23,8 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function:
|
|
|
|
*
|
|
...
|
...
|
@@ -45,6 +40,11 @@ public class IndexController { |
|
|
|
@Autowired
|
|
|
|
private HeartbeatClient heartbeatClient ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private RouteRequest routeRequest ;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 向服务端发消息
|
|
|
|
* @param sendMsgReqVO
|
|
...
|
...
|
@@ -128,39 +128,15 @@ public class IndexController { |
|
|
|
@ApiOperation("群发消息")
|
|
|
|
@RequestMapping(value = "sendGroupMsg",method = RequestMethod.POST)
|
|
|
|
@ResponseBody
|
|
|
|
public BaseResponse<SendMsgResVO> sendGroupMsg(@RequestBody SendMsgReqVO sendMsgReqVO) throws IOException {
|
|
|
|
BaseResponse<SendMsgResVO> res = new BaseResponse();
|
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
|
MediaType MEDIA_TYPE_MARKDOWN
|
|
|
|
= MediaType.parse("text/x-markdown; charset=utf-8");
|
|
|
|
|
|
|
|
String postBody = ""
|
|
|
|
+ "Releases\n"
|
|
|
|
+ "--------\n"
|
|
|
|
+ "\n"
|
|
|
|
+ " * _1.0_ May 6, 2013\n"
|
|
|
|
+ " * _1.1_ June 15, 2013\n"
|
|
|
|
+ " * _1.2_ August 11, 2013\n";
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url("https://api.github.com/markdown/raw")
|
|
|
|
.post(okhttp3.RequestBody.create(MEDIA_TYPE_MARKDOWN, postBody))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
if (!response.isSuccessful()){
|
|
|
|
throw new IOException("Unexpected code " + response);
|
|
|
|
}
|
|
|
|
public BaseResponse sendGroupMsg(@RequestBody SendMsgReqVO sendMsgReqVO) throws Exception {
|
|
|
|
BaseResponse<NULLBody> res = new BaseResponse();
|
|
|
|
|
|
|
|
System.out.println(response.body().string());
|
|
|
|
routeRequest.sendGroupMsg(sendMsgReqVO.getMsg()) ;
|
|
|
|
|
|
|
|
counterService.increment(Constants.COUNTER_SERVER_PUSH_COUNT);
|
|
|
|
|
|
|
|
SendMsgResVO sendMsgResVO = new SendMsgResVO() ;
|
|
|
|
sendMsgResVO.setMsg("OK") ;
|
|
|
|
res.setCode(StatusEnum.SUCCESS.getCode()) ;
|
|
|
|
res.setMessage(StatusEnum.SUCCESS.getMessage()) ;
|
|
|
|
res.setDataBody(sendMsgResVO) ;
|
|
|
|
return res ;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|