国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Weblogic中EJB調(diào)用方法總結(jié)

1、客戶端程序中調(diào)用EJB
前提:EJB要實現(xiàn)了REMOTE接口
客戶端調(diào)用的代碼可以用EJB Test Client工具生成。自己寫就是這個樣子:
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    properties.put(Context.PROVIDER_URL, "t3://localhost:7001");

    Context context= new InitialContext(properties);
    Object ref = context.lookup("DigestSessionBean"); //通過ejb的JNDI name查找到EJBHome對象

    DigestSessionHome digestSessionHome = (DigestSessionHome) PortableRemoteObject.narrow(ref,
        DigestSessionHome.class);//得到EJBHome
    DigestSession digestSession = digestSessionHome.create();//得到EJBObject

    byte[] ret = digestSession.md5(temp.getBytes());//ejb方法調(diào)用

2、SERVLET中調(diào)用EJB
前提:被調(diào)用的EJB實現(xiàn)了REMOTE接口
在Servlet中,調(diào)用的代碼應(yīng)該是這個樣子:
    try {
      Context context = new InitialContext();
      Object ref = context.lookup("UserFacade");
      //look up jndi name and cast to Home interface
      UserFacadeHome userFacadeHome = (UserFacadeHome) PortableRemoteObject.
          narrow(ref, UserFacadeHome.class);
      UserFacade userFacade = userFacadeHome.create();
      userFacade.updateUser("002","老二");
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
跟客戶端程序中調(diào)用EJB的差別是在Context的生成上,servlet中直接用
Context context = new InitialContext();
而客戶端程序中是用
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    properties.put(Context.PROVIDER_URL, "t3://localhost:7001");

    Context context= new InitialContext(properties);

3、EJB中調(diào)用其他的EJB(同一EJB模塊)
前提:
(1)被調(diào)用者實現(xiàn)了LOCAL接口,調(diào)用者則實現(xiàn)了REMOTE接口
(2)調(diào)用者和被調(diào)用者應(yīng)該在同一EJB模塊打包文件(jar)內(nèi)
(3)調(diào)用者的部署描述(ejb-jar.xml)中有關(guān)于Local ref的描述,如下所示:
    <session>
      <display-name>UserFacade</display-name>
      <ejb-name>UserFacade</ejb-name>
      <home>ejbtest.test.UserFacadeHome</home>
      <remote>ejbtest.test.UserFacade</remote>
      <ejb-class>ejbtest.test.UserFacadeBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <ejb-local-ref>
        <ejb-ref-name>ejb/user</ejb-ref-name>
        <ejb-ref-type>Entity</ejb-ref-type>
        <local-home>ejbtest.test.UserHome</local-home>
        <local>ejbtest.test.User</local>
        <ejb-link>User</ejb-link>
      </ejb-local-ref>
    </session>
在調(diào)用者中,調(diào)用的程序代碼應(yīng)該是下面的樣子:
package ejbtest.test;

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;

import javax.ejb.*;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.rmi.RemoteException;

public class UserFacadeBean
    implements SessionBean {
  SessionContext sessionContext;
  private UserHome userHome;
  private static Context context;

  public void ejbCreate() throws CreateException {
  }

  public void ejbRemove() {
  }

  public void ejbActivate() {
  }

  public void ejbPassivate() {
  }

  public void setSessionContext(SessionContext sessionContext) {
    System.out.println("@@@@@@@@@@@@@@@@ UserFacadeBean.setSessionContext()");
    this.sessionContext = sessionContext;
    try {
      findUserHome();
    }
    catch (Exception e) {
      throw new EJBException(e.getMessage());
    }
  }

  private void findUserHome() throws Exception {
    final String ENTITY_NAME = "java:comp/env/ejb/user";

    context = new InitialContext();

    if (userHome == null) {
      try {
        Object object = context.lookup(ENTITY_NAME);
        userHome = (UserHome) object;
      }
      catch (Exception e) {
        throw new EJBException(e.getMessage());
      }
    }
  }

  public void addUser(String id, String name) throws RemoteException {
    try {
      User user = userHome.create(id);
      user.setName(name);
    }
    catch (Exception ex) {
      throw new RemoteException(ex.getMessage());
    }
  }
}

4、EJB中調(diào)用其他的EJB(不同的EJB模塊)
前提:被調(diào)用者實現(xiàn)了REMOTE接口
最簡單的方法是按客戶端程序(或者SERVLET)中調(diào)用EJB的方法。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java筆試題大匯總(二)
j2ee web service開發(fā)(五) 把ejb發(fā)布為web服務(wù) - 一切從實用出發(fā)!...
java – 從無狀態(tài)EJB訪問SessionScoped對象
weblogic使用及部署項目
開發(fā)WTC服務(wù)ejb
有關(guān)J2EE集群的文章
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服