开发者

Java EE Web services: Naming conflict

I'm trying to create Web services proxies with wsimport, but I get an error because of a conflict. "Two declarations cause a collision in the ObjectFactory class."

I've got two EJBs with Webservices deployed in one ear. Both have a method with the same name and parameters. Each WS has it's own targetnamespace.

SEI of WS A:

@Local
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@WebService(name = "AService", targetNamespace = "http://example.com/bla/a")
public interface ASEI {

    @WebMethod
    @WebResult(name = "erpId")
    public Long getId(@WebParam(name = "gid")
    Long gid);
}

WebService A:

@Stateless
@WebService(serviceName = "AWebService",
        endpointInterface = "foo.endpointinterfaces.ASEI",
        targetNamespace = "http://example.com/bla/a")
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public class AWebService implements ASEI {

     public Long getId(Long gid) { ... }
}

SEI of WS B:

@Local
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL,     parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@WebService(name = "BService", targetNamespace = "http://example.com/bla/b")
public interface BSEI {

    @WebMethod
    @WebResult(name = "erpId")
    public Long getId(@WebParam(name = "gid")
    Long gid);
}

Webservice B:

@Stateless
@WebService(serviceName = "BWebService",
        endpointInterface = "foo.endpointinterfaces.ASEI",
        targetNamespace = "http://example.com/bla/b")
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public class BWebService implements BSEI {

     public Long getId(Long gid) { ... }
}

When I deploy the application to my Weblogic server, the first Webservices imports the xml declarations of WS B and uses them for the message types.

WSDL of A:

<definitions targetNamespace="http://example.com/bla/a" name="AWebService" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://example.com/bla/a" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
    <xsd:schema>
        <xsd:import namespace="http://example.com/bla/b" schemaLocation="http://192.168.178.105:7001/BWebService/AWebService?xsd=1"/>
    </xsd:schema>
    <xsd:schema>
        <xsd:import namespace="http://example.com/bla/a" schemaLocation="http://192.168.178.105:7001/AWebService/AWebService?xsd=2"/>
    </xsd:schema>
</types>

<message name="getId">
    <part name="parameters" element="tns:getId"/>
</message>
...

XSD=1:

<xs:schema version="1.0" targetNamespace="http://example.com/bla/b" xmlns:tns="http://example.com/bla/b" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="getId" type="tns:getId"/>
    <xs:complexType name="getId"> ... </xs:complexType>
    ...

XSD=2:

<xs:schema v开发者_如何学Pythonersion="1.0" targetNamespace="http://example.com/bla/a" xmlns:tns="http://example.com/bla/a" xmlns:ns1="http://example.com/bla/b" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:import namespace="http://example.com/bla/b" schemaLocation="http://192.168.178.105:7001/AWebService/AWebService?xsd=1"/>
    <xs:element name="getId" nillable="true" type="ns1:getId"/>
    ...

Is there a way that each WS defines it's own messagetypes? Or what else can I do, to create a WS proxy? (I don't want to separate them into different Java EE-Applications.)


I think you may be having a similar problem as I did. But, I'm not totally sure, so this is just a guess at an answer.

I found that a binding file that did some class customization fixed my issue with elements and complexTypes that had matching names across multiple schemas that were referenced in a singular wsdl file just like you have in your example above.

In XSD=1 you have

<xs:complexType="getId"> and <xs:element name="getId" ...>

And, in XSD=2 you have

<xs:element name="getId" ...>

So, to fix this I used something like this in my binding file...

<jxb:bindings version="2.0"
           xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <jxb:bindings schemaLocation="http://192.168.178.105:7001/BWebService/AWebService?xsd=1" node="//xs:element[@name='getId']">
       <jxb:class name="getIdElement"></jxb:class>
   </jxb:bindings> 
</jxb:bindings> 

This solved my issue of having the same name for a complexType and an element. Since you have the same name for multiple elements in two xsd files with different namespaces, I'm not even sure if this will help that problem.

There's a lot more info about possible collision problems and their solutions here... http://goo.gl/vlQe3

Good Luck, TW

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜