简体   繁体   中英

Create mock soap web services from wsdl - Java

I'm new to implementing soap services. Until now I have implemented only REST services in Java with jax-rs which were deployed in Talend ESB.

I need to create a mock service from a wsdl file. I am using cxf, jax-ws and I need to deploy the bundles in a talend container. I generated web services from wsdl file resulting in service interfaces and DTOs.

At the moment I do not have the implementation of the service and I need to create a mock service. My porblem is that I do not know how to create a mock service that will be replaced in the near future with the real implementation with as minimal effort as possible, this meaning that when I will receive the implemetation I do not want to make any major modificaions for the system to run.

Thanks, Dorin

You can use a tool like SOAPUI (free and paid versions) to import the WSDL and create a mock service from it. From there, you can craft canned response messages and even implement some logic in the mock service such as "if lastName is 'ERROR', raise soap fault" to allow you to test various service response scenarios in your client application.

The trendy industry term for web service stubbing / mocking / virtualizing is " service virtualization ." There are a variety of tools that do this, of varying price ranges and capabilities.

As for your concern of having to modify the client application when the real service provider implementation is available, this is a valid concern. Assuming the WSDL interface itself does not change, here are some web service facets that may not (often do not) appear in WSDL and can cause you more work when the real service provider expects them yet your stub/mock does not:

My suggestion here is to simply inquire of the service provider if there are any of these requirements in the real service implementation or at the live service endpoint.

I've just created a PoC for a simple JUnit Rule that handles most of the heavy lifting: mockito-soap-cxf . I am not familiar with your container, so you might want to adapt it somewhat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM