TL;DR: How can I have an optional <part> in the response <message> for a wsdl service.
I am:
- targeting an existing service
- writing a client to talk to the service
- implemented the service definition as a Java interface
The problem: Depending on the version of the service there could be an additional element in the response Body element.
With the following service definition I can target v1 of the service:
<message name="CreateResponse">
<part name="ResourceCreated" element="ns7:ResourceCreated" />
</message>
And this one works with v2 of the service:
<message name="CreateResponse">
<part name="ResourceCreated" element="ns7:ResourceCreated" />
<part name="Shell" element="ns8:Shell" />
</message>
Question: How can I target both versions with the same service definition? I don't really need the second element so just ignoring it would be fine.
Details:
- The service is the
Windows Remote Management Service
. - I am writing a Java client to target it.
- The code is available at https://github.com/cloudsoft/winrm4j
- When talking to Windows 7 the
Create
response contains a singleResponseCreated
element. - When talking to Windows 2012 the
Create
response contains two elements -ResponseCreated
andShell
.
I don't believe there's a clean solution to the problem - it's not possible to mark <part> elements in the <message> as optional.
The workaround in this case is to strip the additional element before it gets to the JAX-WS parser. This can be done by creating a CXF interceptor or a JAX-WS handler and manipulating the response XML.
Create the JAX-WS handler:
Register the JAX-WS handler:
Declaratively
Create
handlers.xml
file alongside the service interface:And attach it to the service definition using the annotation
@HandlerChain(file = "handlers.xml")
Programmatically
That's an alternative approach which doesn't require the extra xml file.