How to attach documents to a SOAP with XOP using Spring?

609 views Asked by At

I had a WSDL with MTOM and we could handle it properly: there was documentation available. This is what we ended up with. Not much testing was done on it, except that we saw it working.

byte[] document = ... ;
DataSource dataSource = new ByteArrayDataSource(document, "application/octet-stream");
DataHandler dataHandler = new DataHandler(dataSource);
response.setDocument(dataHandler);

Now the infrastructure people changed our XSD to use XOP because it was okay for attachments in the request, not in the response which is our actual use case. So they changed our XSD and added a xop.xsd.

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' 
           xmlns:tns='http://www.w3.org/2004/08/xop/include' 
           targetNamespace='http://www.w3.org/2004/08/xop/include' >
  <xs:element name='Include' type='tns:Include' />
  <xs:complexType name='Include' >
    <xs:sequence>
      <xs:any namespace='##other' minOccurs='0' maxOccurs='unbounded' />
    </xs:sequence>
    <xs:attribute name='href' type='xs:anyURI' use='required' />
    <xs:anyAttribute namespace='##other' />
  </xs:complexType>
</xs:schema>

With this new structure, the method setDocument is now defined as the following: setDocument(Include).

The generated Include class is basically the following:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Include", namespace = "http://www.w3.org/2004/08/xop/include", propOrder = {
    "any"
})
public class Include
    implements org.jvnet.jaxb2_commons.lang.ToString
{

    @XmlAnyElement(lax = true)
    protected List<Object> any;
    @XmlAttribute(name = "href", required = true)
    @XmlSchemaType(name = "anyURI")
    protected String href;
    @XmlAnyAttribute
    private Map<QName, String> otherAttributes = new HashMap<QName, String>();

    public List<Object> getAny() {
        if (any == null) {
            any = new ArrayList<Object>();
        }
        return this.any;
    }

    public String getHref() {
        return href;
    }

    public void setHref(String value) {
        this.href = value;
    }

    public Map<QName, String> getOtherAttributes() {
        return otherAttributes;
    }
    // Other irrelevant methods for ToString.
}

My question is: how and where do I add the document in that Include object? (the document is the byte array as seen in the first code snippet)

0

There are 0 answers