I have a probelm with passing an ArrayList to a Servlet. I use a session bean.
When my business method refers to a single object the everything works fine:
public util.CustDetails aut(int id) throws javax.ejb.FinderException {
CustomerTblLocal cc = custHome.findByPrimaryKey(new Integer(id));
return new util.CustDetails(cc.getCustomerNum(), cc.getCity(), cc.getName());
}
When my business method refers to an ArrayList or Collection of objects then I get an error message
public java.util.ArrayList kkk(java.lang.String city) throws javax.ejb.FinderException,java.rmi.RemoteException {
ArrayList list = null;
Collection m = custHome.findByCity("Miami");
Iterator i = m.iterator();
while(i.hasNext()){
CustomerTblLocal cc = (CustomerTblLocal)i.next();
list.add(new util.CustDetails(cc.getCustomerNum(), cc.getName(),cc.getCity()));
}
return list;
}
The error is seems to happen when I try to get the ArrayList in the servlet with the code:
java.util.ArrayList list = f.kkk("Miami");
Can you possibly figure out what is going on?
The server's log is :
[#|2005-06-18T13:13:54.582+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.container.ejb|_ThreadID=22;|
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:2807)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:2713)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:2521)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:819)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:137)
at $Proxy133.kkk(Unknown Source)
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:585)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:167)
at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(Unknown Source)
at ejb._FaceRemote_DynamicStub.kkk(_FaceRemote_DynamicStub.java)
at web.NewServlet.processRequest(NewServlet.java:42)
at web.NewServlet.doGet(NewServlet.java:63)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
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:585)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:257)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:132)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:185)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:653)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:534)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doTask(ProcessorTask.java:403)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:55)
Caused by: java.lang.NullPointerException
at ejb.FaceBean.kkk(FaceBean.java:107)
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:585)
at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:950)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:158)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:128)
... 41 more
|#]
[#|2005-06-18T13:13:54.584+0100|SEVERE|sun-appserver-pe8.1_02|javax.enterprise.system.container.web|_ThreadID=22;|StandardWrapperValve[NewServlet]: Servlet.service() for servlet NewServlet threw exception
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:657)
at javax.rmi.CORBA.Util.wrapException(Util.java:279)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:177)
at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(Unknown Source)
at ejb._FaceRemote_DynamicStub.kkk(_FaceRemote_DynamicStub.java)
at web.NewServlet.processRequest(NewServlet.java:42)
at web.NewServlet.doGet(NewServlet.java:63)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
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:585)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:257)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:132)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:185)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:653)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:534)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doTask(ProcessorTask.java:403)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:55)
Caused by: java.rmi.RemoteException
|#]
-
Accessing an ArrayList from a Servlet (5 messages)
- Posted by: Georgios Spathoulas
- Posted on: June 18 2005 09:51 EDT
Threaded Messages (5)
- You return null ! by S??bastien Tardif on June 18 2005 11:26 EDT
- Accessing an ArrayList from a Servlet by Georgios Spathoulas on June 18 2005 13:54 EDT
- Accessing an ArrayList from a Servlet by penupati madhusudanarao on June 19 2005 12:26 EDT
- Accessing an ArrayList from a Servlet by Georgios Spathoulas on June 19 2005 14:11 EDT
- Just curious by Mark Vleth on June 20 2005 05:59 EDT
-
You return null ![ Go to top ]
- Posted by: S??bastien Tardif
- Posted on: June 18 2005 11:26 EDT
- in response to Georgios Spathoulas
ArrayList list = null;
...
// lot of statement not setting list
...
return list; -
Accessing an ArrayList from a Servlet[ Go to top ]
- Posted by: Georgios Spathoulas
- Posted on: June 18 2005 13:54 EDT
- in response to Georgios Spathoulas
But I thought that this line could do the job.
list.add(new util.CustDetails(cc.getCustomerNum(), cc.getName(),cc.getCity()));
It is true that it returns a null pointer exception.
But why something like this happens? -
Accessing an ArrayList from a Servlet[ Go to top ]
- Posted by: penupati madhusudanarao
- Posted on: June 19 2005 12:26 EDT
- in response to Georgios Spathoulas
I think you need to initiate ArrayList list.
Hope this works fine. -
Accessing an ArrayList from a Servlet[ Go to top ]
- Posted by: Georgios Spathoulas
- Posted on: June 19 2005 14:11 EDT
- in response to Georgios Spathoulas
It's ok now.
I just needed to check if the object added to the list is null.
if (object!=null){
list.add(object);
}
This way it works. -
Just curious[ Go to top ]
- Posted by: Mark Vleth
- Posted on: June 20 2005 05:59 EDT
- in response to Georgios Spathoulas
Why haven't you something like:
return custHome.findCustomerDetailsByCity("Miami");
:)