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.wsdl.WsdlProject;
16 import com.eviware.soapui.impl.wsdl.panels.monitor.SoapMonitorDesktopPanel;
17 import com.eviware.soapui.model.iface.Interface;
18 import com.eviware.soapui.model.settings.Settings;
19 import com.eviware.soapui.support.StringUtils;
20 import com.eviware.soapui.support.UISupport;
21 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
22 import com.eviware.soapui.support.types.StringList;
23 import com.eviware.x.form.XFormDialog;
24 import com.eviware.x.form.XFormField;
25 import com.eviware.x.form.XFormFieldListener;
26 import com.eviware.x.form.support.ADialogBuilder;
27 import com.eviware.x.form.support.AField;
28 import com.eviware.x.form.support.AForm;
29 import com.eviware.x.form.support.AField.AFieldType;
30
31 public class SoapMonitorAction extends AbstractSoapUIAction<WsdlProject>
32 {
33 private static final String CREATE_TCP_TUNNEL = "Create TCP Tunnel";
34 private static final String CREATE_HTTP_PROXY = "Create HTTP Proxy";
35 private XFormDialog dialog;
36
37 public SoapMonitorAction()
38 {
39 super( "Launch SOAP Monitor", "Launches a SOAP traffic monitor for this project" );
40 }
41
42 public void perform( WsdlProject target, Object param )
43 {
44 if( target.getInterfaceCount() == 0 )
45 {
46 UISupport.showErrorMessage( "Missing interfaces to monitor" );
47 return;
48 }
49
50 if( dialog == null )
51 {
52 dialog = ADialogBuilder.buildDialog( LaunchForm.class );
53 dialog.getFormField( LaunchForm.MODE ).addFormFieldListener( new XFormFieldListener() {
54
55 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
56 {
57 dialog.getFormField( LaunchForm.TARGET_HOST ).setEnabled( !newValue.equals( CREATE_HTTP_PROXY ) );
58 dialog.getFormField( LaunchForm.ADD_ENDPOINT ).setEnabled( !newValue.equals( CREATE_HTTP_PROXY ) );
59 }});
60
61 dialog.setBooleanValue( LaunchForm.ADD_ENDPOINT, true );
62 }
63
64 Settings settings = target.getSettings();
65
66 StringList endpoints = new StringList();
67 endpoints.add( null );
68
69 for( Interface iface : target.getInterfaceList())
70 {
71 endpoints.addAll( iface.getEndpoints() );
72 }
73
74 dialog.setOptions( LaunchForm.TARGET_HOST, endpoints.toStringArray() );
75
76 dialog.setIntValue( LaunchForm.PORT, ( int ) settings.getLong( LaunchForm.PORT, 8081 ));
77 dialog.setValue( LaunchForm.TARGET_HOST, settings.getString( LaunchForm.TARGET_HOST, "" ));
78 String launchMode = settings.getString( LaunchForm.MODE, CREATE_TCP_TUNNEL );
79 dialog.setValue( LaunchForm.MODE, launchMode);
80
81 dialog.getFormField( LaunchForm.TARGET_HOST ).setEnabled( !launchMode.equals( CREATE_HTTP_PROXY ) );
82 dialog.getFormField( LaunchForm.ADD_ENDPOINT ).setEnabled( !launchMode.equals( CREATE_HTTP_PROXY ) );
83
84 dialog.setOptions( LaunchForm.REQUEST_WSS,
85 StringUtils.merge( target.getWssContainer().getIncomingNames(), "<none>" ) );
86 dialog.setOptions( LaunchForm.RESPONSE_WSS,
87 StringUtils.merge( target.getWssContainer().getIncomingNames(), "<none>" ) );
88
89 if( dialog.show())
90 {
91 int listenPort = dialog.getIntValue( LaunchForm.PORT, 8080 );
92 settings.setLong( LaunchForm.PORT, listenPort );
93 String targetHost = dialog.getValue( LaunchForm.TARGET_HOST );
94 settings.setString( LaunchForm.TARGET_HOST, targetHost);
95 settings.setString( LaunchForm.MODE, dialog.getValue( LaunchForm.MODE ));
96
97 openSoapMonitor( target, listenPort, targetHost, dialog.getBooleanValue( LaunchForm.ADD_ENDPOINT ),
98 dialog.getValue( LaunchForm.MODE ).equals( CREATE_HTTP_PROXY ),
99 dialog.getValue( LaunchForm.REQUEST_WSS),
100 dialog.getValue( LaunchForm.RESPONSE_WSS ));
101 }
102 }
103
104 protected void openSoapMonitor( WsdlProject target, int listenPort, String targetHost, boolean addEndpoint,
105 boolean isProxy, String incomingRequestWss, String incomingResponseWss )
106 {
107 UISupport.showDesktopPanel( new SoapMonitorDesktopPanel( target,
108 targetHost,
109 listenPort, addEndpoint, isProxy, incomingRequestWss, incomingResponseWss ) );
110 }
111
112 @AForm(description = "Specify SOAP Monitor settings", name = "Launch SOAP Monitor" )
113 private interface LaunchForm
114 {
115 @AField(description = "The local port to listen on", name = "Port", type=AFieldType.INT )
116 public final static String PORT = "Port";
117
118 @AField(description = "Specifies monitor mode", name = "Mode", type=AFieldType.RADIOGROUP,
119 values= {CREATE_TCP_TUNNEL, CREATE_HTTP_PROXY})
120 public final static String MODE = "Mode";
121
122 @AField(description = "The target host to invoke", name = "Target Host", type=AFieldType.ENUMERATION )
123 public final static String TARGET_HOST = "Target Host";
124
125 @AField(description = "Adds an endpoint for the Tcp Tunnel", name = "Add Endpoint", type=AFieldType.BOOLEAN )
126 public final static String ADD_ENDPOINT = "Add Endpoint";
127
128 @AField(description = "The Incoming WSS configuration to use for processing requests", name = "Incoming Request WSS", type=AFieldType.ENUMERATION )
129 public final static String REQUEST_WSS = "Incoming Request WSS";
130
131 @AField(description = "The Outgoing WSS configuration to use for processing responses", name = "Incoming Response WSS", type=AFieldType.ENUMERATION )
132 public final static String RESPONSE_WSS = "Incoming Response WSS";
133 }
134 }