Commit 80aac79dc99abe914fb9f802cbdda8e036155db6

Authored by liquanyu
1 parent 25c25da3b4

update code

Showing 3 changed files with 75 additions and 4 deletions

platform-common/src/main/java/com/lyms/platform/common/utils/HttpClientUtil.java View file @ 80aac79
... ... @@ -4,7 +4,6 @@
4 4 * Created by Administrator on 2017-01-18.
5 5 */
6 6  
7   -import com.lyms.platform.common.pojo.SyncDataModel;
8 7 import org.apache.http.HttpEntity;
9 8 import org.apache.http.HttpResponse;
10 9 import org.apache.http.HttpStatus;
... ... @@ -173,6 +172,51 @@
173 172 }
174 173 return httpStr;
175 174 }
  175 +
  176 +
  177 + /**
  178 + * sslpost
  179 + * @param apiUrl
  180 + * @param list
  181 + * @return
  182 + */
  183 + public static String doPostSSL(String apiUrl, List<NameValuePair> list) {
  184 + HttpClient httpClient = null;
  185 + HttpPost httpPost = new HttpPost(apiUrl);
  186 + HttpResponse response = null;
  187 + String httpStr = null;
  188 +
  189 + try {
  190 + httpClient = new SSLClient();
  191 + httpPost.setConfig(requestConfig);
  192 + //4.将参数写入到httpost中,并设置编码格式为UTF-8
  193 + UrlEncodedFormEntity paramEntity = new UrlEncodedFormEntity(list,"UTF-8");
  194 + httpPost.setEntity(paramEntity);
  195 + response = httpClient.execute(httpPost);
  196 + int statusCode = response.getStatusLine().getStatusCode();
  197 + System.out.println("return code = "+ statusCode);
  198 + if (statusCode != HttpStatus.SC_OK) {
  199 + return null;
  200 + }
  201 + HttpEntity entity = response.getEntity();
  202 + if (entity == null) {
  203 + return null;
  204 + }
  205 + httpStr = EntityUtils.toString(entity, "utf-8");
  206 + } catch (Exception e) {
  207 + e.printStackTrace();
  208 + } finally {
  209 + if (response != null) {
  210 + try {
  211 + EntityUtils.consume(response.getEntity());
  212 + } catch (IOException e) {
  213 + e.printStackTrace();
  214 + }
  215 + }
  216 + }
  217 + return httpStr;
  218 + }
  219 +
176 220  
177 221 public static void main(String[] args) throws Exception {
178 222  
platform-common/src/main/java/com/lyms/platform/common/utils/MongoSyncUtil.java View file @ 80aac79
... ... @@ -8,10 +8,11 @@
8 8 import org.apache.commons.httpclient.HttpClient;
9 9 import org.apache.commons.httpclient.NameValuePair;
10 10 import org.apache.commons.httpclient.methods.PostMethod;
11   -import org.springframework.data.mongodb.core.query.Query;
12   -import org.springframework.data.mongodb.core.query.Update;
  11 +import org.apache.http.message.BasicNameValuePair;
13 12  
  13 +import java.util.ArrayList;
14 14 import java.util.HashMap;
  15 +import java.util.List;
15 16 import java.util.Map;
16 17  
17 18 /**
... ... @@ -55,6 +56,32 @@
55 56 }
56 57 }
57 58 return true;
  59 + }
  60 +
  61 +
  62 + public static boolean syncSll(String action, String jsonData, String id, String className) {
  63 + if ("1".equals(mongo_sync)) {
  64 + boolean boo = false;
  65 + try {
  66 + List<NameValuePair> list = new ArrayList<>();
  67 + //将用户名与密码作为参数写入(username,password这两个参数是 根据你的接口协议而定)
  68 + list.add(new NameValuePair("action", action));
  69 + list.add(new NameValuePair("token", mongo_sync_token));
  70 + list.add(new NameValuePair("className", className));
  71 + list.add(new NameValuePair("jsonData", jsonData));
  72 + list.add(new NameValuePair("id", id));
  73 + String result = HttpClientUtil.doPostSSL(mongo_sync_url,list);
  74 + if (StringUtils.isNotEmpty(result) && "success".equals(result))
  75 + {
  76 + boo = true;
  77 + }
  78 + return boo;
  79 + } catch (Exception e) {
  80 + e.printStackTrace();
  81 + return boo;
  82 + }
  83 + }
  84 + return false;
58 85 }
59 86  
60 87 public static boolean sync(String action, Object data, String id) {
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/SyncDataTaskService.java View file @ 80aac79
... ... @@ -98,7 +98,7 @@
98 98 query.setNeed("0");
99 99 List<SyncDataModel> list = syncDataService.querySyncData(query);
100 100 for (SyncDataModel model : list) {
101   - if (MongoSyncUtil.sync(model.getAction(), model.getJsonData(), model.getDataId(), model.getClassName())) {
  101 + if (MongoSyncUtil.syncSll(model.getAction(), model.getJsonData(), model.getDataId(), model.getClassName())) {
102 102 model.setStatus(0);
103 103 model.setModified(new Date());
104 104 syncDataService.updateSyncData(model);