2 Replies Latest reply on Apr 30, 2002 2:30 PM by Kevin

    Creating EJB in JSP Null pointer error (JBoss 3 RC1)

    Kevin Newbie

      I've been trying to get my JSP to connect to an ejb and have been having problems.

      I can connect and use the EJB from an application just fine. I use very similar code to connect the JSP, but I get a null pointer exception when doing the home.create(). I'm sure I'm just missing something obvious, but can't put my finger on it yet. I have the ejbs created in a jar, the jsp is in a war archive (with the EJB jar in the WEB-INF/lib dir, then package it all together in an ear.

      Here's the jsp code I use (tried both in JSPinit and in the normal body):
      InitialContext ic = new InitialContext();
      Object objRef = ic.lookup("remoteTableModel/CAMSNew");
      CAMSNewHome home =
      (CAMSNewHome)PortableRemoteObject.narrow(
      objRef, CAMSNewHome.class);

      CAMSNew newTable = home.create();

      I have the following in the ejb-jar.xml:

      <ejb-name>Broker</ejb-name>
      com.effsols.ejb.remoteSQL.BrokerHome
      com.effsols.ejb.remoteSQL.Broker
      <ejb-class>com.effsols.ejb.remoteSQL.BrokerBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Container</transaction-type>


      <ejb-name>CAMSNew</ejb-name>
      com.effsols.ejb.remoteTableModel.CAMSNewHome
      com.effsols.ejb.remoteTableModel.CAMSNew
      <ejb-class>com.effsols.ejb.remoteTableModel.CAMSNewBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>



      And in the jboss.xml:

      <ejb-name>Broker</ejb-name>
      <jndi-name>remoteSQL/Broker</jndi-name>


      <ejb-name>CAMSNew</ejb-name>
      <jndi-name>remoteTableModel/CAMSNew</jndi-name>



      in web.xml:
      <ejb-ref>
      <ejb-ref-name>remoteSQL/Broker</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      com.effsols.ejb.remoteSQL.BrokerHome
      com.effsols.ejb.remoteSQL.Broker
      <ejb-link>Broker</ejb-link>
      </ejb-ref>
      <ejb-ref>
      <ejb-ref-name>remoteTableModel/CAMSNew</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      com.effsols.ejb.remoteTableModel.CAMSNewHome
      com.effsols.ejb.remoteTableModel.CAMSNew
      <ejb-link>CAMSNew</ejb-link>
      </ejb-ref>

      I also tried it without the <ejb-link> above and instead added the following in jboss-web.xml:
      <ejb-ref>
      <ejb-ref-name>remoteSQL/Broker</ejb-ref-name>
      <jndi-name>jnp://kwilliams:1099/remoteSQL/Broker</jndi-name>
      </ejb-ref>
      <ejb-ref>
      <ejb-ref-name>remoteTableModel/CAMSNew</ejb-ref-name>
      <jndi-name>jnp://kwilliams:1099/remoteTableModel/CAMSNew</jndi-name>
      </ejb-ref>

      also tried the jndi names in jboss-web.xml to be just CAMSNew or remoteTableModel/CAMSNew.

      Here's the error I get. The line is the home.create() line in the servlet created from the JSP:
      10:04:48,242 INFO [Engine] jsp: init
      10:04:48,302 ERROR [STDERR] java.rmi.ServerException: null; nested exception is:
      java.lang.NullPointerException
      10:04:48,302 ERROR [STDERR] java.lang.NullPointerException
      10:04:48,312 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invokeHome(StatelessSessionCo
      ntainer.java:598)
      10:04:48,322 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnecti
      onInterceptor.java:167)
      10:04:48,322 ERROR [STDERR] at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invokeHome(StatelessSessionInsta
      nceInterceptor.java:57)
      10:04:48,332 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
      10:04:48,332 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
      10:04:48,342 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
      10:04:48,342 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:104)
      10:04:48,342 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:109)
      10:04:48,352 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.invokeHome(StatelessSessionContainer.java:300)
      10:04:48,352 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java:727)
      10:04:48,352 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:492)
      10:04:48,362 ERROR [STDERR] at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
      10:04:48,362 ERROR [STDERR] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)
      10:04:48,372 ERROR [STDERR] at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:73)
      10:04:48,372 ERROR [STDERR] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:76)
      10:04:48,372 ERROR [STDERR] at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:185)
      10:04:48,382 ERROR [STDERR] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:96)
      10:04:48,382 ERROR [STDERR] at $Proxy49.create(Unknown Source)
      10:04:48,382 ERROR [STDERR] at org.apache.jsp.CAMSMain$jsp._jspService(CAMSMain$jsp.java:121)
      10:04:48,392 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      10:04:48,392 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      10:04:48,392 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
      10:04:48,402 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
      10:04:48,402 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
      10:04:48,402 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      10:04:48,412 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.ja
      va:247)
      10:04:48,422 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      10:04:48,422 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      10:04:48,422 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      10:04:48,432 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      10:04:48,432 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      10:04:48,432 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      10:04:48,442 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      10:04:48,442 ERROR [STDERR] at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      10:04:48,442 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      10:04:48,452 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      10:04:48,452 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      10:04:48,462 ERROR [STDERR] at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      10:04:48,462 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      10:04:48,462 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      10:04:48,472 ERROR [STDERR] at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      10:04:48,472 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      10:04:48,472 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      10:04:48,482 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      10:04:48,482 ERROR [STDERR] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      10:04:48,482 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      10:04:48,492 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      10:04:48,492 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      10:04:48,492 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      10:04:48,502 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      10:04:48,502 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      10:04:48,512 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      10:04:48,512 ERROR [STDERR] at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
      10:04:48,512 ERROR [STDERR] at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
      10:04:48,522 ERROR [STDERR] at java.lang.Thread.run(Thread.java:484)

      Any ideas on what I'm missing?

      Thanks,
      Kevin