配置/开发示例在网上一搜n多,但中文原创的真不多,原创还又能用来参照配置/开发并取得成功的就更少了。关键时候,Oracle网站oracle sample code上关于WTC的示例还不能下载,坑爹啊。折腾了两天多,总算搞定了,希望也能写明白。
环境:Tuxedo8.0 + WebLogic10.3.4
目标:Tuxedo客户端访问WebLogic端的EJB服务:TOLOWER
1、Tuxedo端配置+开发:
Tuxedo客户端的开发很普通,配置也不难,UBB就不多写了,具体的Domain配置文件如下:
*DM_RESOURCES
VERSION=U22
*DM_LOCAL_DOMAINS
TDOM1 GWGRP=LGWGRP01
TYPE=TDOMAIN
DOMAINID="TDOM1"
BLOCKTIME=20
MAXDATALEN=56
MAXRDOM=89
DMTLOGDEV="E:\NOTE\TUXEDO\TEST\TIMEOUTS\DLOG"
AUDITLOG="E:\NOTE\TUXEDO\TEST\TIMEOUTS\AUDITLOG"
*DM_REMOTE_DOMAINS
TDOM2 TYPE=TDOMAIN
DOMAINID="TDOM2"
*DM_TDOMAIN
TDOM1 NWADDR="//127.0.0.1:9998"
TDOM2 NWADDR="//127.0.0.1:9999"
*DM_REMOTE_SERVICES
TOLOWER RDOM="TDOM2"
*DM_LOCAL_SERVICES
TOUPPER RNAME="TOUPPER"
其中TDOM1为Tuxedo端的域,TDOM2为WebLogic端的域,该域配置文件引入WebLogic远端的TOLOWER服务。客户端程序简要示例如下:
Int main(int argc, char *argv[])
… …
snd_buf = (char *)tpalloc("STRING", NULL, 16);
… …
rcv_buf = (char *)tpalloc("STRING", NULL, 16);
… …
(void)strcpy(snd_buf, argv[1]);
ret_value = tpcall("TOLOWER", snd_buf, 0, &rcv_buf, &rcv_len, TPSIGRSTRT);
if (ret_value == -1) {
… …
print_err(stderr, err_str);
exit_value = 1;
}
else {
(void)sprintf(err_str, "Result of TOLOWER request is: %s", rcv_buf);
print_err(stdout, err_str);
}
… …
2、WebLogic端配置+开发:
EJB代码示例如下:
package com.ejb;
import javax.ejb.Stateless;
import weblogic.wtc.jatmi.TPException;
import weblogic.wtc.jatmi.TypedString;
import weblogic.wtc.jatmi.Reply;
import weblogic.wtc.jatmi.TPServiceInformation;
@Stateless(mappedName = "TOLOWER")
public class LowerBean implements LowerBeanRemote {
public LowerBean() {
// TODO Auto-generated constructor stub
}
public Reply service(TPServiceInformation mydata) throws TPException {
TypedString data = (TypedString) mydata.getServiceData();
String lowered = data.toString().toLowerCase();
System.out.println("-----");
System.out.println(lowered);
TypedString return_data = new TypedString(lowered);
mydata.setReplyBuffer(return_data);
return (mydata);
}
EJB Remote Home代码:
package com.ejb;
import javax.ejb.Remote;
@Remote
public interface LowerBeanRemote {
public String convert(String strToConv);
ejb-jar.xml文件示例如下,注意EJB类/EJB名称的对应
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0">
<display-name>MiscTestEJB</display-name>
<enterprise-beans>
<session>
<ejb-name>TOLOWER</ejb-name>
<mapped-name>TOLOWER</mapped-name>
<home>weblogic.wtc.jatmi.TuxedoServiceHome</home>
<remote>weblogic.wtc.jatmi.TuxedoService</remote>
<ejb-class>com.ejb.LowerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>TOLOWER</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Supports</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
weblogic-ejb-jar.xml文件如下,注意EJB名称/JNDI名称对应:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-ejb-jar
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.2/weblogic-ejb-jar.xsd">
<wls:weblogic-enterprise-bean>
<wls:ejb-name>TOLOWER</wls:ejb-name>
<wls:jndi-name>tuxedo.services.TOLOWERHome</wls:jndi-name>
</wls:weblogic-enterprise-bean>
</wls:weblogic-ejb-jar>
上述EJB在WebLogic上部署后,调整WebLogic日志级别为Info,即可从服务日志中看到EJB的JNDI绑定关系:
<BEA-014021> <The EJB 'TOLOWER(Application: MiscTestEE, EJBComponent: MiscTestEJB.jar)' has been successfully deployed. The following remote interfaces have been bound into JNDI with the specified JNDI names:>
<BEA-014022> <******** com.ejb.LowerBeanRemote is bound with JNDI name:TOLOWER#com.ejb.LowerBeanRemote ********>
<BEA-010009> <EJB Deployed EJB with JNDI name tuxedo.services.TOLOWERHome.>
好了,最后在WebLogic上配置WTC服务,这里只列出了WTC服务配置后,配置文件config.xml中相关的部分,注意WTC export服务的resource-name/ejb-name/remote-name的对应关系:
<wtc-server>
<name>MyWTCServer</name>
<target>ManagedServer1</target>
<wtc-local-tux-dom>
<name>TDOM2</name>
<access-point>TDOM2</access-point>
<access-point-id>TDOM2</access-point-id>
<nw-addr>//127.0.0.1:9999</nw-addr>
</wtc-local-tux-dom>
<wtc-remote-tux-dom>
<name>TDOM1</name>
<access-point>TDOM1</access-point>
<access-point-id>TDOM1</access-point-id>
<local-access-point>TDOM2</local-access-point>
<nw-addr>//127.0.0.1:9998</nw-addr>
<federation-url></federation-url>
<federation-name></federation-name>
</wtc-remote-tux-dom>
<wtc-export>
<name>WTCExportedService-0</name>
<resource-name>TOLOWER</resource-name>
<local-access-point>TDOM2</local-access-point>
<ejb-name>tuxedo.services.TOLOWERHome</ejb-name>
<remote-name>TOLOWER</remote-name>
</wtc-export>
<wtc-import>
<name>WTCImportedService-0</name>
<resource-name>TOUPPER</resource-name>
<local-access-point>TDOM2</local-access-point>
<remote-access-point-list>TDOM1</remote-access-point-list>
<remote-name></remote-name>
</wtc-import>
</wtc-server>
注意还要在WebLogic上定义TDOM1用户,具体步骤参见:,我仅列出了定义用户步骤如下(省去翻译了):
Use the following steps to register TDOM1 as an Oracle WebLogic Server user:
1. Click Security Realms in the navigation tree.
2. Click myRealm.
3. Click on Users and Groups tab.
4. Click Users.
5. Click Lock & Edit.
6. Click New.
7. In the Create a New User page, do the following:
1. Add TDOM1 in the Name field.
2. Enter and confirm a password.
3. Click OK.
8. Click Release Configuration.
可以在启动WebLogic服务的脚本里添加OPTION以便调试,如下:
set JAVA_OPTIONS=-Dweblogic.debug.DebugWTCUData=true -Dweblogic.wtc.TraceLevel=100000 %JAVA_OPTIONS%
好了,到这里基本大工告成了,动手试试吧,祝好运!
--转自