java jolt tuxedo_Java中使用Jolt访问Tuxedo服务 – Tomcat环境部署测试
Java中使用Jolt訪問Tuxedo服務(wù) – Tomcat環(huán)境部署測試
Java中使用Jolt訪問Tuxedo服務(wù) – Tomcat環(huán)境部署測試
最近在學(xué)習(xí)基于Tuxedo的系統(tǒng)架構(gòu),網(wǎng)上討論最多的,比較流行的3層架構(gòu)是基于Weglogic+Tuxedo+DB的模式,關(guān)于這類模式的文章也比較多,可以參見鏈接:
http://blog.csdn.net/liwei_cmg/article/details/769150
一般來說,Java可用使用3種聯(lián)機(jī)方式訪問Tuxedo的服務(wù):
1.WTC????????? 用于Weblogic與Tuxedo的互訪,可以實(shí)現(xiàn)雙向的調(diào)用。
2.JOLT????????? 用于Tomcat, Weblogic, Websphere 和其他應(yīng)用服務(wù)器訪問Tuxedo,為單向調(diào)用。
3.CORBA??????? (網(wǎng)上有介紹,自己沒實(shí)踐過)
作為學(xué)習(xí)了解Java如何通過Jolt調(diào)用Tuxedo服務(wù),以及如何使用Jolt的鏈接池技術(shù),本文沒有使用Weblogic作為應(yīng)用服務(wù)器,而是直接在Tomcat應(yīng)用服務(wù)器中配置部署了Html+ Servlet來調(diào)用Tuxedo的服務(wù)。
實(shí)現(xiàn)環(huán)境:
服務(wù)端:?????? GUN/Linux 2.6.32?? +Tuxedo 11gR1
應(yīng)用服務(wù)器:?? Apache-tomcat-6.0.29 for Windows
開發(fā)工具:???? Myeclipse 8.5
實(shí)現(xiàn)步驟如下:
1)準(zhǔn)備Tuxedo服務(wù)程序
2)修改配置ubbconfig
3)修改Jolt訪問服務(wù)的jrepository文件
4)啟動Tuxedo服務(wù)
5)創(chuàng)建Web project
6)準(zhǔn)備Servlet 和 html程序
7)準(zhǔn)備Jolt 連接池配置文件
8)配置web.xml文件
9)部署Web項(xiàng)目simpapp
10)Linux服務(wù)器防火墻設(shè)置
1. 準(zhǔn)備Tuxedo服務(wù)程序
這里我們還是用examples中的simpserv.c程序,以及TOUPPER服務(wù),比較容易。
//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);
}
編譯服務(wù)程序,
buildserver -f simpserv.c -o simpserv -s TOUPPER
2.修改配置ubbconfig, 加入如下的組和服務(wù)
*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的監(jiān)聽服務(wù),
//192.168.1.100:8850為Tuxedo服務(wù)器的地址和端口,在Java客戶端要用。
(注意:Jolt不通過WSL來訪問Tuxedo服務(wù)。)
編譯ubbconfig配置文件,
tmloadcf –y ubbconfig
3.修改Jolt訪問服務(wù)的jrepository文件,加入TOUPPER服務(wù)的定義如下(也可以采用RE.html配置):
add SVC/TOUPPER:vs=1:ex=1:bt=STRING:\
bp:pn=STRING:pt=string:pf=167772161:pa=rw:ep:
4.啟動Tuxedo服務(wù)
服務(wù)端配置完畢。
5. 在Myeclipse下創(chuàng)建Web project,項(xiàng)目名為simpapp,位于 d:\worksapce\simpapp
創(chuàng)建新的 src包,? my.jolt.servlet,位于d:\worksapce\simpapp\src
6.準(zhǔn)備Servlet 和 html程序
程序來自Tuxedo的examples,調(diào)試的時候進(jìn)行了修改。
網(wǎng)頁程序 simp.html,? d:\worksapce\simpapp\WebRoot\simp.html
Jolt SimpApp ExampleJolt 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
原程序中一行如下,調(diào)試的時候報錯,刪掉了。
錯誤如下:
嚴(yán)重: 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("
總結(jié)
以上是生活随笔為你收集整理的java jolt tuxedo_Java中使用Jolt访问Tuxedo服务 – Tomcat环境部署测试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 诺基亚6303c
- 下一篇: ISO20000认证流程是什么,ISO2