"No EJB receiver" trying to lookup local EJB from java main
stonesoft Mar 14, 2013 6:33 PMI am trying to do this in JBOSS 7.1.1.
I have written a java main that trys to lookup an ejb and then invoke a method.
The lookup fails with "No EJB receiver". I have tried just about every imaginable string for the lookup.
I tried the ones that are logged to the console when the jar is deployed and those get a "javax.naming.NoInitialContextException: Need to specify class name" exception.
Thanks for any help anyone can give.
The Local interface:
package xxx.accounting;
import ...
@Local
public interface AccountingRetryLocal extends Serializable {
public void retryFailedRequests() throws NamingException, JMSException;
}
The Remote interface:
package xxx.accounting;
import ...
@Remote
public interface AccountingRetryRemote extends Serializable {
public void retryFailedRequests() throws NamingException, JMSException;
}
The Bean:
package xxx.accounting;
@Stateless
public class AccountingRetryBean implements AccountingRetryLocal, AccountingRetryRemote {
@Override
public void retryFailedRequests() throws NamingException, JMSException {
}
}
The Client Helper:
package xxx.accounting;
import ...
public class RetryClientUtil {
private static final Logger log = Logger.getLogger(RetryClientUtil.class);
private static Context initialContext;
public static Context getInitialContext() throws NamingException {
if (initialContext == null) {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
initialContext = new InitialContext(env);
}
return initialContext;
}
}
The Client: (Run from command line)
package xxx.accounting;
import ...
public class AccountingRetry {
private static final Logger log = Logger.getLogger(AccountingRetry.class);
public static void main(String[] args) {
try {
Context ctx = RetryClientUtil.getInitialContext();
// From EJB example:
// ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>
String appName="";
String moduleName="AccountingServices";
String distinctName = "";
String beanName = AccountingRetryBean.class.getSimpleName();
final String interfaceName = AccountingRetryLocal.class.getName();
String theName = "ejb:"+appName+"/"+moduleName+"/"+distinctName+"/"+beanName+"!"+interfaceName;
AccountingRetryLocal retryLocal = (AccountingRetryLocal) ctx.lookup(theName);
retryLocal.retryFailedRequests();
}
catch (Exception e) {
e.printStackTrace();
}
}
}