wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes WebLogic server-not getting the component interface right Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "WebLogic server-not getting the component interface right" Watch "WebLogic server-not getting the component interface right" New topic
Author

WebLogic server-not getting the component interface right

PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I think this is very strange. I opened a new EJB project in WebLogic server and named it AdviceEJB. Then I opened a new session bean and typed in the following code:

package headfirst;

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

/**
* @ejbgen:session type="Stateless" default-transaction="Supports"
* ejb-name = "Advice"
*
* @ejbgen:jndi-name local="ejb.AdviceLocalHome"
* remote = "ejb.AdviceRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name = "Advice" remote-home = "true" remote-home-name = "AdviceHome" local-class="true" local-class-name = "AdviceLocal" local-home="true" local-home-name = "AdviceLocalHome"
*/
public class AdviceBean

implements SessionBean
{


private String[] adviceStrings = {"One Word: Inappropriate", "You might want to rethink that hair cut",
"Your boss will respect him if you tell him the truth."};

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

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

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

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



public void ejbCreate() {
// Your code here
System.out.println("In ejbCreate");
}

public String getAdvice(){
System.out.println("In getAdvice");
int random = (int) (Math.random() * adviceStrings.length);
return adviceStrings[random];
}

}


Then using the tool I did a "Build the project". Then I clicked the plus sign on adviceEJB.jar. AdviceBean.java is created and it is as follows:
package headfirst;

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

/**
* @ejbgen:session type="Stateless" default-transaction="Supports"
* ejb-name = "Advice"
*
* @ejbgen:jndi-name local="ejb.AdviceLocalHome"
* remote = "ejb.AdviceRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name = "Advice" remote-home = "true" remote-home-name = "AdviceHome" local-class="true" local-class-name = "AdviceLocal" local-home="true" local-home-name = "AdviceLocalHome"
*/
public class AdviceBean

implements SessionBean
{


private String[] adviceStrings = {"One Word: Inappropriate", "You might want to rethink that hair cut",
"Your boss will respect him if you tell him the truth."};

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

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

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

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



public void ejbCreate() {
// Your code here
System.out.println("In ejbCreate");
}

public String getAdvice(){
System.out.println("In getAdvice");
int random = (int) (Math.random() * adviceStrings.length);
return adviceStrings[random];
}

}



Home interface is also created and it is as follows:
package headfirst;


/*
** This file was automatically generated by EJBGen 2.16
** Build: 20031001-1049
*/


import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
import javax.ejb.FinderException;
import java.rmi.RemoteException;
import java.util.Collection;

// BEGIN imports from bean class
import javax.ejb.*;
import weblogic.ejb.*;
// END imports from bean class


public interface AdviceLocalHome extends EJBLocalHome {



public AdviceLocal create() throws CreateException;



}

Component interface is also created and it is as follows:
package headfirst;


/*
** This file was automatically generated by EJBGen 2.16
** Build: 20031001-1049
*/


import javax.ejb.EJBObject;
import java.rmi.RemoteException;

// BEGIN imports from bean class
import javax.ejb.*;
import weblogic.ejb.*;
// END imports from bean class


public interface Advice extends EJBObject {


}


But in the Component interface I don't see my method. Why is this. I thought the tool will create this by itself. Okay I tried to update it. But it wouldn't let me, it is read only. Am I doing it correctly? Please help.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I forgot to post my ejb-jar.xml. It follows:


<?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'>


<!--
** This file was automatically generated by EJBGen 2.16
** Build: 20031001-1049
-->
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Advice</ejb-name>
<home>headfirst.AdviceHome</home>
<remote>headfirst.Advice</remote>
<local-home>headfirst.AdviceLocalHome</local-home>
<local>headfirst.AdviceLocal</local>
<ejb-class>headfirst.AdviceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Advice</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Supports</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Pradeep,

Add the ejb.interface-method to to all your business methods:


Regards.


I think, therefore I exist -- Rene Descartes
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
Please forgive me if this is a stupid question. I am just a beginner.
Is not this between "/**...*/" commented out?
How is this going to affect the bean?
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Pradeep,

This is a common technique for generating ejb related artifacts using doclet classes. It can generate remote/home interfaces, deployment descriptors, etc. Your building process is using the xDoclet tool. xDoclet on the other hand has special doclet classes that can introspect your java sources and generate the appropriate artifacts, based upon some special tags (prefixed with @) you�ve specified. Because all those tags reside within your source files is necessary that they should be enclosed between java comment blocks, otherwise the compiler will complain. Although this is a great idea and it made EJB developers life acceptable, it is nothing new though. Generation javadocs from your source files using the javadoc tool is the source of inspiration for both xDoclet and ejb-gen.
Regards.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I did as you instructed (the updated code follows). But my Component interface(Advice) looks the same.

package headfirst;

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

/**
* @ejbgen:session
* ejb-name = "Advice"
*
* @ejbgen:jndi-name
* remote = "ejb.AdviceRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name = "Advice" remote-home = "true" remote-home-name = "AdviceHome" local-class = "false" local-class-name = "AdviceLocal" local-home = "false" local-home-name = "AdviceLocalHome"
*
*
*/
public class AdviceBean
extends GenericSessionBean
implements SessionBean
{
private String[] adviceStrings = {"One Word: Inappropriate", "You might want to rethink that hair cut",
"Your boss will respect him if you tell him the truth."};

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

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

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

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


/**
* @ejb.interface-method
*/
public String getAdvice(){
System.out.println("In getAdvice");
int random = (int) (Math.random() * adviceStrings.length);
return adviceStrings[random];
}

public void ejbCreate() {
// Your code here
System.out.println("In ejbCreate");
}
}
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Pradeep,

One thing worth noting that I should mention is that most of the generating tools won�t re-generate the artifacts if they have been already generated. These tools assume that you might edit the generated files in the mean time and they won�t override your changes. Did you remove the previous generated files before? If not then do so and let me know if it works.
Regards.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Pradeep,

Please accept my apologies. I was looking at your code again and I just figured out that you�re actually using ejb-gen. I provided you the tag for xDoclet, which of course is not compatible with ejb-gen. Please use the next tags (and don�t forget to remove the generated files before re-generating them):

Regards.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I am very happy to see it created the method declaration in the component interface. But I think still I am a little bit away from deploying it on a WebLogic server using WebLogic Workshop. When I created the build I got two warnings (yellow exclamation). One says
AdviceBean.java:17:No JNDI name was found
AdviceBean.java:17 eclares local method but no local JNDI name.

And also I got some error that opened up in a �WebLogic Workshop window� which says something like
Deployment failed. Last message from server:
����������
����������etc
Deployment descriptor was not found in AdviceEJB.jar.

Do I have to add this with AdviceEJB.jar?

I very much appreciate the effort you put to help me out.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Pradeep,

It�s been a while since I�m not using ejb-gen (we�re using xDoclet though) and I cannot tell you if your tags are correct or not. On the other hand I would expect that ejb-gen to generate the deployment descriptors as well. Check the system file for ejb-jar.xml and weblogic-ejb-jar.xml. These files should be located under the META-INF folder within your deployed archive. I would also expect the archive to be properly packed when using WebLogic Workshop (which by the way I never used it). Make sure that the jndi name is properly specified in weblogic-ejb-jar.xml. Typically it should look like this:

If you can�t find the deployment descriptors you better check the documentation and see why the WebLogic Workshop did not generate and packed them accordingly. If you find them but they don�t contain all required tags (like jndi-name for example), then you make sure you�re using the right ejb tags and the syntax you�ve specified is correct.
Regards.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
This message doesn't make any sense to me.
adviceEJB is the EJB project and it is under C:\projectsWLW. Each time when I build adviceEJB, it creates advanceEJB.jar
in both C:\projectsWLW and C:\projectsWLW\adviceEJB directories. When I open up advanceEJB.jar from WebLogic Workshop, I can see ejb-jar.xml under adviceEJB\advanceEJB.jar

By the way I have another jar file created using sun deploytool. Would I be able to use that in Weblogic workshop and deploy it into weblogic server?
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I tried to modify ejb-jar.xml with <jndi-name> tag. But it is read only. I am in deep trouble
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I still have that warning. But I don't have that error anymore (I don't know why).
Okay then I opened a new java project called "AdviceClientJava" in weblogic and created a java file called AdviceClient.java (which follows)

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

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

public void go() {
try{

Properties props=new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY," weblogic.jndi.WLInitialContextFactory");
props.setProperty(Context.PROVIDER_URL,"t3://localhost:7777");
//Context ctx=new IntitialContext(props);


Context ic = new InitialContext(props);
Object o = ic.lookup("ejb.AdviceLocalHome");

AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
Advice advisor = home.create();
System.out.println( advisor.getAdvice() );

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

}

Then I built this project and ran from weblogic workshop. The result follows:


Trying to create process and attach to 4617...
C:\bea\jdk141_05\bin\javaw.exe -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4617,suspend=y,server=y -classpath "C:\bea\jdk141_05\jre\lib\rt.jar;C:\bea\jdk141_05\lib\tools.jar;C:\bea\weblogic81\server\lib\knex.jar;C:\bea\weblogic81\common\lib\log4j.jar;C:\bea\weblogic81\server\lib\debugging.jar;C:\bea\weblogic81\javelin\lib\javelin.jar;C:\bea\weblogic81\server\lib\wlw-lang.jar;C:\bea\weblogic81\server\lib\weblogic.jar;C:\bea\weblogic81\common\eval\pointbase\lib\pbserver44.jar;C:\bea\weblogic81\common\eval\pointbase\lib\pbclient44.jar;C:\bea\weblogic81\server\lib\webservices.jar;C:\bea\weblogic81\server\li b\webserviceclient.jar;C:\bea\weblogic81\server\lib\webserviceclient+ssl.jar;C:\bea\weblogic81\server\lib\wli.jar;C:\bea\weblogic81\server\lib\xbean.jar;C:\bea\weblogic81\server\lib\wlxbean.jar;C:\bea\weblogic81\server\lib\xqrl.jar;C:\bea\weblogic81\server\lib\netui\netui-compiler.jar;C:\projectsWLW\adviceEJB.jar;C:\projectsWLW\APP-INF\lib\AdviceClientJava.jar;C:\projectsWLW\adviceEJB.jar;C:\bea\jdk141_05\jre\lib\rt.jar;C:\bea\jdk141_05\lib\tools.jar;C:\bea\weblogic81\server\lib\knex.jar;C:\bea\ weblogic81\common\lib\log4j.jar;C:\bea\weblogic81\server\lib\debugging.jar;C:\bea\weblogic81\javelin\lib\javelin.jar;C:\bea\weblogic81\server\lib\wlw-lang.jar;C:\bea\weblogic81\server\lib\weblogic.jar;C:\bea\weblogic81\common\eval\pointbase\lib\pbserver44.jar;C:\bea\weblogic81\common\eval\pointbase\lib\pbclient44.jar;C:\bea\weblogic81\server\lib\webservices.jar;C:\bea\weblogic81\server\lib\webserviceclient.jar;C:\bea\weblogic81\server\lib\webserviceclient+ssl.jar;C:\bea\weblogic81\server\lib\wli .jar;C:\bea\weblogic81\server\lib\xbean.jar;C:\bea\weblogic81\server\lib\wlxbean.jar;C:\bea\weblogic81\server\lib\xqrl.jar;C:\bea\weblogic81\server\lib\netui\netui-compiler.jar" AdviceClient
Process started
Attached successfully.
javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory. Root exception is java.lang.ClassNotFoundException: weblogic/jndi/WLInitialContextFactory
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:217)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at AdviceClient.go(AdviceClient.java:22)
at AdviceClient.main(AdviceClient.java:10)
Debugging Finished



Any idea why this error is coming. May be related to JNDI?
Thank you.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Again I'm not very familiar with Weblogic Workshop and I don't know how it supposes to run classes or load libraries, but from what I can see I'd only assume that your client does not load the weblogic.jar library.
Regards.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I am able to run a jsp as client to this ejb. But no success in running a java as client. I post the jsp here.


<%@ page import="headfirst.Advice"%>
<%@ page import="headfirst.AdviceLocal"%>
<%@ page import="headfirst.AdviceLocalHome"%>
<%@ page import="javax.naming.Context"%>
<%@ page import="javax.naming.InitialContext"%>

<html>
<head>
<title>
Web Application Page
</title>
</head>
<body>
<p>
Hello World EJB
</p>

<%

Context ctx = new InitialContext();
AdviceLocalHome adviceLocalHome =
(AdviceLocalHome)ctx.lookup("ejb.AdviceLocalHome");
AdviceLocal advice = adviceLocalHome.create();
String abc = advice.getAdvice();


%>

Hi <%=abc%>
</body>
</html>
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Your local JSP client will work if packaged in an EAR file with the EJB. But a client outside the EAR must use the bean's remote interface.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Pradeep,


I am able to run a jsp as client to this ejb. But no success in running a java as client. I post the jsp here.


There is no miracle or surprise here. If you remember my previous posting I explain you the steps that the initial context is following in order to get all required properties. As a matter of fact your container will take the responsibility to initialize all these properties with their right values. Since your jsp is sharing the same environment, consequently your code has the privilege to run within an environment that is properly initialized and the InitialContext will make calls to System.getProperty() and will get the right values. Standalone clients on the other hand don�t have this privilege and they have to initialize the environment by themselves.
Regards.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: WebLogic server-not getting the component interface right