Using Ant wsgen task from xfire 1.2.3 against WSDL from
https://adwords.google.com/api/adwords/v8/CampaignService?wsdl
I get:
[wsgen] 15-Dec-2006 09:20:04 org.codehaus.xfire.gen.Wsdl11Generator generate
[wsgen] INFO: Generating code for WSDL at file:/c:/work/workspace/bcp/src/etc/wsdl/ggl/CampaignService.wsdl
with a ba
e URI of file:/c:/work/workspace/bcp/src/etc/wsdl/ggl/CampaignService.wsdl
[wsgen] 15-Dec-2006 09:20:04 org.codehaus.xfire.gen.jsr181.AbstractServiceGenerator generate
[wsgen] INFO: Creating class com.teracode.bcp.api.ggl.CampaignInterface
BUILD FAILED
C:\work\workspace\bcp\build\build.xml:72: org.codehaus.xfire.gen.GenerationException: Could not find holder type.
This seems to be the same as question posted on Nov 2nd here http://www.mail-archive.com/user@xfire.codehaus.org/msg01259.html
to which there never was a reply.
Running the Ant task through a debugger, I can intercept an embedded ClassCastException, which originates at line org.codehaus.xfire.gen.jsr181.AbstractServiceGenerator.java:252.
The code there is as follows:
protected JType getHolderType(GenerationContext context,MessagePartInfo part)
throws GenerationException
{
JType genericType = context.getSchemaGenerator().getType(context, part.getName(), part.getSchemaType().getSchemaType());
try {
JClass holder = context.getCodeModel().ref("javax.xml.ws.Holder");
holder = holder.narrow((JClass) genericType); /* THIS IS WHERE THE CLASSCASTEXCEPTION OCCURS */
return holder;
} catch (Exception e) {
throw new GenerationException("Could not find holder type.", e);
}
}
The MessagePartInfo, when the ClassCast is thrown, contains a schemaType which stringifies to "org.codehaus.xfire.aegis.type.basic.ObjectType[class=<null>,
QName={https://adwords.google.com/api/adwords/v8}responseTime]".
The ClassCastException is from JPrimitiveType to JClass.
Anybody know how to get Xfire wsgen to work with this WSDL? All others from WSDLs from Google AdWords API, not only this service but all others, and not only v8 but v7 and v6 as well, fail in the same way.
It's easy to reproduce, using a testcase as per below:
import junit.framework.TestCase;
public class WsGenTest extends TestCase {
public void testIt() throws Exception {
WsGenTask task = new WsGenTask();
task.setOutputDirectory("C:/EXT");
task.setWsdl("https://adwords.google.com/api/adwords/v8/CampaignService?wsdl");
task.setPackage("blah");
task.setOverwrite(true);
task.setGenerateServerStubs(false);
//task.setCaseSensitive(false);
//task.setDefaultexcludes(false);
try {
task.execute();
} catch( Throwable t ) {
t.printStackTrace();
fail(t.toString());
}
}
}
This is still an issue in XFire 1.2.4, BTW.
I worked around it by means of the following. In org.codehaus.xfire.gen.jsr181.AbstractServiceGenerator, around line 252, add the an instanceof check for JClass, like this:
try {
JClass holder = context.getCodeModel().ref("javax.xml.ws.Holder");
if( genericType instanceof JClass ) { holder = holder.narrow((JClass) genericType); }
return holder;
} catch (Exception e) { throw new GenerationException("Could not find holder type.", e); }
That works for me, for now.