2016-03-29 10 views
0

Ich habe ein Problem mit meinem EJBTest.JNDI Kein EJB-Empfänger für die Verarbeitung verfügbar

Ich habe WildFly installiert und Benutzerverwaltung und Anwendungsverwaltung konfiguriert.

ich eine EJB 3.0 geschrieben und entfaltet es:

@Stateless 
@Remote(NewSessionBeanRemote.class) 
public class NewSessionBean implements NewSessionBeanRemote { 

    List<String> bookShielf; 

    /** 
    * Default constructor. 
    */ 
    public NewSessionBean() { 
     bookShielf = new ArrayList<String>(); 
    } 

    @Override 
    public void addBook(String bookName) { 
     bookShielf.add(bookName); 
    } 

    @Override 
    public List getBook() { 
     return bookShielf; 
    } 
} 

Danach schrieb ich einen einfachen Client eine Verbindung dazu herzustellen:

private static void invokeStatelessBean() throws NamingException { 
    // Let's lookup the remote stateless calculator 
    NewSessionBeanRemote remoteEjb = lookupRemoteSessionBean(); 
    System.out.println("Obtained a remote stateless calculator for invocation"); 
    String bookName = "TEST book"; 
    remoteEjb.addBook(bookName); 
} 

private static NewSessionBeanRemote lookupRemoteSessionBean() throws NamingException { 

    final Hashtable jndiProperties = new Hashtable(); 
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
    jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
    jndiProperties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:10090"); 
    jndiProperties.put(Context.SECURITY_PRINCIPAL, "ejb"); //this is the application user name, not management! it's correct? 
    jndiProperties.put(Context.SECURITY_CREDENTIALS, "ejb");//this is the application password, not management! it's correct? 
    jndiProperties.put("jboss.naming.client.ejb.context", true); 
    final Context context = new InitialContext(jndiProperties); 
    final String appName = ""; 
    final String moduleName = "EjbComponent"; 
    final String distinctName = ""; 
    final String beanName = NewSessionBean.class.getSimpleName(); 
    final String viewClassName = NewSessionBeanRemote.class.getName(); 
    System.out.println("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName); 
    return (NewSessionBeanRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName); 
} 

Sowohl Benutzername und Kennwort der Anwendung Anmeldeinformationen des Benutzers sind, nicht das Management ! Ist es richtig?

Ich erhalte diese Fehlermeldung:

Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EjbComponent, distinctName:] combination for invocation context [email protected] at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128) at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186) at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183) at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146) at com.sun.proxy.$Proxy2.addBook(Unknown Source) at com.studio.java.client.EjbTester.invokeStatelessBean(EjbTester.java:34) at com.studio.java.client.EjbTester.main(EjbTester.java:21)

Ich weiß nicht, warum! Jeder hat eine Idee?

Antwort

2

Sie erhalten den genannten Fehler, weil Sie versuchen, mit dem absoluten JNDI-Namen auf eine Remote-EJB zuzugreifen.

Wie die documentation erklärt:

JNDI bindings for session bean named NewSessionBean in deployment unit deployment <your_deployment_unit> are as follows: 

    java:global[/<application_name>]/<module_name>/<ejb_name>[!<interface_name>] 
    java:app[/<module_name>]/<ejb_name>[!<interface_name>] 
    java:module/<ejb_name>[!<interface_name>] 
    java:jboss/exported[/<application_name>]/<module_name>/<ejb_name>[!<interface_name>] 
    java:global/[/<application_name>]/<module_name>/<ejb_name> 
    java:app[/<module_name>]/<ejb_name> 
    java:module/<ejb_name> 

Daher nehmen:

The http-remoting client assumes JNDI names in remote lookups are relative to java:jboss/exported namespace, a lookup of an absolute JNDI name will fail.

So, nachdem Sie Ihre Anwendung auf Wildfly bereitgestellt haben, sollten Sie so etwas wie dies auf dem Server-Konsole sehen unter Berücksichtigung der java: jboss/exportierte Kontext, sollte der richtige Weg zur Erreichung Ihrer EJB sein:

// Normally the appName is the EAR name 
// Leave it empty if your application isn't packaged in a EAR 
String appName = "your_application_name/"; 
// The EJB module name 
String moduleName = "ejb_module_name/"; 
String beanName = NewSessionBean.class.getSimpleName(); 
String viewClassName = NewSessionBeanRemote.class.getName(); 

(NewSessionBeanRemote) context.lookup(appName + moduleName + beanName + "!" + viewClassName); 

Für weitere Lektüre empfehle ich Ihnen, sich auch die Java EE JNDI Syntax sowie die WildFly's JNDI Reference anzusehen.

In Bezug auf Ihre Anmeldeinformationen sind sie nicht erforderlich, da Ihr EJB keine Authentifizierung benötigt, um darauf zugreifen zu können. Normalerweise ist das nur erforderlich, wenn Sie beispielsweise eine Anwendung haben, die eine LDAP service provider verwendet.

+0

ok! Vielen Dank Aribeiro, aber jetzt bekomme ich java.lang.ClassCastException: org.jboss.ejb.client.naming.ejb.EjbNamingContext kann nicht in com.studio.java.NewSessionBeanRemote umgewandelt werden – reve

+0

Wie machst du die Suche? – aribeiro

+0

immer die Besetzung Ausnahme :( – reve