WTC配置(二)

3 EJB程序开发

3.1编写WeblogicEJB.java

package org.flying.ejb;

 

import javax.ejb.CreateException;

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;

 

import weblogic.wtc.jatmi.TPException;

import weblogic.wtc.jatmi.TypedString;

import weblogic.wtc.jatmi.Reply;

import weblogic.wtc.jatmi.TPServiceInformation;

 

public class WeblogicEjb implements SessionBean {

       private static final long serialVersionUID = 1L;

       static final boolean VERBOSE = true;

       private SessionContext ctx;

       /**

        * Sets the session context.

        * @param ctx

        *            SessionContext Context for session

        */

       public void setSessionContext(SessionContext ctx) {

              this.ctx = ctx;

       }

       /**

        * This method is required by the EJB Specification, but is not used by this

        * example.

        *

        */

       public void ejbActivate() {

       }

       /**

        * This method is required by the EJB Specification, but is not used by this

        * example.

        *

        */

       public void ejbPassivate() {

       }

       /**

        * This method is required by the EJB Specification, but is not used by this

        * example.

        *

        */

       public void ejbRemove() {

       }

       public void ejbCreate() throws CreateException {

       }

       public Reply service(TPServiceInformation mydata) throws TPException {

              TypedString data;

              String lowered;

              TypedString return_data;

              data = (TypedString) mydata.getServiceData();

              log("converting " + data);

              lowered = data.toString().toLowerCase();

              log("converted " + data);

              return_data = new TypedString(lowered);

              mydata.setReplyBuffer(return_data);

              return (mydata);

       }

       private void log(String s) {

              if (VERBOSE) {

                     System.out.println(s);

              }

       }

}

EJBHomeRomote接口不用写,稍后处理。

3.2配置ejb-jar.xml

<?xml version="1.0" encoding="GBK"?>

<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"

       version="2.1">

       <enterprise-beans>

              <session>

                     <ejb-name>TOLOWEREJB</ejb-name>

                     <home>weblogic.wtc.jatmi.TuxedoServiceHome</home>

                     <remote>weblogic.wtc.jatmi.TuxedoService</remote>

                     <ejb-class>org.flying.ejb.WeblogicEjb</ejb-class>

                     <session-type>Stateless</session-type>

                     <transaction-type>Container</transaction-type>

              </session>

       </enterprise-beans>

       <assembly-descriptor>

              <container-transaction>

                     <method>

                            <ejb-name>TOLOWEREJB</ejb-name>

                            <method-name>*</method-name>

                     </method>

                     <trans-attribute>Supports</trans-attribute>

              </container-transaction>

       </assembly-descriptor>

</ejb-jar>

重要:配置中<home/><remote/>被配置为weblogic.wtc.jatmi.TuxedoServiceHomeweblogic.wtc.jatmi.TuxedoService,这是WTC配置的要求,是他们tuxedo ejb服务的统一入口,所以开发中不用写homeromote接口。

3.3配置weblogic-ejb-jar.xml

<?xml version="1.0" ?>

<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90"

       xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">

       <weblogic-enterprise-bean>

              <ejb-name>TOLOWEREJB</ejb-name>

              <stateless-session-descriptor>

                     <pool>

                            <max-beans-in-free-pool>100</max-beans-in-free-pool>

                            <initial-beans-in-free-pool>5</initial-beans-in-free-pool>

                     </pool>

              </stateless-session-descriptor>

              <transaction-descriptor>

                     <trans-timeout-seconds>0</trans-timeout-seconds>

              </transaction-descriptor>

              <enable-call-by-reference>true</enable-call-by-reference>

              <jndi-name>TOLOWER</jndi-name>

       </weblogic-enterprise-bean>

</weblogic-ejb-jar>

3.4 EJB程序打包成JAR

使用MyEclipse中的项目导出(Export)功能,将java文件导出成JAR文件EJB.jar。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值