zebity / onvif-relay

An onvif device relay/device test harness
https://tips.graphica.com.au/onvif-ws-client-consumption/
Other
2 stars 3 forks source link

JAX-WS SOAP 1.1 / 1.2 Client / Server Generated Code Asymmetry #1

Closed zebity closed 1 year ago

zebity commented 1 year ago

Issue:

Testing client and server code generation with JAX-WS SOAP Web Services it seems that the client is generating SOAP 1.2 requests while the server is providing SOAP 1.1 service.

SOAP 1.1 uses HTTP "Content-Type: text/xml" SOAP 1.2 uses HTTP "Content-Type: application/xml+soap"

Result is that get exception due to having incompatible media types

Need to either change client to use SOAP 1.1 or change server to use provide SOAP 1.2

Environment:

Ubuntu: 22.04 OpenJDK: 11

Maven Dependencies:

JAVA EE/JAKARTA TRANSITIONAL:

   <dependency>
     <groupId>jakarta.xml.bind</groupId>
     <artifactId>jakarta.xml.bind-api</artifactId>
     <version>2.3.3</version>
    </dependency>
    <dependency>
     <groupId>com.sun.xml.bind</groupId>
     <artifactId>jaxb-impl</artifactId>
     <version>2.3.3</version>
     <!-- scope>runtime</scope -->
    </dependency>
    <dependency>
     <groupId>jakarta.xml.ws</groupId>
     <artifactId>jakarta.xml.ws-api</artifactId>
     <version>2.3.3</version>
    </dependency>
    <dependency>
     <groupId>com.sun.xml.ws</groupId>
     <artifactId>jaxws-rt</artifactId>
     <version>2.3.3</version>
    </dependency>

<plugin>
     <groupId>com.sun.xml.ws</groupId>
     <artifactId>jaxws-maven-plugin</artifactId>
     <version>2.3.5</version>
...
</plugin>

NOTE: Same problem using more current Jakarta dependencies

Testing:

via curl and generated Java code.

See here for details: ONVIF Web Services Client Consumption with Java

zebity commented 1 year ago

Underlying issues is possibly that ONVIF is using a "dead-end" namespace for its binding definition: http://schemas.xmlsoap.org/soap/http

This gets redirected (multiple time) to a link which just contains empty file (mostly nulls).

Resolution was to change the server EndPoint create/public to explicity use SOAP 1.2 / HTTP Binding as per Jakarta specification:

Where String constant: SOAPBinding.SOAP12HTTP_BINDING == http://www.w3.org/2003/05/soap/bindings/HTTP/

EndPoint create/publish code change to create SOAP 1.2 service:

      String soapver = SOAPBinding.SOAP11HTTP_BINDING;
      if (ver.equals("12"))
        soapver = SOAPBinding.SOAP12HTTP_BINDING;

      String uri = "http://127.0.0.1:" + port + request;
      Endpoint ep = Endpoint.create(soapver, device);
      ep.publish(uri);

This works with both Javax and Jakarta namespace, with difference in import statements to reflect JavaEE vs JakartaEE cases.

See commit: f471f3b146021ccf462544a23eb15bbb61fe6441

Also more details on blog page Appendix "D. ONVIF SOAP Binding URL Goes to Dead End"