How can I tell wsimport that separate WSDL files are referring to the same object classes?

和自甴很熟 提交于 2019-12-10 16:29:59

问题


I have three different JAX-WS services which use the same classes on the server (e.g. ServiceA, ServiceB, and ServiceC, all of which use MyCommonClass as a parameter). Another module we are developing is using wsimport to create a client for these services, however the problem is that wsimport creates separate instances of MyCommonClass for each service:

  • com.company.servicea.endpoint.MyCommonClass
  • com.company.serviceb.endpoint.MyCommonClass
  • etc.

I know that I could use the wsimport -p option to specify a common package for each endpoint, however I'd like to keep most of the classes in separate packages, but just to share certain common ones. From what I have read it sounds like a JAXB bindings file(s) might be able to help, but I haven't yet figured out the exact syntax to achieve the desired result. I think I'll need a separate bindings file for each service (as I call wsimport once for each one), which looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1" xmlns:tns="http://endpoint.servicea.company.com/">
  <bindings node="//xsd:complexType[@name='myCommonClass']">
    <class name="com.company.model.MyCommonClass"/>
  </bindings>
</bindings>

Am I on the right track? Or do you have any alternative solutions to the problem?


回答1:


Define your common classes in an xsd and import it in to the service WSDL's. Then use the schema customization to generate definitions in this schema in to a separate package like "com.company.model"

<jxb:bindings
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
   version="1.0">
    <jxb:bindings schemaLocation="model.xsd" node="/xsd:schema">
        <jxb:schemaBindings>
        <jxb:package name="com.company.model"/>
        </jxb:schemaBindings>
</jxb:bindings>

...

ref: http://jax-ws.java.net/jax-ws-21-ea1/docs/customizations.html#2.6_Class_Customization



来源:https://stackoverflow.com/questions/5567853/how-can-i-tell-wsimport-that-separate-wsdl-files-are-referring-to-the-same-objec

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