I've got a WSDL file with a schema that contains an any element as well as anyType entries in the request message. This WSDL file is used to communicate with different external systems (as client only, no endpoints are created on my side) and every system has some specialties that I need to deal with. This specialties are xml elements that the WSDL file doesn't know about and I don't want to actually touch the WSDL file for every new xml element that is added. I just want to add the xsd files containing the definitions for an external system, generate them and be done. The following request message is just an example to make it a bit more clear:
<xs:element name="RequestMessage" type='mns:RequestMessageType'/>
<xs:complexType name="RequestMessageType">
<xs:sequence>
<xs:any namespace='##any' processContents='lax' minOccurs='0' maxOccurs='unbounded'/>
<xs:element name='test' type="xs:anyType"/>
</xs:sequence>
<xs:anyAttribute namespace='##other' processContents='lax'/>
</xs:complexType>
I've generated the service and corresponding classes with the jaxws-maven-plugin. Now when I instantiate a class that is defined in the WSDL file or in any of the imported schemas, this works just fine. But as soon as I want to put something in the any list or as content for the anyType that is not part of it, the serializer will fail with one of the following message.
1) Using a JAXBElement wrapped type (only any):
Caused by: javax.xml.bind.JAXBException: com.example.mytypes._67890.SomeType is not known to this context
2) Using a raw type (any and anyType):
javax.xml.bind.JAXBException: Class com.example.mytypes._67890.SomeType nor any of its super class is known to this context
From what I understood, the lax option should enable me to throw really any type that is properly annotated at the any list and the marshaller will figure out how to actually find the right context. The same goes for the anyType by default. Searching for the issue I found many people that were actually marshalling simple POJOs using a JAXBContext and they had to add the corresponding class to the context and were done. Unfortunately I don't have access to the JAXBContext while using a generated WSDL service (or do I?).
Is this intended behavior that I actually can't put really anything in the any and anyType elements although the classes are annotated and ready to be serialized (the classes I tried to use are actually also generated)? If so, can I somehow influence this in a way so that I can achieve what I want to do?
Here is the SomeType class for reference:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SomeType", propOrder = {
"myString",
"anotherString"
})
public class SomeType {
@XmlElement(required = true)
protected String myString;
@XmlElement(required = true)
protected String anotherString;
// omitted getters and setters for readability
}