1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.monitor;
14
15 import com.eviware.soapui.impl.WsdlInterfaceFactory;
16 import com.eviware.soapui.impl.wsdl.WsdlProject;
17 import com.eviware.soapui.impl.wsdl.panels.monitor.SoapMonitorDesktopPanel;
18 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
19 import com.eviware.soapui.model.iface.Interface;
20 import com.eviware.soapui.model.settings.Settings;
21 import com.eviware.soapui.support.StringUtils;
22 import com.eviware.soapui.support.UISupport;
23 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
24 import com.eviware.soapui.support.types.StringList;
25 import com.eviware.x.form.XFormDialog;
26 import com.eviware.x.form.XFormField;
27 import com.eviware.x.form.XFormFieldListener;
28 import com.eviware.x.form.support.ADialogBuilder;
29 import com.eviware.x.form.support.AField;
30 import com.eviware.x.form.support.AForm;
31 import com.eviware.x.form.support.AField.AFieldType;
32
33 public class SoapMonitorAction extends AbstractSoapUIAction<WsdlProject>
34 {
35 private static final String HTTPS_PROTOCOL = "https://";
36 private static final String HTTP_TUNNEL = "HTTP Tunnel";
37 private static final String HTTP_PROXY = "HTTP Proxy";
38 private XFormDialog dialog;
39
40 public SoapMonitorAction()
41 {
42 super("Launch SOAP Monitor", "Launches a SOAP traffic monitor for this project");
43 }
44
45 public void perform(WsdlProject project, Object param)
46 {
47 if (project.getInterfaceCount() == 0)
48 {
49 UISupport.showErrorMessage("Missing interfaces to monitor");
50 return;
51 }
52
53 if (dialog == null)
54 {
55 dialog = ADialogBuilder.buildDialog(LaunchForm.class);
56 }
57
58 Settings settings = project.getSettings();
59
60 StringList endpoints = new StringList();
61 endpoints.add(null);
62
63 for (Interface iface : project.getInterfaceList())
64 {
65 if (iface.getInterfaceType().equals(WsdlInterfaceFactory.WSDL_TYPE))
66 endpoints.addAll(iface.getEndpoints());
67 }
68
69 dialog.setIntValue(LaunchForm.PORT, (int) settings.getLong(LaunchForm.PORT, 8081));
70 dialog.setOptions(LaunchForm.REQUEST_WSS, StringUtils.merge(project.getWssContainer().getIncomingWssNames(),
71 "<none>"));
72 dialog.setOptions(LaunchForm.RESPONSE_WSS, StringUtils.merge(project.getWssContainer().getIncomingWssNames(),
73 "<none>"));
74 dialog.setValue(LaunchForm.SETSSLMON, settings.getString(LaunchForm.SETSSLMON, "").length() > 0 ? settings
75 .getString(LaunchForm.SETSSLMON, "") : HTTPS_PROTOCOL);
76 dialog.setOptions(LaunchForm.SSLORHTTP, new String[] { HTTP_TUNNEL, HTTP_PROXY });
77
78 dialog.setValue(LaunchForm.SSLTUNNEL_KEYSTORE, settings.getString(LaunchForm.SSLTUNNEL_KEYSTORE, ""));
79 dialog.setValue(LaunchForm.SSLTUNNEL_PASSWORD, settings.getString(LaunchForm.SSLTUNNEL_PASSWORD, ""));
80 dialog.setValue(LaunchForm.SSLTUNNEL_KEYPASSWORD, settings.getString(LaunchForm.SSLTUNNEL_KEYPASSWORD, ""));
81 dialog.setValue(LaunchForm.SSLTUNNEL_TRUSTSTORE, settings.getString(LaunchForm.SSLTUNNEL_TRUSTSTORE, ""));
82 dialog.setValue(LaunchForm.SSLTUNNEL_TRUSTSTORE_PASSWORD, settings.getString(
83 LaunchForm.SSLTUNNEL_TRUSTSTORE_PASSWORD, ""));
84 dialog.setBooleanValue(LaunchForm.SSLTUNNEL_REUSESTATE, settings.getBoolean(LaunchForm.SSLTUNNEL_REUSESTATE));
85 dialog.setValue(LaunchForm.SSLTUNNEL_KEYSTOREPATH, settings.getString(LaunchForm.SSLTUNNEL_KEYSTOREPATH, ""));
86 dialog.setValue(LaunchForm.SSLTUNNEL_KEYSTOREPASSWORD, settings.getString(LaunchForm.SSLTUNNEL_KEYSTOREPASSWORD, ""));
87
88 XFormField sslOrHttp = dialog.getFormField(LaunchForm.SSLORHTTP);
89 sslOrHttp.setValue(HTTP_PROXY);
90 setDialogState(HTTP_PROXY);
91 sslOrHttp.addFormFieldListener(new XFormFieldListener()
92 {
93
94 public void valueChanged(XFormField sourceField, String newValue, String oldValue)
95 {
96 setDialogState(newValue);
97 }
98
99 });
100
101
102 if (dialog.show())
103 {
104 int listenPort = dialog.getIntValue(LaunchForm.PORT, 8080);
105 settings.setLong(LaunchForm.PORT, listenPort);
106
107 settings.setString(LaunchForm.SETSSLMON, dialog.getValue(LaunchForm.SETSSLMON));
108
109 settings.setString(LaunchForm.SSLTUNNEL_KEYSTORE, dialog.getValue(LaunchForm.SSLTUNNEL_KEYSTORE));
110 settings.setString(LaunchForm.SSLTUNNEL_PASSWORD, dialog.getValue(LaunchForm.SSLTUNNEL_PASSWORD));
111 settings.setString(LaunchForm.SSLTUNNEL_KEYPASSWORD, dialog.getValue(LaunchForm.SSLTUNNEL_KEYPASSWORD));
112 settings.setString(LaunchForm.SSLTUNNEL_TRUSTSTORE, dialog.getValue(LaunchForm.SSLTUNNEL_TRUSTSTORE));
113 settings.setString(LaunchForm.SSLTUNNEL_TRUSTSTORE_PASSWORD, dialog.getValue(LaunchForm.SSLTUNNEL_TRUSTSTORE_PASSWORD));
114 settings.setString(LaunchForm.SSLTUNNEL_REUSESTATE, dialog.getValue(LaunchForm.SSLTUNNEL_REUSESTATE));
115 settings.setString(LaunchForm.SSLTUNNEL_KEYSTOREPATH, dialog.getValue(LaunchForm.SSLTUNNEL_KEYSTOREPATH));
116 settings.setString(LaunchForm.SSLTUNNEL_KEYSTOREPASSWORD, dialog.getValue(LaunchForm.SSLTUNNEL_KEYSTOREPASSWORD));
117
118 if (HTTP_PROXY.equals(dialog.getValue(LaunchForm.SSLORHTTP)))
119 {
120 openSoapMonitor(project, listenPort, dialog.getValue(LaunchForm.REQUEST_WSS), dialog
121 .getValue(LaunchForm.RESPONSE_WSS), dialog.getBooleanValue(LaunchForm.SETASPROXY), null);
122 }
123 else
124 {
125 openSoapMonitor(project, listenPort, dialog.getValue(LaunchForm.REQUEST_WSS), dialog
126 .getValue(LaunchForm.RESPONSE_WSS), dialog.getBooleanValue(LaunchForm.SETASPROXY), dialog
127 .getValue(LaunchForm.SETSSLMON));
128 }
129 }
130 }
131
132 protected void openSoapMonitor(WsdlProject target, int listenPort, String incomingRequestWss,
133 String incomingResponseWss, boolean setAsProxy, String sslEndpoint)
134 {
135 if (sslEndpoint == null)
136 {
137 UISupport.showDesktopPanel(new SoapMonitorDesktopPanel(target, listenPort, incomingRequestWss,
138 incomingResponseWss, setAsProxy, null));
139 }
140 else
141 {
142 String ssl = validate(sslEndpoint);
143 if (ssl == null)
144 {
145 UISupport.showErrorMessage("SSL Monitor needs endpoint.");
146 }
147 else
148 {
149 UISupport.showDesktopPanel(new SoapMonitorDesktopPanel(target, listenPort, incomingRequestWss,
150 incomingResponseWss, setAsProxy, ssl));
151 }
152 }
153 }
154
155 private String validate(String sslEndpoint)
156 {
157 String res = sslEndpoint;
158 int prot = sslEndpoint.indexOf("://");
159 if (prot > 0)
160 res = sslEndpoint.substring(prot + 3);
161 if (res.trim().length() > 0)
162 {
163 return res.trim();
164 }
165 return null;
166 }
167
168 private void setDialogState(String newValue)
169 {
170 if (HTTP_PROXY.equals(newValue))
171 {
172 dialog.getFormField(LaunchForm.SETSSLMON).setEnabled(false);
173 dialog.getFormField(LaunchForm.SSLTUNNEL_KEYSTORE).setEnabled(false);
174 dialog.getFormField(LaunchForm.SSLTUNNEL_PASSWORD).setEnabled(false);
175 dialog.getFormField(LaunchForm.SSLTUNNEL_KEYPASSWORD).setEnabled(false);
176 dialog.getFormField(LaunchForm.SSLTUNNEL_TRUSTSTORE).setEnabled(false);
177 dialog.getFormField(LaunchForm.SSLTUNNEL_TRUSTSTORE_PASSWORD).setEnabled(false);
178 dialog.getFormField(LaunchForm.SSLTUNNEL_REUSESTATE).setEnabled(false);
179 dialog.getFormField(LaunchForm.SSLTUNNEL_KEYSTOREPATH).setEnabled(false);
180 dialog.getFormField(LaunchForm.SSLTUNNEL_KEYSTOREPASSWORD).setEnabled(false);
181
182 dialog.getFormField(LaunchForm.SETASPROXY).setEnabled(true);
183 dialog.getFormField(LaunchForm.REQUEST_WSS).setEnabled(true);
184 dialog.getFormField(LaunchForm.RESPONSE_WSS).setEnabled(true);
185 }
186 else
187 {
188 dialog.getFormField(LaunchForm.SETSSLMON).setEnabled(true);
189 dialog.getFormField(LaunchForm.SSLTUNNEL_KEYSTORE).setEnabled(true);
190 dialog.getFormField(LaunchForm.SSLTUNNEL_PASSWORD).setEnabled(true);
191 dialog.getFormField(LaunchForm.SSLTUNNEL_KEYPASSWORD).setEnabled(true);
192 dialog.getFormField(LaunchForm.SSLTUNNEL_TRUSTSTORE).setEnabled(true);
193 dialog.getFormField(LaunchForm.SSLTUNNEL_TRUSTSTORE_PASSWORD).setEnabled(true);
194 dialog.getFormField(LaunchForm.SSLTUNNEL_REUSESTATE).setEnabled(true);
195 dialog.getFormField(LaunchForm.SSLTUNNEL_KEYSTOREPATH).setEnabled(true);
196 dialog.getFormField(LaunchForm.SSLTUNNEL_KEYSTOREPASSWORD).setEnabled(true);
197
198 dialog.getFormField(LaunchForm.SETASPROXY).setEnabled(false);
199 dialog.getFormField(LaunchForm.REQUEST_WSS).setEnabled(false);
200 dialog.getFormField(LaunchForm.RESPONSE_WSS).setEnabled(false);
201 }
202 }
203
204 @AForm(description = "Specify SOAP Monitor settings", name = "Launch SOAP Monitor", helpUrl = HelpUrls.SOAPMONITOR_HELP_URL)
205 public interface LaunchForm
206 {
207 @AField(description = "SSL tunnel or HTTP proxy", name = "Choose one:", type = AFieldType.RADIOGROUP)
208 public final static String SSLORHTTP = "Choose one:";
209
210 @AField(description = "The local port to listen on", name = "Port", type = AFieldType.INT)
211 public final static String PORT = "Port";
212
213 @AField(description = "The Incoming WSS configuration to use for processing requests", name = "Incoming Request WSS", type = AFieldType.ENUMERATION)
214 public final static String REQUEST_WSS = "Incoming Request WSS";
215
216 @AField(description = "The Outgoing WSS configuration to use for processing responses", name = "Incoming Response WSS", type = AFieldType.ENUMERATION)
217 public final static String RESPONSE_WSS = "Incoming Response WSS";
218
219 @AField(description = "Set as Global Proxy", name = "Set as Proxy", type = AFieldType.BOOLEAN)
220 public final static String SETASPROXY = "Set as Proxy";
221
222 @AField(description = "Set endpoint", name = "Set endpoint for HTTP Tunnel:", type = AFieldType.STRING)
223 public final static String SETSSLMON = "Set endpoint for HTTP Tunnel:";
224
225 @AField(description = "Set SSL Tunnel KeyStore", name = "HTTP tunnel - KeyStore", type = AFieldType.STRING)
226 public final static String SSLTUNNEL_KEYSTORE = "HTTP tunnel - KeyStore";
227
228 @AField(description = "Set SSL Tunnel Password", name = "HTTP tunnel - Password", type = AFieldType.PASSWORD)
229 public final static String SSLTUNNEL_PASSWORD = "HTTP tunnel - Password";
230
231 @AField(description = "Set SSL Tunnel KeyPassword", name = "HTTP tunnel - KeyPassword", type = AFieldType.PASSWORD)
232 public final static String SSLTUNNEL_KEYPASSWORD = "HTTP tunnel - KeyPassword";
233
234 @AField(description = "Set SSL Tunnel TrustStore", name = "HTTP tunnel - TrustStore", type = AFieldType.STRING)
235 public final static String SSLTUNNEL_TRUSTSTORE = "HTTP tunnel - TrustStore";
236
237 @AField(description = "Set SSL Tunnel TrustStore Password", name = "HTTP tunnel - TrustStore Password", type = AFieldType.PASSWORD)
238 public final static String SSLTUNNEL_TRUSTSTORE_PASSWORD = "HTTP tunnel - TrustStore Password";
239
240 @AField(description = "Keep request state", name = "Reuse request state", type = AFieldType.BOOLEAN)
241 public final static String SSLTUNNEL_REUSESTATE = "Reuse request state";
242
243 @AField(description = "Set SSL Client Key Store", name = "HTTP tunnel - Set SSL Client Key Store path", type = AFieldType.STRING)
244 public final static String SSLTUNNEL_KEYSTOREPATH = "HTTP tunnel - Set SSL Client Key Store path";
245
246 @AField(description = "Set SSL Client Key Store Password", name = "HTTP tunnel - Set SSL Client Key Store Password", type = AFieldType.PASSWORD)
247 public final static String SSLTUNNEL_KEYSTOREPASSWORD = "HTTP tunnel - Set SSL Client Key Store Password";
248 }
249 }