WebSphere Integration Developer 7下开发一个Hello World ESB Java Service

本文总结了在WebSphere Integration Developer 7下开发一个Hello World ESB Java Service的过程。

第1步 - 创建ESB Java service

1.1) 在WebSphere Integration Developer 7.0 workspace中, 切换到Business Integration Perspective.

1.2) 从文件菜单中, 选择File - New - Module, 输入HelloWorldServiceModule为Module名, 然后点击Finish.

1.3) 在HelloWorldServiceModule工程下, 右键点击Interfaces, 然后选择New - Integerface, 使用HelloWorldInterface为interface名称, 然后点击Finish.

1.4) 在interface编辑器中, 右键点击然后选择Add Request Response Operation, 使用hello为operation名称, 使用message为输入名称, response为输出名称, 两种同为string类型. 保存所有文件.

1.5) 切换到Assembly Editor, 从Palette中拖拉一个Java部件到Assembly Editor中, 命名为HelloWorldService.

1.6) 右键点击HelloWorldService, 然后选择Add - Interface, 选择HelloWorldInterface.

1.7) 右键HelloWorldService 然后选择Generate Implementation, 新建一个java package demo.

1.8) 切换到HelloWorldServiceImpl Java编辑器, 使用以下代码实现hello方法, 保存文件.


/**
 * 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) 切换到Assembly Editor, 从Palette中拖拉一个References部件到Assembly Editor中.

1.10) 右键点击Stand-alone References, 然后选择Add Reference, 选择HelloWorldInterface

1.11) 连接Stand-alone ReferencesHelloWorldService, 保存文件.

第2步 - 创建ESB客户端

2.1) 切换到Java EE perspective.

2.2) 右键点击HelloWorldServiceModuleWeb工程, 选择New - JSP, 命名为client.jsp, 点击Finish.

2.3) 在client.jsp中使用以下代码, 保存文件.


<%@ 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>

第3步 - 测试运行程序

3.1) 切换到Business Integration Perspective, 右键点击HelloWorldServiceModule, 选择ExportIntegration modules and libraries - Files for server deployment

3.2) 将生成的EAR文件部署到Websphere Process Server上.

3.3) 使用浏览器访问client.jsp以测试该应用.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值