1. # vim file.xml
:set nobomb
x
:wqx
2. Notepad ++:
Save UTF-8 without BOM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| public SOAPMessage sendSoapRequest(String endpointUrl, SOAPMessage request) { try { // Send HTTP SOAP request and get response SOAPConnection soapConnection = SOAPConnectionFactory.newInstance().createConnection(); SOAPMessage response = soapConnection.call(request, endpointUrl); // Close connection soapConnection.close(); return response; } catch (SOAPException ex) { // Do Something } return null ; } |
1
2
3
4
5
6
7
8
| /** * Dummy class implementing HostnameVerifier to trust all host names */ private static class TrustAllHosts implements HostnameVerifier { public boolean verify(String hostname, SSLSession session) { return true ; } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| public SOAPMessage sendSoapRequest(String endpointUrl, SOAPMessage request) { try { final boolean isHttps = endpointUrl.toLowerCase().startsWith( "https" ); HttpsURLConnection httpsConnection = null ; // Open HTTPS connection if (isHttps) { // Open HTTPS connection URL url = new URL(endpointUrl); httpsConnection = (HttpsURLConnection) url.openConnection(); // Trust all hosts httpsConnection.setHostnameVerifier( new TrustAllHosts()); // Connect httpsConnection.connect(); } // Send HTTP SOAP request and get response SOAPConnection soapConnection = SOAPConnectionFactory.newInstance().createConnection(); SOAPMessage response = soapConnection.call(request, endpointUrl); // Close connection soapConnection.close(); // Close HTTPS connection if (isHttps) { httpsConnection.disconnect(); } return response; } catch (SOAPException | IOException ex) { // Do Something } return null ; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| /** * Dummy class implementing X509TrustManager to trust all certificates */ private static class TrustAllCertificates implements X509TrustManager { public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } public X509Certificate[] getAcceptedIssuers() { return null ; } } |
1
2
3
4
5
6
| // Create SSL context and trust all certificates SSLContext sslContext = SSLContext.getInstance( "SSL" ); TrustManager[] trustAll = new TrustManager[] { new TrustAllCertificates()}; sslContext.init( null , trustAll, new java.security.SecureRandom()); // Set trust all certificates context to HttpsURLConnection HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| /** * Sends SOAP request and saves it in a queue. * * @param request SOAP Message request object * @return SOAP Message response object */ public SOAPMessage sendSoapRequest(String endpointUrl, SOAPMessage request) { try { final boolean isHttps = endpointUrl.toLowerCase().startsWith( "https" ); HttpsURLConnection httpsConnection = null ; // Open HTTPS connection if (isHttps) { // Create SSL context and trust all certificates SSLContext sslContext = SSLContext.getInstance( "SSL" ); TrustManager[] trustAll = new TrustManager[] { new TrustAllCertificates()}; sslContext.init( null , trustAll, new java.security.SecureRandom()); // Set trust all certificates context to HttpsURLConnection HttpsURLConnection .setDefaultSSLSocketFactory(sslContext.getSocketFactory()); // Open HTTPS connection URL url = new URL(endpointUrl); httpsConnection = (HttpsURLConnection) url.openConnection(); // Trust all hosts httpsConnection.setHostnameVerifier( new TrustAllHosts()); // Connect httpsConnection.connect(); } // Send HTTP SOAP request and get response SOAPConnection soapConnection = SOAPConnectionFactory.newInstance().createConnection(); SOAPMessage response = soapConnection.call(request, endpointUrl); // Close connection soapConnection.close(); // Close HTTPS connection if (isHttps) { httpsConnection.disconnect(); } return response; } catch (SOAPException | IOException | NoSuchAlgorithmException | KeyManagementException ex) { // Do Something } return null ; } |