Link to home
Start Free TrialLog in
Avatar of Manikandan Thiagarajan
Manikandan ThiagarajanFlag for India

asked on

Please solve my error in ehcache

Aug 24, 2012 11:02:03 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: net.sf.ehcache.Element cannot be cast to javax.servlet.http.HttpSession
      at com.sm.GlobalCacheDataStore2.getChildSessionObj(GlobalCacheDataStore2.java:84)
      at org.apache.jsp.moreCourseInfo2_jsp._jspService(moreCourseInfo2_jsp.java:105)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Thread.java:662)

this is my code

       public static HttpSession getChildSessionObj(String sessID)  
       {  
             widgetCache = cacheManager.getEhcache( "widgets" );
             Element element = widgetCache.get( sessID );
              if( element != null )
              {
                    
                  // Get the value out of the element and cast it to a Widget
                  return (HttpSession) element.getValue();
              }
              return null;
       }

i am calling here

  HttpSession curSess;
        if(curSessId!=null)
        {
              GlobalCacheDataStore2.setChildSessionIdForParentSessionId(parentSessionId, curSessId);
              curSess = GlobalCacheDataStore2.getChildSessionObj(curSessId);
              curSess.setMaxInactiveInterval(val);

that time it provides class cast exception for httpsession in ehcache

please help me
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

  // Get the value out of the element and cast it to a Widget
                  return (HttpSession) element.getValue();

Open in new window


... but you're not doing that. You're casting it to an HttpSession. Why?
Avatar of Manikandan Thiagarajan

ASKER

that is example program so it contains that statement.

my program only returns httpsession at that time it would provide class cast exception
Sorry - i don't understand that. A ClassCastException is pretty simple really - you're trying to cast the object to a type that is foreign to it, so it will fail.
ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
?