Sunday, April 12, 2015

Operation failed with status WAITING

My first learning objective on EJB is to establish a connection to the server and then return a value, say 5063, to the client. Thus, I have the following piece on server side:
public interface AuthenticationRemote {

 public int status();

public class Authentication implements AuthenticationRemote {

     * Default constructor. 
    public Authentication() {

 public int status() {
  return 5063;

The project name for the pieces above, ejb2, will be the context path used by a client to identify the remote path of a specific method call. When the piece is deployed to the server, following log would be seen:
On the client side, as in following piece, is a separate project which will establish a connection to the above piece:
public class EjbClient {

 public static void main(String args[]) throws NamingException {
  Properties props = new Properties();
  props.put("java.naming.factory.url.pkgs", "org.jboss.ejb.client.naming");
  props.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
  props.put("java.naming.provider.url", "remote://");
  props.put("jboss.naming.client.ejb.context", "true");
  InitialContext context = new InitialContext(props);
  String appName = "";
  String moduleName = "ejb2";
  String distinctName = "";
  String beanName = Authentication.class.getSimpleName();
  String interfaceName = AuthenticationRemote.class.getName();
  String name = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + interfaceName;
  AuthenticationRemote bean = (AuthenticationRemote) context.lookup(name);
  int result = bean.status();
I was so unlucky that I was failed to establish a connection to server. End I up I get this:
Exception in thread "main" javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: Operation failed with status WAITING]
 at org.jboss.naming.remote.client.ClientUtil.namingException(
 at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(
 at javax.naming.spi.NamingManager.getInitialContext(
 at javax.naming.InitialContext.getDefaultInitCtx(
 at javax.naming.InitialContext.init(
 at javax.naming.InitialContext.(
 at org.huahsin68.EjbClient.main(
Caused by: java.lang.RuntimeException: Operation failed with status WAITING
 at org.jboss.naming.remote.protocol.IoFutureHelper.get(
 at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(
 at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(
 at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(
 at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(
 ... 5 more
But later I found out I forgot to turn on my server. Finally, the result variable is returning the value of 5063.

No comments: