Friday, June 22, 2012

Develop a Hello World ESB Java Service using WebSphere Integration Developer 7

This note summarise the development of a Hello World ESB Java service using WebSphere Integration Developer 7.0.

Step 1 - Build the ESB Java service

1.1) In WebSphere Integration Developer 7.0 workspace, switch to Business Integration Perspective.

1.2) In file menu, select File - New - Module, use HelloWorldServiceModule as the Module name and click Finish.

1.3) Under the HelloWorldServiceModule project, right click Interfaces, and select New - Integerface, use HelloWorldInterface as the interface name, then click Finish.

1.4) In the interface editor, right click and select Add Request Response Operation, use hello as operation name, and message as the input, response as the output, both with string type. Save the changes.

1.5) Switch to the Assembly Editor, drag and drop a Java component from the Palette to the Assembly Editor, name it HelloWorldService.

1.6) Right click the HelloWorldService and select Add - Interface, select HelloWorldInterface.

1.7) Right click the HelloWorldService and select Generate Implementation, create a new package demo.

1.8) In the HelloWorldServiceImpl Java editor, implemention the hello method as the code below, save changes.

/**
 * Method generated to support implementation of operation "hello" defined for WSDL port type 
 * named "HelloWorldInterface".
 * 
 * Please refer to the WSDL Definition for more information 
 * on the type of input, output and fault(s).
 */
public String hello(String message) {
 return "Hello:" + message;
}

1.9) Switch to the Assembly Editor, drag and drop a References component from the Palette to the Assembly Editor.

1.10) Right click the Stand-alone References, and select Add Reference, then select HelloWorldInterface

1.11) Link the Stand-alone References to HelloWorldService, save changes.

Step 2 - Build the ESB client

2.1) Switch the Java EE perspective.

2.2) Right click the HelloWorldServiceModuleWeb project, and select New - JSP, use client.jsp as the File name, then click Finish.

2.3) Add the code below to the client.jsp page, save changes.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="com.ibm.websphere.sca.*,commonj.sdo.DataObject" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>

<%
String serviceOutput = "N/A";
String message = request.getParameter("message");
if(message != null){
 try{
  ServiceManager serviceManager = new ServiceManager();
  Service service = (Service) serviceManager.locateService("HelloWorldInterfacePartner");
  DataObject respObject = (DataObject) service.invoke("hello", message);
  serviceOutput = respObject.getString("response");
 }catch(Exception e){
  e.printStackTrace();
 }
}
%>

Service Output : <%= serviceOutput %>

<form method="post">
 <input type="text" NAME="message"/>
 <input TYPE="submit"/>
</form>

</body>
</html>

Step 3 - Build and run the application

3.1) Switch to Business Integration Perspective, right click the HelloWorldServiceModule, select Export and Integration modules and libraries - Files for server deployment

3.2) Deploy the generated EAR file to Websphere Process Server.

3.3) Access the client.jsp from browser to test the application.

1 comment: