You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by axiez <le...@gmail.com> on 2008/12/28 16:14:24 UTC
ejb client
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-tp21193112s134p21193112.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
Re: ejb client
Posted by Shawn Jiang <ge...@gmail.com>.
OK, you still need to
- add two jars to the classpath when you execute the client app.
1.
geronimo\repository\org\apache\geronimo\framework\geronimo-security\2.1.3\geronimo-security-2.1.3.jar
2.
geronimo\repository\org\apache\openejb\openejb-client\3.0\openejb-client-3.0.jar
- add a env.put("openejb.authentication.realmName","geronimo-admin");
before creating the InitialContext.
Re: ejb client
Posted by axiez <le...@gmail.com>.
I ran "java Client" from a different PC. It threw exception as given below
Exception in thread "main" javax.naming.NoInitialContextException: Cannot
instantiate class: org.openejb.client.RemoteInitialContextFactory [Root
exception is java.lang.ClassNotFoundException:
org.openejb.client.RemoteInitialContextFactory]]
....
....
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-tp21193112s134p21227093.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
Re: ejb client
Posted by David Blevins <da...@visi.com>.
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 <le...@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.
>
>
Re: ejb client
Posted by axiez <le...@gmail.com>.
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 <le...@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.
Re: ejb client
Posted by Shawn Jiang <ge...@gmail.com>.
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 <le...@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
Re: ejb client
Posted by axiez <le...@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.
Re: ejb client
Posted by Shawn Jiang <ge...@gmail.com>.
With some search, it seems that you do need to provide the ejb
container info by
1, providing a jndi.properties in your client classpath with following content:
java.naming.factory.initial=org.openejb.client.RemoteInitialContextFactory
java.naming.provider.url=ejb_container_ip:4201
java.naming.security.principal=system
java.naming.security.credentials=manager
or
2, using following code to create the initial context in your client code.
Properties env = new Properties();
env.put("java.naming.factory.initial","org.apache.openejb.client.RemoteInitialContextFactory");
env.put("java.naming.factory.host", "ejb_container_ip");
env.put("java.naming.factory.port", "4201");
env.put("java.naming.security.principal", "system");
env.put("java.naming.security.credentials", "manager");
ctx = new InitialContext(env);
hope it helps.
2008/12/28 axiez <le...@gmail.com>:
>
> 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-tp21193112s134p21193112.html
> Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>
>
--
Shawn
Re: ejb client
Posted by Shawn Jiang <ge...@gmail.com>.
[startup] Jndi(name=ShoppingCartBeanRemote)
-----------------------------------------
OK, Just as David said, the ShoppingCartBeanRemote is your EJB remote jndi
name. you can look it up and use it in your client app.
--
Shawn
Re: ejb client
Posted by axiez <le...@gmail.com>.
I checked the contents of jar file. The class files are in a subdirectory and
since there was no package statement, it didn't recognize I guess. I
repackaged and deployed again this time without subdirectory. Log entries
are:
15:26:51,218 INFO [config] Configuring Service(id=Default Stateless
Container, type=Container, provider-id=Default Stateless Container)
15:26:51,250 INFO [config] Configuring Service(id=Default Stateful
Container, type=Container, provider-id=Default Stateful Container)
15:26:51,250 INFO [config] Configuring Service(id=Default BMP Container,
type=Container, provider-id=Default BMP Container)
15:26:51,250 INFO [config] Configuring Service(id=Default CMP Container,
type=Container, provider-id=Default CMP Container)
15:26:51,250 INFO [config] Configuring app:
default/Shopping/1230631009812/jar
15:26:52,484 INFO [OpenEJB] Auto-deploying ejb ShoppingCartBean:
EjbDeployment(deployment-id=Shopping/ShoppingCartBean)
15:26:52,531 WARN [validation] WARN ... ShoppingCartBean: Ignoring @Remove
used on interface ShoppingCart method checkout. Annotation only usable on
the bean class.
15:26:52,562 INFO [config] Loaded Module:
default/Shopping/1230631009812/jar
15:26:56,343 INFO [startup] Assembling app:
D:\g\geronimo-tomcat6-javaee5-2.1.3\var\temp\geronimo-deployer65067.tmpdir\Shopping.jar
15:26:56,437 INFO [startup] Jndi(name=ShoppingCartBeanRemote) -->
Ejb(deployment-id=Shopping/ShoppingCartBean)
15:26:56,453 INFO [startup] Created
Ejb(deployment-id=Shopping/ShoppingCartBean, ejb-name=ShoppingCartBean,
container=Default Stateful Container)
15:26:56,453 INFO [startup] Deployed
Application(path=D:\g\geronimo-tomcat6-javaee5-2.1.3\var\temp\geronimo-deployer65067.tmpdir\Shopping.jar)
Shawn Jiang wrote:
>
> The log below is from log when deploying a simple hello world EJB. Seems
> your EJB does not get recognized. Have you ever deployed a helloworld EJB
> before this shopping EJB ? Can you send your src and exported jar
> as attachment for further diagnose ?
>
> --------------------------------------------
> 2008-12-30 15:37:42,323 INFO [config] Configuring Service(id=Default
> Stateless Container, type=Container, provider-id=Default Stateless
> Container)
> 2008-12-30 15:37:42,323 INFO [config] Configuring Service(id=Default
> Stateful Container, type=Container, provider-id=Default Stateful
> Container)
> 2008-12-30 15:37:42,323 INFO [config] Configuring Service(id=Default BMP
> Container, type=Container, provider-id=Default BMP Container)
> 2008-12-30 15:37:42,323 INFO [config] Configuring Service(id=Default CMP
> Container, type=Container, provider-id=Default CMP Container)
> 2008-12-30 15:37:42,323 INFO [config] Configuring app:
> default/simpleEJB/1230622661698/jar
>
> 2008-12-30 15:37:42,542 INFO [OpenEJB] Auto-deploying ejb HelloEJB:
> EjbDeployment(deployment-id=simpleEJB/HelloEJB)
> 2008-12-30 15:37:42,542 INFO [OpenEJB] Auto-deploying ejb
> HelloStatefulEJB:
> EjbDeployment(deployment-id=simpleEJB/HelloStatefulEJB)
>
> 2008-12-30 15:37:42,573 INFO [config] Loaded Module:
> default/simpleEJB/1230622661698/jar
> 2008-12-30 15:37:43,792 INFO [startup] Assembling app:
> Y:\geronimo-tomcat6-javaee5-2.1.3\var\temp\geronimo-deployer52890.tmpdir\simpleEJB.jar
>
> 2008-12-30 15:37:43,807 INFO [startup] Jndi(name=HelloEJBLocal) -->
> Ejb(deployment-id=simpleEJB/HelloEJB)
> 2008-12-30 15:37:43,807 INFO [startup] Jndi(name=HelloEJBRemote) -->
> Ejb(deployment-id=simpleEJB/HelloEJB)
> 2008-12-30 15:37:43,807 INFO [startup] Jndi(name=HelloStatefulEJBRemote)
> --> Ejb(deployment-id=simpleEJB/HelloStatefulEJB)
> 2008-12-30 15:37:43,807 INFO [startup] Created
> Ejb(deployment-id=simpleEJB/HelloEJB, ejb-name=HelloEJB, container=Default
> Stateless Container)
> 2008-12-30 15:37:43,807 INFO [startup] Created
> Ejb(deployment-id=simpleEJB/HelloStatefulEJB, ejb-name=HelloStatefulEJB,
> container=Default Stateful Container)
>
> 2008-12-30 15:37:43,807 INFO [startup] Deployed
> Application(path=Y:\geronimo-tomcat6-javaee5-2.1.3\var\temp\geronimo-deployer52890.tmpdir\simpleEJB.jar)
>
>
--
View this message in context: http://www.nabble.com/ejb-client-tp21193112s134p21215132.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
Re: ejb client
Posted by Shawn Jiang <ge...@gmail.com>.
The log below is from log when deploying a simple hello world EJB. Seems
your EJB does not get recognized. Have you ever deployed a helloworld EJB
before this shopping EJB ? Can you send your src and exported jar
as attachment for further diagnose ?
--------------------------------------------
2008-12-30 15:37:42,323 INFO [config] Configuring Service(id=Default
Stateless Container, type=Container, provider-id=Default Stateless
Container)
2008-12-30 15:37:42,323 INFO [config] Configuring Service(id=Default
Stateful Container, type=Container, provider-id=Default Stateful Container)
2008-12-30 15:37:42,323 INFO [config] Configuring Service(id=Default BMP
Container, type=Container, provider-id=Default BMP Container)
2008-12-30 15:37:42,323 INFO [config] Configuring Service(id=Default CMP
Container, type=Container, provider-id=Default CMP Container)
2008-12-30 15:37:42,323 INFO [config] Configuring app:
default/simpleEJB/1230622661698/jar
2008-12-30 15:37:42,542 INFO [OpenEJB] Auto-deploying ejb HelloEJB:
EjbDeployment(deployment-id=simpleEJB/HelloEJB)
2008-12-30 15:37:42,542 INFO [OpenEJB] Auto-deploying ejb HelloStatefulEJB:
EjbDeployment(deployment-id=simpleEJB/HelloStatefulEJB)
2008-12-30 15:37:42,573 INFO [config] Loaded Module:
default/simpleEJB/1230622661698/jar
2008-12-30 15:37:43,792 INFO [startup] Assembling app:
Y:\geronimo-tomcat6-javaee5-2.1.3\var\temp\geronimo-deployer52890.tmpdir\simpleEJB.jar
2008-12-30 15:37:43,807 INFO [startup] Jndi(name=HelloEJBLocal) -->
Ejb(deployment-id=simpleEJB/HelloEJB)
2008-12-30 15:37:43,807 INFO [startup] Jndi(name=HelloEJBRemote) -->
Ejb(deployment-id=simpleEJB/HelloEJB)
2008-12-30 15:37:43,807 INFO [startup] Jndi(name=HelloStatefulEJBRemote)
--> Ejb(deployment-id=simpleEJB/HelloStatefulEJB)
2008-12-30 15:37:43,807 INFO [startup] Created
Ejb(deployment-id=simpleEJB/HelloEJB, ejb-name=HelloEJB, container=Default
Stateless Container)
2008-12-30 15:37:43,807 INFO [startup] Created
Ejb(deployment-id=simpleEJB/HelloStatefulEJB, ejb-name=HelloStatefulEJB,
container=Default Stateful Container)
2008-12-30 15:37:43,807 INFO [startup] Deployed
Application(path=Y:\geronimo-tomcat6-javaee5-2.1.3\var\temp\geronimo-deployer52890.tmpdir\simpleEJB.jar)
Re: ejb client
Posted by axiez <le...@gmail.com>.
I undeployed the earlier application and issued the following command:
deploy -u system -p manager deploy path\Shopping.jar
System displayed the following message:
Depoyed default/Shopping/1230625750875/jar
Entries in geronimo.log are:
13:59:16,562 INFO [config] Configuring Service(id=Default Stateless
Container, type=Container, provider-id=Default Stateless Container)
13:59:16,828 INFO [config] Configuring Service(id=Default Stateful
Container, type=Container, provider-id=Default Stateful Container)
13:59:16,843 INFO [config] Configuring Service(id=Default BMP Container,
type=Container, provider-id=Default BMP Container)
13:59:16,843 INFO [config] Configuring Service(id=Default CMP Container,
type=Container, provider-id=Default CMP Container)
13:59:16,843 INFO [config] Configuring app:
default/Shopping/1230625750875/jar
13:59:17,781 INFO [config] Loaded Module:
default/Shopping/1230625750875/jar
13:59:33,609 INFO [startup] Assembling app:
D:\g\geronimo-tomcat6-javaee5-2.1.3\var\temp\geronimo-deployer65065.tmpdir\Shopping.jar
13:59:33,609 INFO [startup] Deployed
Application(path=D:\g\geronimo-tomcat6-javaee5-2.1.3\var\temp\geronimo-deployer65065.tmpdir\Shopping.jar)
Shawn Jiang wrote:
>
> I see no problems in your code, I noticed some
>
> d:\dir1\dir2\dir3\yourDirectory
>
>
> in the log, can you please tell me what's your deploy method ? I suggest
> exporting EJB to a jar file then deploy it to geronimo with
> "deploy.bat|sh
> deploy path/to/jar".
>
>
--
View this message in context: http://www.nabble.com/ejb-client-tp21193112s134p21214398.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
Re: ejb client
Posted by Shawn Jiang <ge...@gmail.com>.
I see no problems in your code, I noticed some
d:\dir1\dir2\dir3\yourDirectory
in the log, can you please tell me what's your deploy method ? I suggest
exporting EJB to a jar file then deploy it to geronimo with "deploy.bat|sh
deploy path/to/jar".
Re: ejb client
Posted by axiez <le...@gmail.com>.
ShoppingCartBean.java
import java.io.Serializable;
import java.util.HashMap;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.ejb.Remote;
@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");
}
}
ShoppingCart.java
import java.util.HashMap;
import javax.ejb.Remove;
public interface ShoppingCart {
void buy(String product, int quantity);
HashMap<String, Integer> getCartContents();
@Remove void checkout();
}
axiez wrote:
>
> I went through <geronimo_home>\var\log\geronimo.log file. It has the
> following entries:
> [startup] Assembling app: d:\dir1\dir2\dir3\yourDirectory
> [startup] Deployed Application(path=d:\dir1\dir2\dir3\yourDirectory). No
> entries matching [startup] Jndi for this application. Is it because I
> don't have ejb-jar.xml? I thought it no longer would be required.
>
> 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-tp21193112s134p21213824.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
Re: ejb client
Posted by Shawn Jiang <ge...@gmail.com>.
sure ejb-jar.xml is only optional for ejb 3.0, But I can't tell what's
wrong with your app with the info you provided. Can you paste your
ShoppingCartBean.java, ShoppingCart.java here ?
--
Shawn
Re: ejb client
Posted by axiez <le...@gmail.com>.
I went through <geronimo_home>\var\log\geronimo.log file. It has the
following entries:
[startup] Assembling app: d:\dir1\dir2\dir3\yourDirectory
[startup] Deployed Application(path=d:\dir1\dir2\dir3\yourDirectory). No
entries matching [startup] Jndi for this application. Is it because I don't
have ejb-jar.xml? I thought it no longer would be required.
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-tp21193112s134p21213078.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
Re: ejb client
Posted by axiez <le...@gmail.com>.
Yes. It worked without any problem.
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-tp21193112s134p21228223.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
Re: ejb client
Posted by Shawn Jiang <ge...@gmail.com>.
Sure you'll want to put your remote interface classes(here is the
ShoppingCart) in your client classpath.
2008/12/31 axiez <le...@gmail.com>
>
> This time it threw Exception as follows:
> Exception in thread "main" javax.naming.NamingException: Cannot lookup
> '/ShoppongCartBeanRemote'. [Root exception is java.rmi.RemoteException:
> Cannot read the response from the server. The class for an object being
> returned is not located in this system:; nested exception is:
> java.lang.ClassNotFoundException: ShoppingCart]
> at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:240)
> at javax.naming.InitialContext.lookup(Unknown Source)
> at Client.main(Client.java:12)
>
> 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-tp21193112s134p21227784.html
> Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
>
>
--
Shawn
Re: ejb client
Posted by axiez <le...@gmail.com>.
This time it threw Exception as follows:
Exception in thread "main" javax.naming.NamingException: Cannot lookup
'/ShoppongCartBeanRemote'. [Root exception is java.rmi.RemoteException:
Cannot read the response from the server. The class for an object being
returned is not located in this system:; nested exception is:
java.lang.ClassNotFoundException: ShoppingCart]
at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:240)
at javax.naming.InitialContext.lookup(Unknown Source)
at Client.main(Client.java:12)
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-tp21193112s134p21227784.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.