• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to retrieve collection from EJB to frontend in WSAD?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
I have a problem in calling a method in EJB from JSP, I am using WSAD5.1.1, below is my source:
Backend
public class CarrierDS{
..
public ArrayList findAllCarrier(){
Connection conn=null;
ArrayList rtnCol = null;
PreparedStatement stat = null;
CarrierPCls getPCls = null;
StringBuffer szSql = new StringBuffer();
ResultSet rs = null;
try{
conn=getConnection();
szSql.append("select carrier_cd, name from car_carrier where carrier_cd like 'AT%' order by carrier_cd");
stat = conn.prepareStatement(szSql.toString());
rs = stat.executeQuery();
rtnCol = new ArrayList();
while (rs.next()){
getPCls = new CarrierPCls();
getPCls.szCarrierCode = rs.getString("CARRIER_CD");
getPCls.szName=rs.getString("NAME");

rtnCol.add(getPCls);/**/
}
}catch (SQLException ex){
ex.printStackTrace();
}finally{
try {
if (rs != null) rs.close();
if (stat != null) stat.close();
if (conn != null) conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return rtnCol;

}
..
}
public class CarrierPCls {
..
public String szName;
public String szCarrierCode;
..
}
public class TPAControllerBean implements javax.ejb.SessionBean {
..
public ArrayList getCarrierList()
{
ArrayList rtnCol = new ArrayList();
try{
rtnCol = new CarrierDS().findAllCarrier();
}catch (Exception ex) {
ex.printStackTrace();
}
return rtnCol;
}
..
}
public interface TPAController extends javax.ejb.EJBObject{
..
public ArrayList getCarrierList() throws RemoteException;
..
}
Frontend
Carrier.jsp
..
TPAController TPARemote=null;
TPAControllerHome TPAHome=null;
InitialContext initCtx = new InitialContext( );
Object homeObject = initCtx.lookup("java:comp/env/websp/TPAController");
TPAHome = (TPAControllerHome) javax.rmi.PortableRemoteObject.narrow(homeObject, TPAControllerHome.class);
TPARemote = TPAHome.create();
ArrayList resultCol= new ArrayList();
resultCol= TPARemote.getCarrierList();
if (resultCol!=null){
Iterator iteCarrier = resultCol.iterator();
while (iteCarrier.hasNext()) {
CarrierPCls tmpPCls = (CarrierPCls)iteCarrier.next();
out.println(tmpPCls.szCarrierCode + "-----" + tmpPCls.szName + "
");
}
..
[End of source]
There are no compile error and deployment error when I deploy the ejb. But if I call the carrier.jsp on browser, it throw an exception below:
Error 500: RemoteException occurred in server thread; nested exception is: java.rmi.MarshalException: Exception occurred in server thread; nested exception is: java.io.NotSerializableException
the stack list below:
[4/1/04 18:42:05:859 PST] 79deecc9 WebGroup E SRVE0026E: [Servlet Error]-[RemoteException occurred in server thread; nested exception is:
java.rmi.MarshalException: Exception occurred in server thread; nested exception is:
java.io.NotSerializableException]: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.MarshalException: Exception occurred in server thread; nested exception is:
java.io.NotSerializableException
at com.ibm.CORBA.iiop.UtilDelegateImpl.wrapException(UtilDelegateImpl.java:690)
at javax.rmi.CORBA.Util.wrapException(Util.java:295)
at com.websp._TPAController_Stub.getCarrierList(_TPAController_Stub.java:257)
at org.apache.jsp._Carrier._jspService(_Carrier.java:136)
at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:662)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.ServicingServletState.service(StrictLifecycleServlet.java:333)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
Caused by: java.rmi.MarshalException: Exception occurred in server thread; nested exception is:
java.io.NotSerializableException
at com.ibm.rmi.util.ProxyUtil.copyObject(ProxyUtil.java:470)
at com.ibm.CORBA.iiop.UtilDelegateImpl.copyObject(UtilDelegateImpl.java:789)
at javax.rmi.CORBA.Util.copyObject(Util.java:332)
at com.websp._TPAController_Stub.getCarrierList(_TPAController_Stub.java:254)
... 27 more
Caused by: java.io.NotSerializableException
... 31 more
P.S. If I change the ArrayList type to Collection in above code, there is a information message prompting "CHKJ2500I: java.util.Collection must be serializable at runtime (EJB 2.0: 7.10.5).". If I use ArrayList, this information message disappear.
Woo! A simple program cause me a lot of time.
Please help! Many thanks!
Raymond
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your CarrierPCls class must implement java.io.Serializable. ALL parameters and return values from an EJB must be serializable, and that includes things included inside of other things.
BTW, ignore the warning about Collection. The ArrayList is Serializable at runtime, so it will work.
Kyle
 
Raymond Ou
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kyle, many many thanks!
I forgot to implement the carrierPCls as serializable! When I correct it, the program runs fine.
Kyle, you are very helpful!
Thanks again!
Raymond
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic