NoClassDefFoundError: Could not initialize class java.awt.image.DataBuffer --> When try to load a PNG Image in Spring Boot - spring-boot

I have a Spring Boot app that basically receives a JSON from the client side and create/return a PDF.
I can load JPG images without problem. But when I load PNG files I have this exception. My Spring Boot "war" app is running inside a Tomcat.
If I execute the Spring Boot app by "java -jar ...", it works well.
Apache Tomcat/9.0.29
Headless OpenJDK 64-Bit VM 1.8
Spring Boot 2.2.1
OpenPDF 1.3
CentOS Linux 7
2020-02-24 01:57:14,042 ERROR [http-nio-8080-exec-217] org.springframework.boot.web.servlet.support.ErrorPageFilter: Forwarding to error page from request [/pdf/create] due to exception [Could not initialize class java.awt.image.DataBuffer]
java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.DataBuffer
at javax.imageio.ImageTypeSpecifier.createComponentCM(ImageTypeSpecifier.java:249)
at javax.imageio.ImageTypeSpecifier$Interleaved.<init>(ImageTypeSpecifier.java:305)
at javax.imageio.ImageTypeSpecifier.createInterleaved(ImageTypeSpecifier.java:399)
at javax.imageio.ImageTypeSpecifier.createSpecifier(ImageTypeSpecifier.java:1169)
at javax.imageio.ImageTypeSpecifier.getSpecifier(ImageTypeSpecifier.java:1118)
at javax.imageio.ImageTypeSpecifier.createFromBufferedImageType(ImageTypeSpecifier.java:901)
at com.sun.imageio.plugins.png.PNGImageReader.getImageTypes(PNGImageReader.java:1531)
at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1318)
at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1614)
at javax.imageio.ImageIO.read(ImageIO.java:1462)
at javax.imageio.ImageIO.read(ImageIO.java:1357)
at com.lowagie.text.ImageLoader.getPngImage(ImageLoader.java:76)
at com.lowagie.text.Image.getInstance(Image.java:284)
at com.company.myapp.service.pdf.pages.Page00.render(Page00.java:69)
at com.company.myapp.service.pdf.pages.PageImpl.<init>(PageImpl.java:27)
at com.company.myapp.service.pdf.pages.Page00.<init>(Page00.java:21)
at com.company.myapp.service.PdfServiceImpl.getPDF(PdfServiceImpl.java:33)
at com.company.myapp.controller.PdfController.generate(PdfController.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Related

Spring Boot 3 and JSP application won't run as standalone

I upgraded a JSP application to Spring Boot 3 and now it won't start when running as a standalone application.
If I start the application using gradle bootRun it runs fine.
When runing it using java -jar oldnewjspapp.war I get the following stacktrace:
ERROR 7082 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164) ~[spring-boot-3.0.1.jar!/:3.0.1]
...
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-3.0.1.jar!/:3.0.1]
...
Caused by: java.lang.IllegalStateException: zip file closed
at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:831) ~[na:na]
at java.base/java.util.zip.ZipFile.getManifestName(ZipFile.java:1057) ~[na:na]
at java.base/java.util.zip.ZipFile$1.getManifestName(ZipFile.java:1100) ~[na:na]
at java.base/java.util.jar.JarFile.getManEntry(JarFile.java:937) ~[na:na]
at java.base/java.util.jar.JarFile.checkForSpecialAttributes(JarFile.java:1000) ~[na:na]
at java.base/java.util.jar.JarFile.isMultiRelease(JarFile.java:389) ~[na:na]
at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:68) ~[tomcat-embed-core-10.1.4.jar!/:na]
Does anyone have a solution?
Spring Boot 3 JSP support is broken:
Spring boot app's .jar not working (issue with tomcat-embed-jasper)
https://github.com/spring-projects/spring-boot/issues/33633
https://github.com/spring-projects/spring-boot/issues/32106
The alternatives are:
downgrade your Spring Boot version
extract the war contents and run it that way
generate a regular war (gradle war) and publish it in your favourite web server
turn off the support for Multi-Release JAR Files (this feature is present in Java since release 9): java -Djdk.util.jar.enableMultiRelease=false -jar oldnewjspapp.war

Problem when deploying project with web socket on Jetty 9.2.13.v20150730

I've experienced a problem while migrating an app from PrimeFaces 5.2 to 10.
This problem is related to migration of web socket implementation from Primefaces to Omnifaces.
The versions I'm using:
PF: 10.0.0
PF extensions: 10.0.6
Omnifaces 2.7.7
CDI 1.1
JSF 2.2
I don't have anything fancy, just a simple PushBean which sends a message.
I've tried downgrading to PF8, but, as expected, the result is the same.
The configuration is made as requested in the documentation, in my web.xml file having this flag enabled:
<context-param>
<param-name>org.omnifaces.SOCKET_ENDPOINT_ENABLED</param-name>
<param-value>true</param-value>
</context-param>
However, when I try to deploy my app to jetty, I'm receiving the following error:
java.lang.IllegalStateException: OmniFaces failed to initialize! Report an issue to OmniFaces.
at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:88)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444)
.
.
.
Caused by: java.lang.RuntimeException: Cannot load platform configurator
at javax.websocket.server.ServerEndpointConfig$Configurator.fetchContainerDefaultConfigurator(ServerEndpointConfig.java:123)
at javax.websocket.server.DefaultServerEndpointConfig.<init>(DefaultServerEndpointConfig.java:85)
at javax.websocket.server.ServerEndpointConfig$Builder.build(ServerEndpointConfig.java:301)
at org.omnifaces.cdi.push.Socket.registerEndpointIfNecessary(Socket.java:1114)
at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:85)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294)
I'm guessing that there is something that I'm not doing right, but, I don't know exactly what is it.
Can you please, give a little hand?
Thanks in advance!
The stacktrace / exception ...
Caused by: java.lang.RuntimeException: Cannot load platform configurator
at javax.websocket.server.ServerEndpointConfig$Configurator.fetchContainerDefaultConfigurator(ServerEndpointConfig.java:123)
at javax.websocket.server.DefaultServerEndpointConfig.<init>(DefaultServerEndpointConfig.java:85)
at javax.websocket.server.ServerEndpointConfig$Builder.build(ServerEndpointConfig.java:301)
This is coming from the javax.websocket API jar, when it attempts to find the Server Container Default Configuration (in other words, the implementation specific defaults, which would be Jetty)
If you are running Jetty, you need to be including the jetty support jar for javax.websocket.server in your classpath.
Which on Jetty 9.2.x would be the javax-websocket-server-impl-<ver>.jar file (and associated dependencies).
Per #BalusC, omnifaces is just a web-fragment deployed in your WAR's WEB-INF/lib.
That means you have to enable support for websocket on the Jetty server side.
For standalone (using ${jetty.base} and ${jetty.home} split) this means enabling the correct module for your version of Jetty.
Jetty ver
WebSocket spec
Module
Jetty 8.x and older
n/a
n/a
Jetty 9.0.x
n/a
n/a
Jetty 9.1.x
javax.websocket (beta)
websocket
Jetty 9.2.x - 9.4.x
javax.websocket 1.0
websocket
Jetty 10.0.x
javax.websocket 1.1
websocket-javax
Jetty 11.0.x
jakarta.websocket 2.0
websocket-jakarta
To do that you'll use the command line.
Jetty 9.x
[~]$ cd /path/to/my-jetty-base
[my-jetty-base]$ java -jar /path/to/jetty-home/start.jar
--add-to-start=websocket
Jetty 10+
[~]$ cd /path/to/my-jetty-base
[my-jetty-base]$ java -jar /path/to/jetty-home/start.jar
--add-module=websocket-javax

Websphere 8.5.5 - spring boot error: SpringServletContainerInitializer not a subtype

I have a spring boot application that works fine on Tomcat 8. When I try to deploy it on Websphere 8.5.5 with "Class loader order" set to "Classes loaded with local class loader first (parent last)" the application fails to start with the following exception:
... 73 more
Caused by: java.util.ServiceConfigurationError: javax.servlet.ServletContainerInitializer: Provider org.springframework.web.SpringServletContainerInitializer not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:242)
at java.util.ServiceLoader.access$300(ServiceLoader.java:192)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:380)
at java.util.ServiceLoader$1.next(ServiceLoader.java:456)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initializeServletContainerInitializers(WebAppImpl.java:537)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:410)
at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)
at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:171)
... 74 more
Just adding my experience with this problem, looking around on the various answers to similar problems I found out that the problem could be caused by some javax-servlet related jar in the classpath. After some trial and error I noticed that the spring-boot-starter-web dependency has an inherited spring-boot-starter-tomcat dependency. Excludung this jar from the application classpath when deploying on Websphere 8.5.5 solved the problem.

Issue in Jboss 7.2.2 migration

I am deploying a WAR file to JBoss EAP 7.2.2. During deployment, I am getting
"Caused by: java.lang.IllegalArgumentException: Unable to load generated mapper class com.amadeus.jcp.services.ttr.display.structured.builder.response.selma.mapper.offer.DisplayTripCartResponseOfferQuotationMapperSelmaGeneratedClass"
which is caused by "Caused by: java.lang.ClassNotFoundException: com.amadeus.jcp.services.ttr.display.structured.builder.response.selma.mapper.offer.DisplayTripCartResponseOfferQuotationMapperSelmaGeneratedClass"
It is a selma generated class and available in a jar inside WEB-INF/lib.
Same WAR file is deploying successfully in JBoss EAP 7.1.
As per class loader hierarchy, it should be identified but not happening.
Anybody have any idea of this issue, please help.
Verified standalone.xml and jboss-deployment-structure.xml. Using same version before and after migration except for name space version upgrade to subsystems.
Using Java 1.8.0_191

Is apache camel compatible with Springboot 2.0?

Which version of apache-camel is compatible with Springboot 2.0?
I keep getting this error
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver
at java.net.URLClassLoader.findClass (URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass (ClassLoader.java:424)
at java.lang.ClassLoader.loadClass (ClassLoader.java:357)
at org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator.isEnabled (HierarchicalPropertiesEvaluator.java:49)
at org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator.evaluate (HierarchicalPropertiesEvaluator.java:42)
at org.apache.camel.spring.boot.util.GroupCondition.getMatchOutcome (GroupCondition.java:40)
It is not yet compatible as it is using Spring 1.15.x. support is planned for Camel 2.22.
Migrated Spring boot 1.5 to 2.0, unable to start app getting: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver

Resources