在JBoss上下文中无法从客户端应用程序获取远程ejb [英] Unable to get remote ejb from client application in the context of JBoss

查看:94
本文介绍了在JBoss上下文中无法从客户端应用程序获取远程ejb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端应用

package com.jeet.client;

import java.util.Properties;


import javax.naming.Context;
import javax.naming.InitialContext; 
import javax.naming.NamingException;
import com.jeet.interfaces.HelloWorldRemoteBean;
import com.jeet.org.HelloWorldBean;

public class EJBApplicationClient {

    public static void main(String[] args) {
        HelloWorldRemoteBean bean = doLookup();
        System.out.println(bean.sayHello()); // 4. Call business logic
    }

    private static HelloWorldRemoteBean doLookup() {


        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        props.put(Context.PROVIDER_URL, "jnp://127.0.0.1:8080");


        HelloWorldRemoteBean bean = null;
        try{
        InitialContext ctx = new InitialContext(props);

        System.out.println("connecting.."); 
            String lookupName = getLookupName();

            bean = (HelloWorldRemoteBean) ctx.lookup(lookupName);
            System.out.println("done"); 
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return bean;
    }

    private static String getLookupName() {
/* 
The app name is the EAR name of the deployed EJB without .ear suffix. 
Since we haven't deployed the application as a .ear, 
the app name for us will be an empty string
*/
        String appName = "";

        /* The module name is the JAR name of the deployed EJB 
        without the .jar suffix.
        */
        String moduleName = "HelloWorldSessionBean";

/*AS7 allows each deployment to have an (optional) distinct name. 
This can be an empty string if distinct name is not specified.
*/
        String distinctName = "";

        // The EJB bean implementation class name
        String beanName = HelloWorldBean.class.getSimpleName();

        // Fully qualified remote interface name
        final String interfaceName = HelloWorldRemoteBean.class.getName();

        // Create a look up string name
        String name = "ejb:" + appName + "/" + moduleName + "/" + 
            distinctName    + "/" + beanName + "!" + interfaceName;

        return name;
    }
}

输出:正在连接..

我没有得到任何输出... JBOSS服务器正在运行,并且已经部署了EJB. 导入了Jbossall-client jar. 我刚接触EJB ...需要帮助吗? 配置也没有问题...

I am not getting any ouput... JBOSS server is running and EJB is already deployed.. Jbossall-client jar is imported.. I am new to EJB...need help? There is no problem with the configuration either...

野生蝇日志

04:20:56,353 INFO  [org.jboss.modules] (main) JBoss Modules version 1.3.3.Final
04:20:56,648 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.2.Final
04:20:56,761 INFO  [org.jboss.as] (MSC service thread 1-2) JBAS015899: WildFly 8.2.1.Final "Tweek" starting
04:20:58,794 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found HelloWorldSessionBean.jar in deployment directory. To trigger deployment create a file called HelloWorldSessionBean.jar.dodeploy
04:20:58,795 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found EjbComponent.jar in deployment directory. To trigger deployment create a file called EjbComponent.jar.dodeploy
04:20:58,828 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
04:20:59,041 INFO  [org.xnio] (MSC service thread 1-1) XNIO version 3.3.0.Final
04:20:59,051 INFO  [org.xnio.nio] (MSC service thread 1-1) XNIO NIO Implementation Version 3.3.0.Final
04:20:59,244 INFO  [org.jboss.remoting] (MSC service thread 1-1) JBoss Remoting version 4.0.7.Final
04:20:59,319 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 32) JBAS010280: Activating Infinispan subsystem.
04:20:59,552 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
04:20:59,604 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017502: Undertow 1.1.8.Final starting
04:20:59,617 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 45) JBAS013171: Activating Security Subsystem
04:20:59,703 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 31) WFLYIO001: Worker 'default' has auto-configured to 4 core threads with 32 task threads based on your 2 available processors
04:20:59,740 INFO  [org.jboss.as.connector.logging] (MSC service thread 1-2) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.9.Final)
04:20:59,745 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017502: Undertow 1.1.8.Final starting
04:20:59,746 INFO  [org.jboss.as.security] (MSC service thread 1-2) JBAS013170: Current PicketBox version=4.0.21.Final
04:20:59,761 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) JBAS010417: Started Driver service with driver-name = h2
04:20:59,790 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017527: Creating file handler for path C:\Jboss8.2.1\wildfly-8.2.1.Final/welcome-content
04:20:59,851 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017525: Started server default-server.
04:20:59,854 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017531: Host default-host starting
04:20:59,861 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 38) JBAS012615: Activated the following JSF Implementations: [main]
04:20:59,900 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 40) JBAS011800: Activating Naming Subsystem
04:20:59,946 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 46) JBAS010153: Node identifier property is set to the default value. Please make sure it is unique.
04:21:00,030 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
04:21:00,462 INFO  [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service
04:21:00,471 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-2) JBAS015400: Bound mail session [java:jboss/mail/Default]
04:21:00,502 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-3) JBAS015012: Started FileSystemDeploymentService for directory C:\Jboss8.2.1\wildfly-8.2.1.Final\standalone\deployments
04:21:00,502 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "EjbComponent.jar" (runtime-name: "EjbComponent.jar")
04:21:00,506 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "HelloWorldSessionBean.jar" (runtime-name: "HelloWorldSessionBean.jar")
04:21:00,856 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) JBAS016002: Processing weld deployment EjbComponent.jar
04:21:00,901 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017519: Undertow HTTP listener default listening on localhost/127.0.0.1:8080
04:21:00,909 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016002: Processing weld deployment HelloWorldSessionBean.jar
04:21:01,301 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-4) HV000001: Hibernate Validator 5.1.3.Final
04:21:01,774 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named HelloWorldBean in deployment unit deployment "HelloWorldSessionBean.jar" are as follows:

    java:global/HelloWorldSessionBean/HelloWorldBean!com.jeet.org.HelloWorldBean
    java:app/HelloWorldSessionBean/HelloWorldBean!com.jeet.org.HelloWorldBean
    java:module/HelloWorldBean!com.jeet.org.HelloWorldBean
    java:global/HelloWorldSessionBean/HelloWorldBean!com.jeet.interfaces.HelloWorldRemoteBean
    java:app/HelloWorldSessionBean/HelloWorldBean!com.jeet.interfaces.HelloWorldRemoteBean
    java:module/HelloWorldBean!com.jeet.interfaces.HelloWorldRemoteBean
    java:jboss/exported/HelloWorldSessionBean/HelloWorldBean!com.jeet.interfaces.HelloWorldRemoteBean

04:21:01,850 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named LibrarySessionBean in deployment unit deployment "EjbComponent.jar" are as follows:

    java:global/EjbComponent/LibrarySessionBean!com.jeet.org.LibrarySessionBeanRemote
    java:app/EjbComponent/LibrarySessionBean!com.jeet.org.LibrarySessionBeanRemote
    java:module/LibrarySessionBean!com.jeet.org.LibrarySessionBeanRemote
    java:jboss/exported/EjbComponent/LibrarySessionBean!com.jeet.org.LibrarySessionBeanRemote
    java:global/EjbComponent/LibrarySessionBean
    java:app/EjbComponent/LibrarySessionBean
    java:module/LibrarySessionBean

04:21:01,907 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
04:21:02,100 INFO  [org.jboss.ws.common.management] (MSC service thread 1-2) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.3.2.Final
04:21:02,217 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016005: Starting Services for CDI deployment: EjbComponent.jar
04:21:02,255 INFO  [org.jboss.weld.Version] (MSC service thread 1-2) WELD-000900: 2.2.6 (Final)
04:21:02,326 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016008: Starting weld service for deployment EjbComponent.jar
04:21:02,397 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016005: Starting Services for CDI deployment: HelloWorldSessionBean.jar
04:21:02,474 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) JBAS016008: Starting weld service for deployment HelloWorldSessionBean.jar
04:21:03,859 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "HelloWorldSessionBean.jar" (runtime-name : "HelloWorldSessionBean.jar")
04:21:03,859 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "EjbComponent.jar" (runtime-name : "EjbComponent.jar")
04:21:04,017 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
04:21:04,019 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
04:21:04,019 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.2.1.Final "Tweek" started in 8101ms - Started 330 of 390 services (98 services are lazy, passive or on-demand)

推荐答案

对于远程EJB,您需要:

For Remote EJB you need:

  1. ejb-client.jar 添加到您的客户端应用程序,而不是 ejb.jar . ejb-client.jar 可容纳所有接口-远程和本地

  1. Add ejb-client.jar to you client application not ejb.jar. ejb-client.jar contient all interfaces — Remote and Local

使用以下属性配置InitialContext:

java.naming.factory.initial = org.jnp.interfaces.NamingContextFactory
java.naming.provider.url    = jnp://host:port/[jndi_path] ( in your case jnp://localhost:1099/ 1099 is the port default but you can modify it in jboss config)
java.naming.factory.url.pkgs = org.jboss.naming:org.jnp.interfaces
jboss.naming.client.ejb.context = true

可选:

java.naming.security.principal=user
java.naming.security.credentials=password

我建议您使用文件属性来获取所有JNDI远程和本地文件,以及另一个用于查找的文件.示例:您需要与您的应用程序共享一个配置文件夹,然后创建4个文件:

I advise you to use file properties to get all JNDI remote and local and another file for lookup. Example: you need to have a configuration folder shared with your application, you create 4 files:

  • jndi_local.properties
  • jndi_remote.properties
  • lookup_local.properties
  • lookup_remote.properties
  • jndi_local.properties
  • jndi_remote.properties
  • lookup_local.properties
  • lookup_remote.properties

此类文件的示例:

java.naming.factory.url.pkgs = org.jboss.naming:org.jnp.interfaces

jndi_Remote.properties

java.naming.factory.initial = org.jnp.interfaces.NamingContextFactory
java.naming.provider.url    = jnp://localhost:1099/
java.naming.factory.url.pkgs = org.jboss.naming:org.jnp.interfaces
jboss.naming.client.ejb.context = true

#optional:
#java.naming.security.principal=user
#java.naming.security.credentials=password

lookup_local.properties

interfaceFacadeLocal(with notation @local) extend interfaceFacade where interfaceFacade with not notation local or remote)
interfaceFacade=java:global/aplicationName/nameejbjar/FacadeBean!org.client.me.ejb.facade.local.interfaceFacadeLocal

lookup_remote.properties

interfaceServiceFacade=ejb/aplicationName/ejb-client.jar/ServiceBean#org.server.me.ejb.ServiceRemoteBean

有关为客户端EJB配置上下文的更多信息,请参见这里.

For more information to configure context for client EJB see here.

这篇关于在JBoss上下文中无法从客户端应用程序获取远程ejb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆