Creating and running a fake web service from a WSDL

I needed to develop some Apex web service callout code – never a pleasant experience see e.g. When “Generate from WSDL” fails – hand-coding web service calls – but did not have access to a running instance of the service. Java 6 includes web service technology by default and I was pleasantly surprised how easy it is to create and run a fake web service to develop against using this…

Having run wsimport to generate the web service classes from the WSDL, creating a server implementation class is simply a matter of extending the service interface and using Eclipse’s “Add unimplemented methods” to create the server skeleton then adding a couple of annotations:

package com.claimvantage.test;

import javax.jws.WebService;

// Other imports removed

        serviceName = "FNCEWS40Service",
        portName = "FNCEWS40MTOMPort",
        targetNamespace = "",
        wsdlLocation = "com/claimvantage/test/filenet.wsdl",
        endpointInterface = "com.claimvantage.filenet.FNCEWS40PortType"
public class ServiceFakeImpl implements FNCEWS40PortType {

    public ObjectSetType executeSearch(SearchRequestType request, Localization header) throws FaultResponse {
        // TODO fake implementation goes here
        return null;

    // Other methods removed

The Endpoint class makes running this service very easy (with no separate web server or XML configuration required):

package com.claimvantage.test;


public class ServiceRunner {

    private static final String URL = "http://localhost:9080/wsi/FNCEWS40MTOM/";

    public static void main(String[] args) {
        Endpoint endpoint = Endpoint.create(new ServiceFakeImpl());
        System.out.println("Service running at " + URL);

Then make the fake service accessible from the internet (and so from by e.g. setting up firewall port forwarding.

Debug output and fake responses can be added to the fake server methods. When combined with debug logging in the Apex and a tool such as tcpmon to view the request and response headers and XML this gives full visibility to what is going on across the whole request/response cycle.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s