Upgraded Spring, Now Freemarker throws NoSutchMethod error - java

I had a perfectly working Spring applicaton (4.2.7 -> 4.3.7) Simple upgrade, but now when I deploy catalina.out is giving me a:
Caused by: java.lang.NoSuchMethodError: freemarker.template.Configuration.<init>(Lfreemarker/template/Version;)V
at org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.newConfiguration(FreeMarkerConfigurationFactory.java:320)
I looked through the API but doesn't look like anything changed. I also can confirm the freemarker-2.3.20.jar is in the lib directory, but this looks like a spring issue

Took a bit of searching, but Spring also upgraded Freemarker to 2.3.23 -- So use that in your pom and it should work.

Related

NoSuchMethodError in org.json.JSONObject after kubernetes upgrade from 1.21 to 1.23

I don't know if the kubernetes upgrade has anything to do with the problem, but it's the only change I know of between the time the application was working as expected and when it started throwing this exception.
I have some code in a Spring Boot app that adds a List<Object> to a JSONObject. The line looks like this:
jsonObject.put("some_name", someList);
This code hasn't been touched in a year, but suddenly started throwing this exception after a k8s upgrade from 1.21 to 1.23:
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'org.json.JSONObject org.json.JSONObject.put(java.lang.String, java.util.Collection)' at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082)
[...]
Caused by: java.lang.NoSuchMethodError: 'org.json.JSONObject org.json.JSONObject.put(java.lang.String, java.util.Collection)' at com.example.service.MyClass.convertToJson(MyClass.java:109)
The k8s upgrade also included a change from Java 17.0.5+8 to Java 17.0.6+10, but everything runs as expected locally using both of those JDK versions.
I ran a mvn dependency tree -Dverbose and couldn't find anything weird there either. These were the only entries that had to do with json.
org.json:json:jar:20220320
org.springframework.boot:spring-boot-starter-json:jar:2.6.4
I'm out of ideas for what might be causing this issue, so any suggestions on what to look at next are welcome.
It could be that the version of org.json:json included in your project is out of date, and doesn't include the put(String, Collection) method you're trying to use. Try updating this dependency to a more recent version and seeing if that resolves the issue. It's also possible there are some other dependencies in your project which conflict with org.json:json or override it with an older version - check for any similarly named libraries (e.g., json-simple instead of org.json). You may also want to check the version of Spring Boot you're using, as this might be incompatible with the org.json library you're trying to use.

Spring boot 2.2.6 application with apache axis Issue

My question is similar to this one (Spring boot application with apache axis) but I am running Spring Boot v2.2.6. When I execute the command
java -jar -Dspring.profiles.active=local myjar-0.0.1-SNAPSHOT.jar
I get the error
2021-06-01 00:41:53,152 myjar [http-nio-9090-exec-1] ERROR
org.apache.axis2.deployment.ModuleDeployer - deploy:94 - The addressing-1.6.3-classpath-
module.jar module, which is not valid, caused The /Users/xxxx/workspace/myjar/build/libs/myjar-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/addressing-1.6.3-classpath-
module.jar file cannot be found.
org.apache.axis2.AxisFault: The /Users/xxxx/workspace/.../build/libs/myjar-0.0.1-
SNAPSHOT.jar!/BOOT-INF/lib/addressing-1.6.3-classpath-module.jar file cannot be found.
I also have the relevant build.gradle snippet
api "org.apache.axis2:addressing:1.6.3:classpath-module"
api "org.apache.axis2:axis2:1.6.3"
api "org.apache.axis2:axis2-adb:1.6.3"
api "org.apache.axis2:axis2-transport-local:1.6.3"
api "org.apache.axis2:axis2-transport-http:1.6.3"
I confirmed that the file /Users/xxxx/workspace/myjar/build/libs/myjar-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/addressing-1.6.3-classpath-module.jar does exist. Can anyone help fix this issue?
It looks like Axis cannot cope with one jar file being nested inside another. For situations like this, you can configure Spring Boot to automatically unpack the nested jar when you start your application:
bootJar {
requiresUnpack '**/addressing-*-classpath-module.jar'
}

Spring-webflux application startup failures

The application is failing during the startup with this error:
The bean 'requestDataValueProcessor', defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebMvcSecurityConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.class] and overriding is disabled.
All team members have the same problem and it seems that even if we're checking out an old git tag, the same problem persist. We've checked all the build files and dependencies, and nothing seemed to be changed in the last period of time. What's even more interesting is that the Bamboo seemed to run the build and the IT's pack with success with a day before, but today's morning it seem that the same issue is replicated there.
Not sure exactly why is complaining about WebMvcSecurityConfiguration, since we're using only reactive security in our project. So at this point we don't have any spring-mvc dependencies..
Does anyone have any clue ? Thx
So after we've enabled debug level logs on spring and force spring app to use only the reactive configurations like this:
spring:
main:
web-application-type: reactive
it seemed that the springfox dependencies were failing with:
java.lang.NoSuchMethodError: org.springframework.util.MultiValueMap.addIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)V
at springfox.documentation.spring.web.scanners.ModelSpecificationRegistryBuilder.lambda$add$0(ModelSpecificationRegistryBuilder.java:37)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at springfox.documentation.spring.web.scanners.ModelSpecificationRegistryBuilder.add(ModelSpecificationRegistryBuilder.java:34)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at
So that error ^^^ point us towards sprinfox dependencies which were:
compile ("io.springfox:springfox-swagger-ui:3.0.0-SNAPSHOT")
compile ("io.springfox:springfox-swagger2:3.0.0-SNAPSHOT")
compile ("io.springfox:springfox-spring-webflux:3.0.0-SNAPSHOT")
After furthermore investigation, it seemed that some of those contains the spring-mvc dependency and that interfere with the spring-webflux one, and the application got confused which beans to inject.
We've downgrade those dependencies to 2.10.0, and everything seems to work now. My guess is that they've made some releases with that snapshot version and that include spring mvc, but until now it was absent. Lesson learned, never use some external libraries snapshots versions, otherwise you could end up in a very bad situation.
X.X.X-SNAPSHOT Dependencies are not the stable ones.
we were using <springfox.version>3.0.0-SNAPSHOT</springfox.version> which suddenly stopped working.
So below solution worked for us.
<springfox.version>2.10.5</springfox.version>
Cheers!!

How to fix 'javax.xml.parsers.FactoryConfigurationError on every second server startup'

I'm writing a web application which uses JAXB and JAX-RS. The content-type used for getting/sending data to the server is XML. The web application runs in a GlassFish server(4.1.2/ 5), the JDK used is 1.8.
The problem is that the internal SAXParser allows doctype declarations which makes XEE-Attacks possible. I'm not able to inject the specific feature into the SAXParserFactory, so i built a wrapper for the SAXParserFactory, which sets the feature. The SAXParserFactory is registered using the system properties.
System.setProperty("javax.xml.parsers.SAXParserFactory","de.mycompany.sdk.parser.SAXParserFactoryWrapper");
Unfortunately, the server throws a ClassNotFoundException on every second startup, otherwise the application behaves normal.
Has anyone ideas how to fix it?
I've also tried to include the jar into the class path or specify it using the manifest, but did not work neither.
I get the following error:
javax.xml.parsers.FactoryConfigurationError: Provider de.mycompany.sdk.parser.SAXParserFactoryWrapper not found
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:200)
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:152)
at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:232)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.getSAXParser(DeploymentDescriptorFile.java:125)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:305)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:245)
Caused by: java.lang.ClassNotFoundException: de/mycompany/sdk/parser/SAXParserFactoryWrapper
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at javax.xml.parsers.FactoryFinder.getProviderClass(FactoryFinder.java:124)
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:188)
... 56 more```
ClassNotFoundException
can occur if you have multiple versions of a class (de.mycompany.sdk.parser.SAXParserFactoryWrapper in this case) in your class path. This generally happens when you have multiple versions of the same library in your classpath.
Thanks for your help! I found a solution for my problem. I deployed the application using the GlassFish CLI and it works! The previous tries were done using NetBeans. It seems that NetBeans does anything different during the startup or shutdown process of the GlassFish server wich involves the exception.

JSF / Spring Security : view wrapper generates LinkageError

I'm having an issue with JSF rendering. Here's my setup:
CentOS
TomEE Plus 1.5.2
Icefaces
Spring Security 3
And my app is set up like this:
/opt/tomee/lib/[all the normal TomEE jars]
/opt/tomee/lib/[all the Spring Security jars]
/opt/tomee/lib/icefaces.jar
/opt/tomee/lib/icefaces-compat.jar
/opt/tomee/lib/icepush.jar
/opt/tomee/webapps/UI/index.xhtml
/opt/tomee/webapps/UI/WEB-INF/lib/icefaces-ace.jar
/opt/tomee/webapps/UI/[normal jsf 2 configuration]
There isn't anything obvious in the logs but when the JSF attempts to render I get the following error:
com/sun/crypto/provider/HmacCore
viewId=/index.xhtml
location=/opt/tomee/webapps/UI/index.xhtml
phaseId=RENDER_RESPONSE(6)
Caused by:
java.lang.LinkageError - com/sun/crypto/provider/HmacCore
at com.sun.crypto.provider.HmacSHA1.(DashA13*..)
The stack trace on the error page is massive, so I'm not going to dump a novel here, but here are the calls of note.
java.lang.LinkageError: com/sun/crypto/provider/HmacCore
at com.sun.crypto.provider.HmacSHA1.(DashA13*..)
{...}
at java.security.Provider$Service.newInstance(Provider.java:1221)
{...}
at org.apache.myfaces.shared.util.StateUtils.encrypt(StateUtils.java:328)
{...}
at org.icefaces.impl.renderkit.RenderWrapper.encodeEnd(RenderWrapper.java:53)
{...}
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
I dumped the contents of all the jars in tomee/lib but com.sun.crypto isn't anywhere that I can find in the web server. Apps that don't use Spring Security work just fine.
Any thoughts?
OK. I got it to work so I'm going to be 'that guy' and answer my own question. I hope that it helps save someone else from the migraine it gave me. The problem went away after I did the following:
delete my war
let tomcat clean up the webapps dir
stop tomcat
delete the related directories from work
add the spring security taglibs jar to my app
remove the encoder declaration from my applicationSecurity.xml
rebuild the app
start tomcat
redeploy
drink heavily
profit
Step 10 wasn't actually a part of debugging process but I wouldn't have complained if it was. Share and enjoy.

Categories