error when getting a remote EJB stateless session Bean (EJB)
flamant Sep 24, 2014 11:49 AMHello,
I work in java and use JBOSS eap 6.2
I have an EJB client and try to use a remote stateless EJB session that I get with a context (with an object Properties (see the code below).) In debug mode, when I do a lookup on my context to get my remote stateless EJB (in blue), it seems to work. But when I try to use a method of that remote bean (red line), I get the following error
[CODE]
EJBCLIENT000025: No EJB receiver available for handling [appName:EJBTutorial, moduleName:EJBTutorialEJB, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@56811df
[/CODE]
Have you an idea?
[CODE]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.tutorialspoint.sessionbean.stateless.LibrarySessionBeanRemote;
public class Main {
BufferedReader brConsoleReader = null;
Properties jndiProperties = new Properties();
Context ctx = null;
public void initializeContextAndConsoleReader() {
// Context.URL_PKG_PREFIXES = "java.naming.factory.url.pkgs"
jndiProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
// Context.INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial"
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
// Context.PROVIDER_URL = "java.naming.provider.url"
jndiProperties.put(Context.PROVIDER_URL, "remote://localhost:4447");
jndiProperties.put("jboss.naming.client.ejb.context", true);
try {
ctx = new InitialContext(jndiProperties);
} catch (NamingException ex) {
ex.printStackTrace();
}
brConsoleReader = new BufferedReader(new InputStreamReader(System.in));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Main ejbTester = new Main();
ejbTester.initializeContextAndConsoleReader();
ejbTester.testStatelessEjb();
}
public Context getContext() throws NamingException {
return new InitialContext(jndiProperties);
}
/*
* (non-Java-doc)
*
* @see java.lang.Object#Object()
*/
public Main() {
super();
}
private void showGUI() {
System.out.println("**********************");
System.out.println("Welcome to Book Store");
System.out.println("**********************");
System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice: ");
}
private void testStatelessEjb() {
try {
int choice = 1;
String viewClassName = LibrarySessionBeanRemote.class.getName();
LibrarySessionBeanRemote libraryBean = (LibrarySessionBeanRemote) ctx.lookup("ejb:EJBTutorial/EJBTutorialEJB//LibrarySessionBean!"+ viewClassName);
while (choice != 2) {
String bookName;
showGUI();
String strChoice = brConsoleReader.readLine();
choice = Integer.parseInt(strChoice);
if (choice == 1) {
System.out.print("Enter book name: ");
bookName = brConsoleReader.readLine();
libraryBean.addBook(bookName);
} else if (choice == 2) {
break;
}
}
List<String> booksList = libraryBean.getBooks();
System.out.println("Book(s) entered so far: " + booksList.size());
for (int i = 0; i < booksList.size(); ++i) {
System.out.println((i + 1) + ". " + booksList.get(i));
}
LibrarySessionBeanRemote libraryBean1 = (LibrarySessionBeanRemote) ctx
.lookup("ejb:EJBTutorial/EJBTutorialEJB//LibrarySessionBean!"
+ viewClassName);
List<String> booksList1 = libraryBean1.getBooks();
System.out.println("***Using second lookup to get library stateless object***");
System.out.println("Book(s) entered so far: " + booksList1.size());
for (int i = 0; i < booksList1.size(); ++i) {
System.out.println((i + 1) + ". " + booksList1.get(i));
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
try {
if (brConsoleReader != null) {
brConsoleReader.close();
}
ctx.close();
} catch (IOException | NamingException ex) {
System.out.println(ex.getMessage());
}
}
}
}
[/CODE]