GridDragon
GridDragon

Reputation: 3145

How to create SOAP Client with shared objects

I'm trying to create a java client to consume SOAP Services which are maintained by another team.

The services use a series of related objects

Then I have corresponding WSDL files:

When I use wsdl2java on Customer the service works great. Same thing for Employee. Both WSDL files create the WSException file. I've verified with a diff tool that the generated files are identical. However, when I run wsdl2java against both wsdl2java my testing program throws a long series of exceptions.

For testing I'm generating the stub code from command line:

wsdl2java -client -impl -verbose -d src\main\java service.company.com/Customer.srv?wsdl
wsdl2java -client -impl -verbose -d src\main\java service.company.com/Employee.srv?wsdl

I've gotten around this before by creating separate binding files for each service and forcing them into separate packages. However this is generating ALOT of redundant code and is making using the library very cumbersome. Is there a more efficient way to work with related services like this?

For clarity here is a sample of the exceptions I get when using both services together:

Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
    at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:334)
    at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:319)
    at javax.xml.ws.Service.getPort(Service.java:119)
    at org.tempuri.People.getBasicHttpBindingIPeople(People.java:79)
    at com.gallup.oms.TestDriver.main(TestDriver.java:38)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:332)
    at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:434)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:538)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:252)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:205)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:90)
    at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:156)
    at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:156)
    at org.apache.cxf.jaxws.ServiceImpl.createPort(ServiceImpl.java:465)
    at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:332)
    ... 4 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 72 counts of IllegalAnnotationExceptions
There's no ObjectFactory with an @XmlElementDecl for the element {http://schemas.company.com/oms/2010/10/}request.
    this problem is related to the following location:
        at protected javax.xml.bind.JAXBElement com.company.schemas.oms._2010._10.AddPrivilege.request
        at com.gallup.schemas.oms._2010._10.AddPrivilege

Edit

I've simplified the situation considerably for brevity. In actuality I'm dealing with a dozen related services and wsdl files all using various shared objects like the WSEception object in the example.

Edit 2

Based on this ticket, and a series of additional name collisions I just discovered I'm writing this off as not worth the effort to automate. I'll have to come up with a solution to deal with the messy code from the current implementation of these services. At least until the CXF dev team comes up with an update to better handle overlapping services like this.

Upvotes: 1

Views: 1202

Answers (2)

GridDragon
GridDragon

Reputation: 3145

I posted this question on Reddit as well and received an interesting potential solution. I'm posting it here so that others can find it if needed: http://www.reddit.com/r/java/comments/24ax71/having_trouble_using_soap_services_that_rely_on/ch5gond

Upvotes: 0

Chris Goldman
Chris Goldman

Reputation: 307

Since the problem is that each successive ObjectFactory code generation overwrites the last, rather than being additive, can you copy each one before the next is generated, and then combine them?

If this is something that needs to be automated, or part of a Maven build, that may be tricky. But manually combining the ObjectFactory definitions shouldn't be difficult, unless there are mutually incompatible parts.

Upvotes: 1

Related Questions