aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes help with client error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "help with client error" Watch "help with client error" New topic
Author

help with client error

blackcarlos Dibia
Greenhorn

Joined: Mar 30, 2005
Posts: 21
I'm using J2EE 1.4 to package this application
but I get an internal error when trying to call the servlet client
here are the codes for the stateless Bean

import java.util.*;
import java.io.*;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class LoanBean implements SessionBean
{
private javax.ejb.SessionContext m_ctx = null;
public void setSessionContext(SessionContext ctx)
{
m_ctx = ctx;
}
public void ejbCreate() throws java.rmi.RemoteException,javax.ejb.CreateException
{
System.out.println("ejbCreate() on obj" + this);
}
public void ejbRemove()
{
System.out.println("ejbRemove() on obj" + this);
}
public void ejbActivate()
{
System.out.println("ejbActivate() on obj" + this);
}
public void ejbPassivate()
{
System.out.println("ejbPassivate() on obj" + this);
}
public float calculateInterest(float rate, float time, float amount)throws java.rmi.RemoteException
{
float interest = time * amount * (rate/ 100);
return interest;
}
}

the code for the home interface

import javax.ejb.EJBHome;
public interface LoanHome extends EJBHome
{
public Loan create() throws java.rmi.RemoteException,javax.ejb.CreateException;
}

the code for the remote interface

import javax.ejb.EJBObject;
public interface Loan extends EJBObject
{
public float calculateInterest(float rate, float time, float amount)throws java.rmi.RemoteException;
}

and here is the code for my servlet client

import java.io.*;
import javax.servlet.*;
import javax.naming.*;
import javax.servlet.http.*;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
public class LoanServlet extends HttpServlet
{

public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
PrintWriter out = res.getWriter();
res.setContentType("text/html");
float rate = Float.valueOf(req.getParameter("rate")).floatValue();
float time = Float.valueOf(req.getParameter("time")).floatValue();
float amount = Float.valueOf(req.getParameter("amount")).floatValue();
Loan myLoanRemote = null;
LoanHome myLoanHome = null;
InitialContext initCon = null;
try
{
initCon = new InitialContext();
}
catch(Exception e)
{
out.println("First" + e.toString());
}
try
{
String JNDIName = "ejb/SimpleLoan";
Object obj = initCon.lookup(JNDIName);
myLoanHome = (LoanHome)PortableRemoteObject.narrow(obj, LoanHome.class);
}
catch(Exception e)
{
out.println("Second" + e.toString());
}
try
{
****myLoanRemote = myLoanHome.create();
}
catch(CreateException e)
{
out.println("Third" + e.toString());
}
float interest = myLoanRemote.calculateInterest(rate, time, amount);
out.println("<B> Interest : " + interest + " </B>");
}
}

I get an internal error that points to the line with **** (that is line 40)
here is the error log
java.lang.NullPointerException
at LoanServlet.doGet(LoanServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:748)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:289)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:283)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:102)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:192)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:261)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:200)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:180)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:582)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
at com.sun.enterprise.webservice.EjbWebServiceValve.invoke(EjbWebServiceValve.java:134)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
at com.sun.enterprise.security.web.SingleSignOn.invoke(SingleSignOn.java:254)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
at com.sun.enterprise.web.VirtualServerValve.invoke(VirtualServerValve.java:209)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:161)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)
at com.sun.enterprise.web.VirtualServerMappingValve.invoke(VirtualServerMappingValve.java:166)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:979)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:692)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:647)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:691)
at java.lang.Thread.run(Thread.java:534)

help pls
[ September 11, 2005: Message edited by: blackcarlos Dibia ]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

What does this line print out: out.println("Second" + e.toString());

In general, you want to have everything in one try/catch block. If an exception is thrown, you don't realy want to continue. And then you get a later error (like the NullPointer) that masks the true error.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with client error