2016-01-24 3 views
0

Je souhaite personnaliser le nom du package des entités utilisées sur un service Web. L'objectif principal est de partager des entités entre différents webservices. J'utilise jaxws + jaxb pour lier des entités à leur paquet correspondant. Toutefois, seul le lien ObjectFactory avec l'entité fonctionne. Il semble que je ne peux pas remplacer l'utilisation de la wsdl: definition: @targetnamespace pour le nom du paquet.jaxws wsdl entités communes

Voici un exemple:

J'ai un FooBarRemoteService retourning deux entités: Foo et Bar. Chacun d'eux est @XmlRootElement annoté avec un espace de noms défini (Foo: com.test.foo, Bar: com.test.bar).

Voici le wsdl:

<wsdl:definitions name="FooBarRemoteService" targetNamespace="com.test.foobar" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="com.test.foobar" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"> 
    <wsdl:types> 
     <xs:schema elementFormDefault="unqualified" targetNamespace="com.test.foobar" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns2="com.test.bar" xmlns:ns1="com.test.foo"> 
     <xs:import namespace="com.test.foo"/> 
     <xs:import namespace="com.test.bar"/> 
     <xs:element name="getBar" type="tns:getBar"/> 
     <xs:element name="getBarResponse" type="tns:getBarResponse"/> 
     <xs:element name="getFoo" type="tns:getFoo"/> 
     <xs:element name="getFooResponse" type="tns:getFooResponse"/> 
     <xs:complexType name="getFoo"> 
      <xs:sequence/> 
     </xs:complexType> 
     <xs:complexType name="getFooResponse"> 
      <xs:sequence> 
       <xs:element minOccurs="0" name="return" type="tns:foo"/> 
      </xs:sequence> 
     </xs:complexType> 
     <xs:complexType name="foo"> 
      <xs:sequence/> 
     </xs:complexType> 
     <xs:complexType name="getBar"> 
      <xs:sequence/> 
     </xs:complexType> 
     <xs:complexType name="getBarResponse"> 
      <xs:sequence> 
       <xs:element minOccurs="0" name="return" type="tns:bar"/> 
      </xs:sequence> 
     </xs:complexType> 
     <xs:complexType name="bar"> 
      <xs:sequence/> 
     </xs:complexType> 
     </xs:schema> 
     <xs:schema targetNamespace="com.test.foo" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="com.test.foobar"> 
     <xs:import namespace="com.test.foobar"/> 
     <xs:element name="foo" type="ns1:foo"/> 
     </xs:schema> 
     <xs:schema targetNamespace="com.test.bar" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="com.test.foobar"> 
     <xs:import namespace="com.test.foobar"/> 
     <xs:element name="bar" type="ns1:bar"/> 
     </xs:schema> 
    </wsdl:types> 
    <wsdl:message name="getFooResponse"> 
     <wsdl:part element="tns:getFooResponse" name="parameters"/> 
    </wsdl:message> 
    <wsdl:message name="getFoo"> 
     <wsdl:part element="tns:getFoo" name="parameters"/> 
    </wsdl:message> 
    <wsdl:message name="getBarResponse"> 
     <wsdl:part element="tns:getBarResponse" name="parameters"/> 
    </wsdl:message> 
    <wsdl:message name="getBar"> 
     <wsdl:part element="tns:getBar" name="parameters"/> 
    </wsdl:message> 
    <wsdl:portType name="InterfaceFooBar"> 
     <wsdl:operation name="getFoo"> 
     <wsdl:input message="tns:getFoo" name="getFoo"/> 
     <wsdl:output message="tns:getFooResponse" name="getFooResponse"/> 
     </wsdl:operation> 
     <wsdl:operation name="getBar"> 
     <wsdl:input message="tns:getBar" name="getBar"/> 
     <wsdl:output message="tns:getBarResponse" name="getBarResponse"/> 
     </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="FooBarRemoteServiceSoapBinding" type="tns:InterfaceFooBar"> 
     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
     <wsdl:operation name="getFoo"> 
     <soap:operation soapAction="" style="document"/> 
     <wsdl:input name="getFoo"> 
      <soap:body use="literal"/> 
     </wsdl:input> 
     <wsdl:output name="getFooResponse"> 
      <soap:body use="literal"/> 
     </wsdl:output> 
     </wsdl:operation> 
     <wsdl:operation name="getBar"> 
     <soap:operation soapAction="" style="document"/> 
     <wsdl:input name="getBar"> 
      <soap:body use="literal"/> 
     </wsdl:input> 
     <wsdl:output name="getBarResponse"> 
      <soap:body use="literal"/> 
     </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="FooBarRemoteService"> 
     <wsdl:port binding="tns:FooBarRemoteServiceSoapBinding" name="FooBar"> 
     <soap:address location="http://localhost:8080/poc/FooBarRemoteService"/> 
     </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

Voici le fichier de liaison

<?xml version="1.0" encoding="UTF-8"?> 
<jaxws:bindings version="2.1" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" 
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"> 
    <jaxb:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='com.test.foo']"> 
     <jaxb:schemaBindings> 
      <jaxb:package name="subpackage.foo" /> 
     </jaxb:schemaBindings> 
    </jaxb:bindings> 
    <jaxb:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='com.test.bar']"> 
     <jaxb:schemaBindings> 
      <jaxb:package name="subpackage.bar" /> 
     </jaxb:schemaBindings> 
    </jaxb:bindings> 
</jaxws:bindings> 

est la commande Ici pour générer des fichiers objet java:

wsimport ../FooBar.wsdl -b ../binding.xml -verbose 

Et voici le produit fichiers:

. 
|-- foobar 
| `-- test 
|  `-- com 
|   |-- Bar.class 
|   |-- FooBarRemoteService.class 
|   |-- Foo.class 
|   |-- GetBar.class 
|   |-- GetBarResponse.class 
|   |-- GetFoo.class 
|   |-- GetFooResponse.class 
|   |-- InterfaceFooBar.class 
|   |-- ObjectFactory.class 
|   `-- package-info.class 
`-- subpackage 
    |-- bar 
    | `-- ObjectFactory.class 
    `-- foo 
     `-- ObjectFactory.class 

Les dossiers de destination sont renommés en sous-dossier. Donc, la liaison est prise en compte, mais seulement ObjectFactory est présent. Est-ce un moyen d'avoir ObjectFactory avec l'entité qui en dépend?

Mon WSDL a été généré avec un programme simple sous wildfly: Voici mes fichiers:

InterfaceFooBar

@WebService(targetNamespace = "com.test.foobar") 
public interface InterfaceFooBar {  
    @WebMethod 
    public Bar getBar(); 
    @WebMethod 
    public Foo getFoo(); 
} 

FooBarRemoteService

@WebService(serviceName = "FooBarRemoteService", 
    portName = "FooBar", 
    name = "FooBar", 
    endpointInterface = "poc.interfaces.helloworld.ws.InterfaceFooBar", 
    targetNamespace = "com.test.foobar") 
public class FooBar implements InterfaceFooBar { 
    @Override 
    public Bar getBar() { 
     return new Bar(); 
    } 
    @Override 
    public Foo getFoo() { 
     return new Foo(); 
    } 
} 

Bar

@XmlRootElement(namespace = "com.test.bar") 
@XmlAccessorType(XmlAccessType.FIELD) 
public class Bar { 
} 

Foo

@XmlRootElement(namespace = "com.test.foo") 
@XmlAccessorType(XmlAccessType.FIELD) 
public class Foo { 
} 

Merci de votre réponse.

Cordialement,

Damien

Répondre

0

Ok ... Je viens de trouver la réponse ...

il suffit de changer la déclaration de Foo et Bar à l'aide @XmlType au lieu de @XmlRootElement et il est travail ...

. 
|-- foobar 
| `-- test 
|  `-- com 
|   |-- FooBarRemoteService.class 
|   |-- GetBar.class 
|   |-- GetBarResponse.class 
|   |-- GetFoo.class 
|   |-- GetFooResponse.class 
|   |-- InterfaceFooBar.class 
|   |-- ObjectFactory.class 
|   `-- package-info.class 
`-- subpackage 
    |-- bar 
    | |-- Bar.class 
    | |-- ObjectFactory.class 
    | `-- package-info.class 
    `-- foo 
     |-- Foo.class 
     |-- ObjectFactory.class 
     `-- package-info.class 

Damned je passe une journée sur ce

:(