Returning multiple values from an Axis2 Service

Most of you who wants to create a quick Axis2 Service to mock a web-service would encounter a situation where you want to return more than 1 value from a service. You can simply return more than 1 value by returning a Hashmap. But this would return the values in the following format.

This would be a nightmare for any developer who would want to use the response from this service to perform message mediator or orchestration as all the XML elements share the same name ‘return’ making it impossible to extract values through XPath.

Solution for this problem is to return an object type from the Axis2 service. Given below is a sample code snippet on how this can be done.

Axis 2 service

WorkOrderResponse Class

By returning an object, the Axis2 service would return values with correct XML elements names. XML element names would correspond to the variable names in the object. Given below is a sample response from the above service.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s