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