This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Weblogic with Ejb, HFEJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Weblogic with Ejb, HFEJB" Watch "Weblogic with Ejb, HFEJB" New topic
Author

Weblogic with Ejb, HFEJB

Frederik Ericsson
Ranch Hand

Joined: Apr 27, 2005
Posts: 128
Hello all,

am geting bit diff error..I read all the links.. which you gave ..but still am not geting it..cleared.

As I told you before am using weblogic8.1, first of all I would like to know do we need to give a name("Advisor") in JNDI in weblogic, as its mentioned in HFEJB page52 for RI Server. if you say that we have give the JNDI name in weblogic, where do we ned to give?

this is where I stand now...
AdviceBean.ejb

package headfirst;

import javax.ejb.*;
import weblogic.ejb.*;
import headfirst.*;

/**
* @ejbgen:session
* ejb-name = "Advice"
*
* @ejbgen:jndi-name
* remote = "ejb.AdviceRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name = "AdviceRemote" remote-home = "true" remote-home-name = "AdviceHome" local-class = "false" local-class-name = "AdviceLocal" local-home = "false" local-home-name = "AdviceLocalHome"
*/
public class AdviceBean implements SessionBean {
// OK, not very exciting advice! You should come up with something better...

private String[] adviceStrings = {"test", "test1", "test2", "test3"};

public void ejbActivate() {
System.out.println("ejb activate");
}

public void ejbPassivate() {
System.out.println("ejb passivate");
}

public void ejbRemove() {
System.out.println("ejb remove");
}

public void setSessionContext(SessionContext ctx) {
System.out.println("session context");
}

// this business method name is changed from the book, because
// there of a bug on some versions of the J2EE RI

public String getMessage() {
System.out.println("in get advice");
int random = (int) (Math.random() * adviceStrings.length);
return adviceStrings[random];
}

public void ejbCreate() {
System.out.println("in ejb create");
}
}

AdviceClient.java

package headfirst;

import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

// not all of these imports are used in this code...
// but in a *real* client you'd probably need at least
// java.rmi.RemoteException and javax.ejb.CreateException

public class AdviceClient {

public static void main(String[] args) {
new AdviceClient().go();
}

public void go() {
try {
Context ic = new InitialContext();


Object o = ic.lookup("Advisor"); // replace with YOUR JNDI name for the bean

AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);

Advice advisor = home.create();

System.out.println(advisor.getMessage());

} catch (Exception ex) {
ex.printStackTrace();
}
}
}


I cant able to build with this file D:\Weblogic\user_projects\AdviceApp\AdviceApp\headfirst\AdviceClient.java
So I remove this client file for a while to build the .jar

after removing this client file, I can able to build. Done, now i got the AdviceApp.jar. again I brought back the client file to the same place..

I tried from cmd

D:\Weblogic\user_projects\AdviceApp\AdviceApp\headfirst>javac -classpath "C:\Program Files\j2sdkee1.3.1\lib\j2ee.jar";"D:\Weblogic\user_projects\AdviceApp\Advic
eApp\AdviceApp.jar" AdviceClient.java
AdviceClient.java:28: cannot resolve symbol
symbol : class Advice
location: class headfirst.AdviceClient
Advice advisor = home.create();
^
1 error

Please tel me how to get rid of this issue...
Mihai Lihatchi
Ranch Hand

Joined: Oct 28, 2005
Posts: 138

Hello.
First of all you have to run ejbgen and obtain the remote component interface (advice) and remote Home interface (advice home) and also the ejb-jar.xml.
Second you need to archive all these files in a jar according to EJB requirements with META-INF/ejb-jar.xml and advice classes.
Third if it is not generated you need to create weblogic-ejb-jar.xml - the Bea weblogic deployment descriptor - and this is where you put your JNDI name.
I have done a ejb-jar on Bea WLI without ejb gen so I am not fully aware about it's features kind of an ejb-doclet.
Good luck!
[ October 02, 2006: Message edited by: Mihai Lihatchi ]

Better, faster, lighter Java ... you mean Ruby right ?
SCEA5,SCBCD1.3,SCWCD5,SCJP1.4 - memories from my youth.
Frederik Ericsson
Ranch Hand

Joined: Apr 27, 2005
Posts: 128
Hi Mihai,

I really thankful to man. I was worndering for the past 2 days.. you helped me a lot.

You told me 3 points.Actually I wrote only the bean, rest of the process done by WLS.

I already done the first point and I got Advice, Advicehome, ejb-jar.xml, weblogic-ejb-jar.xml

actally 1rst and 2nd point done by WLS.. it seems doclet is set like that..

I got the headfirst/AdviceApp.jar
in that jar I got all the xml'es under META-INF/***.xml

here are my xml files

ejb-jar.xml
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Advice</ejb-name>
<home>headfirst.AdviceHome</home>
<remote>headfirst.AdviceRemote</remote>
<ejb-class>headfirst.AdviceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>






weblogic-ejb-jar.xml

<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Advice</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<jndi-name>ejb.AdviceRemoteHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

Here is my client code

Context ic = new InitialContext();
Object o = ic.lookup("Advisor"); // replace with YOUR JNDI name for the bean
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
Advice advisor = home.create();
System.out.println(advisor.getMessage());

can you please tel me where & how give JNDI name "Advisor".

I badly need your help Mihai. sorry to bother you.

Cheers
Mihai Lihatchi
Ranch Hand

Joined: Oct 28, 2005
Posts: 138

Hello.
You shoud focus on weblogic-ejb-jar.xml now.
First of all the <jndi-name> should be

<jndi-name>ejb/Advisor</jndi-name>

Remember that this is Bea specific and for other app server you need to use other deployment descriptors .. it has nothing to do with the certification objectives.
When you do the lookup in the client you should do lookup for advisor..
something like

AdviceHome adviceHome= (AdviceHome)PortableRemoteObject.narrow(context.lookup("ejb/Advisor"),AdviceHome.class);

Any way the best idea would be to use J2EE RI for this exam although Bea is a pretty used server in commercial world.

I am not following this cause I do testing on JBoss 3.2.8 .. but it is not safe to work with Containers that are not following precisely the EJB2.0 spec.

Mihai
Frederik Ericsson
Ranch Hand

Joined: Apr 27, 2005
Posts: 128
Hello Mihai,

I have tried to change the weblogic-ejb-jar.xml, but I cudnt, it say "you cant change this xml because it is inside the jar "

what shud I do now?

Cheers
[ October 03, 2006: Message edited by: Frederik Ericsson ]
 
 
subject: Weblogic with Ejb, HFEJB
 
Similar Threads
Plz guys help me to fix JNDI
HFEJB - Basic Question from
AdviceClient again!!
Trouble running Advice EJB
JNDI