wood burning stoves 2.0*
The moose likes Web Services and the fly likes Existing java class as a web service using axis2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Existing java class as a web service using axis2 " Watch "Existing java class as a web service using axis2 " New topic
Author

Existing java class as a web service using axis2

andy kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 57
I have java application in which a particular class has a method say "getInformation()", the argument to this method is a jabx generated java class. Now I want to expose this method as a Web service using axis2. I use the java2wsdl utility to get the wsdl. Next I use the wsdl2java to create the server side stubs which gives me a skeleton class whose argument is a not the same as the one of my existing java class. So I have to extract the information from this axis2 generated java object and then populate the jaxb generated java object and then call my original method (getINformation()).

Is this approach correct? Is there some way I can avoid the manual conversion of axis2 java object to jaxb java object. I already have the application so I dnt want to change existing java method with the jaxb object as its argument.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

anuj kumar kumar welcome to Javaranch
please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41101
    
  45
Instead of running java2wsdl, try deploying the service, and then pointing wsdl2java at its published WSDL.


Ping & DNS - my free Android networking tools app
andy kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 57
Thanks for the response. But how can I directly deploy the service without generating the server side stubs.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41101
    
  45
What do you mean by "server side stubs"? Axis services are deployed as *.aar files, which include the classes (just a single POJO in the simplest case), along with a META-INF/services.xml file. That's sufficient to deploy them.
andy kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 57
I am currently using tomcat and have the axis2 in the webapps folder. In the dir axis2\WEB-INF\services I have a folder which contains my service. How to deploy the service as a *.aar files? I am very new to the topic of WS thats why I am having these very basic doubts.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41101
    
  45
Well, how is your service deployed, then? If it's in WEB-INF\services, then it must be an *.aar file, no?

Information on how to deploy services in Axis can be found in the http://ws.apache.org/axis2/1_5/userguide-buildingservices.html page, particularly the "Deploying Plain Old Java Objects" and "Deploying and Running an Axis2 Service Created from WSDL" sections.
andy kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 57
The service is in WEB-INF\services folder but it is not a .aar file. I have a folder called MyService which in turn has the class files in the MyService\com folder and I have a MyService\META-INF folder which has the services.xml and .wsdl file.
Thanks for giving me the link and pointing the required section to be read. Will get back in case I have further questions.
andy kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 57
I was able to deploy my POJO class and test it using RPCServiceClient. Thank you very much. But I have a small issue. My schema file has an elements items which had 0 or more item in it.
The xsd is
<xsd:complexType name="Items">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="anitem"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="anitem">
<xsd:sequence>
<xsd:element name="productName" type="xsd:string"/>
<xsd:element name="quantity" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>

The jaxb class "Items" has a class variable of type list which is declared as = list<anitem> item.
But when I deploy this service using the POJO method and click on the service link it displays the wsdl file in the browser. But it seems the wsdl is not correct as it shows the description of items as below

<xs:complexType name="Items">
<xs:sequence>
<xs:element minOccurs="0" name="item" nillable="true" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>

What does it mean by xs:anytype? Shouldn't it be of type anitem and then anitem should be declared having productName and quantity as xsd:String types.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Existing java class as a web service using axis2
 
Similar Threads
Help: Creating web service proxy using JAXB generated domains
How to integrate AXIS2 envirnoment into the current webapllication.
invoking a Axis2/Soap webservice
Java objects to XML, possibly using JAXB
Mark Hansen: Data Binding Approaches