Replacing XmlType.namespace using jaxb bindings during type generation

≡放荡痞女 提交于 2020-06-27 08:40:51

问题


My web-services application is moving from Axis to JAX-WS and I'm having trouble doing some of the conversions. My primary issue is that I have several XSD's with the same types defined slightly differently, but with the same names. During my wsimport I'm able to use an external JAXB bindings file to resolve the packages, but the generated classes still end up with the same @XmlType annotations.

V1:

package com.service.v1.bill.request;
@XmlType(name = "FileBillReqType", namespace = "http://epayments.metavante.com/types/bill/request"})
public class FileBillReqType extends AbstractContextMethodRequest...

V2:

package com.service.v2.bill.request;
@XmlType(name = "FileBillReqType", namespace = "http://epayments.metavante.com/types/bill/request"})
public class FileBillReqType extends AbstractContextMethodRequest...

Binding:

<jaxb:bindings schemaLocation="file:../wsdl/v1/bill/BillRequest.xsd" 
    node="/xs:schema[@targetNamespace='http://service.example.com/bill/request']">
    <jaxb:schemaBindings>
        <jaxb:package name="com.service.v1.bill.request" />
    </jaxb:schemaBindings>
</jaxb:bindings>

Previously this would have been resolved with the type mappings provided by axis (which we hard coded into a massively ugly wsdd):

<service name="v1" provider="java:RPC" style="document" use="literal">...
<typeMapping
    xmlns:ns="http://service.example.com/bill/request"
    qname="ns:FileBillReqType"
    type="java:com.service.v1.bill.request.FileBillReqType"
    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
    deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
    encodingStyle=""
  />...

Is there anyway to get my generated JAXB objects to have a custom namespace without modifying the generated files manually every time I regenerate them (there are hundreds)?


回答1:


Specifying another xjb customization with v2 as schema location while generating the client classes using wsimport might solve the problem.

<jaxb:bindings schemaLocation="file:../wsdl/v2/bill/BillRequest.xsd"
node="/xs:schema[@targetNamespace='http://service.example.com/bill/request']">
    <jaxb:schemaBindings>
        <jaxb:package name="com.service.v2.bill.request" />
    </jaxb:schemaBindings>
</jaxb:bindings>


来源:https://stackoverflow.com/questions/5599910/replacing-xmltype-namespace-using-jaxb-bindings-during-type-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!