2013-01-15 11 views
6

Nach einiger Zeit habe ich den Fernzugriff auf einen zustandslosen EJB-Lauf unter JBoss 7.1.1 gemacht. mit Eigenschaften Objekt:JBoss 7: JNDI lookup

Properties jndiProps = new Properties(); 
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, 
    "org.jboss.naming.remote.client.InitialContextFactory"); 
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447"); 
jndiProps.put(Context.SECURITY_PRINCIPAL, "remote"); 
jndiProps.put(Context.SECURITY_CREDENTIALS, "remotepwd"); 
jndiProps.put("jboss.naming.client.ejb.context", true); 
Context ctx = new InitialContext(jndiProps); 

String lookupString = "//HelloWorld/HelloWorldBean!org.acme.test.HelloWorld"; 
HelloWorld hw = (HelloWorld) ctx.lookup(lookupString); 
System.out.println("Response: "+ hw.sayHello("Hi there")); 

So das funktioniert gut aber jetzt will ich die JNDI Sache in jndi.properties Datei setze aber nicht, das ist, wie die Datei wie folgt aussieht:

java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory 
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming 
java.naming.provider.url=remote://localhost:4447 
java.naming.security.principal=remote 
java.naming.security.credentials=remotepwd 

Die ausnahme:

Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorld,distinctname:] combination for invocation context [email protected] 
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584) 
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119) 
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181) 
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136) 
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121) 
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104) 
at $Proxy0.sayHello(Unknown Source) 
at de.brockhaus.test.client.TestClient.main(TestClient.java:35) 

ich bin schon durch mehrere doco gegangen aber gescheitert, also wie muss es dann aussehen?

Antwort

7

OK, so fand ich die Antwort mich ...

Zuerst müssen Sie zwei Eigenschaften Dateien, jndi.properties und jboss-ejb-client.properties haben.

jndi.properties:

# 
# jndi.properties 
# 
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory 
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming 
java.naming.provider.url=remote://localhost:4447 
java.naming.security.principal=remote 
java.naming.security.credentials=remotepwd 

jboss-ejb-client.properties:

# 
# jboss-ejb-client.properties 
# 
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 

beide auf dem Classpath Mit dem Code läuft wie ein Zauber machen, auch ohne die Eigenschaften zu spezifizieren innerhalb des Codes.

Noch verwirrender ist die Konstruktion des Lookup-String ...

+0

Für den Bau von Lookup-String, können Sie hier Referenz: https://docs.jboss.org/author/display/AS72/Remote+EJB+ Aufrufe + via + JNDI + - + EJB + Client + API + oder + Remote-Benennung + Projekt. Beim Start von jboss server, für Remote-Link, ist die Suchzeichenfolge normalerweise direkt nach "java: jboss/exportierte /" – dellgg