java 从远程独立客户端调用 EJB

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16408750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:52:08  来源:igfitidea点击:

calling EJB from remote standalone client

javajakarta-eejbossejb

提问by Gravian

i have a problem with connecting standalone desktop client with ejb on Jboss AS. So the question is how to remote call for EJB class from standalone client propably in java SE with swing windows ? and on the other side, is there something wrong with my concept ?

我在 Jboss AS 上使用 ejb 连接独立桌面客户端时遇到问题。所以问题是如何在带有swing windows的java SE中从独立客户端远程调用EJB类?另一方面,我的概念有什么问题吗?

img link: http://i.imgur.com/ZnmRROU.jpg

img 链接:http: //i.imgur.com/ZnmRROU.jpg

回答by Arturo Volpe

First, read this article EJB invocations from a remote client using JNDI.

首先,阅读这篇文章使用 JNDI 从远程客户端调用 EJB

  1. You need a file called 'jboss-ejb-client.properties' in your classpath, the file needs the basic config to connecto to your jboss server, for example:

    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=default remote.connection.default.host=localhost remote.connection.default.port = 4447 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

  2. Create the EJB Remote proxy

    Properties p = new Properties();
    p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    final Context context = new InitialContext(p);
    final String appName = "YOUR APP NAME";
    final String moduleName = "YOUR EJB MODULE NAME";
    final String distinctName = "DISTINCT NAME";
    final String beanName = "Your bean name";
    final String viewClassName = ClienteDAORemote.class.getName();
    String path = "ejb:" + appName + "/" + moduleName + "/"
            + distinctName + "/" + beanName + "!" + viewClassName;
    Object o = context.lookup(path);
    return (RemoteBean) o; //Cast to your remote interface
    
  1. 你的类路径中需要一个名为“jboss-ejb-client.properties”的文件,该文件需要基本配置来连接到你的 jboss 服务器,例如:

    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=default remote.connection.default.host=localhost remote.connection.default.port = 4447 remote.connection.default.connect.options。 org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

  2. 创建 EJB 远程代理

    Properties p = new Properties();
    p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    final Context context = new InitialContext(p);
    final String appName = "YOUR APP NAME";
    final String moduleName = "YOUR EJB MODULE NAME";
    final String distinctName = "DISTINCT NAME";
    final String beanName = "Your bean name";
    final String viewClassName = ClienteDAORemote.class.getName();
    String path = "ejb:" + appName + "/" + moduleName + "/"
            + distinctName + "/" + beanName + "!" + viewClassName;
    Object o = context.lookup(path);
    return (RemoteBean) o; //Cast to your remote interface
    

You need:

你需要:

  1. A EJB with a remote interface
  2. A copy of the interface in your standalone client
  3. My properties files is for local and unsecured connections.
  1. 带有远程接口的 EJB
  2. 独立客户端中的界面副本
  3. 我的属性文件用于本地和不安全的连接。

A example implementation is in this file. Its a example aplication that connects to a EJB Services, the entire repo is like your concept:

此文件中有一个示例实现。它是连接到 EJB 服务的示例应用程序,整个存储库就像您的概念:

  1. A web application with JSF + PrimeFaces
  2. A EJB Bussiness Tier
  3. JPA with hibernate
  4. A standalone client
  5. EJB Web Services
  1. 一个带有 JSF + PrimeFaces 的 Web 应用程序
  2. EJB 业务层
  3. 带休眠的 JPA
  4. 独立客户端
  5. EJB 网络服务

Sorry for my bad english, cheers.

对不起,我的英语不好,干杯。