1
votes

I have a stateless bean

 @Stateless
 public class CalculatorImpl implements Calculator {
 private static final long serialVersionUID = 1L;
 @Override
  public int add(int a, int b) {
return a+b;
  }
    @Override
   public int sub(int a, int b) {
return a-b;
   }
   @Override
   public int mul(int a, int b) {
return a*b;
  }
   @Override
    public float div(int a, int b) {
return a/b;
   }
    }

I have deployed this on glassfish with interface annotated with @Remote

  @Remote
  public interface Calculator extends Serializable{
  public int add(int a, int b)throws RemoteException;
  public int sub(int a, int b)throws RemoteException;
   public int mul(int a, int b)throws RemoteException;
   public float div(int a, int b)throws RemoteException;
  }

When I am trying to access it by the client i.e. a java desktop application: It is throwing a NullpointerException

Client code:

      MyClient client= new MyClient();
  Properties props = new Properties();
  props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
  props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");

  // glassfish default port value will be 3700, 
  // but im using tcpviewer to redirect my 50005 port to 3700
  props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

  InitialContext context = new InitialContext(props);

 client.cart = (ShoppingCart) context
        .lookup("java:global/EJBDemo2EAR/EJBDemo2/CalculatorImpl!com.java.stateless.Calculator");
System.out.println("In doget");
client.cart.buy("soap", 12);
client.cart.getCartContents();

Error is: java.lang.NullPointerException at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:347) at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:354) at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:384) at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:329) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438) at javax.naming.InitialContext.lookup(InitialContext.java:417) at com.java.client.MyClient.main(MyClient.java:30) Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/EJBDemo2EAR/EJBDemo2/CalculatorImpl!com.java.stateless.Calculator' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.NullPointerException]] at com.sun.enterprise.naming.impl.SerialContext.lookup

1
Have added gf-client and appserv-rt.jar to the classpath, but not workingPayal Bansal

1 Answers

2
votes

In context.lookup just pass the fully qualified interface name:

client.cart=(ShoppingCart)context.lookup("com.java.stateless.Calculator");