Server-side mobile application development with IBM Worklight: Part 2. IBM Worklight adapter integration with web service business logic

This is Part 2 of a series that explains how to use IBM® Rational® Application Developer for WebSphere® Software and IBM® Worklight together to develop applications for mobile devices, including those that run Android, iOS, BlackBerry, and Microsoft Windows Metro operating systems. This part demonstrates how to extend and transform existing server-side business logic assets to the mobile domain without re-engineering. Bhargav Perepa first shows how to use Rational Application Developer workbench to develop and test a JAX-WS application. Then he explains how to use Worklight Studio to develop and test a mobile application that uses the logic developed in the web service application.

Share:

Bhargav Perepa (bvperepa@us.ibm.com), WebSphere Architect and IT Specialist, IBM Japan

Bhargav PerepaBhargav Perepa is a WebSphere architect and IT specialist in the IBM Federal Software Group in Washington DC area. Previously, he was a developer in the Austin WebSphere Development Lab and had Smalltalk and C++ development experience at IBM Chicago. Bhargav holds a master's degree in Computer Science from the Illinois Institute of Technology, Chicago, and a master's in business administration (MBA) from the University of Texas, Austin.



07 May 2013

Also available in Chinese

Introduction

In Part 1 of this article series, you have developed and tested a Java application using the IBM® Rational® Application Developer for WebSphere® Version 8.5.1 developer workbench. Then you used the custom Java application logic that you developed in a mobile application, using an extend and transform approach. To develop a mobile application that contained a HTTP adapter invoking the Java application logic, you used IBM® Worklight Studio developer workbench.

In Part 2, you will learn, how to take the Java application that you developed in Part 1 to create/test a Java bean bottom-up based JAX-WS using Rational Application Developer for WebSphere v8.5.1 developer workbench. You will then learn to incorporate this custom Java API for XML Web Services (JAX-WS) application logic in a server-side mobile application featuring an HTTP adapter. You then learn how to test the mobile application, end to end.

Note about the use case architecture

This article builds on the previous one and uses the same use case that you developed in the first part. It incorporates the same programming artifacts. Be sure to read Part 1 to get acquainted with the use case and programming artifacts (you can also just click "More in this series").


Use case implementation approach

The use case implementation consists of six distinct activities, broadly identified as these steps:

  1. Develop the JAX-WS application in IBM Rational Application Developer.
  2. Test the JAX-WS application by using IBM Rational Application Developer.
  3. Package the JAX-WS application logic as a Java archive (.jar) for mobile application use.
  4. Develop the mobile application in IBM Worklight Studio.
  5. Incorporate the JAX-WS application logic provided as a JAX-WS archive library in the mobile application.
  6. Test the mobile application with IBM Worklight Studio by invoking JAX-WS application logic developed in previous steps, using the Worklight adapter. This constitutes an end-to-end testing.

Develop a JAX-WS application using Rational Application Developer

The following steps outline the JAX-WS application development, using Rational Application Developer for WebSphere, Version 8.5.1.

  1. Launch Rational Application Developer, and specify the location of the workspace on your file system: c:\temp\RADWS\WSUsecasesJAX-WSProject.
  2. Open the Java Enterprise Edition perspective, if it is not open already, by selecting Window > Open Perspective > Other > Java EE (default), and then click OK.
  3. Create a new JAX-WS project:
    1. In Enterprise Explorer , select UsecasesJavaProject > src > com.worklight.customcode > Usecases.java.
    2. To launch the Web Service creation wizard, right-click, and select Web Services > Create Web Service (see Figure 1).
Figure 1. Launch create Web Service wizard
Menu selections to launch the wizard
  1. Accept the default service definition values (see Figure 2):
    • Web service type: Bottom up JavaBean Web Service
    • Service implementation: com.worklight.customcode.Usecases
    • Server runtime: WebSphere Application Server v8.5
    • Web service runtime: IBM WebSphere JAX_WS
    • Service project: WebServiceProject
    • Service EAR project: WebServiceProjectEAR
    • Client type: Java Proxy
    • Configuration: No client generation
    • Box checked: Overwrite files without warning
  2. Click Next.
Figure 2. Web Service creation wizard, service definition
Details of the web service definition
  1. Accept the default values in the Web Service Configuration screen (see Figure 3):
    • Delegate class name: com.worklight.customcode.UsecasesDelegate
    • Java to WSDL mapping style: Document Wrapped
    • Box checked: Generate WSDL file into the project
    • WSDL file: UsecasesService.wsdl
    • Box checked: Generate Web Service Deployment Descriptor
  2. Click Next.
Figure 3. Web Service creation wizard, service configuration
Specific details of web service configuration
  1. Accept the default values for the WSDL interface options screen (see Figure 4):
    1. Check box: WSDL Target Namespace
    2. WSDL Target Namespace: http://customcode.worklight.com/
    3. Check box: Configure WSDL Service Name
    4. WSDL Service Name: UsecasesService
    5. Check box: Configure WSDL Port Name
    6. WSDL Port Name: UsecasesPort
  2. Click Next.
Figure 4. Web Service creation wizard, interface configuration
Specific details of interface configuration
Figure 5. Create Web Service wizard, publication options
Whether and where to publish the web service
  1. Click Finish (see Figure 5).

You have now created the JAX-WS application that is based on your previously developed Java application and deployed it to WebSphere Application Server, Version 8.5.0.2 as shown in Figure 6.

Figure 6. Enterprise Applications lists confirms successful deployment of the service
Successfully run UsecaseEJBProjEAR application

Test the JAX-WS application in Rational Application Developer

The following steps outline testing of the JAX-WS web service application that you developed in Rational Application Developer for WebSphere 8.5.1.

  1. Build the project cleanly by selecting Project > Clean > Clean all projects, and then click OK.
  2. Run the application as a Java EE JAX-WS service application:
    1. From the Java EE perspective, select the Services tab.
    2. Expand JAX-WS, and select WebServiceProject:UsecasesService.
    3. Select Test with Web Services Explorer (see Figure 7).
Figure 7. Launch the Web Services Explorer
Selections under Services tab as described

Invoke the getNumOfUsecasesInstances() method for testing

  1. From the Navigator pane, select these options:
    WSDL Main > platform:/resource/WebServiceProject/WebContent/WEB-INF/wsdl/UsecasesService.wsdl > UsecasesService > UsecasesPortBinding > getNumOfUsecasesInstances.
  2. Click the Go button in Actions pane (see Figure 8, scroll down top pane to see Go button).
Figure 8. Invocation of the getNumOfUsecasesInstances() operation
Execution results of getNumOfUsecasesInstances()
  1. In the bottom pane, double-click the Status bar to expand the view to full size.
  2. Click the Source hyperlink.
  3. Select and copy the SOAP request envelope code shown in Listing 1 to a temporary file (also see Figure 9).
Listing 1. SOAP request envelope code
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0=
"http://customcode.worklight.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:
xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:getNumOfUsecasesInstances />
</soapenv:Body>
</soapenv:Envelope>
Figure 9. SOAP request envelope for getNumOfUsecasesInstances()
SOAP request details of geNumOfUsecasesInstances()

Invoke the getUsecase () method for testing

  1. In the Web Services Explorer, select Actions > Operations > getUsecase.
  2. In the arg0 int field, type 4.
  3. Click the Go button (see Figure 10).
Figure 10. Invocation of getUsecase(4) operation
Execution results of getNumOfUsecasesInstances()
  1. In the bottom pane, double-click the Status bar to expand it to full size.
  2. Click the Source hyperlink.
  3. Select and copy the SOAP request envelope code shown in Listing 2 (also see Figure 11):
Listing 2. SOAP request envelope code
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0=
"http://customcode.worklight.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:
xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:getUsecase>
<arg0>4</arg0>
</q0:getUsecase>
</soapenv:Body>
</soapenv:Envelope>
Figure 11. SOAP request envelope for getUsecase(4)
SOAP request details of getUsecase()

Invoke the getAllUsecases () method for testing

  1. In the Web Services Explorer > Actions > Operations > getAllUsecases
  2. Click the Go button (see Figure 12).
Figure 12. Invocation of getAllUsecases() operation
Execution results of getAllUsecases()
  1. In the bottom status pane, double-click the bar to expand the view
  2. Click the Source link.
  3. Select and copy the SOAP request envelope code in Listing 3 (also see Figure 13).
Listing 3. SOAP request envelope
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0=
"http://customcode.worklight.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:
xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:getAllUsecases />
</soapenv:Body>
</soapenv:Envelope>
Figure 13. SOAP request envelope for getAllUsecases()
SOAP request details of getAllUsecases()

Packaging JAX-WS application logic for a mobile application use

Follow these steps to package a JAX-WS application so that its logic is usable in mobile application:

  1. Navigate to this folder:
    c:\temp\RADWS\WSUsecasesJAX-WSProject\WebServiceProject\WebContent\WEB-INF
  2. Compress the file tree classes and WSDL folders to a Java archive (.jar) file with this name:
    UsecasesJAX-WSProjectUtils.jar (see Figure 14)
  3. Files in the UsecasesJAX-WSProjectUtils.jar file are organized in this structure:
UsecasesJAX-WSProjectUtils.jar
  com
    worklight
	  customcode
	    jaxws
		  GetAllUsecases.class
		  GetAllUsecasesResponse.class
		  GetNumOfUsecasesInstances.class
		  GetNumOfUsecasesInstancesResponse.class
		  GetUsecase.class
		  GetUsecaseResponse.class
		  Main.class
		  MainResponse.class
		  ToString.class
		  ToStringResponse.class
		  UsecasesExceptionBean.class				
		UsecasesDelegate.class
  wsdl
    UsecasesService.wsdl
	UsecasesService_schema1.xsd
Figure 14. Packaging the JAX-WS application as a usable library
Java archive library contents (folders)

Mobile application development using IBM Worklight Studio

The following steps outline mobile application development using IBM Worklight Studio Version 5.0.6:

  1. Launch Worklight Studio, and specify this location for the workspace in the file system:
    C:\temp\WRKLT\WSAdapterCall2JAX-WSService
  2. Create a new Worklight project:
    1. To start new Worklight project creation wizard, click File > New > Worklight Project.
    2. Specify the Worklight project name: WLHTTPAdapterCall2JAXWSProject
    3. Specify the Worklight project template: HybridApplication.
    4. Click Next.
    5. Specify the application name: WLHTTPAdapterCall2JAXWS
    6. Select the rest of default values on this screen, and then click Finish.
  3. Create a new Worklight adapter:
    1. To launch new Worklight adapter creation wizard, select WLHTTPAdapterCall2JAXWSProject > adapters > Worklight Adapter.
    2. Start the new Worklight adapter creation wizard by clicking New > Worklight Adapter.
    3. Specify the project name: WLHTTPAdapterCall2JAXWSProject
    4. Specify the adapter type: HTTP Adapter
    5. Specify the adapter name adapter name: Call2JAXWSAdapter
    6. Click Finish.

Figure 15 shows the configured adapter metadata file in the editor.

Figure 15. Worklight adapter metadata in editor
Content of the adapter configuration file

Figure 16 shows the completed implementation of adapter logic in the editor. The adapter implements three methods in the JavaScript functions, and each of these functions makes a call to the JAX-WS application logic developed in previous steps. The application logic is made available to the mobile application in a Java archive (JAR) library. The implementation demonstrates how to invoke JAX-WS application static methods, as well as JAX-WS application instance methods.

Figure 16. Worklight adapter implementation in the editor
Adapter function implementations in JavaScript
  1. Start the Worklight server:
    1. Select WLHTTPAdapterCall2JAXWSProject.
    2. Click the Start Worklight Server option.
  2. Deploy the Worklight adapter to the Worklight server:
    1. Select WLHTTPAdapterCall2JAXWSProject > adapters > Call2JAXWSAdapter.
    2. Select Run As > Deploy Worklight Adapter.

Figure 17 shows successful deployment of the Worklight adapter in the Worklight Studio console view.

Figure 17. Verifying adapter deployment, Worklight Studio Console tab view
Console tab says adapter deployed successfully

Figure 18 shows successful deployment of the Worklight adapter in the Worklight admin console.

  1. Verify the deployment by entering this address in the Google Chrome browser:
    http://localhost:8080/console
Figure 18. Verifying adapter deployment, Worklight admin console view
Browser display of successful adapter deployment

Incorporating Java application logic in a mobile application

The following steps describe how to import the JAX-WS application library to be used in mobile application being developed in Worklight Studio:

  1. Launch the import wizard to import the Java application library into the Worklight Studio workspace, to be deployed to Worklight Server.
  2. Navigate to WLHTTPAdapterCall2JAXWS > server > lib folder.
  3. Right click to select Import > File System > Next to get to file system import wizard.
  4. Specify the Java application library to be used in the mobile application by selecting the .jar file to import from the file system: c:\temp\ UsecasesJAX-WSProjectUtils.jar
  5. Click Finish.

Figure 19 shows completed Worklight application project, ready for testing.

Figure 19. Completed Worklight project
Project Explorer display of completed project

Mobile application testing using IBM Worklight Studio

The following steps explain end-to-end testing of a mobile application. In this execution, the JAX-WS application logic is invoked from the adapter component of the mobile application.

Invoke the getNumOfUsecasesInstances() static method

  1. Select WLHTTPAdapterCall2JAXWSProject > adapters > Call2JAXWSAdapter.
  2. Select Run As > Invoke Worklight Procedure.
  3. Accept Project name: WLHTTPAdapterCall2JAXWSProject.
  4. Accept Adapter name: Call2JAXWSAdapter.
  5. Specify Procedure name: getNumOfUsecaseInstances().
  6. Click Apply and then click Run (see Figure 20).
Figure 20. Procedure testing, getNumOfUsecaseInstances()
Invocation of getNumOfUsecasesInstances() steps

Figure 21 shows successful invocation of getNumOfUsecasesInstances() static adapter method.

Figure 21. Successful invocation – getNumOfUsecasesInstances()
Invocation result: is successful

Invoke the getUsecase(4) instance method

  1. For adapter name, select WLHTTPAdapterCall2JAXWSProject > adapters > Call2JAXWSAdapter.
  2. Select Run As > Invoke Worklight Procedure.
  3. Accept Project name: WLHTTPAdapterCall2JAXWSProject
  4. Accept Adapter name: Call2JAXWSAdapter
  5. Specify Procedure name: getUsecase(4)
  6. Click Apply and then click Run (see Figure 22).
Figure 22. Procedure testing, getUsecase(4)
Invocation steps of getUsecase(4)

Figure 23 shows successful invocation of the getUsecase(4) instance adapter method.

Figure 23. Successful invocation, getUsecase(4)
Invocation results

Invoke the getAllUsecases() instance method

  1. Select WLHTTPAdapterCall2JAXWS > adapters > Call2JAXWSAdapter.
  2. Select Run As > Invoke Worklight Procedure.
  3. Accept Project name: WLHTTPAdapterCall2JAXWSProject
  4. Accept Adapter name: Call2JAXWSAdapter
  5. Specify the procedure name: getAllUsecases()
  6. Click Apply and then click Run (see Figure 24).
Figure 24. Procedure testing, getAllUsecases()
Invocation steps of getAllUsecases()

Figure 25 shows successful invocation of the getAllUsecases() instance adapter method.

Figure 25. Successful invocation, getAllUsecases()
Results screen

Summary

Part 2 of this series shows how to use the Rational Application Developer for WebSphere workbench to develop and test a Java API for XML Web Services (JAX-WS) application and how to use IBM Worklight Studio to develop and test a mobile application that uses logic previously developed in JAX-WS application. It demonstrates how to extend and transform the existing server-side business logic assets to the mobile domain without wholesale re-engineering by using IBM Rational Application Developer for WebSphere and IBM Worklight Studio developer workbench tools. To further your learning, the download section contains sample artifacts for you to use. In subsequent parts of this series, you will learn how to extend and transform a JAX-RS service and Enterprise JavaBeans (EJB) 3.1 Java Persistence API (JPA) application assets to the mobile domain by using the same approach explained in this article.


Acknowledgments

The author gratefully acknowledges receiving review feedback, constructive suggestions, support, and productive teamwork from Sujatha Perepa (perepa@us.ibm.com) and Roger Snook (rcsnook@us.ibm.com), both IBMers.


Downloads

DescriptionNameSize
File referenced in articleRAD_UsecasesJAX-WSProject_March242013.zip38KB
File referenced in articleUsecasesJAX-WSProjectUtils.zip9KB
File referenced in articleWL_UsecasesJAX-WSProject_March242013.zip574KB

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Rational software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational, Mobile development, DevOps
ArticleID=928620
ArticleTitle=Server-side mobile application development with IBM Worklight: Part 2. IBM Worklight adapter integration with web service business logic
publish-date=05072013