[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1023
  • Last Modified:

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
0
Manikandan Thiagarajan
Asked:
Manikandan Thiagarajan
  • 3
1 Solution
 
CEHJCommented:
  // 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?
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
that is example program so it contains that statement.

my program only returns httpsession at that time it would provide class cast exception
0
 
CEHJCommented:
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.
0
 
cmalakarCommented:
before the following line...
   return (HttpSession) element.getValue();

Open in new window


put the following line to see what is the type of the object that is stored in ehcache.

System.out.println(element.getObjectValue().getClass().getName());

Open in new window

0
 
CEHJCommented:
?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now