[jboss-user] [EJB/JBoss] - Re: javax.naming.CommunicationException while executing a cl
mahak
do-not-reply at jboss.com
Fri Oct 12 04:11:55 EDT 2007
Hi i am also facing same problem
/*
* CartClient.java
*
* Created on October 11, 2007, 10:31 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package ejb_stateful;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class CartClient {
public static void main(String [] args) throws NamingException {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL,"localhost");
env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
Context context = new InitialContext(env);
if(context!=null)
System.out.println("context: success");
ejb_stateful.CartRemote cart=null;
try{
cart = (ejb_stateful.CartRemote)context.lookup("CartBean");
}catch(Exception e){
System.out.println("naming ex here"+e);
}
if(cart==null)
System.out.println("cart is null");
if(cart!=null)
System.out.println("cart: success");
System.out.println("Adding items to cart");
cart.addItem("Pizza");
cart.addItem("Pasta");
cart.addItem("Noodles");
cart.addItem("Bread");
cart.addItem("Butter");
System.out.println("Listing cart contents");
Collection items = cart.getItems();
for (Iterator i = items.iterator(); i.hasNext();) {
String item = (String) i.next();
System.out.println(" " + item);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4094402#4094402
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4094402
More information about the jboss-user
mailing list