It's not a secret anymore!*
The moose likes Web Services and the fly likes WDSL2Java using Axis2 via Ant in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "WDSL2Java using Axis2 via Ant in Eclipse" Watch "WDSL2Java using Axis2 via Ant in Eclipse" New topic
Author

WDSL2Java using Axis2 via Ant in Eclipse

Rene Schubert
Greenhorn

Joined: Aug 19, 2011
Posts: 1
Hello everybody,

I am new here and also am new to Web Services, Eclipse, Ant and Axis(2). My task is simple: Generate Java sources based on a WSDL file that was generated by some SAP backend system. But it seems like I won't get any further than I am now without help.

I tried generating the Java code using Apache Axis(1) with an Ant task inside Eclipse. Sorrily it seemed like Axis1 was not able to interpret the WSDL correctly. The references to the Elements "Request", "Response" and "Fault" inside the messages could not be resolved, though a test for this WSDL with soapUI was successful. The same problem appeared when I tried the command line of Axis' WSDL2Java. I tried fixing these references by adding p1: to the element-attribute of the referencing wsdl:part inside the message-elements. Example:


This worked in that Axis now was able to interpret the WSDL and create all source files. Sorrily it turned out that this lead to a wrong request being sent to the Web Service, later. So it was clear now that the WSDL must not be modified. But at least I got an idea of what the source files would be like.

So I tried Axis2 (using the original/unmodified WSDL again). The command line version first. I called WSDL2Java with the following command:
...\axis2-1.6.0\bin>wsdl2java.bat -ss -o ./java -uri statusExternalGetAllByAccount.wsdl


This resulted in some source files being generated under the ./java folder. But also some files were missing. This probably had to do with an Exception that was thrown during the generation. This is the output of the command line call:
Using AXIS2_HOME: D:\Users\Rene.Schubert\Desktop\axis2-1.6.0
Using JAVA_HOME: C:\Program Files\Java\jdk1.6.0_18
Retrieving document at 'statusExternalGetAllByAccount.wsdl'.
log4j:WARN No appenders could be found for logger (org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.RuntimeException: WSDL writing failed!
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:293)
at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)
at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
Caused by: org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.RuntimeException: WSDL writing failed!
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.emitSkeleton(AxisServiceBasedMultiLanguageEmitter.java:1451)
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:275)
... 2 more
Caused by: java.lang.RuntimeException: WSDL writing failed!
at org.apache.axis2.wsdl.codegen.writer.WSDL11Writer.writeWSDL(WSDL11Writer.java:87)
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.writeWSDLFiles(AxisServiceBasedMultiLanguageEmitter.java:1520)
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.emitSkeleton(AxisServiceBasedMultiLanguageEmitter.java:1422)
... 3 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=OTHER_ERROR: Can't find prefix for 'http://schemas.xmlsoap.org/wsdl/soap/'. Namespace prefixes mus
t be set on the Definition object using the addNamespace(...) method.
at com.ibm.wsdl.util.xml.DOMUtils.getPrefix(Unknown Source)
at com.ibm.wsdl.util.xml.DOMUtils.getQualifiedValue(Unknown Source)
at com.ibm.wsdl.extensions.soap.SOAPBindingSerializer.marshall(Unknown Source)
at com.ibm.wsdl.xml.WSDLWriterImpl.printExtensibilityElements(Unknown Source)
at com.ibm.wsdl.xml.WSDLWriterImpl.printBindings(Unknown Source)
at com.ibm.wsdl.xml.WSDLWriterImpl.printDefinition(Unknown Source)
at com.ibm.wsdl.xml.WSDLWriterImpl.writeWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLWriterImpl.writeWSDL(Unknown Source)
at org.apache.axis2.wsdl.codegen.writer.WSDL11Writer.writeWSDL(WSDL11Writer.java:185)
at org.apache.axis2.wsdl.codegen.writer.WSDL11Writer.writeWSDL(WSDL11Writer.java:84)
... 5 more


So I tried to generate the source files using an Ant task inside Eclipse. I tried to follow the example of Apache's Axis2 Code Generator Tool Guide. This is what I made out of it:


The above XML code is the content of the statusExternalGetAllByAccountService.xml file that I included inside the build.xml as follows:


Sorrily this resulted in an exception, as well:
..\statusExternalGetAllByAccountService.xml:19: org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDL


Now I don't know any further. Can you help me, please?

The WSDL looks as follows (I was not able to attach a .wsdl-file would there be a better way to attach large code files?):


First of all I need to find out two things:
  • Is it possible to generate working code out of the WSDL without changing it?
  • If not, where is the error in the WSDL file? I was told that the SAP generated WSDL can not be changed, but if I knew that there's definitely something wrong with the WSDL, I'd at least have something on the SAP guys.


  • Facts:
    Eclipse Version: 3.5.2
    Axis2 Version: 1.6.0
    JDK: 1.6.0_18

    Thank you very much in advance!


    Regards,
    Ren├ę
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: WDSL2Java using Axis2 via Ant in Eclipse
     
    Similar Threads
    Can't generate java classes from WSDL file
    Problem related to XML validation using XSD
    Error creatin Top down web service with Eclipse Helios
    org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement
    problem with WSDL2Java and nested complex types