Skip to content

Create mock for WSDL web services

JGuillemotte edited this page Oct 6, 2011 · 8 revisions

There are several ways to create mocks to simulate localy a web service.

WSDL2JAVA and CXF :

With this tool, it is possible to generate Java classes for a server and/or a client. You just have to complete some classes (with the values to return for instance) and make a main classe to publish the mock web service.

To use the tool, execute the following command :

wsdl2java -server [HelloWorld.wsdl] -d [outputFolder]

Remark : change the text between brackets as your convenience.

Think to remove or comment the wsdlLocation attributes. If these attributes are not removed in the classes, the service will try to download the original WSDL from the Internet.

FraSCAti :

With a WS binding configured in a composite file.

This is an example of a mock configured to reproduce an existing meteo service :

<implementation.java class="net.webservicex.GlobalWeatherSoapImpl1" />

<service name="meteoServiceBackup">

    <interface.java interface="net.webservicex.GlobalWeatherSoap"/>

    <binding.ws uri="http://localhost:9020/WeatherService" />

</service>

Main problem : the generated WSDL doesn"t correspond exactly to the original WSDL. This is a serious problem to use it with existing clients that already work with the original service. This problems occurs because fraSCAti doesn't take care of the jaxws annotations present in the classes and uses it's own rules to name the bindings, ports ...

See this issue in EasySOA Github : https://github.com/easysoa/EasySOA/issues/23

Frascati has also a WSDL2JAVA tool (the same offered by CXF) To use it, execute the following command :

frascati wsdl2java -u [http://192.168.2.157:9010/PureAirFlowers?wsdl] -o [src/generated/java]

Remark : change the text between brackets as your convenience.

Soap UI :

Maybe the most simple way to make a mock server or/and a client for a WSDl web service. Create a new project with the WSDL file corresponding to the web service to work with and all is automatically done.

Avantages : nothing to do, all is automatic. Inconvenients : cannot be embeded or run in a standalone executable. Soap UI is required. With the Soap UI api, it is maybe possible to build a project and to obtain a mock programmatically.

Clone this wiki locally