Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom parse & print methods for WSDLs with several schemas

I have problems using custom javaTypes for WSDL's where there are several schemas. The bindings works for the schemas with the given namespace, but the compilation fails for the schemas without the namespace.

this is the bindings.xml file:

<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:common="urn:my:ns">
<jaxb:globalBindings generateElementProperty="false">
    <jaxb:serializable uid="1"/>
    <jaxb:javaType name="java.util.Date" xmlType="xs:date"
                   parseMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.parseDate"
                   printMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.printDate"/>
    <jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
                   parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
                   printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/>
    <jaxb:javaType name="java.util.UUID" xmlType="common:uuid"
                   parseMethod="my.package.UuidConverter.parse"
                   printMethod="my.package.UuidConverter.print"/>
</jaxb:globalBindings>
</jaxb:bindings>

I am using cxf-codegen-plugin

the error message is: undefined simple type

Is it possible to ignore the UUID binding when urn:my:ns is not present in one of the schemas? or is it possible to archive this binding using a different method?

like image 396
Vegard Avatar asked Nov 11 '22 19:11

Vegard


1 Answers

I do not believe it is possible to conditionally ignore the UUID binding like you describe; and I am not sure I follow what you mean by asking whether it is "possible to archive this binding", but I sense it is not too.

UUID typically converts to xs:string as discussed in the Java forums. JAX-B documentation confirms this mapping too. (Just search for UUID in the linked documentation page.)

Consider something like this instead:

<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:globalBindings generateElementProperty="false">
    <jaxb:serializable uid="1"/>
    <jaxb:javaType name="java.util.Date" xmlType="xs:date"
                   parseMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.parseDate"
                   printMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.printDate"/>
    <jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
                   parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
                   printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/>
    <jaxb:javaType name="java.util.UUID" xmlType="xs:string"
                   parseMethod="my.package.UuidConverter.parse"
                   printMethod="my.package.UuidConverter.print"/>
</jaxb:globalBindings>
</jaxb:bindings>

If you still have problems, consider this related SO answer.

like image 110
J0e3gan Avatar answered Nov 15 '22 05:11

J0e3gan