I'd backup and go with the suggestion from Shawn Jiang. You're really
close.
It's just:
Properties env = new Properties();
env
.put
("java
.naming
.factory
.initial","org.apache.openejb.client.RemoteInitialContextFactory");
env.put("java.naming.provider.url", "ejbd://localhost:4201");
env.put("java.naming.security.principal", "system");
env.put("java.naming.security.credentials", "manager");
InitialContext ctx = new InitialContext(env);
ShoppingCart shoppingCart = ctx.lookup("ShoppingCartBeanRemote");
Looking at your bean code the JNDI name will likely be
"ShoppingCartBeanRemote", but as Shawn mentions the geronimo.log file
will list it exactly.
I would not investigate using annotations in remote clients until you
can get a simple client like the one above working. The reason being
is annotations in clients only work for Java EE App Clients running in
a Java EE App Client Container. Java EE Application Clients are
definitely far more complicated than plain java clients that use the
code above.
-David
On Dec 29, 2008, at 1:39 AM, axiez wrote:
I am trying to use annotations instead of JNDI. My Bean class code is:
import java.io.*;
import java.util.*;
import javax.ejb.*;
@Stateful
@Remote(ShoppingCart.class)
public class ShoppingCartBean implements ShoppingCart, Serializable {
private HashMap<String, Integer> cart = new HashMap<String,
Integer>();
public void buy(String product, int quantity) {
if(cart.containsKey(product)) {
int currq = cart.get(product);
currq += quantity;
cart.put(product, currq);
}
else {
cart.put(product, quantity);
}
}
public HashMap<String, Integer> getCartContents() {
return cart;
}
@Remove
public void checkout() {
System.out.println("To be implemented");
}
}
I used the inPlace option of deploy command. It said "Deployed
default/yourDirectory/1230542660703/jar". From EJB 3.0 spec, it
looks like
we can use annotations and avoid JNDI. My attempt is to use remote
client
with simplest EJB 3.0 code.
Shawn Jiang wrote:
you need to use the bean's remote interface name here instead of the
bean class name itself.
As for "ShoppingCartBean/remote" in the lookup method, you need to
confirm it's the JNDI name of your EJB remote interface.(you can get
the JNDI name of your EJB by searching "[startup] Jndi(name=" in the
geronimo/var/log/geronimo.log file)
2008/12/29 axiez <lesai...@gmail.com>:
I added jndi.properties. Modified code is given below:
Properties p = new Properties();
p.load(new FileInputStream("jndi.properties"));
InitialContext ctx = new InitialContext(p);
ShoppingCart cart = (ShoppingCart) ctx.lookup("ShoppingCartBean/
remote");
I compiled the java files and am planning to create a jar file
"a.jar"
and
deploy it. In the lookup method given above, I simply mentioned
the bean
class name. Nowhere did I mention jar file/module name. Is this
correct?
axiez wrote:
I want to run sample code to understand ejb 3.0 basics. I am new
to ejb.
I
have the following java files: ShoppingCartBean.java,
ShoppingCart.java
and Client.java. The Client.java file has the following code:
import javax.naming.InitialContext;
public class Client {
public static void main(String[] args) throws Exception {
InitialContext ctx = new InitialContext();
ShoppingCart cart = (ShoppingCart)
ctx.lookup("ShoppingCartBean/remote");
...
}
My plan is to have client on a different JVM than ejb
container. I
wonder how the client can execute bean method without even
knowing IP
address etc of the JVM that has the other code on ejb container.
--
View this message in context:
http://www.nabble.com/ejb-client-tp21193112s134p21199643.html
Sent from the Apache Geronimo - Users mailing list archive at
Nabble.com.
--
Shawn
--
View this message in context:
http://www.nabble.com/ejb-client-tp21193112s134p21200805.html
Sent from the Apache Geronimo - Users mailing list archive at
Nabble.com.