Commit 758c5c3e by caojingji

修改数据库连接为线上正式库地址

parent 71751c14
package com.founder.interservice.protogenesis.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.founder.interservice.VO.ResultVO;
......@@ -255,4 +256,70 @@ public class ProtoController {
}
return resultVO;
}
//多区域碰撞分析统计-发送任务
@RequestMapping(value = "/sendMultiResionalsAnalyTask",method = {RequestMethod.GET})
@ResponseBody
public ResultVO sendMultiResionalsAnalyTask(String param){
ResultVO resultVO = null;
try{
String result = protoService.doPostWaData("multiRegionalsAnalyseTask",param);
resultVO = ResultVOUtil.success(result);
}catch (InterServiceException e){
resultVO = ResultVOUtil.error(e.getCode(),e.getMessage(),e);
}
return resultVO;
}
//多区域碰撞分析统计-获取结果
@RequestMapping(value = "/getMultiResionalsAnalyTask",method = {RequestMethod.GET})
@ResponseBody
public ResultVO getMultiResionalsAnalyTask(String taskId){
ResultVO resultVO = null;
try{
JSONObject param = new JSONObject();
param.put("taskId",taskId);
String result = protoService.doPostWaData("multiRegionalsAnalyseTaskFetch",param.toJSONString());
resultVO = ResultVOUtil.success(result);
}catch (InterServiceException e){
resultVO = ResultVOUtil.error(e.getCode(),e.getMessage(),e);
}
return resultVO;
}
/**
* 获取任务状态
* @param taskId
* @return
*/
@RequestMapping(value = "/getTaskStatus",method = {RequestMethod.GET})
@ResponseBody
public ResultVO getTaskStatus(String taskId){
ResultVO resultVO = null;
try{
JSONObject param = new JSONObject();
param.put("taskId",taskId);
String result = protoService.doPostWaData("taskStatus",param.toJSONString());
resultVO = ResultVOUtil.success(result);
}catch (InterServiceException e){
resultVO = ResultVOUtil.error(e.getCode(),e.getMessage(),e);
}
return resultVO;
}
@RequestMapping(value = "/getObjectRelation",method = {RequestMethod.GET})
@ResponseBody
public ResultVO getObjectRelation(String caseId,String caseName,String username,String objectValue){
ResultVO resultVO = null;
try{
JSONObject param = new JSONObject();
param.put("caseId",caseId);
param.put("caseName", caseName);
param.put("username", username);
param.put("objectValue", objectValue);
String result = protoService.doPostWaData("objectRelation",param.toJSONString());
resultVO = ResultVOUtil.success(result);
}catch (InterServiceException e){
resultVO = ResultVOUtil.error(e.getCode(),e.getMessage(),e);
}
return resultVO;
}
}
......@@ -26,4 +26,6 @@ public interface ProtoService {
String getDzgzTaskStatus(String taskId);
String getDzgzTaskInfos(String taskId);
public String doPostWaData(String urlName,String param) throws InterServiceException;
}
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.founder.interservice.enums.ResultEnum;
import com.founder.interservice.exception.InterServiceException;
import com.founder.interservice.protogenesis.service.ProtoService;
import com.founder.interservice.util.HttpClientUtils;
import com.founder.interservice.util.HttpUtil;
import com.founder.interservice.util.StringUtil;
import org.springframework.beans.factory.annotation.Value;
......@@ -41,6 +42,9 @@ public class ProtoServiceImpl implements ProtoService {
@Value("${wabigdata.fixedEvidenceByRegionTaskFetch.url}")
private String DZGZ_INFO_URL;
@Value("${wabigdata.unified.url}")
private String UNIFIED_URL;
/**
* 获取远程的网安数据轨迹数据 不做任何操作
* @param obj
......@@ -262,4 +266,16 @@ public class ProtoServiceImpl implements ProtoService {
throw new InterServiceException(ResultEnum.RESULT_ERROR.getCode(),ResultEnum.RESULT_ERROR.getMessage());
}
}
@Override
public String doPostWaData(String urlName,String param) throws InterServiceException {
try{
String url = UNIFIED_URL + urlName;
String result = HttpClientUtils.doPostWaData(url,param);
return result;
}catch (InterServiceException e){
e.printStackTrace();
throw new InterServiceException(ResultEnum.RESULT_ERROR.getCode(),ResultEnum.RESULT_ERROR.getMessage());
}
}
}
package com.founder.interservice.util;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.*;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import com.alibaba.fastjson.JSONObject;
import com.founder.interservice.enums.ResultEnum;
import com.founder.interservice.exception.InterServiceException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.ByteArrayBuffer;
import org.apache.http.util.EntityUtils;
/**
* 封装了一些采用HttpClient发送HTTP请求的方法
*
* 本工具所采用的是最新的HttpComponents-Client-4.2.1
*/
public class HttpClientUtils {
private static Log logger = LogFactory.getLog(HttpClientUtils.class);
/**
* Http Get方法 可携带请求头信息
*
* @param url
* @param param
* @return
*/
public static String doGet(String url,Map<String, String> headMap,Map<String, String> param) throws InterServiceException {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
String resultString = "";
CloseableHttpResponse response = null;
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet()) {
builder.addParameter(key, param.get(key));
}
}
URI uri = builder.build();
// 创建http GET请求
HttpGet httpGet = new HttpGet(uri);
if (headMap != null && !headMap.isEmpty()) {
for (String key : headMap.keySet()) {
logger.info("头部信息key:" + key + "===值: " + headMap.get(key));
httpGet.addHeader(key, headMap.get(key));
}
}
// 执行请求
response = httpclient.execute(httpGet);
// 判断返回状态是否为200
if (response.getStatusLine().getStatusCode() == 200) {
resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
}
} catch (Exception e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
} finally {
try {
if (response != null) {
response.close();
}
httpclient.close();
} catch (IOException e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
}
}
return resultString;
}
public static String doGet(String url) {
return doGet(url,null, null);
}
/**
* httpclient post方法
*
* @param url
* @param param
* @return
*/
public static String doPost(String url,Map<String, String> headers,Map<String, String> param)throws InterServiceException {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
if(headers != null) {
for (String key : headers.keySet()) {
httpPost.setHeader(key, headers.get(key));
}
}
// 创建参数列表
if (param != null) {
List<NameValuePair> paramList = new ArrayList<>();
for (String key : param.keySet()) {
paramList.add(new BasicNameValuePair(key, param.get(key)));
}
// 模拟表单
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList, "utf-8");
httpPost.setEntity(entity);
}
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
} finally {
try {
if (response!=null) {
response.close();
}
} catch (IOException e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
}
}
return resultString;
}
public static String doPost(String url) {
return doPost(url,null,null);
}
/**
* 请求的参数类型为json
* @param url
* @param json
* @return {username:"",pass:""}
*/
public static String doPostJson(String url,Map<String, String> headers,String json) throws InterServiceException {
logger.info("=====请求地址:"+url);
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
//设置请求头参数
if(headers != null) {
for (String key : headers.keySet()) {
httpPost.setHeader(key, headers.get(key));
}
}
// 创建请求内容
logger.info("=====请求参数:"+json);
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
logger.info("=====响应参数:"+response);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
} finally {
try {
if (response!=null) {
response.close();
}
} catch (IOException e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
}
}
return resultString;
}
/**
* 请求的参数类型为json
* @param url
* @param json
* @return {username:"",pass:""}
*/
public static String doPostJson(String url, String json) throws InterServiceException {
logger.info("=====请求地址:"+url);
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
logger.info("=====请求参数:"+json);
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
logger.info("=====响应参数:"+response);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
} finally {
try {
if (response!=null) {
response.close();
}
} catch (IOException e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
}
}
return resultString;
}
public static String doPostWaData(String url,String json) throws InterServiceException{
String result_token = null;
try {
//1 先比较已有token是否过期
long nowtime = new Date().getTime();
String token = PropertieUtil.readValue("token.properties","token");
String expiration = PropertieUtil.readValue("token.properties","expiration");
if(StringUtil.ckeckEmpty(token) || nowtime > Long.valueOf(expiration)){
//2 如果过期先获取新的token值
String apikey = PropertieUtil.readValue("token.properties","apikey");
String username = PropertieUtil.readValue("token.properties","username");
String token_url = PropertieUtil.readValue("token.properties","token_url");
JSONObject object = new JSONObject();
object.put("apikey", apikey);
object.put("username", username);
String result = doPostJson(token_url,object.toString());
if(!StringUtil.ckeckEmpty(result)){
JSONObject o = JSONObject.parseObject(result);
result_token = o.getString("token");
String result_expiration = o.getString("expiration");
PropertieUtil.writeProperties("token.properties","token",result_token);
PropertieUtil.writeProperties("token.properties","expiration",result_expiration);
}
}else{
result_token = token;
}
//2 将token值传递
Map<String,String> headers = new HashMap<String,String>();
headers.put("token",result_token);
return doPostJson(url,headers,json);
} catch (Exception e) {
throw new InterServiceException(ResultEnum.REQUEST_URL_ERROR.getCode(),ResultEnum.REQUEST_URL_ERROR.getMessage(),e);
}
}
}
......@@ -15,8 +15,6 @@ import org.apache.http.util.EntityUtils;
import java.io.*;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.util.*;
public class HttpUtil {
......@@ -156,7 +154,7 @@ public class HttpUtil {
return resultString.trim();
}
public static void main(String[] args) {
try {
Date date1=new Date();
......
......@@ -51,6 +51,8 @@ xdhbigdata:
cjServiceId: XDHDS0004
getCjDataServiceId: XDHWS0022
wabigdata:
unified:
url: http://www.adu.cq:8071/doc/api/api/
objectrelation:
url: http://www.adu.cq:8608/api?name=objectRelation&key=88f3f909655065532073c41b0f1784df
gettrack:
......
apikey=fb5aaf49482721d6c495d3ae26796216
username=xjzd-fangzheng
token_url=http://www.adu.cq:8071/doc/token/token
token=
expiration=
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment