wood burning stoves 2.0*
The moose likes Web Services and the fly likes Axis2 - WSDL to code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Web Services
Bookmark "Axis2 - WSDL to code" Watch "Axis2 - WSDL to code" New topic
Author

Axis2 - WSDL to code

Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
I have started learning webservices development using Axis2.

We need to follow the contract first approach. I have created this simple WSDL.



Using this WSDL I need to write the webservice. Can someone please let me know how can I generate the classes from this WSDL. Is there a tool/command available to do so? Once the classes are generated I can write my businesslogic in them and then expose the service to the clients.
Thank you
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263



The binding names which you are using in your service are not defined. Modify it as follows.


There are couple of tools which you can use to validate WSDL. One of them is mentioned in link below
http://charithaka.blogspot.com/2008/07/how-to-validate-wsdl-using-eclipse.html

And regarding generating classes axis provide utility wsdltojava which you can use to generate classes.

-Shiv
Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
Thanks a lot for replying.

I went through wsdl2java
http://ws.apache.org/axis/java/user-guide.html#UsingWSDLWithAxis

but it says
"This will generate only those bindings necessary for the client.".

But I need to generate the classes for creating the service. Is this even the right approach to creating webservices, that is, first write the wsdl, then generate the webservice classes and then put your business logic in those classes?

shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
Top down (wsdl first/ contract first) or bottom up (code first) depends on the requirement. Suppose you have same existing code and want to expose as webservice then you would go for code first but if you are developing from scratch then contract first can be a good approach. Developer would like to do code first while business analyst would like to have contract first. There are lot of discussion you can find on net.

Regarding generation of classes, see the "Implementation Template Description" heading in the axis tutorial link you have mentioned. Here it generates template implementation where you can write your business logic.
Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
Thanks a lot.

I tried doing the following

C:\axis2-1.5.1\samples\quickstart\build>C:\axis2-1.5.1\bin\wsdl2java.bat -o c:\t
emp -ss -sd -g -S c:\temp\src -uri ResumeService.wsdl

but it gave me the following error



Can you please let me know how to resolve this?

This is my updated wsdl


Thank you
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
Welcome :-)
It's document literal style wsdl so it doesn't expect more than one part in message according to ws basic profile. Lets modify wsdl as follows



This should work.

If you want to retain everything then create complex types say, EmpDetails and Emp. Wrap EmpDetails and EmpName in Emp complex type and refer it in wsdl:message.
Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
Thanks a lot.

Now I am getting the following



But "c:\temp" is a valid directory in my system. So can't make out why this error.

This is my updated WSDL



Thank you
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263


first of all modify employee as follows

<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="ns:employeeName" />
<xs:element minOccurs="0" ref="ns:employeeDetails" />
</xs:sequence>
</xs:complexType>
</xs:element>

In case it's still not working I can be reached at shivendra2u@gmail.com
Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
Still getting the same error.
Here is the updated wsdl

shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
I guess the output location is not a folder. Can you provide complete detail of all the steps you are following to generate classes. So that I can try and debug it?
Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
I am executing the following from command line

C:\axis2-1.5.1\bin\wsdl2java.bat -o c:\temp -ss -sd -g -S c:\temp\src -uri ResumeService.wsdl

c:\temp and c:\temp\src are valid directories. Which root directory is the error pointing to?

Thank you
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
I tried following and it's worked. A peace of advice don't try all the available option first time rather try one by one. This way you can figure out where is the problem.

C:\MyFolder\MySoftwareLab\tools\axis2-1.5.1-bin\axis2-1.5.1\bin>wsdl2java.bat -s
s -sd -g -ssi -uri C:\MyFolder\MySoftwareLab\Test.wsdl
Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
shivendra tripathi wrote:I tried following and it's worked. A peace of advice don't try all the available option first time rather try one by one. This way you can figure out where is the problem.

C:\MyFolder\MySoftwareLab\tools\axis2-1.5.1-bin\axis2-1.5.1\bin>wsdl2java.bat -s
s -sd -g -ssi -uri C:\MyFolder\MySoftwareLab\Test.wsdl


Thanks a lot. It worked. I was able to generate with Eclipse.

Thanks for the help.
Sunil swain
Greenhorn

Joined: Jul 14, 2009
Posts: 10
Hi, I am using java,tomcat 5.5 ,Axis2 and eclipse. I created .aar file in deployment directory while going through top down approach.After that when i typed "http://localhost:8080/axis2/" i got the exception as "org.apache.jasper.JasperException" pointing root cause as "java.lang.NullPointerException".Any one can give the pointer for the solution? Thanks in adv.
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
Can you post your WSDL, stack trace and steps you followed?
Sunil swain
Greenhorn

Joined: Jul 14, 2009
Posts: 10
Sorry actually i was using bottom up approach.
The stack trace is:
exception:
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:965)
org.apache.jsp.axis2_002dweb.index_jsp._jspService(index_jsp.java:67)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause:
java.lang.NullPointerException
org.apache.jsp.axis2_002dweb.include.httpbase_jsp.jspInit(httpbase_jsp.java:22)
org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:79)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:145)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:314)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:965)
org.apache.jsp.axis2_002dweb.index_jsp._jspService(index_jsp.java:67)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

Thanks for the response.
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
If you are using java 1.6 use java 1.5 and try.
Sunil swain
Greenhorn

Joined: Jul 14, 2009
Posts: 10
Thanks for the response. Actually i got the solution by changing the axis2.war file.
Kevin Eddy
Ranch Hand

Joined: Feb 24, 2010
Posts: 74
Sunil swain wrote:Thanks for the response. Actually i got the solution by changing the axis2.war file.


I'm curious, what do you mean by "changing the axis2.war file"?
Sunil swain
Greenhorn

Joined: Jul 14, 2009
Posts: 10
Initially i took the zip file of axis2.But when i downloaded axis2.war,it worked with that.Actually in the unzip version of downloaded asix2 there was no services directory under WEB-INF.
Srini Vady
Greenhorn

Joined: Jul 16, 2012
Posts: 1
I was getting the same error ("Root Location Needs to be a Directory!")
In my case, the problem was with the way i had specified the destination folder path for the generated files

Solution:
Changed the wsdl2java command from:
wsdl2java -s -S “D:\Srini\MyProject\Build\Workspaces\ServiceProvider\src-gen” -ssi LoginInterface -u -or -Ejavaversion 1.5 -uri LogonServices.wsdl

to

wsdl2java -s -S \..\src-gen -ssi LoginInterface -u -or -Ejavaversion 1.5 -uri LogonServices.wsdl

In case this helped, congratulations!
 
GeeCON Prague 2014
 
subject: Axis2 - WSDL to code