Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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

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.


advertisement
Testing the Service
You can truly test a service only from a consumer point of view. You can easily verify the REST implementation by directly invoking it from a browser. Figure 7 shows the input and output for REST invocation.

Browser URL:
http://localhost:9080/AccountWeb/rest/Accountservice/getAccount?accountId=2

Response:

Figure 7. REST-based Service Invocation and Response



Now, you will create a simple client and try to invoke the service over SOAP/HTTP. Create a simple Java project and include the client jar that contains the stubs generated earlier. In real applications, service providers most likely will provide these or a WSDL that the consumer can use to generate the stubs and the message receivers. You again use ADB to invoke the service for convenience and demonstration purposes. For applications with any amount of complexity, you should use JiBX for schema binding integrated with Axis2. Axis2's "wsdl2java" command line utilities provide support for generating JiBX clients.

The following is the code for your SOAP-service test client:

AccountserviceStub stub = new AccountserviceStub("http://localhost:9080/AccountWeb/services/Accountservice"); .. AccountserviceStub.GetAccount req =new AccountserviceStub.GetAccount(); req.setAccountId(accountId); AccountserviceStub.GetAccountResponse res = stub.getAccount(req); name = res.get_return().getFirstName() + " " + res.get_return().getLastName();

When you run the class and monitor the TCP/IP traffic between the client and the server, you can see the following, indicating a successful call. The calls were for the method getAccount for any method with the parameter accountId value of '2':

Request: <?xml version="1.0" encoding="http://www.w3.org/2003/05/soap-envelope"?> <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"> <soapenv:Header/> <soapenv:Body> <ns2:getAccount xmlns:ns2="http://AccountManager.domain.account.corp.com/types"> <ns2:accountId>2</ns2:accountId> </ns2:getAccount> </soapenv:Body> </soapenv:Envelope> Response: <?xml version="1.0" encoding="http://www.w3.org/2003/05/soap-envelope"?> <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"> <soapenv:Header/> <soapenv:Body> <ns2:getAccountResponse xmlns:ns2="http://AccountManager.domain.account.corp.com/types"> <ns2:return> <ns6:accountId xmlns:ns6="http://bo.domain.account.corp.com/xsd">2</ns6:accountId> <ns7:address xmlns:ns7="http://bo.domain.account.corp.com/xsd">2222, Lincoln Av, New York</ns7:address> <ns8:firstName xmlns:ns8="http://bo.domain.account.corp.com/xsd">Jane</ns8:firstName> <ns9:lastName xmlns:ns9="http://bo.domain.account.corp.com/xsd">Smith</ns9:lastName> <ns10:status xmlns:ns10="http://bo.domain.account.corp.com/xsd">false</ns10:status> </ns2:return> </ns2:getAccountResponse> </soapenv:Body> </soapenv:Envelope>

Looking Ahead
This tutorial described the basic creation of web services using an existing domain. However, typical enterprise applications that use web services have other crosscutting concerns such as security, reliable messaging, etc. Axis2's architecture allows for implementation of these features in a relatively simple and modular way. The process broadly involves editing the service descriptor to add references to the appropriate modules and configuring the respective policies.

With this introduction to Axis2 as an easy alternative for exposing existing POJO-based domain functions in J2EE applications, you now can use Axis2 to preserve current investment in application architecture and with minimal code intrusion still expose existing POJO-based domain applications as robust, remotely consumable web services.



Ramanujam A. Rao is a software architect and engineer specializing in designing and developing enterprise applications. He currently consults in the areas of enterprise application architecture and helps build scalable, distributed applications on the J2EE platform. Contact him at arrao@acm.org.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap