当前位置:   article > 正文

java jolt tuxedo_Java中使用Jolt访问Tuxedo服务 – Tomcat环境部署测试

jolt连接tuxedo

Java中使用Jolt访问Tuxedo服务 – Tomcat环境部署测试

Java中使用Jolt访问Tuxedo服务 – Tomcat环境部署测试

最近在学习基于Tuxedo的系统架构,网上讨论最多的,比较流行的3层架构是基于Weglogic+Tuxedo+DB的模式,关于这类模式的文章也比较多,可以参见链接:

http://blog.csdn.net/liwei_cmg/article/details/769150

一般来说,Java可用使用3种联机方式访问Tuxedo的服务:

1.WTC          用于Weblogic与Tuxedo的互访,可以实现双向的调用。

2.JOLT          用于Tomcat, Weblogic, Websphere 和其他应用服务器访问Tuxedo,为单向调用。

3.CORBA        (网上有介绍,自己没实践过)

作为学习了解Java如何通过Jolt调用Tuxedo服务,以及如何使用Jolt的链接池技术,本文没有使用Weblogic作为应用服务器,而是直接在Tomcat应用服务器中配置部署了Html+ Servlet来调用Tuxedo的服务。

实现环境:

服务端:       GUN/Linux 2.6.32   +Tuxedo 11gR1

应用服务器:   Apache-tomcat-6.0.29 for Windows

开发工具:     Myeclipse 8.5

实现步骤如下:

1)准备Tuxedo服务程序

2)修改配置ubbconfig

3)修改Jolt访问服务的jrepository文件

4)启动Tuxedo服务

5)创建Web project

6)准备Servlet 和 html程序

7)准备Jolt 连接池配置文件

8)配置web.xml文件

9)部署Web项目simpapp

10)Linux服务器防火墙设置

1. 准备Tuxedo服务程序

这里我们还是用examples中的simpserv.c程序,以及TOUPPER服务,比较容易。

//simpserv.c

#include

#include

#include     /* TUXEDO Header File */

#include /* TUXEDO Header File */

#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 2");

return(0);

}

#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.c -o simpserv -s TOUPPER

2.修改配置ubbconfig, 加入如下的组和服务

*GROUPS

JSLGRP          LMID=simpapp1   GRPNO=101

JREPGRP         LMID=simpapp1   GRPNO=102

*SERVERS

JSL             SRVGRP=JSLGRP SRVID=1

CLOPT="-A -- -n //192.168.1.100:8850 -m 5 -M 5 -x 10"

JREPSVR         SRVGRP=JREPGRP SRVID=1

CLOPT="-A -- -W –P /home/tuxedo/udataobj/jolt/repository/jrepository"

JSL 为Java通过Jolt访问Tuxedo的监听服务,

//192.168.1.100:8850为Tuxedo服务器的地址和端口,在Java客户端要用。

(注意:Jolt不通过WSL来访问Tuxedo服务。)

编译ubbconfig配置文件,

tmloadcf –y ubbconfig

3.修改Jolt访问服务的jrepository文件,加入TOUPPER服务的定义如下(也可以采用RE.html配置):

add SVC/TOUPPER:vs=1:ex=1:bt=STRING:\

bp:pn=STRING:pt=string:pf=167772161:pa=rw:ep:

4.启动Tuxedo服务

服务端配置完毕。

5. 在Myeclipse下创建Web project,项目名为simpapp,位于 d:\worksapce\simpapp

创建新的 src包,  my.jolt.servlet,位于d:\worksapce\simpapp\src

6.准备Servlet 和 html程序

程序来自Tuxedo的examples,调试的时候进行了修改。

网页程序 simp.html,  d:\worksapce\simpapp\WebRoot\simp.html

Jolt SimpApp Example

Jolt SimpApp Example

This examples demonstrates how a Java HTTP Servlet running in the

Weblogic Server services a POST request from a

<FORM> in

this HTML file. The simpapp

servlet invokes a service on the BEA TUXEDO Server that converts the

text you enter here into uppercase. The result is posted back inside

a servlet-generated html file.

Type some text here and click the Post button:

Click here for session pools statistics

原程序中一行如下,调试的时候报错,删掉了。

错误如下:

严重: Servlet.service() for servlet SimpAppServlet threw exception

java.lang.NoSuchFieldError: SVCNAME

Servlet程序,SimpAppServlet.java,位于  d:\worksapce\simpapp\src\my\jolt\servlet

package my.jolt.servlet;

import bea.jolt.pool.servlet.*;

import bea.jolt.pool.ApplicationException;

import bea.jolt.pool.SessionPoolException;

import bea.jolt.pool.ServiceException;

import java.util.Properties;

import java.util.Hashtable;

import java.io.IOException;

import javax.servlet.*;

import javax.servlet.http.*;

/**

* This example demonstrates how a Servlet may connect to Tuxedo

* and call upon one of its services; it should be invoked from the

* simpapp.html file. The servlet creates a session pool

* manager at initialization, which is used to obtain a session when the

* doPost() method is invoked. This session is used to connect to a service

* in Tuxedo with a name described by the posted "SVCNAME" argument. In this

* example the service is called "TOUPPER", which transposes the posted

* "STRING" argument text into uppercase, and returns the result. This is

* returned to the client browser within some generated HTML.

* THIS IS SOURCE CODE PUBLISHED FOR DEMONSTRATION PURPOSES

*

* @author Copyright (c) 1999 BEA Systems, Inc.  All rights reserved.

*/

public class SimpAppServlet extends HttpServlet {

/**

* Private variable to hold the pool manager object.

*/

private ServletSessionPoolManager b_mgr;

/**

* Initializes the servlet.  The session pool manager and the

* simpapp session pool is established here.  The properties of

* the session pool is specified through an external property

* file whose path comes from the servlet initial parameter "properties".

*

* @param config            Servlet configuration

* @exception               ServletException if the servlet fails

*/

public void init(ServletConfig config) throws ServletException {

super.init(config);

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());

}

}

/**

* Destroys this servlet. The ServletSessionPoolManager

* resource is deallocated.

*/

public void destroy() {

b_mgr = null;

}

/**

* Implements the HttpServlet doPost() method.

* This method expects POSTed arguments for:

*

*

"SVCNAME"The name of the service to be invoked in Tuxedo.

*

"STRING"The text to be transposed to uppercase.

*

*

*

See the provided simpapp.html for the HTML form

* used to submit the data.

*/

public void doPost(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException

{

ServletResult result;

ServletOutputStream out = resp.getOutputStream();

out.println("

Jolt SimpApp Example Response");

out.println("

" +

"

" +

"This is the response from the SimpAppServlet:" +

"

");

// Get the "simpapp" session pool

ServletSessionPool session = (ServletSessionPool)

b_mgr.getSessionPool("simpapp");

if (session == null) {

out.println("The servlet failed to obtain a SessionPool for simpapp. "+

"
"+

"Possibly the Tuxedo server is not running, "+

"or there is a configuration problem."+

"

");

out.close();

return;

}

//String svcnm[] = req.getParameterValues("SVCNAME");

// Invoke a service and get the result.  Process the

// template with input and result if there is no error.

try {

//result = session.call(svcnm[0], req);

Result = session.call("TOUPPER");

// No error; present the result page.

out.println("The simpapp sevice was successfully called, and "+

"responded with the output string: ");

out.println("

"+

result.getValue("STRING", "")+

"


");

}

catch (SessionPoolException e) {

// All sessions are busy.

out.println("Your request cannot be completed at this moment.\n"+

"

Diagnostic Message is: "+e.getMessage()+"

\n"+

"Possible reasons:

  • \n"+

"

No sessions are available\n"+

"

The session pool is suspended\n"+

"

The session pool is shutdown\n"+

"

Please resubmit your request later.");

}

catch (ServiceException e) {

// There is a Service Exception.

out.println("

Service exception

"

Error message:"+e.getMessage()+

"

Error number:"+e.getErrno()+

"

");

}

catch (ApplicationException e) {

// There is an application error.

result = (ServletResult) e.getResult();

out.println("

Application error

\n"+

"

Application code is "+result.getApplicationCode());

}

catch (Exception e) {

out.println("

Unexpected exception

"+

"

Exception is "+

"");

}

out.println("

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/461020
推荐阅读
相关标签
  

闽ICP备14008679号