To explain further, I have JAXB generated classes that make up the request for my web service. Inside some of these classes are xs:IDREF type attributes, the XML schema defines the object similar to this (only showing the relevant attributes)...
XML Schema
<xs:complexType name="StrucDoc.RenderMultiMedia">
<xs:attribute name="referencedObject" type="xs:IDREFS" use="required"/>
...
</xs:complexType>
...which ends up looking like this in Java...
JAXB Object
@XmlAttribute(name = "IDREF", required = true)
@XmlIDREF
@XmlSchemaType(name = "IDREF")
protected List<Object> referencedObject;
That's nothing too out of the ordinary and very valid to have. So now I added a SOAPHandler to the web service like this...
Web Service
@HandlerChain(file = "handler-chain.xml")
The defined handler chain has 1 handler that implements SOAPHandler
Now when I processed this unmarshalled object, I got a JAXBElement, then fetched its value object, which gave me the StrucDocRenderMultiMedia object in my case, then I printed out the array of referenced objects. This produced output similar to this...
Output
That's all normal because my XML request did indeed have a valid object reference (not shown here).
Now when I removed the @HandlerChain annotation from the web service, the exact same request gave me this kind of output...
Output
The object references were gone!
I tried to track this down to no avail, however what I did discover was this wasn't entirely dependent on having or not having the SOAPHandler. You could have the SOAPHandler and as long as you didn't call context.getMessage() method, the behaviour didn't change. In other words, this was the culprit...
SOAPHandler
public boolean handleMessage(SOAPMessageContext context) {
Boolean isOutbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!isOutbound) {
...
SOAPMessage soapMsg = context.getMessage(); // <-- this line causes the behaviour change
...
I am guessing that when the SOAP Message is fetched from the context it does some kind of JAXB processing or initialisation that forces object references to resolve correctly, otherwise MOXy just returns an empty reference array.
In my case I actually didn't want these references to be resolved so I changed the generated JAXB classes to use @XmlTransient instead. That does not explain the strange behaviour that I saw, which I'd like to fully understand.
-i