geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Four Sticks" <fours...@gmail.com>
Subject Re: Eclipse + Geronimo + EJB = NullPointerException?
Date Fri, 27 Oct 2006 12:19:57 GMT
Hi Hubert,

I'm glad your code is working now, sorry I just saw your post.  I ran into
this problem also with Eclipse, and I wanted to pass along something
that I learned that helped me get the Eclipse Tiger EJB example
working with
Geronimo.

One problem with the original code was the TigerUtil() class was not
finding the EJB home in the context and this led to a null pointer
exception.  The generated TigerUtil class has the wrong string to look
up the EJB home in the JNDI.  This is why looking it up directly in
your JSP works, but looking it up by the generated utility class
fails.

The XDoclet code from the eclipse tools doesn't generate the correct
utility code to get the ejb home for Geronimo, unless you include the
@ejb.util tag with "generate" parameter set to "logical" in the EJB
java file.  You can change Eclipse XDoclet preferences to set this
value as the default, so you don't have to include this tag in every
EJB class you write.

You can change the Eclipse preferences to have XDoclet to generate the
right utility classes for Geronimo, by going to:

Window -> Preferences -> XDoclet -> ejbdoclet.

Then highlight the line that says "UtilObject" in the list and press the
"Edit" button.  On the dialog that appears, select "logical" in the  "kind"
dropdown and press the "Finish" button.  Then select "Apply" and "Ok" to
save your changes.  Finally, rebuild all your projects in Eclipse to
regenerate the correct code.

Your com.zoo.TigerUtil.getHome() class should now contain the right
code to look up the EJB home from the context in your original JSP.

Best of luck to you!
Gaston

On 10/27/06, HubertB <hubertb@hab-verschlafen.de> wrote:
> > Also do a small change in you JSP file give a try too.
> >
> > tl.foo("Test!"); => String s = tl.foo("Test!");
>
> This was the problem...
>
> String s = tl.foo("Test!"); works, thanx very much!
>
> Am Freitag, den 27.10.2006, 16:01 +0530 schrieb Lasantha Ranaweera:
> > Again things looks ok for me  :-) .
> >
> > Not sure whether you are deploying correct version or not .
> >
> > Also do a small change in you JSP file give a try too.
> >
> > tl.foo("Test!"); => String s = tl.foo("Test!");
> >
> > Otherwise I am running out of ideas.  :-\
> > Thanks,
> > Lasantha Ranaweera
> >
> > HubertB wrote:
> > > This is the content of TigerLocal.java:
> > >
> > > /*
> > >  * Generated by XDoclet - Do not edit!
> > >  */
> > > package com.zoo;
> > >
> > > /**
> > >  * Local interface for Tiger.
> > >  * @generated
> > >  * @wtp generated
> > >  */
> > > public interface TigerLocal
> > >    extends javax.ejb.EJBLocalObject
> > > {
> > >    /**
> > >     * <!-- begin-xdoclet-definition -->
> > >     * @generated //TODO: Must provide implementation for bean method
> > > stub    */
> > >    public java.lang.String foo( java.lang.String param ) ;
> > >
> > > }
> > >
> > >
> > > Am Freitag, den 27.10.2006, 15:20 +0530 schrieb Lasantha Ranaweera:
> > >
> > > > Everything looks correct to me here. Can you share xdoclet generated
> > > > TigerLocal.java files with us?
> > > >
> > > > Thanks,
> > > > Lasantha Ranaweera
> > > > HubertB wrote:
> > > >
> > > > > OK, now my web.xml looks like this:
> > > > >
> > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > <web-app id="WebApp_ID" version="2.4"
> > > > > xmlns="http://java.sun.com/xml/ns/j2ee"
> > > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > > > > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> > > > > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
> > > > >         <display-name>
> > > > >         ZooWeb</display-name>
> > > > >         <welcome-file-list>
> > > > >                 <welcome-file>index.html</welcome-file>
> > > > >                 <welcome-file>index.htm</welcome-file>
> > > > >                 <welcome-file>index.jsp</welcome-file>
> > > > >                 <welcome-file>default.html</welcome-file>
> > > > >                 <welcome-file>default.htm</welcome-file>
> > > > >                 <welcome-file>default.jsp</welcome-file>
> > > > >         </welcome-file-list>
> > > > >         <ejb-local-ref>
> > > > >                 <ejb-ref-name>ejb/Tiger</ejb-ref-name>
> > > > >                 <ejb-ref-type>Session</ejb-ref-type>
> > > > >                 <local-home>com.zoo.TigerLocalHome</local-home>
> > > > >                 <local>com.zoo.TigerLocal</local>
> > > > >                 <ejb-link>Tiger</ejb-link>
> > > > >         </ejb-local-ref>
> > > > > </web-app>
> > > > >
> > > > > I updated the test.jsp to use the LocalHome:
> > > > >
> > > > > <%@ page language="java" contentType="text/html; charset=UTF-8"
> > > > >     pageEncoding="UTF-8"%>
> > > > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> > > > > "http://www.w3.org/TR/html4/loose.dtd">
> > > > > <%@page import="javax.naming.*"%>
> > > > > <%@page import="com.zoo.*"%>
> > > > > <html>
> > > > > <head>
> > > > > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> > > > > <title>Insert title here</title>
> > > > > </head>
> > > > > <body>
> > > > > <%
> > > > > Context ctx = new InitialContext();
> > > > > TigerLocalHome tlh = (TigerLocalHome)
> > > > > ctx.lookup("java:comp/env/ejb/Tiger");
> > > > > TigerLocal tl = tlh.create();
> > > > > tl.foo("Test!");
> > > > > %>
> > > > > <b></b>
> > > > > </body>
> > > > > </html>
> > > > >
> > > > > Now I am getting this error:
> > > > >
> > > > > Unable to compile class for JSP
> > > > > An error occurred at line: 12 in the jsp file: /test.jsp
> > > > > Generated servlet error:
> > > > > The method foo(String) is undefined for the type TigerLocal
> > > > >
> > > > > So I chanced the XDoclet-Tag in TigerBean.java from "remote" to "both":
> > > > >
> > > > >         /**
> > > > >          *
> > > > >          * <!-- begin-xdoclet-definition -->
> > > > >          * @ejb.interface-method view-type="both"
> > > > >          * <!-- end-xdoclet-definition -->
> > > > >          * @generated
> > > > >          *
> > > > >          * //TODO: Must provide implementation for bean method stub
> > > > >          */
> > > > >         public String foo(String param) {
> > > > >                 return null;
> > > > >         }
> > > > >
> > > > > But I am still getting the "method is undefinded" error. Whats wrong
> > > > > now?
> > > > >
> > > > > Am Donnerstag, den 26.10.2006, 17:45 +0530 schrieb Lasantha Ranaweera:
> > > > >
> > > > >
> > > > > > There must be a tag like given in the web.xml if your EJB is
locally
> > > > > > referred one.
> > > > > >
> > > > > > <!-- To refer local EJB's  -->
> > > > > >       <ejb-local-ref>
> > > > > >               <ejb-ref-name>ejb/BankManagerFacade</ejb-ref-name>
> > > > > >               <ejb-ref-type>Session</ejb-ref-type>
> > > > > >               <local-home>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeHomeLocal</local-home>
> > > > > >               <local>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal</local>
> > > > > >               <ejb-link>BankManagerFacadeBean</ejb-link>
> > > > > >       </ejb-local-ref>
> > > > > > If still have problem please post your TigerUtil.java, ejb-jar.xml
and
> > > > > > openejb-jar.xml files.
> > > > > >
> > > > > > Have a look at :
> > > > > > http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html
> > > > > >
> > > > > > Thanks,
> > > > > > Lasantha Ranaweera
> > > > > > HubertB wrote:
> > > > > >
> > > > > >
> > > > > > > Hi!
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > The web.xml looks like this:
> > > > > > >
> > > > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > > > <web-app id="WebApp_ID" version="2.4"
> > > > > > > xmlns="http://java.sun.com/xml/ns/j2ee"
> > > > > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > > > > > > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> > > > > > > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
> > > > > > >     <display-name>
> > > > > > >     ZooWeb</display-name>
> > > > > > >     <welcome-file-list>
> > > > > > >             <welcome-file>index.html</welcome-file>
> > > > > > >             <welcome-file>index.htm</welcome-file>
> > > > > > >             <welcome-file>index.jsp</welcome-file>
> > > > > > >             <welcome-file>default.html</welcome-file>
> > > > > > >             <welcome-file>default.htm</welcome-file>
> > > > > > >             <welcome-file>default.jsp</welcome-file>
> > > > > > >     </welcome-file-list>
> > > > > > > </web-app>
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > This is the content of geronimo-web.xml:
> > > > > > >
> > > > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > > > <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"
> > > > > > > xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
> > > > > > > xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"
> > > > > > > xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
> > > > > > >   <sys:environment>
> > > > > > >     <sys:moduleId>
> > > > > > >       <sys:groupId>default</sys:groupId>
> > > > > > >       <sys:artifactId>ZooWeb</sys:artifactId>
> > > > > > >       <sys:version>1.0</sys:version>
> > > > > > >       <sys:type>car</sys:type>
> > > > > > >     </sys:moduleId>
> > > > > > >   </sys:environment>
> > > > > > >   <context-root>/ZooWeb</context-root>
> > > > > > > </web-app>
> > > > > > >
> > > > > > > Am Donnerstag, den 26.10.2006, 16:46 +0530 schrieb Lasantha
Ranaweera:
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > > Hi Hurbert,
> > > > > > > >
> > > > > > > > Can you post geronimo-web.xml file and web.xml files?
I think you can
> > > > > > > > find those files from your project.
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Lasantha Ranaweera
> > > > > > > > HubertB wrote:
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > > Hi!
> > > > > > > > >
> > > > > > > > > I need a bit help getting this EJB-Tutorial to
run on Geronimo 1.1:
> > > > > > > > > http://www.eclipse.org/webtools/community/tutorials/ejbtutorial/buildingejbs.html
> > > > > > > > >
> > > > > > > > > I am using Eclipse 3.2.1 with WTP 1.5.1, JEM
1.2.1, EMF 2.1, GEF 3.2.1,
> > > > > > > > > Geronimo-Plugin 1.1 (from this file:
> > > > > > > > > g-eclipse-plugin-1.1-v200610161117-deployable)
and XDoclet 1.2.3.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > This is what I have done:
> > > > > > > > >
> > > > > > > > > 1. Create a J2EE => Enterprise Application
Project and name it
> > > > > > > > > "ZooBeansProject"
> > > > > > > > > 2. Create a EJB => EJB Project, name it "ZooBeans",
check "Add project
> > > > > > > > > to an EAR" and choose "ZooBeansProject"
> > > > > > > > > 3. In "ZooBeans" I created a new EJB => XDoclet
Enterprise JavaBean,
> > > > > > > > > Type = Session Bean, Package = com.zoo, name
= "TigerBean"
> > > > > > > > > 4. Rightclick on "Apache Geronimo v1.1 Server
@ localhost", choose "Add
> > > > > > > > > and Remove Projects..." and add "ZooBeansProject"
> > > > > > > > > 5. Started Geronimo and noticed that ZooBeansProject
has been deployed
> > > > > > > > > to the server
> > > > > > > > > 6. Created a Web => Dynamic Web Project named
"ZooWeb", also checked
> > > > > > > > > "Add project to an EAR" and chose "ZooBeansProject"
> > > > > > > > > 7. In "ZooWeb", I created "test.jsp" containing
the following code:
> > > > > > > > >
> > > > > > > > > <%@ page language="java" contentType="text/html;
charset=UTF-8"
> > > > > > > > >     pageEncoding="UTF-8"%>
> > > > > > > > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
> > > > > > > > > "http://www.w3.org/TR/html4/loose.dtd">
> > > > > > > > > <html>
> > > > > > > > > <head>
> > > > > > > > > <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
> > > > > > > > > <title>Insert title here</title>
> > > > > > > > > </head>
> > > > > > > > > <body>
> > > > > > > > > <%
> > > > > > > > > com.zoo.Tiger tiger = null;
> > > > > > > > > try {
> > > > > > > > >         com.zoo.TigerHome home = com.zoo.TigerUtil.getHome();
> > > > > > > > >         tiger = home.create();
> > > > > > > > > } catch(Exception exception) {
> > > > > > > > > }
> > > > > > > > > %>
> > > > > > > > > <b><%= tiger.foo("Test") %></b>
> > > > > > > > > </body>
> > > > > > > > > </html>
> > > > > > > > >
> > > > > > > > > 8. Rightclick on "test.jsp", select "Run As"
=> "Run on Server" then I
> > > > > > > > > get this error:
> > > > > > > > >
> > > > > > > > > 12:13:56,670 ERROR [[jsp]] Servlet.service()
for servlet jsp threw
> > > > > > > > > exception
> > > > > > > > > java.lang.NullPointerException
> > > > > > > > >         at org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:60)
> > > > > > > > >         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
> > > > > > > > >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
> > > > > > > > >         at
> > > > > > > > > org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
> > > > > > > > >         at
> > > > > > > > > org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
> > > > > > > > >         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
> > > > > > > > >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
> > > > > > > > >         at
> > > > > > > > > org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSubjectValve.java:56)
> > > > > > > > >         at org.apache.geronimo.tomcat.GeronimoStandardContext
> > > > > > > > > $SystemMethodValve.invoke(GeronimoStandardContext.java:342)
> > > > > > > > >         at
> > > > > > > > > org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:31)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
> > > > > > > > >         at
> > > > > > > > > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
> > > > > > > > >         at
> > > > > > > > > org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
> > > > > > > > >         at org.apache.coyote.http11.Http11BaseProtocol
> > > > > > > > > $Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
> > > > > > > > >         at
> > > > > > > > > org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
> > > > > > > > >         at
> > > > > > > > > org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
> > > > > > > > >         at org.apache.tomcat.util.threads.ThreadPool
> > > > > > > > > $ControlRunnable.run(ThreadPool.java:684)
> > > > > > > > >         at java.lang.Thread.run(Thread.java:595)
> > > > > > > > >
> > > > > > > > > Whats wrong here?
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > >
> > > > > > >
> > > > >
> > > > >
> > >
> > >
> > >
> >
>
>

Mime
View raw message