• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Problem in HelloWorld example in EJB

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am learning EJB right now. I used weblogic before. I followed HelloWorld example in chapter three in book "Master Enterprise JavaBean II" and tried to make it work on Weblogic 6.1. But I have some problems as I described as below:
The OS: Window 2000 Server with sp2
Application Server: BEA weblogic 6.1
JDK 1.3.1
The code is the same as in the book:
// Hello.java
package examples;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
import javax.ejb.EJBHome;
import javax.ejb.Handle;
public interface Hello extends EJBObject {
public String hello() throws RemoteException;
}
// HelloHome.java
package examples;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface HelloHome extends EJBHome {
Hello create() throws RemoteException, CreateException;
}
// HelloLocal.java
package examples;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBLocalHome;
public interface HelloLocal extends EJBLocalObject {
public String hello();
}
// HelloLocalHome.java
package examples;
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
public interface HelloLocalHome extends EJBLocalHome {
HelloLocal create() throws CreateException;
}
// HelloBean.java
package examples;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class HelloBean implements SessionBean {
private SessionContext ctx;
public void ejbCreate() {
System.out.println("ejbCreate()");
}
public void ejbRemove() {
System.out.println("ejbRemove()");
}
public void ejbActivate() {
System.out.println("ejbActivate()");
}
public void ejbPassivate() {
System.out.println("ejbPassivate()");
}
public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
}
public String hello() {
System.out.println("hello()");
return "Hello World!";
}
}
// ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<home>examples.HelloHome</home>
<remote>examples.Hello</remote>
<local-home>examples.HelloLocalHome</local-home>
<local>examples.HelloLocal</local>
<ejb-class>examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
//weblogic-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.2 U (http://www.xmlspy.com) by name (china) -->
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN" "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Hello</ejb-name>
<jndi-name>HelloHome</jndi-name>
<local-jndi-name>HelloHome</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
I can deploy the jar file into weblgoic successfully. I didn't see any error message in the weblogic console, so I assume that everything is fine. Now I create HelloClient.java file:
// HelloClient.java
package examples;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
public class HelloClient {
public static void main(String[] args) throws Exception {
Properties props = System.getProperties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);
Hello hello = home.create();
System.out.println(hello.hello());
hello.remove();
}
}
The only thing I changed from the book for this file is that I add the JNDI look up properties as weblogic's requirement. I compiled this file, and try to run it, I got the following errors:
Exception in thread "main" javax.naming.ConfigurationException. Root exception
is java.rmi.MarshalException: error marshalling return; nested exception is:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHo
meImpl
Start server side stack trace:
java.rmi.MarshalException: error marshalling return; nested exception is:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHo
meImpl
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHomeImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace
; nested exception is:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHo
meImpl
Start server side stack trace:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHomeImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHomeImpl
Start server side stack trace:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHomeImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace
<
It looks like that it complains that HelloBean is not serializable, but it implements SessionBean interface which finaly extends from serializable. I don't know why this error happened? Is anything wrong with the code? Or some configuration is not right? I am very new to EJB and now I hang up on this error. Any one knew the reason?
Thanks
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You are trying to access an EJB object from a local class which does not reside within the APP server. I suggest you first test the class using a simple JSP. To access an EJB ref from a local class you'll have to compile using the IIOP option.
Cheers,
Amit
 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you ensured that you have the same set of classes (namely Remote and Home) interfaces available to the Client and Server.
 
Lu Jin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Amit Shanker,
could u pls tell me how to access an ejb ref from the local class? i am quite new to ejb. thanx a lot.
Cheers,
Amit
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"logic gate",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"logic gate",
Your session bean only exposes a local interface. Add a remote
interface to it and you should be able to invoke it from your
HelloClient app.
Pho
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic