You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Rob Leland <th...@gmail.com> on 2022/09/02 21:49:04 UTC
Tomee 10.0.21 Class cast Exception when undeploying application with @PostConstruct LifeCycle
Summary:
I am seeing the Class cast Exception shown at the bottom when stopping the
container.
The tomee profile I downloaded seems to have the required EE jars under
tomee/lib.
I tried the code on GlassFish 6.2.5 and did not see this error.
Note:
The code I am working with is 2 classes, see below, is from a Book on
Jakarta Persistence.
There may be come issues with the code itself since the Servlet is not
Displayed , but that may also be due to my setup I am still checking.
The WAR WEB-INF/lib folder only has Derby Jars nothing else.
The Repo with this code is at:
https://github.com/free2create/pro-jakarta-persistence-jakarta-ee10
It uses maven to build and after building you would want to deploy:
examples/Chapter3/03-slsbLifecycleExample/servlet/target/ WAR file.
______________
LoggerBean.java:
______________
package examples.stateless;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.Stateless;
import java.util.logging.Logger;
@Stateless
public class LoggerBean {
private Logger logger;
@PostConstruct
private void init() {
logger = Logger.getLogger("notification");
}
public void logMessage(String message) {
logger.info(message);
}
}
_____________
LoggerServlet.java
_____________
package examples.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.naming.InitialContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.ejb.EJB;
import examples.stateless.LoggerBean;
@WebServlet(name="LoggerServlet",
urlPatterns="/LoggerServlet")
public class LoggerServlet extends HttpServlet {
private final String TITLE =
"Chapter 3: Stateless Session Bean Lifecycle Example";
private final String DESCRIPTION =
"This example demonstrates the basic use of lifecycle callbacks to
initialize a Stateless Session Bean. </br>" +
"Enter a and click 'Go'. This will trigger a servlet client that
talks " +
"to a Stateless Session Bean to log a message.";
@EJB LoggerBean logger;
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
printHtmlHeader(out);
// if there was a message submitted, log it
String message = request.getParameter("message");
if (message != null) {
// use the logger bean to log a message
logger.logMessage(message);
out.println("Message '" + message + "' sent to logger. " +
"See the output on the server console or the log file at
<SERVER_ROOT>/glassfish/domains/domain1/logs/server.log.");
}
printHtmlFooter(out);
}
private void printHtmlHeader(PrintWriter out) throws IOException {
//Code Deleted
}
private void printHtmlFooter(PrintWriter out) throws IOException {
//Code Deleted
}
}
__________________________________________
Exception
__________________________________________
02-Sep-2022 16:38:17.996 WARNING [main]
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches
Failed to clear soft references from ObjectStreamClass$Caches for web
application [ch3-03-slsb-servlet-1.0.0]
java.lang.ClassCastException: class java.io.ObjectStreamClass$Caches$1
cannot be cast to class java.util.Map (java.io.ObjectStreamClass$Caches$1
and java.util.Map are in module java.base of loader 'bootstrap')
at
org.apache.catalina.loader.WebappClassLoaderBase.clearCache(WebappClassLoaderBase.java:2374)
at
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches(WebappClassLoaderBase.java:2349)
at
org.apache.catalina.loader.WebappClassLoaderBase.clearReferences(WebappClassLoaderBase.java:1711)
at
org.apache.catalina.loader.WebappClassLoaderBase.stop(WebappClassLoaderBase.java:1639)
at
org.apache.tomee.catalina.TomEEWebappClassLoader.internalStop(TomEEWebappClassLoader.java:306)
at
org.apache.tomee.catalina.TomcatWebAppBuilder.afterStop(TomcatWebAppBuilder.java:2149)
at
org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:127)
at
org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at
org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:265)
at
org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1412)
at
org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1401)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at
org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at
java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at
org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:986)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
at
org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1412)
at
org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1401)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at
org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at
java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at
org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:986)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
at
org.apache.catalina.core.StandardService.stopInternal(StandardService.java:497)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
at
org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:979)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:872)
at org.apache.catalina.startup.Catalina.start(Catalina.java:834)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
Re: Tomee 10.0.21 Class cast Exception when undeploying application with @PostConstruct LifeCycle
Posted by Cesar Hernandez <ce...@gmail.com>.
Hi Rod,
I tested your example code
examples/Chapter3/03-slsbLifecycleExample/servlet/, and it's working now
with latest TomEE 9.0.0-M8:)!.
I see Richard already replied and patched the shutdown exception via
TOMEE-4032 [1], thank you for filling the JIRA and Richard for the patch
and overall follow-up.
[1]
https://issues.apache.org/jira/browse/TOMEE-4032?jql=project%20%3D%20TOMEE%20AND%20fixVersion%20%3D%209.0.0-M9
El vie, 2 sept 2022 a las 17:51, Rob Leland (<th...@gmail.com>)
escribió:
> Thanks, that was the key to fixing the application which now works!
>
> However: I am still seeing the same exception when stopping tomcat:
>
> java.lang.ClassCastException: class java.io.ObjectStreamClass$Caches$1
> cannot be cast to class java.util.Map (java.io.ObjectStreamClass$Caches$1
> and java.util.Map are in module java.base of loader 'bootstrap
>
>
> I tried this under both Java 11 & 17 with the same result....
>
>
>
>
>
>
> On Fri, Sep 2, 2022 at 6:35 PM Cesar Hernandez <ce...@gmail.com>
> wrote:
>
> > Hi Rod,
> >
> > I would assume you are using TomEE 9. x milestone release because you are
> > using the Jakarta namespace. If this is not the case, you can find the
> > latest TomEE 9.x.x-M release here
> https://tomee.apache.org/download.html
> >
> > Indeed your app packaging seems to be missing the actual servlet class, a
> > tree command to the exploited .war does not show the class file for
> > LoggerServlet.java at all.
> >
> > ch3-03-slsb-servlet-1.0.0 tree
> > .
> > ├── META-INF
> > │ ├── MANIFEST.MF
> > │ └── maven
> > │ └── apress.jakarta.persistence.ee10
> > │ └── ch3-03-slsb-servlet
> > │ ├── pom.properties
> > │ └── pom.xml
> > └── WEB-INF
> > ├── classes
> > └── lib
> > ├── ch3-02-slsb-model-1.0.0.jar
> > ├── derby-10.14.2.0.jar
> > ├── derbyclient-10.14.2.0.jar
> > └── derbytools-10.14.2.0.jar
> >
> > 7 directories, 7 files
> >
> >
> >
> > El vie, 2 sept 2022 a las 15:49, Rob Leland (<th...@gmail.com>)
> > escribió:
> >
> > > Summary:
> > >
> > > I am seeing the Class cast Exception shown at the bottom when stopping
> > the
> > > container.
> > > The tomee profile I downloaded seems to have the required EE jars under
> > > tomee/lib.
> > >
> > > I tried the code on GlassFish 6.2.5 and did not see this error.
> > >
> > >
> > > Note:
> > > The code I am working with is 2 classes, see below, is from a Book
> on
> > > Jakarta Persistence.
> > > There may be come issues with the code itself since the Servlet is not
> > > Displayed , but that may also be due to my setup I am still checking.
> > >
> > > The WAR WEB-INF/lib folder only has Derby Jars nothing else.
> > >
> > > The Repo with this code is at:
> > > https://github.com/free2create/pro-jakarta-persistence-jakarta-ee10
> > >
> > > It uses maven to build and after building you would want to deploy:
> > > examples/Chapter3/03-slsbLifecycleExample/servlet/target/ WAR file.
> > >
> > > ______________
> > > LoggerBean.java:
> > > ______________
> > > package examples.stateless;
> > >
> > > import jakarta.annotation.PostConstruct;
> > > import jakarta.ejb.Stateless;
> > > import java.util.logging.Logger;
> > >
> > > @Stateless
> > > public class LoggerBean {
> > > private Logger logger;
> > >
> > > @PostConstruct
> > > private void init() {
> > > logger = Logger.getLogger("notification");
> > > }
> > >
> > > public void logMessage(String message) {
> > > logger.info(message);
> > > }
> > > }
> > > _____________
> > > LoggerServlet.java
> > > _____________
> > >
> > > package examples.servlet;
> > >
> > > import java.io.IOException;
> > > import java.io.PrintWriter;
> > >
> > > import javax.naming.InitialContext;
> > > import jakarta.servlet.ServletException;
> > > import jakarta.servlet.http.HttpServlet;
> > > import jakarta.servlet.http.HttpServletRequest;
> > > import jakarta.servlet.http.HttpServletResponse;
> > > import jakarta.servlet.annotation.WebServlet;
> > > import jakarta.ejb.EJB;
> > >
> > > import examples.stateless.LoggerBean;
> > >
> > > @WebServlet(name="LoggerServlet",
> > > urlPatterns="/LoggerServlet")
> > > public class LoggerServlet extends HttpServlet {
> > >
> > > private final String TITLE =
> > > "Chapter 3: Stateless Session Bean Lifecycle Example";
> > >
> > > private final String DESCRIPTION =
> > > "This example demonstrates the basic use of lifecycle callbacks
> > to
> > > initialize a Stateless Session Bean. </br>" +
> > > "Enter a and click 'Go'. This will trigger a servlet client
> that
> > > talks " +
> > > "to a Stateless Session Bean to log a message.";
> > >
> > > @EJB LoggerBean logger;
> > >
> > > public void doGet(HttpServletRequest request, HttpServletResponse
> > > response) throws ServletException, IOException {
> > > response.setContentType("text/html");
> > > PrintWriter out = response.getWriter();
> > > printHtmlHeader(out);
> > >
> > > // if there was a message submitted, log it
> > > String message = request.getParameter("message");
> > > if (message != null) {
> > > // use the logger bean to log a message
> > > logger.logMessage(message);
> > > out.println("Message '" + message + "' sent to logger. " +
> > > "See the output on the server console or the log file at
> > > <SERVER_ROOT>/glassfish/domains/domain1/logs/server.log.");
> > > }
> > >
> > > printHtmlFooter(out);
> > > }
> > >
> > >
> > > private void printHtmlHeader(PrintWriter out) throws IOException {
> > > //Code Deleted
> > > }
> > >
> > >
> > > private void printHtmlFooter(PrintWriter out) throws IOException {
> > > //Code Deleted
> > > }
> > > }
> > >
> > > __________________________________________
> > > Exception
> > > __________________________________________
> > >
> > >
> > >
> > > 02-Sep-2022 16:38:17.996 WARNING [main]
> > >
> > >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches
> > > Failed to clear soft references from ObjectStreamClass$Caches for web
> > > application [ch3-03-slsb-servlet-1.0.0]
> > > java.lang.ClassCastException: class java.io.ObjectStreamClass$Caches$1
> > > cannot be cast to class java.util.Map
> (java.io.ObjectStreamClass$Caches$1
> > > and java.util.Map are in module java.base of loader 'bootstrap')
> > > at
> > >
> > >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.clearCache(WebappClassLoaderBase.java:2374)
> > > at
> > >
> > >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches(WebappClassLoaderBase.java:2349)
> > > at
> > >
> > >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferences(WebappClassLoaderBase.java:1711)
> > > at
> > >
> > >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.stop(WebappClassLoaderBase.java:1639)
> > > at
> > >
> > >
> >
> org.apache.tomee.catalina.TomEEWebappClassLoader.internalStop(TomEEWebappClassLoader.java:306)
> > > at
> > >
> > >
> >
> org.apache.tomee.catalina.TomcatWebAppBuilder.afterStop(TomcatWebAppBuilder.java:2149)
> > > at
> > >
> > >
> >
> org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:127)
> > > at
> > >
> > >
> >
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
> > > at
> > >
> > >
> >
> org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
> > > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:265)
> > > at
> > >
> > >
> >
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1412)
> > > at
> > >
> > >
> >
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1401)
> > > at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> > > at
> > >
> > >
> >
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> > > at
> > >
> > >
> >
> java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
> > > at
> > >
> >
> org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:986)
> > > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> > > at
> > >
> > >
> >
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1412)
> > > at
> > >
> > >
> >
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1401)
> > > at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> > > at
> > >
> > >
> >
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> > > at
> > >
> > >
> >
> java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
> > > at
> > >
> >
> org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:986)
> > > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> > > at
> > >
> > >
> >
> org.apache.catalina.core.StandardService.stopInternal(StandardService.java:497)
> > > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> > > at
> > >
> > >
> >
> org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:979)
> > > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> > > at org.apache.catalina.startup.Catalina.stop(Catalina.java:872)
> > > at org.apache.catalina.startup.Catalina.start(Catalina.java:834)
> > > at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > Method)
> > > at
> > >
> > >
> >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
> > > at
> > >
> > >
> >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > at java.base/java.lang.reflect.Method.invoke(Method.java:568)
> > > at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
> > > at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
> > >
> >
> >
> > --
> > Atentamente:
> > César Hernández.
> >
>
--
Atentamente:
César Hernández.
Re: Tomee 10.0.21 Class cast Exception when undeploying application with @PostConstruct LifeCycle
Posted by Rob Leland <th...@gmail.com>.
Thanks, that was the key to fixing the application which now works!
However: I am still seeing the same exception when stopping tomcat:
java.lang.ClassCastException: class java.io.ObjectStreamClass$Caches$1
cannot be cast to class java.util.Map (java.io.ObjectStreamClass$Caches$1
and java.util.Map are in module java.base of loader 'bootstrap
I tried this under both Java 11 & 17 with the same result....
On Fri, Sep 2, 2022 at 6:35 PM Cesar Hernandez <ce...@gmail.com> wrote:
> Hi Rod,
>
> I would assume you are using TomEE 9. x milestone release because you are
> using the Jakarta namespace. If this is not the case, you can find the
> latest TomEE 9.x.x-M release here https://tomee.apache.org/download.html
>
> Indeed your app packaging seems to be missing the actual servlet class, a
> tree command to the exploited .war does not show the class file for
> LoggerServlet.java at all.
>
> ch3-03-slsb-servlet-1.0.0 tree
> .
> ├── META-INF
> │ ├── MANIFEST.MF
> │ └── maven
> │ └── apress.jakarta.persistence.ee10
> │ └── ch3-03-slsb-servlet
> │ ├── pom.properties
> │ └── pom.xml
> └── WEB-INF
> ├── classes
> └── lib
> ├── ch3-02-slsb-model-1.0.0.jar
> ├── derby-10.14.2.0.jar
> ├── derbyclient-10.14.2.0.jar
> └── derbytools-10.14.2.0.jar
>
> 7 directories, 7 files
>
>
>
> El vie, 2 sept 2022 a las 15:49, Rob Leland (<th...@gmail.com>)
> escribió:
>
> > Summary:
> >
> > I am seeing the Class cast Exception shown at the bottom when stopping
> the
> > container.
> > The tomee profile I downloaded seems to have the required EE jars under
> > tomee/lib.
> >
> > I tried the code on GlassFish 6.2.5 and did not see this error.
> >
> >
> > Note:
> > The code I am working with is 2 classes, see below, is from a Book on
> > Jakarta Persistence.
> > There may be come issues with the code itself since the Servlet is not
> > Displayed , but that may also be due to my setup I am still checking.
> >
> > The WAR WEB-INF/lib folder only has Derby Jars nothing else.
> >
> > The Repo with this code is at:
> > https://github.com/free2create/pro-jakarta-persistence-jakarta-ee10
> >
> > It uses maven to build and after building you would want to deploy:
> > examples/Chapter3/03-slsbLifecycleExample/servlet/target/ WAR file.
> >
> > ______________
> > LoggerBean.java:
> > ______________
> > package examples.stateless;
> >
> > import jakarta.annotation.PostConstruct;
> > import jakarta.ejb.Stateless;
> > import java.util.logging.Logger;
> >
> > @Stateless
> > public class LoggerBean {
> > private Logger logger;
> >
> > @PostConstruct
> > private void init() {
> > logger = Logger.getLogger("notification");
> > }
> >
> > public void logMessage(String message) {
> > logger.info(message);
> > }
> > }
> > _____________
> > LoggerServlet.java
> > _____________
> >
> > package examples.servlet;
> >
> > import java.io.IOException;
> > import java.io.PrintWriter;
> >
> > import javax.naming.InitialContext;
> > import jakarta.servlet.ServletException;
> > import jakarta.servlet.http.HttpServlet;
> > import jakarta.servlet.http.HttpServletRequest;
> > import jakarta.servlet.http.HttpServletResponse;
> > import jakarta.servlet.annotation.WebServlet;
> > import jakarta.ejb.EJB;
> >
> > import examples.stateless.LoggerBean;
> >
> > @WebServlet(name="LoggerServlet",
> > urlPatterns="/LoggerServlet")
> > public class LoggerServlet extends HttpServlet {
> >
> > private final String TITLE =
> > "Chapter 3: Stateless Session Bean Lifecycle Example";
> >
> > private final String DESCRIPTION =
> > "This example demonstrates the basic use of lifecycle callbacks
> to
> > initialize a Stateless Session Bean. </br>" +
> > "Enter a and click 'Go'. This will trigger a servlet client that
> > talks " +
> > "to a Stateless Session Bean to log a message.";
> >
> > @EJB LoggerBean logger;
> >
> > public void doGet(HttpServletRequest request, HttpServletResponse
> > response) throws ServletException, IOException {
> > response.setContentType("text/html");
> > PrintWriter out = response.getWriter();
> > printHtmlHeader(out);
> >
> > // if there was a message submitted, log it
> > String message = request.getParameter("message");
> > if (message != null) {
> > // use the logger bean to log a message
> > logger.logMessage(message);
> > out.println("Message '" + message + "' sent to logger. " +
> > "See the output on the server console or the log file at
> > <SERVER_ROOT>/glassfish/domains/domain1/logs/server.log.");
> > }
> >
> > printHtmlFooter(out);
> > }
> >
> >
> > private void printHtmlHeader(PrintWriter out) throws IOException {
> > //Code Deleted
> > }
> >
> >
> > private void printHtmlFooter(PrintWriter out) throws IOException {
> > //Code Deleted
> > }
> > }
> >
> > __________________________________________
> > Exception
> > __________________________________________
> >
> >
> >
> > 02-Sep-2022 16:38:17.996 WARNING [main]
> >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches
> > Failed to clear soft references from ObjectStreamClass$Caches for web
> > application [ch3-03-slsb-servlet-1.0.0]
> > java.lang.ClassCastException: class java.io.ObjectStreamClass$Caches$1
> > cannot be cast to class java.util.Map (java.io.ObjectStreamClass$Caches$1
> > and java.util.Map are in module java.base of loader 'bootstrap')
> > at
> >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.clearCache(WebappClassLoaderBase.java:2374)
> > at
> >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches(WebappClassLoaderBase.java:2349)
> > at
> >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferences(WebappClassLoaderBase.java:1711)
> > at
> >
> >
> org.apache.catalina.loader.WebappClassLoaderBase.stop(WebappClassLoaderBase.java:1639)
> > at
> >
> >
> org.apache.tomee.catalina.TomEEWebappClassLoader.internalStop(TomEEWebappClassLoader.java:306)
> > at
> >
> >
> org.apache.tomee.catalina.TomcatWebAppBuilder.afterStop(TomcatWebAppBuilder.java:2149)
> > at
> >
> >
> org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:127)
> > at
> >
> >
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
> > at
> >
> >
> org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
> > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:265)
> > at
> >
> >
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1412)
> > at
> >
> >
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1401)
> > at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> > at
> >
> >
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> > at
> >
> >
> java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
> > at
> >
> org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:986)
> > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> > at
> >
> >
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1412)
> > at
> >
> >
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1401)
> > at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> > at
> >
> >
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> > at
> >
> >
> java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
> > at
> >
> org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:986)
> > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> > at
> >
> >
> org.apache.catalina.core.StandardService.stopInternal(StandardService.java:497)
> > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> > at
> >
> >
> org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:979)
> > at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> > at org.apache.catalina.startup.Catalina.stop(Catalina.java:872)
> > at org.apache.catalina.startup.Catalina.start(Catalina.java:834)
> > at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> > at
> >
> >
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
> > at
> >
> >
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > at java.base/java.lang.reflect.Method.invoke(Method.java:568)
> > at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
> > at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
> >
>
>
> --
> Atentamente:
> César Hernández.
>
Re: Tomee 10.0.21 Class cast Exception when undeploying application with @PostConstruct LifeCycle
Posted by Cesar Hernandez <ce...@gmail.com>.
Hi Rod,
I would assume you are using TomEE 9. x milestone release because you are
using the Jakarta namespace. If this is not the case, you can find the
latest TomEE 9.x.x-M release here https://tomee.apache.org/download.html
Indeed your app packaging seems to be missing the actual servlet class, a
tree command to the exploited .war does not show the class file for
LoggerServlet.java at all.
ch3-03-slsb-servlet-1.0.0 tree
.
├── META-INF
│ ├── MANIFEST.MF
│ └── maven
│ └── apress.jakarta.persistence.ee10
│ └── ch3-03-slsb-servlet
│ ├── pom.properties
│ └── pom.xml
└── WEB-INF
├── classes
└── lib
├── ch3-02-slsb-model-1.0.0.jar
├── derby-10.14.2.0.jar
├── derbyclient-10.14.2.0.jar
└── derbytools-10.14.2.0.jar
7 directories, 7 files
El vie, 2 sept 2022 a las 15:49, Rob Leland (<th...@gmail.com>)
escribió:
> Summary:
>
> I am seeing the Class cast Exception shown at the bottom when stopping the
> container.
> The tomee profile I downloaded seems to have the required EE jars under
> tomee/lib.
>
> I tried the code on GlassFish 6.2.5 and did not see this error.
>
>
> Note:
> The code I am working with is 2 classes, see below, is from a Book on
> Jakarta Persistence.
> There may be come issues with the code itself since the Servlet is not
> Displayed , but that may also be due to my setup I am still checking.
>
> The WAR WEB-INF/lib folder only has Derby Jars nothing else.
>
> The Repo with this code is at:
> https://github.com/free2create/pro-jakarta-persistence-jakarta-ee10
>
> It uses maven to build and after building you would want to deploy:
> examples/Chapter3/03-slsbLifecycleExample/servlet/target/ WAR file.
>
> ______________
> LoggerBean.java:
> ______________
> package examples.stateless;
>
> import jakarta.annotation.PostConstruct;
> import jakarta.ejb.Stateless;
> import java.util.logging.Logger;
>
> @Stateless
> public class LoggerBean {
> private Logger logger;
>
> @PostConstruct
> private void init() {
> logger = Logger.getLogger("notification");
> }
>
> public void logMessage(String message) {
> logger.info(message);
> }
> }
> _____________
> LoggerServlet.java
> _____________
>
> package examples.servlet;
>
> import java.io.IOException;
> import java.io.PrintWriter;
>
> import javax.naming.InitialContext;
> import jakarta.servlet.ServletException;
> import jakarta.servlet.http.HttpServlet;
> import jakarta.servlet.http.HttpServletRequest;
> import jakarta.servlet.http.HttpServletResponse;
> import jakarta.servlet.annotation.WebServlet;
> import jakarta.ejb.EJB;
>
> import examples.stateless.LoggerBean;
>
> @WebServlet(name="LoggerServlet",
> urlPatterns="/LoggerServlet")
> public class LoggerServlet extends HttpServlet {
>
> private final String TITLE =
> "Chapter 3: Stateless Session Bean Lifecycle Example";
>
> private final String DESCRIPTION =
> "This example demonstrates the basic use of lifecycle callbacks to
> initialize a Stateless Session Bean. </br>" +
> "Enter a and click 'Go'. This will trigger a servlet client that
> talks " +
> "to a Stateless Session Bean to log a message.";
>
> @EJB LoggerBean logger;
>
> public void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> response.setContentType("text/html");
> PrintWriter out = response.getWriter();
> printHtmlHeader(out);
>
> // if there was a message submitted, log it
> String message = request.getParameter("message");
> if (message != null) {
> // use the logger bean to log a message
> logger.logMessage(message);
> out.println("Message '" + message + "' sent to logger. " +
> "See the output on the server console or the log file at
> <SERVER_ROOT>/glassfish/domains/domain1/logs/server.log.");
> }
>
> printHtmlFooter(out);
> }
>
>
> private void printHtmlHeader(PrintWriter out) throws IOException {
> //Code Deleted
> }
>
>
> private void printHtmlFooter(PrintWriter out) throws IOException {
> //Code Deleted
> }
> }
>
> __________________________________________
> Exception
> __________________________________________
>
>
>
> 02-Sep-2022 16:38:17.996 WARNING [main]
>
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches
> Failed to clear soft references from ObjectStreamClass$Caches for web
> application [ch3-03-slsb-servlet-1.0.0]
> java.lang.ClassCastException: class java.io.ObjectStreamClass$Caches$1
> cannot be cast to class java.util.Map (java.io.ObjectStreamClass$Caches$1
> and java.util.Map are in module java.base of loader 'bootstrap')
> at
>
> org.apache.catalina.loader.WebappClassLoaderBase.clearCache(WebappClassLoaderBase.java:2374)
> at
>
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches(WebappClassLoaderBase.java:2349)
> at
>
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferences(WebappClassLoaderBase.java:1711)
> at
>
> org.apache.catalina.loader.WebappClassLoaderBase.stop(WebappClassLoaderBase.java:1639)
> at
>
> org.apache.tomee.catalina.TomEEWebappClassLoader.internalStop(TomEEWebappClassLoader.java:306)
> at
>
> org.apache.tomee.catalina.TomcatWebAppBuilder.afterStop(TomcatWebAppBuilder.java:2149)
> at
>
> org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:127)
> at
>
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
> at
>
> org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
> at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:265)
> at
>
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1412)
> at
>
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1401)
> at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> at
>
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> at
>
> java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
> at
> org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:986)
> at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> at
>
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1412)
> at
>
> org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1401)
> at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> at
>
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> at
>
> java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
> at
> org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:986)
> at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> at
>
> org.apache.catalina.core.StandardService.stopInternal(StandardService.java:497)
> at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> at
>
> org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:979)
> at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
> at org.apache.catalina.startup.Catalina.stop(Catalina.java:872)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:834)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
> at
>
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
> at
>
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base/java.lang.reflect.Method.invoke(Method.java:568)
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
>
--
Atentamente:
César Hernández.