*
The moose likes EJB and other Java EE Technologies and the fly likes Simple Session bean in weblogic8.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Simple Session bean in weblogic8.1" Watch "Simple Session bean in weblogic8.1" New topic
Author

Simple Session bean in weblogic8.1

Darmasubramanian Gopalan
Greenhorn

Joined: Feb 21, 2005
Posts: 3
I am new to weblogic8.1 and I am not able to call my ejb example from my client application deployed. Please help me to solve this.

For the stateless bean HelloWorld application, I have created
Hello.java,HelloBean.java and HelloHome.java along with the two decripters.
---------------------------
(1) weblogic-ejb-jar:
----------------------
<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd'>

<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>HelloBean2</ejb-name>
<stateless-session-descriptor>
<pool></pool>
<stateless-clustering></stateless-clustering>
</stateless-session-descriptor>
<transaction-descriptor></transaction-descriptor>
<jndi-name>HelloBean2</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
---------------------------
2) ejb-jar.xml:
----------------------

<!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>HelloBean2</ejb-name>
<home>HelloHome</home>
<remote>Hello</remote>
<ejb-class>HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>HelloBean2</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
----------------
I have created the jar using jar option and created the jar file named Stl.jar.

In the weblogic console in Deployments---> EJB Modules-->Deploy a new EJB Module...

I have deployed the application in
localhost\D:\bea\user_projects\mydomain\myserver\upload\Stl.jar

Now the deployment is success.
----------------
I wrote the JSP for accessing this

<%@page import="javax.naming.*,java.util.*" %>
<%
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx = new InitialContext(h);
Object obj = ctx.lookup("HelloBean2");
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);
Hello hello = home.create();
hello.remove();
%>

I also wrote the two deployment decripters for the war file.

------------------------
web.xml
----------
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>HelloClient</display-name>
<servlet>
<servlet-name>HelloClient</servlet-name>
<jsp-file>HelloClient.jsp</jsp-file>
</servlet>
<login-config><auth-method></auth-method></login-config>
</web-app>
-------------
weblogic.xml
----------
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">
<weblogic-web-app>
</weblogic-web-app>
--------------

I bundled these three in a war file named StlClient.war and installed in weblogic using

deployments-->web application modules-->Deploy a new Web Application Module...
I have uploaded the war file and the deployment was success.

In the configuration the context root shown as
Context Root: /HelloClient

So when I typed
http://localhost:7001/HelloClient/HelloClient.jsp

I am getting the following error.

Compilation of 'D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java' failed:
--------------------------------------------------------------------------------
D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:137: cannot resolve symbol
probably occurred due to an error in /HelloClient.jsp line 19:
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);

D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:137: cannot resolve symbol
probably occurred due to an error in /HelloClient.jsp line 19:
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);

D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:137: cannot resolve symbol
probably occurred due to an error in /HelloClient.jsp line 19:
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);

D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:140: cannot resolve symbol
probably occurred due to an error in /HelloClient.jsp line 22:
Hello hello = home.create();


--------------------------------------------------------------------------------
Full compiler error(s):
D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:137: cannot resolve symbol
symbol : class HelloHome
location: class jsp_servlet.__helloclient
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class); //[ /HelloClient.jsp; Line: 19]
^
D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:137: cannot resolve symbol
symbol : class HelloHome
location: class jsp_servlet.__helloclient
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class); //[ /HelloClient.jsp; Line: 19]
^
D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:137: cannot resolve symbol
symbol : class HelloHome
location: class jsp_servlet.__helloclient
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class); //[ /HelloClient.jsp; Line: 19]
^
D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:140: cannot resolve symbol
symbol : class Hello
location: class jsp_servlet.__helloclient
Hello hello = home.create(); //[ /HelloClient.jsp; Line: 22]
^
4 errors

Please help.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Please don't mind if I'll make couple of suggestions that can help your development effort in the future:

  • Don't build home and remote interface, use either EJBGen or Xdoclet tools.
  • Use the appc tool to manually compile the jsp(s). This will generate the source files as well and you can see the code in order to figure out where the problems might be. It will also help you to identify the errors as compile time rather than run time (avoiding unnecessary deployments).



  • As for the example you've sent I believe that your jsp doesn't import the ejb home and remote interfaces, or at least the class loader cannot find them.
    And by the way if your test will be successful after importing those interfaces, try to comment out the lines that initialize the initial context. Use only:



    This should work fine since your jsp runs within the container and the initial context is already initialized.
    I hope this will help.
    Regards.


    I think, therefore I exist -- Rene Descartes
    Darmasubramanian Gopalan
    Greenhorn

    Joined: Feb 21, 2005
    Posts: 3
    I have given the jar in my classpath.

    When I import the Home and Remote I am getting the following Error.

    D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:19: '.' expected
    probably occurred due to an error in /HelloClient.jsp line 1:
    <%@page import="javax.naming.*,java.util.*,HelloHome,Hello" %>


    Full compiler error(s):
    D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:19: '.' expected
    import HelloHome; //[ /HelloClient.jsp; Line: 1]
    ^
    D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:20: '.' expected
    import Hello; //[ /HelloClient.jsp; Line: 1]
    ^
    D:\bea\user_projects\mydomain\.\myserver\.wlnotdelete\extract\myserver_HelloClient_HelloClient\jsp_servlet\__helloclient.java:139: cannot resolve symbol
    symbol : class HelloHome
    location: class jsp_servlet.__helloclient
    HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class); //[ /HelloClient.jsp; Line: 19]
    ^

    Please help me
    Valentin Tanase
    Ranch Hand

    Joined: Feb 17, 2005
    Posts: 704
    Java won't let you to import a class without specifying the package name (ultimately it�s a matter of syntax). The peculiarity is that if you have two classes A and B that are not package name qualified, they must be in the same folder in order to compile them. Your problem occurs at compile time, because the server is not capable to compile your jsp, which imports unqualified classes (your ejb classes) that are located in different jars (although your classpath includes them).
    Please try to use package names for your beans.
    Darmasubramanian Gopalan
    Greenhorn

    Joined: Feb 21, 2005
    Posts: 3
    Thanks Valentin Tanase.
    After providing the package structure, the code is working fine.
    But this is new to me as Websphere 5.x never expects this packaging.
    [ February 22, 2005: Message edited by: Darmasubramanian Gopalan ]
    Valentin Tanase
    Ranch Hand

    Joined: Feb 17, 2005
    Posts: 704
    You're most welcomed!
     
     
    subject: Simple Session bean in weblogic8.1