1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface.tools.gsoap;
14
15 import java.io.File;
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import com.eviware.soapui.SoapUI;
20 import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.AbstractToolsAction;
21 import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ArgumentBuilder;
22 import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ProcessToolRunner;
23 import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ToolHost;
24 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
25 import com.eviware.soapui.model.iface.Interface;
26 import com.eviware.soapui.settings.ToolsSettings;
27 import com.eviware.soapui.support.Tools;
28 import com.eviware.soapui.support.UISupport;
29 import com.eviware.soapui.support.types.StringToStringMap;
30 import com.eviware.x.form.XForm;
31 import com.eviware.x.form.XFormDialog;
32 import com.eviware.x.form.XFormDialogBuilder;
33 import com.eviware.x.form.XFormFactory;
34
35 /***
36 * Invokes GSoap wsdl2h
37 *
38 * @author Ole.Matzura
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 public class GSoapAction extends AbstractToolsAction<Interface>
74 {
75 private static final String WSDL2H_PATH = "path";
76 private static final String WSDL2H_OUTPUT = "file";
77
78
79 private static final String GENERATE_INDEXED_STRUCT = "generate indexed struct names";
80 private static final String GENERATE_C_SOURCE = "generate C source code";
81 private static final String DOM = "use DOM";
82 private static final String DONT_QUALIFY_ENUM_NAMES = "don't qualify enum names";
83 private static final String FLAT_CPP_CLASS_HIERARCHY = "generate flat C++ class hierarchy";
84 private static final String GLOBAL_TOP_LEVEL_DECLARATIONS = "generate global top-level declarations";
85 private static final String PATH = "path to find files";
86 private static final String INCLUDE_LICENSE_INFORMATION = "include license information";
87 private static final String USE_XSD_H = "use xsd.h module";
88 private static final String BASE_NAMESPACE_PREFIX_INSTEAD_OF_NS = "prefixNs";
89 private static final String BASE_NAMESPACE_PREFIX_FOR_SERVICE_NS = "servicePrefixNs";
90 private static final String POLYMORPHIC_TYPES = "create polymorphic types";
91 private static final String PROXY_HOST_PORT = "proxy host:port";
92 private static final String NO_STL = "don't generate STL code";
93 private static final String TYPE_MAP_FILE = "use type map file";
94 private static final String NO_UNIONS = "don't generate unions";
95 private static final String VERBOSE = "verbose output";
96 private static final String WRAP_RESPONSE_STRUCT = "wrap response in struct";
97 private static final String NO_ANY = "don't generate _XML any/anyAttribute";
98 private static final String TYPEDEF_SYNONYMS = "generate typedef synonyms for structs and enums";
99
100
101 private static final String SOAP_11 = "generate SOAP 1.1 bindings";
102 private static final String SOAP_12 = "generate SOAP 1.2 bindings";
103 private static final String CLIENT_SIDE = "generate client-side code only";
104 private static final String SERVER_SIDE = "generate server-side code only";
105 private static final String NO_LIB = "don't generate soapClientLib/soapServerLib";
106 private static final String SOAP_ACTION = "use value of SOAPAction HTTP header to dispatch method at server side";
107 private static final String GENERATE_C_SOURCE_CPP = "generate C source code";
108 private static final String SAVE_PATH = "use path to save files";
109 private static final String SOAP_RPC = "generate SOAP RPC encoding style bindings";
110 private static final String SERVICE_PROXIES = "generate service proxies and objects inherited from soap struct";
111 private static final String IMPORT_PATH = "import path(s)";
112 private static final String GENERATE_LINKABLE_MODULES = "generate linkable modules (experimental)";
113 private static final String GENERATE_MATLAB_CODE = "generate Matlab(tm) code for MEX compiler";
114 private static final String SERVICE_NAME = "use service name to rename service functions and namespace table";
115 private static final String NAME_PREFIX = "file prefix";
116 private static final String XSI_TYPED = "generate code for fully xsi:type typed SOAP/XML messaging";
117 private static final String NO_GEN_WSDL_SCHEMA = "don't generate WSDL and schema files";
118 private static final String NO_GEN_SAMPLE_XML = "don't generate sample XML message files";
119
120 private static final String WSDL2H = "run wsdl2h";
121 private static final String SOAPCPP2 = "run soapcpp2";
122
123 public GSoapAction( Interface iface )
124 {
125 super( iface, "GSoap Artifacts", "Generates GSoap artifacts using wsdl2h and soap2cpp");
126 }
127
128 protected StringToStringMap initValues()
129 {
130 StringToStringMap values = super.initValues();
131
132 values.putIfMissing( WSDL2H, Boolean.toString( true ));
133 values.putIfMissing( SOAPCPP2, Boolean.toString( true ));
134 return values;
135 }
136
137 protected XFormDialog buildDialog()
138 {
139 XFormDialogBuilder builder = XFormFactory.createDialogBuilder("GSoap Artifacts");
140
141 XForm wsdl2hAdvForm = builder.createForm( "wsdl2h" );
142
143 wsdl2hAdvForm.addCheckBox( WSDL2H, null );
144 addWSDLFields( wsdl2hAdvForm );
145
146 wsdl2hAdvForm.addTextField( WSDL2H_OUTPUT, "name of output file", XForm.FieldType.PROJECT_FILE );
147
148 XForm soapcpp2AdvForm = builder.createForm( "soapcpp2" );
149
150 soapcpp2AdvForm.addCheckBox( SOAPCPP2, null );
151
152 wsdl2hAdvForm.addCheckBox(GENERATE_INDEXED_STRUCT, null);
153 wsdl2hAdvForm.addCheckBox(GENERATE_C_SOURCE, null);
154 wsdl2hAdvForm.addCheckBox(DOM,null);
155 wsdl2hAdvForm.addCheckBox(DONT_QUALIFY_ENUM_NAMES, null);
156 wsdl2hAdvForm.addCheckBox(FLAT_CPP_CLASS_HIERARCHY, null);
157 wsdl2hAdvForm.addCheckBox(GLOBAL_TOP_LEVEL_DECLARATIONS, null);
158 wsdl2hAdvForm.addTextField(PATH, "use path to find files", XForm.FieldType.PROJECT_FOLDER);
159 wsdl2hAdvForm.addCheckBox(INCLUDE_LICENSE_INFORMATION, null);
160 wsdl2hAdvForm.addCheckBox(USE_XSD_H, null);
161 wsdl2hAdvForm.addTextField( BASE_NAMESPACE_PREFIX_INSTEAD_OF_NS, "use name as the base namespace prefix name instead of ns", XForm.FieldType.TEXT );
162 wsdl2hAdvForm.addTextField( BASE_NAMESPACE_PREFIX_FOR_SERVICE_NS, "use name as the base namespace prefix name for service namespaces", XForm.FieldType.TEXT );
163
164 wsdl2hAdvForm.addCheckBox(POLYMORPHIC_TYPES, null);
165 wsdl2hAdvForm.addTextField( PROXY_HOST_PORT, "connect via proxy host and port (host:port)", XForm.FieldType.TEXT );
166 wsdl2hAdvForm.addCheckBox(NO_STL, null);
167 wsdl2hAdvForm.addTextField(TYPE_MAP_FILE, "use type map file instead of the default file typemap.dat", XForm.FieldType.PROJECT_FILE);
168 wsdl2hAdvForm.addCheckBox(NO_UNIONS,null);
169 wsdl2hAdvForm.addCheckBox(VERBOSE, null);
170 wsdl2hAdvForm.addCheckBox(WRAP_RESPONSE_STRUCT, null);
171 wsdl2hAdvForm.addCheckBox(NO_ANY, null);
172 wsdl2hAdvForm.addCheckBox(TYPEDEF_SYNONYMS, null);
173
174 soapcpp2AdvForm.addCheckBox(SOAP_11, null);
175 soapcpp2AdvForm.addCheckBox(SOAP_12, null);
176 soapcpp2AdvForm.addCheckBox(CLIENT_SIDE, null);
177 soapcpp2AdvForm.addCheckBox(SERVER_SIDE, null);
178 soapcpp2AdvForm.addCheckBox(NO_LIB, null);
179 soapcpp2AdvForm.addCheckBox(SOAP_ACTION, null);
180 soapcpp2AdvForm.addCheckBox(GENERATE_C_SOURCE_CPP, null);
181
182 soapcpp2AdvForm.addCheckBox(SOAP_RPC, null);
183 soapcpp2AdvForm.addCheckBox(SERVICE_PROXIES, null);
184 soapcpp2AdvForm.addTextField(IMPORT_PATH, "use path(s) for #import", XForm.FieldType.PROJECT_FOLDER);
185 soapcpp2AdvForm.addCheckBox(GENERATE_LINKABLE_MODULES, null);
186 soapcpp2AdvForm.addCheckBox(GENERATE_MATLAB_CODE, null);
187 soapcpp2AdvForm.addCheckBox(SERVICE_NAME, null);
188 soapcpp2AdvForm.addTextField(NAME_PREFIX, "save files with new prefix name instead of 'soap'", XForm.FieldType.TEXT);
189 soapcpp2AdvForm.addCheckBox(XSI_TYPED, null);
190 soapcpp2AdvForm.addCheckBox(NO_GEN_WSDL_SCHEMA, null);
191 soapcpp2AdvForm.addCheckBox(NO_GEN_SAMPLE_XML, null);
192
193 return builder.buildDialog( buildDefaultActions( HelpUrls.GSOAP_HELP_URL ),
194 "Specify arguments for GSoap wsdl2h and soap2cpp", UISupport.TOOL_ICON );
195 }
196
197 protected void generate(StringToStringMap values, ToolHost toolHost) throws Exception
198 {
199 String gsoapDir = SoapUI.getSettings().getString( ToolsSettings.GSOAP_LOCATION, null );
200 if( Tools.isEmpty( gsoapDir ))
201 {
202 UISupport.showErrorMessage( "GSoap directory must be set in global preferences" );
203 return;
204 }
205
206 List<ProcessBuilder> builders = new ArrayList<ProcessBuilder>();
207
208 if( values.getBoolean( WSDL2H ))
209 {
210 ProcessBuilder wsdl2hBuilder = new ProcessBuilder();
211 ArgumentBuilder wsdl2hArgs = buildWsdl2HArgs();
212 wsdl2hBuilder.command( wsdl2hArgs.getArgs());
213
214 wsdl2hBuilder.directory ( new File(Tools.getDir( values.get( WSDL2H_OUTPUT ) )));
215 builders.add( wsdl2hBuilder );
216 }
217
218 if( values.getBoolean( SOAPCPP2 ))
219 {
220 ProcessBuilder soapcpp2Builder = new ProcessBuilder();
221 ArgumentBuilder soapcpp2Args = buildSoapcpp2Args();
222 soapcpp2Builder.command( soapcpp2Args.getArgs());
223 soapcpp2Builder.directory( new File(Tools.getDir( values.get( WSDL2H_OUTPUT ) )));
224
225 builders.add( soapcpp2Builder );
226 }
227
228 if( builders.isEmpty() )
229 UISupport.showErrorMessage( "Nothing to run!" );
230 else
231 toolHost.run( new ProcessToolRunner( builders.toArray( new ProcessBuilder[builders.size()]), "GSoap", modelItem ));
232 }
233
234 private ArgumentBuilder buildWsdl2HArgs()
235 {
236 String gsoapDir = SoapUI.getSettings().getString( ToolsSettings.GSOAP_LOCATION, null );
237 StringToStringMap values = dialog.getValues();
238 ArgumentBuilder builder = new ArgumentBuilder( values );
239 builder.startScript( gsoapDir + File.separator + "wsdl2h", "", "" );
240 builder.addArgs( new String[] { "-v" } );
241
242 values.put( WSDL2H_OUTPUT, Tools.getFilename( values.get( WSDL2H_OUTPUT ) ));
243
244 builder.addString( WSDL2H_OUTPUT, "-o", "");
245 builder.addArgs( getWsdlUrl( values ));
246
247 builder.addBoolean(GENERATE_INDEXED_STRUCT, "-a");
248 builder.addBoolean(GENERATE_C_SOURCE, "-c");
249 builder.addBoolean(DOM, "-c");
250 builder.addBoolean(DONT_QUALIFY_ENUM_NAMES, "-e");
251 builder.addBoolean(FLAT_CPP_CLASS_HIERARCHY, "-f");
252 builder.addBoolean(GLOBAL_TOP_LEVEL_DECLARATIONS, "-g");
253 builder.addString(PATH, "-I", "");
254 builder.addBoolean(INCLUDE_LICENSE_INFORMATION, "-l");
255 builder.addBoolean(USE_XSD_H, "-m");
256 builder.addString(BASE_NAMESPACE_PREFIX_INSTEAD_OF_NS, "-n", "");
257 builder.addString(BASE_NAMESPACE_PREFIX_FOR_SERVICE_NS, "-N", "");
258 builder.addBoolean(POLYMORPHIC_TYPES, "-p");
259 builder.addString(PROXY_HOST_PORT, "-r", "");
260 builder.addBoolean(NO_STL, "-s");
261 builder.addString(TYPE_MAP_FILE, "-t", "");
262 builder.addBoolean(NO_UNIONS, "-u");
263 builder.addBoolean(VERBOSE, "-v");
264 builder.addBoolean(WRAP_RESPONSE_STRUCT, "-w");
265 builder.addBoolean(NO_ANY, "-x");
266 builder.addBoolean(TYPEDEF_SYNONYMS, "-y");
267 return builder;
268 }
269
270 private ArgumentBuilder buildSoapcpp2Args()
271 {
272 String gsoapDir = SoapUI.getSettings().getString( ToolsSettings.GSOAP_LOCATION, null );
273 StringToStringMap values = dialog.getValues();
274 ArgumentBuilder builder = new ArgumentBuilder( values );
275 builder.startScript( gsoapDir + File.separator + "soapcpp2", "", "" );
276 builder.addArgs( new String[] { "-Iimport", values.get( WSDL2H_OUTPUT ) } );
277
278 builder.addBoolean(SOAP_11, "-1");
279 builder.addBoolean(SOAP_12, "-2");
280 builder.addBoolean(CLIENT_SIDE, "-C");
281 builder.addBoolean(SERVER_SIDE, "-S");
282 builder.addBoolean(NO_LIB, "-L");
283 builder.addBoolean(SOAP_ACTION, "-a");
284 builder.addBoolean(GENERATE_C_SOURCE_CPP, "-c");
285 builder.addBoolean(SOAP_RPC, "-e");
286 builder.addBoolean(SERVICE_PROXIES, "-i");
287 builder.addString(IMPORT_PATH, "-I", "");
288 builder.addBoolean(GENERATE_LINKABLE_MODULES, "-l");
289 builder.addBoolean(GENERATE_MATLAB_CODE, "-m");
290 builder.addBoolean(SERVICE_NAME, "-n");
291 builder.addString(NAME_PREFIX, "-p", "");
292 builder.addBoolean(XSI_TYPED, "-t");
293 builder.addBoolean(NO_GEN_WSDL_SCHEMA, "-w");
294 builder.addBoolean(NO_GEN_SAMPLE_XML, "-x");
295
296 return builder;
297 }
298 }