...
|
...
|
@@ -7,18 +7,24 @@ import com.yoho.opsmanager.other.model.response.BaseRespone; |
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
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.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.*;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.zip.GZIPInputStream;
|
|
|
|
|
|
/**
|
|
|
* @author zhengyouwei 2016年5月12日 下午1:49:55
|
|
|
*/
|
|
|
@Controller
|
|
|
public class DnsCollectionCtrl {
|
|
|
Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
/**
|
|
|
* 上发dns
|
...
|
...
|
@@ -27,12 +33,10 @@ public class DnsCollectionCtrl { |
|
|
*/
|
|
|
@RequestMapping(value = "android_dns_report")
|
|
|
@ResponseBody
|
|
|
public BaseRespone androidDnsData(@RequestParam String _mlogs) throws UnsupportedEncodingException {
|
|
|
if (StringUtils.isBlank(_mlogs)) {
|
|
|
return BaseRespone.failResp("failed");
|
|
|
}
|
|
|
public BaseRespone androidDnsData(HttpServletRequest request) throws UnsupportedEncodingException {
|
|
|
String _mlogs = getMlogs(request);
|
|
|
JSONObject json = getJson(_mlogs);
|
|
|
if (json == null){
|
|
|
if (json == null) {
|
|
|
return BaseRespone.failResp("failed");
|
|
|
}
|
|
|
if (json.has("dnsdata")) {
|
...
|
...
|
@@ -53,12 +57,10 @@ public class DnsCollectionCtrl { |
|
|
*/
|
|
|
@RequestMapping(value = "ios_dns_report")
|
|
|
@ResponseBody
|
|
|
public BaseRespone iosDnsData(@RequestParam String _mlogs) throws UnsupportedEncodingException {
|
|
|
if (StringUtils.isBlank(_mlogs)) {
|
|
|
return BaseRespone.failResp("failed");
|
|
|
}
|
|
|
public BaseRespone iosDnsData(HttpServletRequest request) throws UnsupportedEncodingException {
|
|
|
String _mlogs = getMlogs(request);
|
|
|
JSONObject json = getJson(_mlogs);
|
|
|
if (json == null){
|
|
|
if (json == null) {
|
|
|
return BaseRespone.failResp("failed");
|
|
|
}
|
|
|
if (json.has("dnsdata")) {
|
...
|
...
|
@@ -67,17 +69,53 @@ public class DnsCollectionCtrl { |
|
|
dnsRequest.setClient("ios");
|
|
|
dnsRequest.setArray(array);
|
|
|
DnsWriteRunnable dnsWriteRunnable = new DnsWriteRunnable(dnsRequest);
|
|
|
ThreadPool.run(dnsWriteRunnable); }
|
|
|
ThreadPool.run(dnsWriteRunnable);
|
|
|
}
|
|
|
return BaseRespone.successResp(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
public JSONObject getJson(String _mlogs){
|
|
|
public JSONObject getJson(String _mlogs) {
|
|
|
try {
|
|
|
return JSONObject.fromObject(_mlogs);
|
|
|
|
|
|
}catch (Exception e){
|
|
|
} catch (Exception e) {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public String getMlogs(HttpServletRequest request) {
|
|
|
try {
|
|
|
String encoding = request.getHeader("Content-Encoding");
|
|
|
String result;
|
|
|
if ("gzip".equalsIgnoreCase(encoding)) {
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
GZIPInputStream gunzip = new GZIPInputStream(request.getInputStream());
|
|
|
byte[] buffer = new byte[256];
|
|
|
int n;
|
|
|
while ((n = gunzip.read(buffer)) >= 0) {
|
|
|
out.write(buffer, 0, n);
|
|
|
}
|
|
|
gunzip.close();
|
|
|
out.close();
|
|
|
result = URLDecoder.decode(out.toString(), "UTF-8");
|
|
|
} else {
|
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(request.getInputStream()));
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
String data;
|
|
|
while ((data = bufferedReader.readLine()) != null) {
|
|
|
stringBuilder.append(data);
|
|
|
}
|
|
|
bufferedReader.close();
|
|
|
result = URLDecoder.decode(stringBuilder.toString(), "UTF-8");
|
|
|
}
|
|
|
if (!result.startsWith("_mlogs=")) {
|
|
|
return null;
|
|
|
}
|
|
|
return result.substring(7);
|
|
|
} catch (IOException e) {
|
|
|
logger.error("get mlogs error {} ", e.toString());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
} |
...
|
...
|
|