JAVA中使用jolt调用TUXEDO服务[原创]

声明,本文转载自:http://softhood.net/cn/2010/08/04/java%E4%B8%AD%E4%BD%BF%E7%94%A8jolt%E8%B0%83%E7%94%A8tuxedo%E6%9C%8D%E5%8A%A1%E5%8E%9F%E5%88%9B/

jolt是一组java的开发包,用于完成从java向tuxedo服务的调用。开发一个jolt客户端的流程如下所示:


下面用一个简单的例子对调用过程进行说明:

1.开发环境:MyEclipse 6, JDK1.4.2

2.依赖的jolt包:

jolt.jar, jolti18n.jar, joltjse.jar, joltwls.jar

3. jolt服务配置

在tuxedo的ubb中配置jolt相关服务:

*GROUPS

“JOLTGRP” LMID=”SERVER1″ GRPNO=1

*SERVERS
JREPSVR
SRVGRP=JOLTSVR SRVID=1
CLOPT=”-A — -W -P /opt/app/tuxapp/TUX91/tuxedo9.1/udataobj/jolt/repository/jrepository”
JSL
SRVGRP=JSLGRP_1 SRVID=2
CLOPT=”-A — -n //10.6.157.43:9001″

4. tuxedo示例服务配置

在示例中实现了转大写的服务(tuxedo的经典实例)。代码如下:

/* #ident “@(#) samples/atmi/simpapp/simpserv.c $Revision: 1.5 $” */

#include <stdio.h>
#include <ctype.h>
#include <atmi.h> /* TUXEDO Header File */
#include <userlog.h> /* TUXEDO Header File */

/* tpsvrinit is executed when a server is booted, before it begins
processing requests. It is not necessary to have this function.
Also available is tpsvrdone (not used in this example), which is
called at server shutdown time.
*/

#if defined(__STDC__) || defined(__cplusplus)
tpsvrinit(int argc, char *argv[])
#else
tpsvrinit(argc, argv)
int argc;
char **argv;
#endif
{
/* Some compilers warn if argc and argv aren’t used. */
argc = argc;
argv = argv;

/* userlog writes to the central TUXEDO message log */
userlog(“Welcome to the simple server”);
return(0);
}

/* This function performs the actual service requested by the client.
Its argument is a structure containing among other things a pointer
to the data buffer, and the length of the data buffer.
*/

#ifdef __cplusplus
extern “C”
#endif
void
#if defined(__STDC__) || defined(__cplusplus)
TOUPPER(TPSVCINFO *rqst)
#else
TOUPPER(rqst)
TPSVCINFO *rqst;
#endif
{

int i;

for(i = 0; i < rqst->len-1; i++)
rqst->data[i] = toupper(rqst->data[i]);

/* Return the transformed buffer to the requestor. */
tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
}

编译: buildserver -f simpserv.o -o simpserv -s TOUPPER

配置至ubb,配置如下:

*GROUPS

“JOLTGRP” LMID=”SERVER1″ GRPNO=1
“SIMPGRP” LMID=”SERVER1″ GRPNO=2

*SERVERS

“JREPSVR”
SRVGRP=JOLTGRP SRVID=1
CLOPT=”-A — -W -P /opt/app/tuxapp/TUX91/tuxedo9.1/udataobj/jolt/repository/jrepository”
“JSL”
SRVGRP=JOLTGRP SRVID=2
CLOPT=”-A — -n //10.10.10.10:9001″
“simpserv”
SRVGRP=SIMPGRP SRVID=10
CLOPT=”-A”

在启动服务前,需要在jrepository加入服务的访问权限,不然你将会看到这样的异常:

bea.jolt.ServiceException:Service not available:TOUPPER

如下所示:add SVC/TOUPPER:vs=1:ex=1:bt=STRING:\
bp:pn=STRING:pt=string:pf=167772161:pa=rw:ep:
配置完毕后,启动tuxedo服务器。

4. 配置文件

网上有很多资料介绍如何在weblogic中配置链接jolt,在这里并为使用weblogic,只是简单实现了tuxedo的连接调用。配置内容如下:

poolname=simpapp
appaddrlist=//10.10.10.10:9001
failoverlist=//10.10.10.11:9001
minpoolsize=4
maxpoolsize=8
appaddrlist中配置的时我们要访问的tuxedo服务器中JSL配置的访问地址,failoverlist可以配置备份地址。poolname为连接池名称 .

5.访问代码:

private ServletSessionPoolManager b_mgr;

启动管理器:

try {
// Create a session pool and get the session pool manager through
// a property file.
String path = config.getServletContext().getRealPath(“/”) +
“/simpapp.properties”;
Properties prop = ServletPoolManagerConfig.load(path);
if (prop == null)
throw new ServletException(path + ” not found”);
ServletPoolManagerConfig.startup(prop);

b_mgr = ServletPoolManagerConfig.getSessionPoolManager();
}
catch (Exception e) {
throw new ServletException(e.toString());
}

调用服务:

ServletResult result;
ServletSessionPool session = (ServletSessionPool) b_mgr.getSessionPool(“simpapp”);
result = session.call(“TOUPPER”, req);
value = result.getValue(“STRING”, “”);
示例源码请参见:webtest
[img][/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值