简体   繁体   English

如何对客户端应用程序和Web应用程序都使用单个EJB

[英]How to Use single EJB for both client application and Web application

I am very new to this EJB concept. 我对这个EJB概念非常陌生。 I am assigned a task to develop an application which is a replica of netflix. 我分配了一个任务来开发一个应用程序,该应用程序是netflix的副本。 We have two modules: 我们有两个模块:

  • Owner will have a desktop application 所有者将拥有一个桌面应用程序
  • users will have web application. 用户将拥有Web应用程序。

How do I line both desktop application and web based application for single EJB? 如何为单个EJB排列桌面应用程序和基于Web的应用程序?

So you have an EJB deployed in an app server (eg Glassfish, JBoss, etc) and you want clients from a desktop (J2SE) and web (eg Tomcat) app to use this (remote, of course) EJB. 因此,您在应用服务器(例如Glassfish,JBoss等)中部署了EJB,并且希望桌面(J2SE)和Web(例如Tomcat)应用中的客户端使用该EJB(当然是远程的)。

If that's what you have, you need your clients to connect to the remote EJB using JNDI, as follows (JBoss example): 如果是这样,则需要您的客户端使用JNDI连接到远程EJB,如下所示(JBoss示例):

try {
    Context context = new InitialContext(getJNDISetup());
    MyServiceEJBRemote delegate = (MyServiceEJBRemote)context.lookup(MY_SERVICEEJB_JNDI_NAME);               
} catch (NamingException e) {
    // log exception
}

private static Hashtable<?, ?> getJNDISetup() {
    // perform jndi lookup with your favorite method, hashtable, properties file... in this case, hashtable.
    Hashtable<String, String> setup = new Hashtable<String, String>();
    setup.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
    setup.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
    setup.put("java.naming.provider.url","localhost:1099");

    return setup;

}

Depending on your app server you might need to modify the key elements defined in the HashMap. 根据您的应用服务器,您可能需要修改HashMap中定义的关键元素。

Your clients (destkop, web) will need to be aware of the EJB interface obviously. 您的客户(destkop,web)显然需要了解EJB接口。 Both the web server and the desktop module will need also the app server naming libraries. Web服务器和桌面模块都将需要应用服务器命名库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从Web应用程序使用EJB - Can't use EJB from Web Application 如何在java Web应用程序中同时使用http服务器和应用程序服务器 - How to use both http server and application server in a java web application 如何在Servlet中使用EJB 3.1 DI? (无法通过@EJB从Web应用程序注入会话Bean) - How to use EJB 3.1 DI in Servlet ? (Could not inject session bean by @EJB from web application) 如何使用was7在客户端应用程序中测试ejb - how to test an ejb in a client application using was7 如何创建使用EJB组件的客户端应用程序? - How create a client application that uses EJB Component? 用于单个应用程序的REST和SOAP Web服务 - Both REST and SOAP Web Services for a single application EJB3企业应用程序作为门户和客户端Web应用程序 - 架构/设计 - EJB3 Enterprise Application As Portal & Client Web Apps - Architecture/Design 如何从客户端应用程序调用weblogic服务器中的Clustered EJB应用程序 - How to call Clustered EJB application in weblogic server from a client application EJB远程应用程序客户端 - EJB remote application-client 需要在单个应用程序中同时使用@soapaction和@PayloadRoot - need to use both @soapaction and @PayloadRoot in single application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM