-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvokerJob.java
More file actions
97 lines (68 loc) · 2.45 KB
/
Copy pathInvokerJob.java
File metadata and controls
97 lines (68 loc) · 2.45 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.util.HashMap;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.ibm.websphere.ssl.JSSEHelper;
/**
* A job that invokes an XML-RPC service within Websphere
* Application Server using a dynamic SSL configuration
* that head already been setup.
* @author rmurali
*
*/
public class InvokerJob implements Job {
public void execute(JobExecutionContext jec) throws JobExecutionException {
BufferedWriter out = null;
HttpsURLConnection connection = null;
try {
String urlString = System.getProperty("RPCURL");
String[] components =urlString.split(":");
String port = components[2].substring(0, 4);
URL url = new URL(urlString);
//accepts the certificate presented by the server regardless of whether there is a mismatch between the hostname
//in the cert and what is requested in the URL
HostnameVerifier hv = new HostnameVerifier()
{
public boolean verify(String urlHostName, SSLSession session)
{
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
connection = (HttpsURLConnection) url.openConnection();
String alias = "<DunamicSSLConfigurationName>";
final HashMap connectionInfo = new HashMap();
connectionInfo.put(JSSEHelper.CONNECTION_INFO_DIRECTION, JSSEHelper.DIRECTION_OUTBOUND);
connectionInfo.put(JSSEHelper.CONNECTION_INFO_REMOTE_HOST, "localhost");
connectionInfo.put(JSSEHelper.CONNECTION_INFO_REMOTE_PORT, port);
javax.net.ssl.SSLSocketFactory sslFact = JSSEHelper.getInstance().getSSLSocketFactory(alias, connectionInfo, null);
connection.setSSLSocketFactory(sslFact);
connection.setDoOutput(true);
out = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
if (connection.getResponseCode() == 200) {
System.out.println("Invoked RPC successfully on Port-"+port);
} else {
throw new Exception("Error in invoking Pool Servlet Refresh url -"+urlString);
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
//Disconnecting HTTPSConnection
connection.disconnect();
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}