dev
dev

Reputation: 175

How to generate mock web service using WSDL in Java?

I have WSDL file and for local testing I need to generate mock web service.

Please do not recommend SoapUI.

Can anybody please help how to generate mock web service in Java using WSDL?

Upvotes: 12

Views: 15988

Answers (2)

walter
walter

Reputation: 356

One option is to create a Web Services project using an IDE. This will allow you to create a mock service and also implement your business logic.

As an example, using Eclipse:

Before starting, ensure that:

  • Eclipse has a server installed (Apache Tomcat)
  • Your WSDL file have a .wsdl extension (if not, rename as .wsdl)

Now, start Eclipse:

  1. Create a new java "Dynamic Web Project"
  2. Create a folder WebContent\wsdl and copy your WSDL file
  3. Right-click on project > select new "Web Service"
  4. Select:

    • Web Service type: "Top down Java bean Web Service"

    • Service definition: browser your WSDL file

    • Select "Start Service"

    • Select "Java Proxy / Start Client"

    • Select both option at the bottom of the form (publish/monitor)

  5. Click next to complete process

At the end, your server should be started and WS deployed - check that your WSDL is available.

Now, you can:

  • call your WS using Eclipse Web Services Explorer see explorer
  • implement your WS mockup business logic see method implementation
  • or use a working java client to call your WS programmatically

Hope this help.

Upvotes: 8

Raveen Athapaththu
Raveen Athapaththu

Reputation: 190

Try using Wiremock. However you will be needing to create and structure json/xml files according to your need.
This will give you an better idea. Using WireMock with SOAP Web Services in Java

Upvotes: 0

Related Questions