Java通过Jolt调用Tuxedo服务-补充说明

时间:2023-01-23 12:29:15

Java通过Jolt访问Tuxedo服务-补充说明

草木瓜

2006-6-2

一、页面参数文件说明以及通过WebLogic调用Tuxedo服务

《Java通过Jolt访问Tuxedo服务》一文是在Eclipse环境下开发调用Tuxedo服务。

其中在index.asp和liwei.java中有这么几句语句:

index.asp

<form id=form1 name="form1" action=liwei method=post>
<input type="text" name="STRING" value="1">
<input type=submit value=submit>

liwei.java

//跟据传递的变量STRING值,获取返回值
out.println("返回值:"+result.getValue("STRING", ""));

这两段的STRING是不可以随便替换的,这必须与E:/bea/tuxedo9.0/udataobj/jolt/repository
下jrepository文件描述的服务参数相一致!且必须为大写!即:

add SVC/DBREAD:vs=1:ex=1:bt=STRING:/
 bp:pn=STRING:pt=string:pf=167772161:pa=rw:ep:       //这里面定义的参数就是STRING
add PKG/SIMPSERV:DBREAD:
     
下面用WebLogic对Tuxedo服务调用再详细的举例说明。

WebLogic通过jolt调用Tuxedo服务,有了上文的前提就显得很容易,说白了只是Servlet与Jsp的一点
小转换。除了最后一步在Eclipse3.1编写Servlet代码,其他的前提步骤是必须的。WebLogic要使用
Jolt接口,同样需要jolt,joltjse,joltwls三个jar包,将它们Copy到WEB-INF下的lib文件夹即可。

以下是完整的示例,参数名用大写的TEST。

index.jsp
---------------------------------

<form action="_test/testTuxedo.jsp" method="post">
<p>
<input type="text" value="1" name="TEST" id="text1"><input type="submit" value="tuxedo">
</p>
</form>

testTuxedo.jsp
---------------------------------

<body>
<p>
   
    <%
      bea.jolt.pool.servlet.ServletSessionPoolManager bool_mgr = (bea.jolt.pool.servlet.ServletSessionPoolManager) bea.jolt.pool.SessionPoolManager.poolmgr;
      bea.jolt.pool.servlet.ServletResult result;
     //获取在WebLogic服务定义好的连接池
     bea.jolt.pool.servlet.ServletSessionPool pool_session = (bea.jolt.pool.servlet.ServletSessionPool)
       bool_mgr.getSessionPool("JoltPool");
     if (pool_session == null) {
       out.println("获取Tuxedo服务失败。"+
                   "<br>"+
                   "确认Tuxedo服务已启动且配置正确。");
       out.close();
       return;
     }
     // 调用服务
     try
     {
       result = pool_session.call("DBREAD", request);
       System.out.println("OK!");
       out.println("传递的参数 = " + sendvalue);
       out.println("Tuxedo服务成功调用。 ");
       out.println("返回值:"+result.getValue("TEST", ""));
     }
     catch (bea.jolt.pool.SessionPoolException e)
     {
       // 连接池繁忙
       out.println("此时请求不能被处理。/n"+
                   "错误信息: "+e.getMessage()+"/n"+
                   "可能的原因:1.无效的连接池 2.连接池已关闭");
     }
     catch (bea.jolt.pool.ServiceException e)
     {
       // 服务出错
     e.printStackTrace();
       out.println("Error:"+
                   "Error message:"+e.getMessage()+
                   "Error number:"+e.getErrno());
     }
     catch (bea.jolt.pool.ApplicationException e)
     {
       // 应用程序出错
       result = (bea.jolt.pool.servlet.ServletResult) e.getResult();
       out.println("错误代码:"+result.getApplicationCode());
     }
     catch (Exception e)
     {
       out.println("意外错误:"+e);
     }
    
  %>
</p>
</body>


二、典型的服务应用

Oracle服务器   192.168.0.111
Tuxedo服务器   192.168.0.66
Web服务器     

通过Web客户端访问Web服务器,调用Tuxedo服务访问数据库

1.配置Tuxedo服务器的Oracle连接字符串(TNSNAME)。注意Oracle服务器的防火墙

WINDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.111)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = wincn)
    )
  )
 
2.配置Tuxedo的jrepository文件
3.配置Tuxedo的Config文件,JSR服务的IP与端口要与本地IP一致。

JSL SRVGRP=JSLGRP SRVID=301
CLOPT="-A -- -n //192.168.0.66:9988 -M 10 -x 10 -m 2"

4.配置Web服务器的WebServer,config.xml中ip与端口即为Tuxedo服务器的JSR服务IP与端口
注意Tuxedo服务器的防火墙。

<JoltConnectionPool FailoverAddresses="//192.168.0.66:9988"
    MaximumPoolSize="2" MinimumPoolSize="1" Name="JoltPool"
    PrimaryAddresses="//192.168.0.66:9988"
    SecurityContextEnabled="false" Targets="webServer"/>