Код
Код: Выделить всё
public Map ConnectRestService(MyRequest myRequest, String postURL, String httpProxy,int timeout int httpPort, Map responseMap)
throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CustomException{
MyResponse myResponse = new MyResponse();
Map responseReturnMap = new HashMap();
String output = "";
TrustStrategy acceptingTrustStrategy = new TrustStrategy() {
@Override
public boolean isTrusted(java.security.cert.X509Certificate[] chain, String authType)
throws java.security.cert.CertificateException {
// TODO Auto-generated method stub
return true;
}
};
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
HttpClient httpClient;
httpClient = HttpClients.custom().setSSLSocketFactory(csf).setProxy(new HttpHost(httpProxy, httpPort)).build();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Content-type", "text/xml");
httpHeaders.add("Accept", "text/xml");
httpHeaders.add("access-control-allow-origin", "*");
httpHeaders.add("content-encoding", "UTF-8");
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
requestFactory.setConnectTimeout(timeout);
try {
RestTemplate restTemplate = new RestTemplate(requestFactory);
HttpEntity entity = new org.springframework.http.HttpEntity(
myRequest, httpHeaders);
ResponseEntity response = restTemplate.exchange(postURL, HttpMethod.POST, entity, String.class);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
return responseReturnMap;
}
Подробнее здесь: https://stackoverflow.com/questions/567 ... cationally