为什么CXF不能使用@XmlJavaAdapter注释裸参数?

时间:2018-01-25 12:22:51

标签: java jaxb cxf wsd

关于问题

我使用Wsdl2Java从wsdl文件生成java类。 Jaxb抛出异常"未知的unmarshaller"使用生成的Web服务接口时。 在输入参数是xs:dateTime类型的元素的操作中存在问题,例如此模式:

<?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>

和JAXB有绑定:

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

Jaxws绑定:

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

然后,生成的MyServiceInterface.java将LocalDateTime作为输入参数。 JaxB从unmarshall方法抛出异常,因为unmarshaller对于上下文是未知的。

我对发电机的期望

在MyServiceInterface.java文件中,生成器应在LocalDateTime输入参数上方添加@XmlJavaTypeAdapter(Adapter1.class)行。 手动插入有效并使JAXB能够理解如何解组此类型:

@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在相应的LocalDateTime字段中都有@XmlJavaAdapter注释。复杂的类型是可以的。

0 个答案:

没有答案