Browse DevX
Sign up for e-mail newsletters from DevX


Expose Your POJO-Based Domain Apps as Web Services : Page 2

Combine Axis2, the next-generation web services API of Apache Axis, with Spring to expose POJO-based, domain-tier applications as both REST- and SOAP-based web services.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Generating WSDL
To generate WSDL from an existing class, you can use the command line executable binaries provided by the Axis2 distribution, such as "wsdl2java." Axis2 documentation provides detailed instructions for using a binary both as a standalone binary and as an ANT task. The project also provides plug-ins for Eclipse, IntelliJ IDEA, and Maven 2.

This article uses the Eclipse plug-in. Although, less powerful than the command line binaries, this plug-in makes the process of creating web services very efficient. It provides support for both WSDL-to-Java and Java-to-WSDL generations.

It's a good practice to place the web service-related code that is generated, including WSDL, in a separate project for better flexibility and clarity. Hence, before you generate your components, you need to create an empty Java project in the IDE with clear source and binary trees. Call this project AccountWS.

You can now use the Eclipse plug-in and generate WSDL from Java classes by referencing the AccountManagerImpl class. To ensure appropriate variable naming, make sure that the implementation class—not the interface—is referenced. See the following screenshots for the details.

Click to Enlarge
Screenshot 1
  Click to Enlarge
Screenshot 2
Click to Enlarge
Screenshot 3
  Click to Enlarge
Screenshot 4
Click to Enlarge
Screenshot 5

A file named "services.wsdl" should be created under the new empty project AccountWS now. The WSDL now defines the two services with their input/output values, as follows:

<xs:element name="getAccount"> <xs:complexType> <xs:sequence> <xs:element name="accountId" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="getAccountResponse"> <xs:complexType> <xs:sequence> <xs:element name="return" nillable="true" type="ns0:Account" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="setStatus"> <xs:complexType> <xs:sequence> <xs:element name="accountId" nillable="true" type="xs:string" />
xs:element name="status" nillable="true" type="xs:boolean" /> </xs:sequence> </xs:complexType> </xs:element>

After the WSDL is generated, you need to manually edit the <soap:address> parameter, changing it to the right URL and port of the service. The plug-in generates a default value.

Thanks for your registration, follow us on our social networks to keep up-to-date