Showing
14 changed files
with
233 additions
and
51 deletions
| ... | @@ -57,8 +57,7 @@ public class HsCodeInterface { | ... | @@ -57,8 +57,7 @@ public class HsCodeInterface { |
| 57 | return resultHsCode; | 57 | return resultHsCode; |
| 58 | } | 58 | } |
| 59 | }catch(Exception ex){ | 59 | }catch(Exception ex){ |
| 60 | - log.error(ex.getMessage()); | 60 | + log.error(ex.getMessage(),ex); |
| 61 | - ex.printStackTrace(); | ||
| 62 | resultHsCode = new ResultHsCode(Boolean.FALSE,"30101","数据查询异常",null); | 61 | resultHsCode = new ResultHsCode(Boolean.FALSE,"30101","数据查询异常",null); |
| 63 | return resultHsCode; | 62 | return resultHsCode; |
| 64 | }finally { | 63 | }finally { | ... | ... |
| ... | @@ -62,6 +62,14 @@ public class ApiService { | ... | @@ -62,6 +62,14 @@ public class ApiService { |
| 62 | @Value("${api.address.complete-msg-url}") | 62 | @Value("${api.address.complete-msg-url}") |
| 63 | String completeMsgUrl; | 63 | String completeMsgUrl; |
| 64 | 64 | ||
| 65 | + @Value("${api.address.proxy-url}") | ||
| 66 | + String proxyUrl; | ||
| 67 | + @Value("${api.address.proxy-port}") | ||
| 68 | + Integer proxyPort; | ||
| 69 | + | ||
| 70 | + @Value("${spring.profiles.active}") | ||
| 71 | + String env; | ||
| 72 | + | ||
| 65 | @Autowired | 73 | @Autowired |
| 66 | ReceiptMessageRepository receiptMessageRepository; | 74 | ReceiptMessageRepository receiptMessageRepository; |
| 67 | 75 | ||
| ... | @@ -89,7 +97,11 @@ public class ApiService { | ... | @@ -89,7 +97,11 @@ public class ApiService { |
| 89 | Map<String,String> map = new HashMap<String,String>(); | 97 | Map<String,String> map = new HashMap<String,String>(); |
| 90 | map.put("username", this.username); | 98 | map.put("username", this.username); |
| 91 | map.put("password", this.password); | 99 | map.put("password", this.password); |
| 92 | - String tokenJson = HttpUtils.doPost(this.tokenUrl,map); | 100 | +// String tokenJson = HttpUtils.doPost(this.tokenUrl,map); |
| 101 | + log.info("tokenUrl:"+this.tokenUrl); | ||
| 102 | + String tokenJson = HttpUtils.doProxyPost(this.tokenUrl,map,this.proxyUrl,this.proxyPort); | ||
| 103 | + log.info("getToken:"+tokenJson); | ||
| 104 | + | ||
| 93 | TokenResult tokenResult = JsonToJava.parseJson(tokenJson,TokenResult.class); | 105 | TokenResult tokenResult = JsonToJava.parseJson(tokenJson,TokenResult.class); |
| 94 | return tokenResult; | 106 | return tokenResult; |
| 95 | } | 107 | } |
| ... | @@ -141,7 +153,8 @@ public class ApiService { | ... | @@ -141,7 +153,8 @@ public class ApiService { |
| 141 | String objJson = JsonToJava.toJson(d); | 153 | String objJson = JsonToJava.toJson(d); |
| 142 | log.info("推送海关回执json: " + objJson); | 154 | log.info("推送海关回执json: " + objJson); |
| 143 | //推送海关回执数据 | 155 | //推送海关回执数据 |
| 144 | - String json = HttpUtils.doPost(this.customsUrl,objJson,headerMap); | 156 | +// String json = HttpUtils.doPost(this.customsUrl,objJson,headerMap); |
| 157 | + String json = HttpUtils.doProxyPost(this.customsUrl,objJson,headerMap,this.proxyUrl,this.proxyPort); | ||
| 145 | //接口响应时间 | 158 | //接口响应时间 |
| 146 | declearTask.setResponseTime(new Date()); | 159 | declearTask.setResponseTime(new Date()); |
| 147 | TokenResult tokenResult = JsonToJava.parseJson(json,TokenResult.class); | 160 | TokenResult tokenResult = JsonToJava.parseJson(json,TokenResult.class); |
| ... | @@ -166,7 +179,8 @@ public class ApiService { | ... | @@ -166,7 +179,8 @@ public class ApiService { |
| 166 | declearTask.setResponseResults("99999"); | 179 | declearTask.setResponseResults("99999"); |
| 167 | declearTask.setResponseContent(ex.getMessage()); | 180 | declearTask.setResponseContent(ex.getMessage()); |
| 168 | declearTaskList.add(declearTask); | 181 | declearTaskList.add(declearTask); |
| 169 | - ex.printStackTrace(); | 182 | + |
| 183 | + log.error(ex.getMessage(),ex); | ||
| 170 | } | 184 | } |
| 171 | }); | 185 | }); |
| 172 | declearTaskList.forEach(declearTask -> { | 186 | declearTaskList.forEach(declearTask -> { |
| ... | @@ -204,7 +218,8 @@ public class ApiService { | ... | @@ -204,7 +218,8 @@ public class ApiService { |
| 204 | }); | 218 | }); |
| 205 | this.sendMawb(token,mawbList); | 219 | this.sendMawb(token,mawbList); |
| 206 | }catch(Exception ex){ | 220 | }catch(Exception ex){ |
| 207 | - ex.printStackTrace(); | 221 | + |
| 222 | + log.error(ex.getMessage(),ex); | ||
| 208 | } | 223 | } |
| 209 | } | 224 | } |
| 210 | /** | 225 | /** |
| ... | @@ -262,7 +277,8 @@ public class ApiService { | ... | @@ -262,7 +277,8 @@ public class ApiService { |
| 262 | declearTask.setResponseResults("99999"); | 277 | declearTask.setResponseResults("99999"); |
| 263 | declearTask.setResponseContent(ex.getMessage()); | 278 | declearTask.setResponseContent(ex.getMessage()); |
| 264 | declearTaskList.add(declearTask); | 279 | declearTaskList.add(declearTask); |
| 265 | - ex.printStackTrace(); | 280 | + |
| 281 | + log.error(ex.getMessage(),ex); | ||
| 266 | } | 282 | } |
| 267 | }); | 283 | }); |
| 268 | declearTaskList.forEach(declearTask -> { | 284 | declearTaskList.forEach(declearTask -> { | ... | ... |
| ... | @@ -234,7 +234,8 @@ public class ChmConsignmentService { | ... | @@ -234,7 +234,8 @@ public class ChmConsignmentService { |
| 234 | 234 | ||
| 235 | }catch (Exception e){ | 235 | }catch (Exception e){ |
| 236 | result=null; | 236 | result=null; |
| 237 | - e.printStackTrace(); | 237 | + |
| 238 | + log.error(e.getMessage(),e); | ||
| 238 | log.error("convertToChmConsignment() error:"+e.getMessage()); | 239 | log.error("convertToChmConsignment() error:"+e.getMessage()); |
| 239 | } | 240 | } |
| 240 | return result; | 241 | return result; |
| ... | @@ -292,7 +293,8 @@ public class ChmConsignmentService { | ... | @@ -292,7 +293,8 @@ public class ChmConsignmentService { |
| 292 | } | 293 | } |
| 293 | }catch (Exception e){ | 294 | }catch (Exception e){ |
| 294 | result=null; | 295 | result=null; |
| 295 | - e.printStackTrace(); | 296 | + |
| 297 | + log.error(e.getMessage(),e); | ||
| 296 | log.error("convertToChmConsignmentFedex() error:"+e.getMessage()); | 298 | log.error("convertToChmConsignmentFedex() error:"+e.getMessage()); |
| 297 | } | 299 | } |
| 298 | return result; | 300 | return result; |
| ... | @@ -430,7 +432,8 @@ public class ChmConsignmentService { | ... | @@ -430,7 +432,8 @@ public class ChmConsignmentService { |
| 430 | result.setOverseasConsigneeEname(consignment.getOverseasConsignorFnCname()); | 432 | result.setOverseasConsigneeEname(consignment.getOverseasConsignorFnCname()); |
| 431 | }catch (Exception e){ | 433 | }catch (Exception e){ |
| 432 | result=null; | 434 | result=null; |
| 433 | - e.printStackTrace(); | 435 | + |
| 436 | + log.error(e.getMessage(),e); | ||
| 434 | log.error("convertToChmConsignment() error:"+e.getMessage()); | 437 | log.error("convertToChmConsignment() error:"+e.getMessage()); |
| 435 | } | 438 | } |
| 436 | return result; | 439 | return result; | ... | ... |
| ... | @@ -45,7 +45,8 @@ public class DeclearTaskService{ | ... | @@ -45,7 +45,8 @@ public class DeclearTaskService{ |
| 45 | declareTaskRepository.saveAll(declareTaskList); | 45 | declareTaskRepository.saveAll(declareTaskList); |
| 46 | } | 46 | } |
| 47 | }catch (Exception e){ | 47 | }catch (Exception e){ |
| 48 | - e.printStackTrace(); | 48 | + |
| 49 | + log.error(e.getMessage(),e); | ||
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | } | 52 | } |
| ... | @@ -70,7 +71,8 @@ public class DeclearTaskService{ | ... | @@ -70,7 +71,8 @@ public class DeclearTaskService{ |
| 70 | declareTaskRepository.saveAll(declareTaskList); | 71 | declareTaskRepository.saveAll(declareTaskList); |
| 71 | } | 72 | } |
| 72 | }catch (Exception e){ | 73 | }catch (Exception e){ |
| 73 | - e.printStackTrace(); | 74 | + |
| 75 | + log.error(e.getMessage(),e); | ||
| 74 | } | 76 | } |
| 75 | 77 | ||
| 76 | } | 78 | } | ... | ... |
| ... | @@ -27,8 +27,8 @@ public class DictionaryEntriesService { | ... | @@ -27,8 +27,8 @@ public class DictionaryEntriesService { |
| 27 | try { | 27 | try { |
| 28 | result=dictionaryEntriesRepository.findAllDictionaryEntries(); | 28 | result=dictionaryEntriesRepository.findAllDictionaryEntries(); |
| 29 | }catch (Exception e){ | 29 | }catch (Exception e){ |
| 30 | - e.printStackTrace(); | 30 | + |
| 31 | - log.error("getAllDictionaryEntries() error:"+e.getMessage()); | 31 | + log.error(e.getMessage(),e); |
| 32 | } | 32 | } |
| 33 | return result; | 33 | return result; |
| 34 | } | 34 | } | ... | ... |
| ... | @@ -3,14 +3,18 @@ package com.erry.iclear.dateInterface.service; | ... | @@ -3,14 +3,18 @@ package com.erry.iclear.dateInterface.service; |
| 3 | import com.erry.iclear.dateInterface.api.request.FedexConsignment; | 3 | import com.erry.iclear.dateInterface.api.request.FedexConsignment; |
| 4 | import com.erry.iclear.dateInterface.api.request.ConsignmentDetail; | 4 | import com.erry.iclear.dateInterface.api.request.ConsignmentDetail; |
| 5 | import com.erry.iclear.dateInterface.entity.DeclaredInfo; | 5 | import com.erry.iclear.dateInterface.entity.DeclaredInfo; |
| 6 | +import lombok.extern.slf4j.Slf4j; | ||
| 6 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| 7 | 8 | ||
| 8 | import java.util.ArrayList; | 9 | import java.util.ArrayList; |
| 9 | import java.util.List; | 10 | import java.util.List; |
| 10 | 11 | ||
| 11 | @Service | 12 | @Service |
| 13 | +@Slf4j | ||
| 12 | public class FedexConsignmentService { | 14 | public class FedexConsignmentService { |
| 13 | 15 | ||
| 16 | + | ||
| 17 | + | ||
| 14 | public List<FedexConsignment> fedexConsignmentList(List<DeclaredInfo> consignment){ | 18 | public List<FedexConsignment> fedexConsignmentList(List<DeclaredInfo> consignment){ |
| 15 | List<FedexConsignment> fedexConsignmentList = new ArrayList<>(); | 19 | List<FedexConsignment> fedexConsignmentList = new ArrayList<>(); |
| 16 | try{ | 20 | try{ |
| ... | @@ -62,7 +66,8 @@ public class FedexConsignmentService { | ... | @@ -62,7 +66,8 @@ public class FedexConsignmentService { |
| 62 | fedexConsignmentList.add(fedexConsignment); | 66 | fedexConsignmentList.add(fedexConsignment); |
| 63 | } | 67 | } |
| 64 | }catch (Exception e){ | 68 | }catch (Exception e){ |
| 65 | - e.printStackTrace(); | 69 | + |
| 70 | + log.error(e.getMessage(),e); | ||
| 66 | } | 71 | } |
| 67 | return fedexConsignmentList; | 72 | return fedexConsignmentList; |
| 68 | } | 73 | } | ... | ... |
| ... | @@ -61,8 +61,7 @@ public class HsCodeService { | ... | @@ -61,8 +61,7 @@ public class HsCodeService { |
| 61 | resultHsCode.setMsg("操作成功"); | 61 | resultHsCode.setMsg("操作成功"); |
| 62 | resultHsCode.setHsCodeResultList(hsCodeList); | 62 | resultHsCode.setHsCodeResultList(hsCodeList); |
| 63 | }catch(Exception ex){ | 63 | }catch(Exception ex){ |
| 64 | - log.error(ex.getMessage()); | 64 | + log.error(ex.getMessage(),ex); |
| 65 | - ex.printStackTrace(); | ||
| 66 | resultHsCode.setSuccess(Boolean.FALSE); | 65 | resultHsCode.setSuccess(Boolean.FALSE); |
| 67 | resultHsCode.setCode("30101"); | 66 | resultHsCode.setCode("30101"); |
| 68 | resultHsCode.setMsg("数据查询异常"); | 67 | resultHsCode.setMsg("数据查询异常"); |
| ... | @@ -84,7 +83,8 @@ public class HsCodeService { | ... | @@ -84,7 +83,8 @@ public class HsCodeService { |
| 84 | resultHsCode.setHsCodeResultList(hsCodeList); | 83 | resultHsCode.setHsCodeResultList(hsCodeList); |
| 85 | }catch(Exception ex){ | 84 | }catch(Exception ex){ |
| 86 | log.error(ex.getMessage()); | 85 | log.error(ex.getMessage()); |
| 87 | - ex.printStackTrace(); | 86 | + |
| 87 | + log.error(ex.getMessage(),ex); | ||
| 88 | resultHsCode.setSuccess(Boolean.FALSE); | 88 | resultHsCode.setSuccess(Boolean.FALSE); |
| 89 | resultHsCode.setCode("30101"); | 89 | resultHsCode.setCode("30101"); |
| 90 | resultHsCode.setMsg("数据查询异常"); | 90 | resultHsCode.setMsg("数据查询异常"); | ... | ... |
| ... | @@ -44,7 +44,7 @@ public class IClearApiHsCodeLogService { | ... | @@ -44,7 +44,7 @@ public class IClearApiHsCodeLogService { |
| 44 | rs = true; | 44 | rs = true; |
| 45 | } | 45 | } |
| 46 | }catch(Exception ex){ | 46 | }catch(Exception ex){ |
| 47 | - ex.printStackTrace(); | 47 | + log.error(ex.getMessage(),ex); |
| 48 | } | 48 | } |
| 49 | return rs; | 49 | return rs; |
| 50 | } | 50 | } | ... | ... |
| ... | @@ -14,7 +14,7 @@ import org.springframework.stereotype.Component; | ... | @@ -14,7 +14,7 @@ import org.springframework.stereotype.Component; |
| 14 | /** | 14 | /** |
| 15 | * @author Administrator | 15 | * @author Administrator |
| 16 | */ | 16 | */ |
| 17 | -//@Component | 17 | +@Component |
| 18 | @Slf4j | 18 | @Slf4j |
| 19 | public class IClearApiTask { | 19 | public class IClearApiTask { |
| 20 | @Autowired | 20 | @Autowired |
| ... | @@ -54,10 +54,31 @@ public class IClearApiTask { | ... | @@ -54,10 +54,31 @@ public class IClearApiTask { |
| 54 | log.error("pushMawbTask() error:" +e.getMessage()); | 54 | log.error("pushMawbTask() error:" +e.getMessage()); |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | - /* | 57 | + /** |
| 58 | - * wy on 2022年1月20日17:50:57 | 58 | + * 获取token |
| 59 | - * 经clj确认,这两个任务没有必要 | 59 | + * @throws Exception |
| 60 | - * *//** | 60 | + */ |
| 61 | + private void getToken() throws Exception{ | ||
| 62 | + if(token == null){ | ||
| 63 | + try { | ||
| 64 | + //获取token | ||
| 65 | + TokenResult tokenResult = apiService.getToken(); | ||
| 66 | + if(tokenResult.getErrorcode().equals(Constants.ApiResponseKeys.SUCCESS)){ | ||
| 67 | + this.token = tokenResult.getData().getToken(); | ||
| 68 | + } | ||
| 69 | + }catch(Exception ex){ | ||
| 70 | + log.error(ex.getMessage(),ex); | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + if(this.token == null){ | ||
| 74 | + throw new Exception("获取token失败!"); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /* | ||
| 79 | + * wy on 2022年1月20日17:50:57 | ||
| 80 | + * 经clj确认,这两个任务没有必要 | ||
| 81 | + * *//** | ||
| 61 | * TODO 定时任务:每分钟推送: 推送失败的回执数据, | 82 | * TODO 定时任务:每分钟推送: 推送失败的回执数据, |
| 62 | *//* | 83 | *//* |
| 63 | @Scheduled(cron = "${task.pushErrorReturnDate}") | 84 | @Scheduled(cron = "${task.pushErrorReturnDate}") |
| ... | @@ -90,24 +111,4 @@ public class IClearApiTask { | ... | @@ -90,24 +111,4 @@ public class IClearApiTask { |
| 90 | }*//* | 111 | }*//* |
| 91 | }*/ | 112 | }*/ |
| 92 | 113 | ||
| 93 | - /** | ||
| 94 | - * 获取token | ||
| 95 | - * @throws Exception | ||
| 96 | - */ | ||
| 97 | - private void getToken() throws Exception{ | ||
| 98 | - if(token == null){ | ||
| 99 | - try { | ||
| 100 | - //获取token | ||
| 101 | - TokenResult tokenResult = apiService.getToken(); | ||
| 102 | - if(tokenResult.getErrorcode().equals(Constants.ApiResponseKeys.SUCCESS)){ | ||
| 103 | - this.token = tokenResult.getData().getToken(); | ||
| 104 | - } | ||
| 105 | - }catch(Exception ex){ | ||
| 106 | - ex.printStackTrace(); | ||
| 107 | - } | ||
| 108 | - } | ||
| 109 | - if(this.token == null){ | ||
| 110 | - throw new Exception("获取token失败!"); | ||
| 111 | - } | ||
| 112 | - } | ||
| 113 | } | 114 | } | ... | ... |
| 1 | package com.erry.iclear.dateInterface.util; | 1 | package com.erry.iclear.dateInterface.util; |
| 2 | 2 | ||
| 3 | +import java.io.IOException; | ||
| 3 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
| 4 | import java.util.Iterator; | 5 | import java.util.Iterator; |
| 5 | import java.util.List; | 6 | import java.util.List; |
| 6 | import java.util.Map; | 7 | import java.util.Map; |
| 7 | import java.util.Map.Entry; | 8 | import java.util.Map.Entry; |
| 8 | import org.apache.http.HttpEntity; | 9 | import org.apache.http.HttpEntity; |
| 10 | +import org.apache.http.HttpHost; | ||
| 9 | import org.apache.http.HttpResponse; | 11 | import org.apache.http.HttpResponse; |
| 10 | import org.apache.http.NameValuePair; | 12 | import org.apache.http.NameValuePair; |
| 11 | import org.apache.http.client.HttpClient; | 13 | import org.apache.http.client.HttpClient; |
| 12 | import org.apache.http.client.entity.UrlEncodedFormEntity; | 14 | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| 13 | import org.apache.http.client.methods.HttpPost; | 15 | import org.apache.http.client.methods.HttpPost; |
| 16 | +import org.apache.http.conn.params.ConnRoutePNames; | ||
| 14 | import org.apache.http.entity.StringEntity; | 17 | import org.apache.http.entity.StringEntity; |
| 18 | +import org.apache.http.impl.client.HttpClientBuilder; | ||
| 15 | import org.apache.http.message.BasicNameValuePair; | 19 | import org.apache.http.message.BasicNameValuePair; |
| 16 | import org.apache.http.util.EntityUtils; | 20 | import org.apache.http.util.EntityUtils; |
| 21 | +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | ||
| 17 | 22 | ||
| 18 | /** | 23 | /** |
| 19 | * 利用HttpClient进行post请求的工具类 | 24 | * 利用HttpClient进行post请求的工具类 |
| ... | @@ -23,6 +28,88 @@ import org.apache.http.util.EntityUtils; | ... | @@ -23,6 +28,88 @@ import org.apache.http.util.EntityUtils; |
| 23 | public class HttpUtils { | 28 | public class HttpUtils { |
| 24 | private static String CHARSET = "utf-8"; | 29 | private static String CHARSET = "utf-8"; |
| 25 | 30 | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * post请求 | ||
| 34 | + * @param url | ||
| 35 | + * @param json | ||
| 36 | + * @return | ||
| 37 | + */ | ||
| 38 | + public static String doProxyPost(String url,String json,Map<String,String> headerMap,String proxyUrl,Integer port) throws Exception { | ||
| 39 | + HttpClient httpClient = null; | ||
| 40 | + HttpPost httpPost = null; | ||
| 41 | + String result = null; | ||
| 42 | + | ||
| 43 | + httpClient = SSLClient.getProxyHttpsClient(proxyUrl,port); | ||
| 44 | + | ||
| 45 | + try{ | ||
| 46 | + httpPost = new HttpPost(url); | ||
| 47 | + //设置参数 | ||
| 48 | + List<NameValuePair> list = new ArrayList<NameValuePair>(); | ||
| 49 | + StringEntity entity = new StringEntity(json, HttpUtils.CHARSET);//解决中文乱码问题 | ||
| 50 | + entity.setContentEncoding("UTF-8"); | ||
| 51 | + entity.setContentType("application/json"); | ||
| 52 | + httpPost.setEntity(entity); | ||
| 53 | + | ||
| 54 | + Iterator headerIterator = headerMap.entrySet().iterator(); | ||
| 55 | + while(headerIterator.hasNext()){ | ||
| 56 | + Entry<String,String> elem = (Entry<String, String>) headerIterator.next(); | ||
| 57 | + httpPost.addHeader(elem.getKey(),elem.getValue()); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | +// /** 设置代理IP **/ | ||
| 61 | +// HttpHost proxy = new HttpHost(proxyUrl, 3128); | ||
| 62 | +// httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); | ||
| 63 | + | ||
| 64 | + HttpResponse response = httpClient.execute(httpPost); | ||
| 65 | + if(response != null){ | ||
| 66 | + HttpEntity resEntity = response.getEntity(); | ||
| 67 | + if(resEntity != null){ | ||
| 68 | + result = EntityUtils.toString(resEntity,HttpUtils.CHARSET); | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + } finally { | ||
| 72 | + httpClient.getConnectionManager().shutdown(); //关闭连接 | ||
| 73 | + } | ||
| 74 | + return result; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + | ||
| 78 | + public static String doProxyPost(String url,Map<String,String> paramMap,String proxyUrl,Integer port) throws Exception { | ||
| 79 | + | ||
| 80 | +// HttpClient httpClient = null; | ||
| 81 | + HttpPost httpPost = null; | ||
| 82 | + String result = null; | ||
| 83 | + HttpClient httpClient = SSLClient.getProxyHttpsClient(proxyUrl,port); | ||
| 84 | + try{ | ||
| 85 | + httpPost = new HttpPost(url); | ||
| 86 | + //设置参数 | ||
| 87 | + List<NameValuePair> list = new ArrayList<NameValuePair>(); | ||
| 88 | + Iterator iterator = paramMap.entrySet().iterator(); | ||
| 89 | + while(iterator.hasNext()){ | ||
| 90 | + Entry<String,String> elem = (Entry<String, String>) iterator.next(); | ||
| 91 | + list.add(new BasicNameValuePair(elem.getKey(),elem.getValue())); | ||
| 92 | + } | ||
| 93 | + if(list.size() > 0){ | ||
| 94 | + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,HttpUtils.CHARSET); | ||
| 95 | + httpPost.setEntity(entity); | ||
| 96 | + } | ||
| 97 | + /** 设置代理IP **/ | ||
| 98 | +// HttpHost proxy = new HttpHost(proxyUrl, 3128); | ||
| 99 | +// httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); | ||
| 100 | + | ||
| 101 | + HttpResponse response = httpClient.execute(httpPost); | ||
| 102 | + if(response != null){ | ||
| 103 | + HttpEntity resEntity = response.getEntity(); | ||
| 104 | + if(resEntity != null){ | ||
| 105 | + result = EntityUtils.toString(resEntity,HttpUtils.CHARSET); | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + } finally { | ||
| 109 | + httpClient.getConnectionManager().shutdown(); //关闭连接 | ||
| 110 | + } | ||
| 111 | + return result; | ||
| 112 | + } | ||
| 26 | /** | 113 | /** |
| 27 | * post请求 | 114 | * post请求 |
| 28 | * @param url | 115 | * @param url |
| ... | @@ -62,6 +149,7 @@ public class HttpUtils { | ... | @@ -62,6 +149,7 @@ public class HttpUtils { |
| 62 | return result; | 149 | return result; |
| 63 | } | 150 | } |
| 64 | 151 | ||
| 152 | + | ||
| 65 | /** | 153 | /** |
| 66 | * post请求 map参数 | 154 | * post请求 map参数 |
| 67 | * @param url | 155 | * @param url |
| ... | @@ -141,4 +229,4 @@ public class HttpUtils { | ... | @@ -141,4 +229,4 @@ public class HttpUtils { |
| 141 | } | 229 | } |
| 142 | return result; | 230 | return result; |
| 143 | } | 231 | } |
| 144 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 232 | +} | ... | ... |
| 1 | package com.erry.iclear.dateInterface.util; | 1 | package com.erry.iclear.dateInterface.util; |
| 2 | 2 | ||
| 3 | +import java.io.IOException; | ||
| 4 | +import java.security.KeyManagementException; | ||
| 5 | +import java.security.NoSuchAlgorithmException; | ||
| 3 | import java.security.cert.CertificateException; | 6 | import java.security.cert.CertificateException; |
| 4 | import java.security.cert.X509Certificate; | 7 | import java.security.cert.X509Certificate; |
| 5 | import javax.net.ssl.SSLContext; | 8 | import javax.net.ssl.SSLContext; |
| 6 | import javax.net.ssl.TrustManager; | 9 | import javax.net.ssl.TrustManager; |
| 7 | import javax.net.ssl.X509TrustManager; | 10 | import javax.net.ssl.X509TrustManager; |
| 11 | + | ||
| 12 | +import com.alibaba.fastjson.JSONObject; | ||
| 13 | +import org.apache.http.HttpHost; | ||
| 14 | +import org.apache.http.client.config.RequestConfig; | ||
| 15 | +import org.apache.http.client.methods.CloseableHttpResponse; | ||
| 16 | +import org.apache.http.client.methods.HttpGet; | ||
| 8 | import org.apache.http.conn.ClientConnectionManager; | 17 | import org.apache.http.conn.ClientConnectionManager; |
| 9 | import org.apache.http.conn.scheme.Scheme; | 18 | import org.apache.http.conn.scheme.Scheme; |
| 10 | import org.apache.http.conn.scheme.SchemeRegistry; | 19 | import org.apache.http.conn.scheme.SchemeRegistry; |
| 20 | +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||
| 11 | import org.apache.http.conn.ssl.SSLSocketFactory; | 21 | import org.apache.http.conn.ssl.SSLSocketFactory; |
| 22 | +import org.apache.http.impl.client.CloseableHttpClient; | ||
| 12 | import org.apache.http.impl.client.DefaultHttpClient; | 23 | import org.apache.http.impl.client.DefaultHttpClient; |
| 24 | +import org.apache.http.impl.client.HttpClients; | ||
| 25 | +import org.apache.http.util.EntityUtils; | ||
| 13 | 26 | ||
| 14 | /** | 27 | /** |
| 15 | * 用于进行Https请求的HttpClient,指定传输协议为TLSv1.2 | 28 | * 用于进行Https请求的HttpClient,指定传输协议为TLSv1.2 |
| ... | @@ -19,6 +32,9 @@ import org.apache.http.impl.client.DefaultHttpClient; | ... | @@ -19,6 +32,9 @@ import org.apache.http.impl.client.DefaultHttpClient; |
| 19 | public class SSLClient extends DefaultHttpClient{ | 32 | public class SSLClient extends DefaultHttpClient{ |
| 20 | public SSLClient() throws Exception{ | 33 | public SSLClient() throws Exception{ |
| 21 | super(); //传输协议需要根据自己的判断 | 34 | super(); //传输协议需要根据自己的判断 |
| 35 | + trustAllHosts(); | ||
| 36 | + } | ||
| 37 | + private void trustAllHosts() throws NoSuchAlgorithmException, KeyManagementException { | ||
| 22 | SSLContext ctx = SSLContext.getInstance("TLSv1.2"); | 38 | SSLContext ctx = SSLContext.getInstance("TLSv1.2"); |
| 23 | X509TrustManager tm = new X509TrustManager() { | 39 | X509TrustManager tm = new X509TrustManager() { |
| 24 | @Override | 40 | @Override |
| ... | @@ -40,4 +56,40 @@ public class SSLClient extends DefaultHttpClient{ | ... | @@ -40,4 +56,40 @@ public class SSLClient extends DefaultHttpClient{ |
| 40 | SchemeRegistry sr = ccm.getSchemeRegistry(); | 56 | SchemeRegistry sr = ccm.getSchemeRegistry(); |
| 41 | sr.register(new Scheme("https", 443, ssf)); | 57 | sr.register(new Scheme("https", 443, ssf)); |
| 42 | } | 58 | } |
| 43 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 59 | + | ||
| 60 | + public CloseableHttpClient getProxyHttpClient(String qlb,int port){ | ||
| 61 | + HttpHost proxy = new HttpHost(qlb, port, "http"); | ||
| 62 | + //把代理设置到请求配置 | ||
| 63 | + RequestConfig defaultRequestConfig = RequestConfig.custom() | ||
| 64 | + .setProxy(proxy) | ||
| 65 | + .build(); | ||
| 66 | + CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build(); | ||
| 67 | + return httpclient; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public static CloseableHttpClient getProxyHttpsClient(String qlb,Integer port) throws NoSuchAlgorithmException, KeyManagementException { | ||
| 71 | + X509TrustManager x509mgr = new X509TrustManager() { | ||
| 72 | + @Override | ||
| 73 | + public void checkClientTrusted(X509Certificate[] xcs, String string) { | ||
| 74 | + } | ||
| 75 | + @Override | ||
| 76 | + public void checkServerTrusted(X509Certificate[] xcs, String string) { | ||
| 77 | + } | ||
| 78 | + @Override | ||
| 79 | + public X509Certificate[] getAcceptedIssuers() { | ||
| 80 | + return null; | ||
| 81 | + } | ||
| 82 | + }; | ||
| 83 | + SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
| 84 | + sslContext.init(null, new TrustManager[] { x509mgr }, null); | ||
| 85 | + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); | ||
| 86 | + HttpHost proxy = new HttpHost(qlb, port, "http"); | ||
| 87 | + RequestConfig defaultRequestConfig = RequestConfig.custom() | ||
| 88 | + .setProxy(proxy) | ||
| 89 | + .build(); | ||
| 90 | + CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf) | ||
| 91 | + .setDefaultRequestConfig(defaultRequestConfig).build(); | ||
| 92 | + return httpclient; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | +} | ... | ... |
| ... | @@ -12,9 +12,9 @@ task: | ... | @@ -12,9 +12,9 @@ task: |
| 12 | #推送完整报文 | 12 | #推送完整报文 |
| 13 | pushMawbTask: 0 0/1 * * * ? | 13 | pushMawbTask: 0 0/1 * * * ? |
| 14 | #推送失败的回执数据 | 14 | #推送失败的回执数据 |
| 15 | - pushErrorReturnDate: 0 0/30 * * * ? | 15 | + pushErrorReturnDate: 0 0/3 * * * ? |
| 16 | #推送失败的申报数据 | 16 | #推送失败的申报数据 |
| 17 | - pushErrorDeclareDate: 0 0/30 * * * ? | 17 | + pushErrorDeclareDate: 0 0/3 * * * ? |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #推送地址 | 20 | #推送地址 |
| ... | @@ -40,3 +40,8 @@ api: | ... | @@ -40,3 +40,8 @@ api: |
| 40 | customs-url: https://apiuat.iclrccd-fedex.com/export/outbound/customs | 40 | customs-url: https://apiuat.iclrccd-fedex.com/export/outbound/customs |
| 41 | #推送完整报文地址 | 41 | #推送完整报文地址 |
| 42 | complete-msg-url: https://apiuat.iclrccd-fedex.com/export/outbound/mawb | 42 | complete-msg-url: https://apiuat.iclrccd-fedex.com/export/outbound/mawb |
| 43 | + #http代理地址(刷新token、传输海关回执地址、推送完整报文地址) | ||
| 44 | + # http://cn2-proxy.apac.fedex.com:3128 | ||
| 45 | + # http://internet.proxy.fedex.com:80 | ||
| 46 | + proxy-url: cn2-proxy.apac.fedex.com | ||
| 47 | + proxy-port: 3128 | ... | ... |
| ... | @@ -37,4 +37,9 @@ api: | ... | @@ -37,4 +37,9 @@ api: |
| 37 | #传输海关回执地址 | 37 | #传输海关回执地址 |
| 38 | customs-url: https://apictm.iclrccd-fedex.com/export/outbound/customs | 38 | customs-url: https://apictm.iclrccd-fedex.com/export/outbound/customs |
| 39 | #推送完整报文地址 | 39 | #推送完整报文地址 |
| 40 | - complete-msg-url: https://apictm.iclrccd-fedex.com/export/outbound/mawb | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 40 | + complete-msg-url: https://apictm.iclrccd-fedex.com/export/outbound/mawb | ||
| 41 | + #代理地址(刷新token、传输海关回执地址、推送完整报文地址) | ||
| 42 | + # http://cn2-proxy.apac.fedex.com:3128 | ||
| 43 | + # http://internet.proxy.fedex.com | ||
| 44 | + proxy-url: cn2-proxy.apac.fedex.com | ||
| 45 | + proxy-port: 3128 | ... | ... |
| ... | @@ -16,9 +16,9 @@ task: | ... | @@ -16,9 +16,9 @@ task: |
| 16 | #推送完整报文 | 16 | #推送完整报文 |
| 17 | pushMawbTask: 0 0/1 * * * ? | 17 | pushMawbTask: 0 0/1 * * * ? |
| 18 | #推送失败的回执数据 | 18 | #推送失败的回执数据 |
| 19 | - pushErrorReturnDate: 0 0/30 * * * ? | 19 | + pushErrorReturnDate: 0 0/3 * * * ? |
| 20 | #推送失败的申报数据 | 20 | #推送失败的申报数据 |
| 21 | - pushErrorDeclareDate: 0 0/30 * * * ? | 21 | + pushErrorDeclareDate: 0 0/3 * * * ? |
| 22 | 22 | ||
| 23 | #推送地址 | 23 | #推送地址 |
| 24 | api: | 24 | api: |
| ... | @@ -37,9 +37,15 @@ api: | ... | @@ -37,9 +37,15 @@ api: |
| 37 | iclear-check-url-c: ${api.base-address}/chmConsignmentController/checkChmAndDetaliC | 37 | iclear-check-url-c: ${api.base-address}/chmConsignmentController/checkChmAndDetaliC |
| 38 | #获取token地址 | 38 | #获取token地址 |
| 39 | token-url: https://apiuat.iclrccd-fedex.com/login | 39 | token-url: https://apiuat.iclrccd-fedex.com/login |
| 40 | +# token-url: https://apictm.iclrccd-fedex.com/login | ||
| 40 | #刷新token地址 | 41 | #刷新token地址 |
| 41 | refresh-token-url: https://apiuat.iclrccd-fedex.com/user/token/refresh | 42 | refresh-token-url: https://apiuat.iclrccd-fedex.com/user/token/refresh |
| 42 | #传输海关回执地址 | 43 | #传输海关回执地址 |
| 43 | customs-url: https://apiuat.iclrccd-fedex.com/export/outbound/customs | 44 | customs-url: https://apiuat.iclrccd-fedex.com/export/outbound/customs |
| 44 | #推送完整报文地址 | 45 | #推送完整报文地址 |
| 45 | complete-msg-url: https://apiuat.iclrccd-fedex.com/export/outbound/mawb | 46 | complete-msg-url: https://apiuat.iclrccd-fedex.com/export/outbound/mawb |
| 47 | + #代理地址(刷新token、传输海关回执地址、推送完整报文地址) | ||
| 48 | +# http://cn2-proxy.apac.fedex.com:3128 | ||
| 49 | +# http://internet.proxy.fedex.com | ||
| 50 | + proxy-url: cn2-proxy.apac.fedex.com | ||
| 51 | + proxy-port: 3128 | ... | ... |
-
Please register or login to post a comment