Tuesday, July 16, 2013

WSConsume Task and Jaxb Issues

My experience with WSDL and JAXB is not much. So I face various issues while working on those WSDL once a while. Though most of the issues have wide support on internet but this issue took plenty of time to find the solution.

Following is my ant entry to run the wsconsume utility.

<wsconsume keep="true" binding="TEST_bindings.xml"   wsdlLocation="/META-INF/wsdl/TEST/TEST.wsdl"  destdir="${TEST.3.0.bin}" sourcedestdir="${TEST.3.0.src}"  wsdl="${TEST.3.0.wsdl}" additionalHeaders="true"   target="${wsdl.jaxws.targetver}"/>

Content of TEST_binding xml are as following
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="1.0" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
                xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
                xmlns:xs="http://www.w3.org/2001/XMLSchema">
                <jxb:bindings schemaLocation="TEST.wsdl#types?schema1">
                                <jxb:schemaBindings>
                                                <jxb:package name="com.test " />
                                </jxb:schemaBindings>
                                <jxb:bindings node=                "//xs:complexType[@name='test']/xs:simpleContent/xs:extension[@base='s:string']/xs:attribute[@name='value']">
                                                <jxb:property name="testValue" />
                                </jxb:bindings>
                </jxb:bindings>
</jxb:bindings>
My file TEST.wsdl is stored in /META-INF/wsdl/TEST folder. So it is kind of all messed up from the start. Developer has already built a monster and I had to deal with it without knowing much about functionality.

When I ran the build xml with the following set up, I encountered the following issue.
"<COMPLETE_PATH>/TEST.wsdl" is not a part of this compilation. Is this a mistake for "file: <COMPLETE_PATH>/TEST.wsdl #types?schema1"? 

I found few links which suggested me to copy the WSDL under wsdl folder.
So now I moved WSDL files to /META-INF/wsdl/TEST/wsdl folder.

On Rerunning the application, I got file not found exception. As my application was already messed up, so I messed up a little more, and backed up the files in /META-INF/wsdl/TEST/wsdl and /META-INF/wsdl/TEST/ folders.

I reran the application, but again I faced same issues. So with some help of google sir, I got one alternative of TEST.wsdl#types?schema1. So I attempted that.
I replaced TEST.wsdl#types?schema1 test to TEST.wsdl#types1, and run the application again.

This time I did not get the compilation error. Now error was different. Error was as mentioned below.
[wsconsume] org.apache.cxf.tools.common.ToolException: java.lang.reflect.UndeclaredThrowableException
[wsconsume]     at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:279)
[wsconsume]     at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
[wsconsume]     at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
 [wsconsume] Caused by: java.lang.NoSuchMethodException: javax.xml.bind.annotation.XmlElementRef.required()
[wsconsume]     at java.lang.Class.getDeclaredMethod(Unknown Source)

It means that required method did not exist in the library files of jaxb. Java 6 works older version of JAXB, and Java 7 works with latest version of jaxb. You can choose to either use Java 7 or provide endorsed libraries to java. For me endorsed library path did not work, so I ran the application on Java 7 and it compiled and created respective jar to me.


I know, I have not given reasons and facts, but still I tried to write down all the problems I faced. Hope helps.

No comments:

Post a Comment