You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Steve Revilak <sr...@KAYAK.com> on 2012/11/05 20:25:53 UTC

TESTCASE: ObjectFactory and Multiple WSDLs in same namespace

Hi all.  A few days ago, I asked about a problem I was having with
CXF, unmarshalling, and multi-wsdl generation. I've spent some more
time trying to figure out what's going wrong, and I'd like to provide
a test case.

dfp-test.tgz (attached) contains the test case.  To run it,

   - unpack dfp-test.tgz
   - sen the CXF_HOME environment variable to an appropriate place.
   - run ant 

Running ant will

  - run wsdl2java to generate java code from two wsdls.  (Both WSDLs
    come from Google APIs)

  - Compile the code, and a test driver (Main.java)

  - Run Main.java

Main.java runs four test cases; three positive and one negative.  The
negative test case illustrates JAXB failing to unmarshall xml produced
by one of the services in question.  I believe the unmarshalling
failure is due to a missing @XmlSeeAlso element a class called
ApiError.

In the .tgz, there's a README.txt with full stacktraces.

I'm hoping the .tgz is allowed through the mailing list.  If not,
please let me how I should submit it.

I worked around the unmarshalling problem by using xmlbeans data
bindings instead of JAXB.

Steve



>Date: Mon, 29 Oct 2012 14:15:16 -0400
>From: Steve Revilak <sr...@kayak.com>
>To: users@cxf.apache.org
>Subject: ObjectFactory and Multiple WSDLs in same namespace
>
>Hello CXF Users,
>
>I'm having trouble generating java code from a collection of WSDLs.
>I'm finding that even if all code generation is done in one pass (via
>wsdl2java -wsdlList), I'm left with an incomplete ObjectFactory.  This
>is similar to the issue reported in
>https://issues.apache.org/jira/browse/CXF-1340.
>
>I understand that wsdl2java presumes a 1:1 mapping between namespaces
>and packages; but I have a case where the 1:1 mapping poses problems,
>and I'd like to understand my options for working around it.
>
>I'm working with public WSDLs, so I'd like to provide a small, but
>real-world use case for what I'm trying to do.
>
>The WSDLs in question come from Google's DoubleClick for Publishers
>API.  The API has a CRUD design, where each type of entity has its own
>SEI (and WSDL).
>
>I'll pick three WSDLs for my example:
>
>  https://www.google.com/apis/ads/publisher/v201208/CustomTargetingService?wsdl
>  https://www.google.com/apis/ads/publisher/v201208/LineItemService?wsdl
>  https://www.google.com/apis/ads/publisher/v201208/UserService?wsdl
>
>I can generate code like this (where wsdl.txt contains
>CustomTargetingService.wsdl, LineItemService.wsdl, and
>UserService.wsdl):
>
>  ~/apache-cxf-2.7.0/bin/wsdl2java -verbose -d ~/dfp-src -p dfp.example -wsdlList ./wsdl.txt
>
>The resulting ObjectFactory only creates objects from UserService.
>
>
>As google provides them, all WSDLs have
>
>  targetNamespace="https://www.google.com/apis/ads/publisher/v201208"
>
>
>I looked into using separate packages for each WSDL, but this approach
>comes with problems.  Several classes are common between WSDLs.  For
>example, there's a type called DateTime that appears in several
>service definitions, and there are cases where I'd might get a
>DateTime object from service A, and would want to pass it to a call to
>service B.  I can't do that if A and B are in different packages.
>
>What can I do in this case?
>
>  http://cxf.547215.n5.nabble.com/Wsdl2java-package-usage-td553695.html
>
>suggests merging ObjectFactory code by hand.  This is certainly
>possible, but it's also labor-intensive and error-prone.
>
>Is there a way to intercept missing type errors from CXF?  For
>example, if CXF can't find an ObjectFactory method to create a
>UniqueError, I'd like to try and instantiate a dfp.example.UniqueError
>(since I know that the types are in one package, and I know what that
>package is).
>
>Any suggestions would be sincerely appreciated.
>
>Steve



Re: TESTCASE: ObjectFactory and Multiple WSDLs in same namespace

Posted by Daniel Kulp <dk...@apache.org>.
On Nov 7, 2012, at 10:38 AM, Steve Revilak <sr...@kayak.com> wrote:

>> I really don't think there is anything we can do about this as its the way JAXB works (and it's really poor design on googles part).  About the only think you can really do is to download all the wsdl's, merge the schema sections together into a full schema that includes all the various types, and then use that for the basis of the code generation.   Not exactly easy or convenient.
>> 
>> Dan
> 
> 
> Dan,
> 
> That's more or less what I expected.  Thanks for weighing in.
> 
> Steve


The other option is to use the -p flag to wsdl2java to stick each individual wsdl into a new package.   That should work, but would mean types would not be shareable at all and if you have to pass objects from one service to another, you would need to write utilities to map the objects.  :-(


-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: TESTCASE: ObjectFactory and Multiple WSDLs in same namespace

Posted by Steve Revilak <sr...@KAYAK.com>.
>I really don't think there is anything we can do about this as its the way JAXB works (and it's really poor design on googles part).  About the only think you can really do is to download all the wsdl's, merge the schema sections together into a full schema that includes all the various types, and then use that for the basis of the code generation.   Not exactly easy or convenient.
>
>Dan


Dan,

That's more or less what I expected.  Thanks for weighing in.

Steve

Re: TESTCASE: ObjectFactory and Multiple WSDLs in same namespace

Posted by Daniel Kulp <dk...@apache.org>.
On Jan 14, 2013, at 10:16 AM, MK <sp...@gmail.com> wrote:

> Daniel, 
> 
> how I can improve WS server side avoiding this situation? No I getting the
> same problem with my WS. When I providing wsdls to others developers, they
> generating wsdl2java get conflicts based on this thread problems. 

The best option is to make sure ALL the objects in the package pretty much get included in the schemas for all the WSDL's, even if they aren't used in a particular WSDL.   You can do that with @XmlSeeAlso annotations all over the place to make sure all the objects get included.   You can also add a"jaxb.index" file into the package that is a simple list of simple class names in that package.   That should be picked up by JAXB and then all those types included.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: TESTCASE: ObjectFactory and Multiple WSDLs in same namespace

Posted by MK <sp...@gmail.com>.
Daniel, 

how I can improve WS server side avoiding this situation? No I getting the
same problem with my WS. When I providing wsdls to others developers, they
generating wsdl2java get conflicts based on this thread problems. 



--
View this message in context: http://cxf.547215.n5.nabble.com/ObjectFactory-and-Multiple-WSDLs-in-same-namespace-tp5717528p5721555.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: TESTCASE: ObjectFactory and Multiple WSDLs in same namespace

Posted by Daniel Kulp <dk...@apache.org>.
I really don't think there is anything we can do about this as its the way JAXB works (and it's really poor design on googles part).  About the only think you can really do is to download all the wsdl's, merge the schema sections together into a full schema that includes all the various types, and then use that for the basis of the code generation.   Not exactly easy or convenient.  

Dan


On Nov 5, 2012, at 2:25 PM, Steve Revilak <sr...@kayak.com> wrote:

> Hi all.  A few days ago, I asked about a problem I was having with
> CXF, unmarshalling, and multi-wsdl generation. I've spent some more
> time trying to figure out what's going wrong, and I'd like to provide
> a test case.
> 
> dfp-test.tgz (attached) contains the test case.  To run it,
> 
>  - unpack dfp-test.tgz
>  - sen the CXF_HOME environment variable to an appropriate place.
>  - run ant 
> Running ant will
> 
> - run wsdl2java to generate java code from two wsdls.  (Both WSDLs
>   come from Google APIs)
> 
> - Compile the code, and a test driver (Main.java)
> 
> - Run Main.java
> 
> Main.java runs four test cases; three positive and one negative.  The
> negative test case illustrates JAXB failing to unmarshall xml produced
> by one of the services in question.  I believe the unmarshalling
> failure is due to a missing @XmlSeeAlso element a class called
> ApiError.
> 
> In the .tgz, there's a README.txt with full stacktraces.
> 
> I'm hoping the .tgz is allowed through the mailing list.  If not,
> please let me how I should submit it.
> 
> I worked around the unmarshalling problem by using xmlbeans data
> bindings instead of JAXB.
> 
> Steve
> 
> 
> 
>> Date: Mon, 29 Oct 2012 14:15:16 -0400
>> From: Steve Revilak <sr...@kayak.com>
>> To: users@cxf.apache.org
>> Subject: ObjectFactory and Multiple WSDLs in same namespace
>> 
>> Hello CXF Users,
>> 
>> I'm having trouble generating java code from a collection of WSDLs.
>> I'm finding that even if all code generation is done in one pass (via
>> wsdl2java -wsdlList), I'm left with an incomplete ObjectFactory.  This
>> is similar to the issue reported in
>> https://issues.apache.org/jira/browse/CXF-1340.
>> 
>> I understand that wsdl2java presumes a 1:1 mapping between namespaces
>> and packages; but I have a case where the 1:1 mapping poses problems,
>> and I'd like to understand my options for working around it.
>> 
>> I'm working with public WSDLs, so I'd like to provide a small, but
>> real-world use case for what I'm trying to do.
>> 
>> The WSDLs in question come from Google's DoubleClick for Publishers
>> API.  The API has a CRUD design, where each type of entity has its own
>> SEI (and WSDL).
>> 
>> I'll pick three WSDLs for my example:
>> 
>> https://www.google.com/apis/ads/publisher/v201208/CustomTargetingService?wsdl
>> https://www.google.com/apis/ads/publisher/v201208/LineItemService?wsdl
>> https://www.google.com/apis/ads/publisher/v201208/UserService?wsdl
>> 
>> I can generate code like this (where wsdl.txt contains
>> CustomTargetingService.wsdl, LineItemService.wsdl, and
>> UserService.wsdl):
>> 
>> ~/apache-cxf-2.7.0/bin/wsdl2java -verbose -d ~/dfp-src -p dfp.example -wsdlList ./wsdl.txt
>> 
>> The resulting ObjectFactory only creates objects from UserService.
>> 
>> 
>> As google provides them, all WSDLs have
>> 
>> targetNamespace="https://www.google.com/apis/ads/publisher/v201208"
>> 
>> 
>> I looked into using separate packages for each WSDL, but this approach
>> comes with problems.  Several classes are common between WSDLs.  For
>> example, there's a type called DateTime that appears in several
>> service definitions, and there are cases where I'd might get a
>> DateTime object from service A, and would want to pass it to a call to
>> service B.  I can't do that if A and B are in different packages.
>> 
>> What can I do in this case?
>> 
>> http://cxf.547215.n5.nabble.com/Wsdl2java-package-usage-td553695.html
>> 
>> suggests merging ObjectFactory code by hand.  This is certainly
>> possible, but it's also labor-intensive and error-prone.
>> 
>> Is there a way to intercept missing type errors from CXF?  For
>> example, if CXF can't find an ObjectFactory method to create a
>> UniqueError, I'd like to try and instantiate a dfp.example.UniqueError
>> (since I know that the types are in one package, and I know what that
>> package is).
>> 
>> Any suggestions would be sincerely appreciated.
>> 
>> Steve
> 
> 
> <dfp-test.tgz>

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com