Why won't CXF annotate a bare parameter with @XmlJavaAdapter?

About the problem

I am using Wsdl2Java to create java classes from a wsdl file. Jaxb throws an “unknown unmarshaller” exception when using the generated web service interface. The problem exists in operations where their input parameter is an element of type xs: dateTime, such as this diagram:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="asd:asd"
  elementFormDefault="qualified">
  <xsd:element name="DateSinceStart" type="xsd:dateTime"/>
</xsd:schema>

and JAXB has a binding:

<globalBindings>
    <javaType
            name="java.time.LocalDateTime"
            xmlType="xs:dateTime"
            parseMethod="LocalDateTimeAdapter.unmarshal"
            printMethod="LocalDateTimeAdapter.marshal"/>
</globalBindings>

Binding Jaxws:

<bindings xmlns="http://java.sun.com/xml/ns/jaxws">
    <!-- Disable default wrapper style -->
    <enableWrapperStyle>false</enableWrapperStyle>
</bindings>

Then created MyServiceInterface.java takes the input argument LocalDateTime. JaxB throws an exception to the unmarshall method because unmarshaller is unknown to the context.

What do I expect from a generator

In the MyServiceInterface.java file, the generator should add a line @XmlJavaTypeAdapter(Adapter1.class)above the LocalDateTime input parameter. Manual insertion works and allows JAXB to understand how to untie this type:

@WebService(targetNamespace = "asd:asd", name = "MyServiceInterface")
@XmlSeeAlso({asd.asd.ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface MyServiceInterface {

    @WebMethod(operationName = "Operation", action = "asd:asd:#Operation")
    @WebResult(name = "OperationResponse", targetNamespace = "asd:asd", partName = "OperationResponseBody")
    public asd.asd.OperationResponseType operation(
        @WebParam(partName = "OperationBody", name = "DateSinceStart", targetNamespace = "asd:asd")
        @XmlJavaTypeAdapter(Adapter1.class)
        java.time.LocalDateTime operationBody
    );
}

? ?

: , @XmlJavaAdapter .

, :

MyService.wsdl:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:tt="asd:asd"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  name="MyService"
  targetNamespace="asd:asd">
  <wsdl:documentation>
    <ServiceName>MyService</ServiceName>
    <Version>1</Version>
  </wsdl:documentation>
  <wsdl:types>
    <xsd:schema elementFormDefault="qualified" targetNamespace="asd:asd">
      <xsd:include schemaLocation="Operation.xsd"/>
      <xsd:include schemaLocation="OperationResponse.xsd"/>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="OperationMessage">
    <wsdl:part element="tt:DateSinceStart" name="OperationBody"/>
  </wsdl:message>
  <wsdl:message name="OperationResponseMessage">
    <wsdl:part element="tt:Response" name="OperationResponseBody"/>
  </wsdl:message>
  <wsdl:portType name="MyServiceInterface">
    <wsdl:operation name="Operation">
      <wsdl:input message="tt:OperationMessage" name="OperationIn">
      </wsdl:input>
      <wsdl:output message="tt:OperationResponseMessage" name="OperationOut">
      </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="MyServiceBinding" type="tt:MyServiceInterface">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="Operation">
      <soap:operation soapAction="asd:asd:#Operation"/>
      <wsdl:input name="OperationIn">
        <soap:body parts="OperationBody" use="literal"/>
      </wsdl:input>
      <wsdl:output name="OperationOut">
        <soap:body parts="OperationResponseBody" use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding> 
  <wsdl:service name="MyService">
    <wsdl:port binding="tt:MyServiceBinding" name="MyService">
      <soap:address location="http://address"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Operation.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="asd:asd"
  elementFormDefault="qualified">
  <xsd:element name="DateSinceStart" type="xsd:dateTime"/>
</xsd:schema>

OperationResponse.xsd, xs: complexType, dateTimes @XmlJavaAdapter LocalDateTime. - .

+4

Source: https://habr.com/ru/post/1692707/


All Articles