mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
107 stars 77 forks source link

MTOM/XOP - byte array field not populated when using hexBinary #224

Open steinrr opened 2 years ago

steinrr commented 2 years ago

We are creating the server side for a SOAP based service that uses MTOM/XOP to receive binary files (zip files).

The xsd for the service has the following element definition for the binary file:

<xs:element name="thebinaryfile" type="xs:hexBinary" xmime:contentType="application/octet-stream"/> We have been using the same approach as demo'ed here (but without all the repository classes etc):

https://github.com/spring-projects/spring-ws-samples/tree/main/mtom/server

The issue is that when the type "hexBinary" is used, the get'er on the generated request object always returns null. If we change the type to "base64Binary", we get the proper value populated in the byte array.

We send identical requests from SoapUI and see that they reaches the server as expected. But something happens on the receiving side when the libraries are trying to populate the request objects when using "hexBinary" - since the byte field is not populated properly. The fields in the main part of the SOAP request are populated just fine.

If we change the definition in XSD to base64Binary, it can receive the bytes just fine - but would this be safe when the client uses hexBinary? I've used SoapUI with "encodeAttachments" - which are supposed to handle this - and seems to work fine.

This is how the field is generated when using hexBinary:

    @XmlElement(name = "zip-file", required = true, type = String.class)
    @XmlJavaTypeAdapter(HexBinaryAdapter.class)
    @XmlSchemaType(name = "hexBinary")
    protected byte[] zipFile; 

This is how the field is generated when using base64Binary:

    @XmlElement(name = "trr-file", required = true)
    protected byte[] trrFile;

Using the following configuration:

                            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.5.0</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sourceType>WSDL</sourceType>
                    <sources>${project.basedir}/src/main/resources/file-interface.wsdl</sources>
                    <packageName>my.package.schema</packageName>
                    <target>2.1</target>
                </configuration>
            </plugin>