Jackson NoClassDefFoundError: com/fasterxml/jackson/core/JsonFactory - java

I am trying to read a yaml file from a java class, but I have two problems. The first is that in my yaml file, I have a list of objects of an abstract class, and I am not sure of what to do about it. Is it possible to read this as a default object and then get the properties with something like obj.get("my-propertie")so that I can reconstruct the object afterward with the correct subclass ? Here is a sample of my yaml. The overall is represented by an Equipment class, and each element belongs to an abstract Invocable class, of which Jetpack is a subclass.
unblocked:
main_hand: []
helmet: []
boots: []
Chestplate:
- className: Jetpack
fuel: 120
color: RED
offhand: []
leggings: []
invoked:
main_hand: null
chestplate: null
helmet: null
boots: null
offhand: null
leggings: null
The second problem is that I get this error when running my code :
java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonFactory, but I don't use JsonFactory anywhere, and the stack trace does not seem relevant. I have this error even with a simple yaml file. Here are my maven dependencies:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
Thanks for any help I could get.

You are using the JsonFactory under the hood as an indirect dependency. Maven should normally add such dependencies automatically but it often does not due to wrong configuration (on their server side and in the libs).
In case of YAML parsing I know for sure that dependencies are missing. I had the same issue some few weeks ago.

Related

Connect SMB endpoint with Camel v3 and the camel-jcifs from camel-extra

I have the following maven versions in my pom.xml (among others):
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.apache-extras.camel-extra</groupId>
<artifactId>camel-jcifs</artifactId>
<version>2.25.2</version>
<exclusions>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
Camel spring-boot version = 3.7.0 and I want to connect to a SMB endpoint like this:
smb://sharedriveuser#server-instance.sub.domain.net/folder?initialDelay=0&delay=9000&autoCreate=false&noop=true&idempotent=true&password=ThePassWorD&filter=#csvFileFilter
I read the Camel 3 Migration Guide and found nothing regarding this camel-extras.
When trying to connect, I get an error like the password option is not supported anymore:
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: smb://sharedriveuser#server-instance.sub.domain.net/folder?initialDelay=0&delay=9000&autoCreate=false&noop=true&idempotent=true&password=xxxxxx&filter=#csvFileFilter due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{password=ThePassWorD}]
The actual documentation link google found many times, seems dead.
From Maven central, there is no version 3.x of the lib camel-jcifs and I am wondering if the lib is still compatible with Camel 3.x.x, otherwise is there another alternative with Camel 3?
I also tried to downgrade the camel-jcifs to 2.24.3 with the same error.
Camel-extras is a separated project from the Apache Camel. There is some work in place in the camel-extra repository to support camel 3[1], but it is still to be completed and there is no release in sight.
[1] https://github.com/camel-extra/camel-extra/commit/f028dfdfaa467958c58abea0d604f8fe2f17be04
There is now a pull request to add camel-jcifs to the 3.x version:
https://github.com/camel-extra/camel-extra/pull/39
You might also get my fork and build it yourself:
https://github.com/bebbo/camel-extra *
It got merged and is in the official repository:
https://github.com/camel-extra/camel-extra
To use it with quarkus, you have to convert some List types to arrays.

How to override DataFetcherExceptionHandler in GraphQL Java?

I am using the following starter for Graphql integration
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>6.0.1</version>
</dependency>
I am not sure how to override the SimpleDataFetcherExceptionHandler with my own CustomExceptionHandler. The library already autowires a lot of stuff. Do I need to create a separate configuration for graphQl object? The documentation is not much helpful.
I also tried to integrate #ControllerAdvice to my Graphql java spring boot application but the errors are not matched by the exception handlers inside it. They are handled by GraphQl error handler. How does error propagates inside Graphql?
How can I change this behaviour?
I have this and it's working for me. Pretty much regular spring stuff for exception handling, but there is no #ControllerAdvice (it's kotlin btw, if you can't understand - let me know, but I think it's pretty clear even without kotlin knowledge).
import org.springframework.web.bind.annotation.ExceptionHandler
import com.oembedler.moon.graphql.boot.error.ThrowableGraphQLError
internal class GraphQLExceptionHandler {
#ExceptionHandler(AppException::class)
fun handleGenericException(ex: AppException): ThrowableGraphQLError {
return ThrowableGraphQLError(ex)
}
#ExceptionHandler(Exception::class)
fun handleGenericException(ex: Exception): ThrowableGraphQLError {
return ThrowableGraphQLError(TechnicalException())
}
}
#Configuration
internal open class GraphQLConfiguration {
#Bean
open fun graphQLExceptionHandler(): GraphQLExceptionHandler {
return GraphQLExceptionHandler()
}
}
I have quite a few dependencies tho, in case they matter here:
<graphql.version>5.4.1</graphql.version>
<graphql-datetime-spring-boot-starter.version>1.4.0</graphql-datetime-spring-boot-starter.version>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>voyager-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.zhokhov.graphql</groupId>
<artifactId>graphql-datetime-spring-boot-starter</artifactId>
<version>${graphql-datetime-spring-boot-starter.version}</version>
</dependency>

Keycloak admin client - javax.ws.rs.ProcessingException: RESTEASY003215

Im using the Keycloak admin client (version 4.5.0.Final) and am trying to do some simple queries such as looking up a user. The client code is running in a plugin module in another java server, not standalone. The code looks like this:
...
try {
Keycloak kc = Keycloak.getInstance(URL, REALM, USER, PWD, CLIENT_ID);
UserRepresentation kcuser = kc.realm(REALM).users().get(USER).toRepresentation();
trace(String.format("Got user: %s", kcuser.toString()));
} catch (Exception e) {
trace("Error authenticating: " + e);
}
...
It creates the kc instance successfully, but barfs when trying to look up the user.
This is the error:
javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type application/x-www-form-urlencoded type: javax.ws.rs.core.Form$1
at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:146)
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:121)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:394)
at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:666)
at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:631)
at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:509)
at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:310)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:439)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:148)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy362.grantToken(Unknown Source)
at org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:89)
at org.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:69)
at org.keycloak.admin.client.token.TokenManager.getAccessTokenString(TokenManager.java:64)
at org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:52)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterRequest(ClientInvocation.java:587)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:436)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:148)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy372.toRepresentation(Unknown Source)
...
My pom has the latest dependencies and classpath seems ok, any ideas why this is not working?
<properties>
<keycloak.version>4.5.0.Final</keycloak.version>
<resteasy.version>3.6.1.Final</resteasy.version>
</properties>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
</dependencies>
I noticed that during the instantiation of a new Keycloak instance, resteasy is checking here for the available providers with the help of the current thread. In version 3.9.1.Final which is currently used by the last keycloak-admin-client so far (version 11.0.0).
In my specific case we are using keycloak-admin-client in combination with graphql-java and CompletableFuture.supplyAsync for our data loaders. Which implies that in some cases, without further configuration, the current thread is not an instance of Thread but actually ForkJoinWorkerThread. Which apparently breaks the retrieval of the providers.
I am still a beginner to java so I would be glad if someone could explain why the registerProviders method does not work with a ForkJoinWorkerThread.
I learned on DZone is that JVM sizes the commonPool to two threads when you have more than 2 CPUs available. So I tried and noticed that my app works with 2 CPUs, but I have the same error (RESTEASY003215) with 3 CPUs.
My current "workaround" is to to use CompletableFuture.completedStage when loading data using the keycloak-admin-client.

How to avoid dependency conflict when using dropwizard + jersey client

I have a DropWizard REST API written and works. One of the resource endpoints actually writes an email, however as soon as I add the following dependencies DropWizard starts to fail on start up
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.18.1</version>
</dependency>
The DropWizard dependency is:
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.8.1</version>
</dependency>
The error on startup is really long, summarised below
WARN [2015-05-01 20:06:08,887] org.glassfish.jersey.internal.Errors: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 2
java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(AbstractJAXBProvider.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
....
MultiException stack 2 of 2
java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:395)
....
MultiException stack 3 of 3
java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
...
I'm guessing DropWizard is using another conflicting dependency so how do I deal with this?
Thanks in advance
Dropwizard 0.8.x uses Jersey 2.x which naturally conflicts with your Jersey 1.x dependencies.
I think it might be fine with jersey-client as long as you don't have dropwizard-client dependency but jersey-core will conflict at many points with dropwizard's jersey which I don't think you can fix. And also I don't think you'd need jersey-core for sending email anyway.
If you do need jersey for this, try using Jersey 2.16 instead which is the version dropwizard is using.
I had the same problem (I'm using DW 0.9.2 and have unwanted transitive dependencies of both DW 0.7.2 and Jersey 1.x)
The solution was pretty simple: in the dependency that's bringing you those two family of libraries, declare an exclusion and it should work, for instance, this is how I did it in Gradle:
compile("com.example.culprit:culprit:1.2.3") {
exclude group: 'io.dropwizard'
exclude group: 'com.sun.jersey'
}
The syntax for Maven is pretty similar (more verbose actually ;-) )
Hope this helps someone.

no such method jsch.JSch.setLogger

The below behavior occurs when i call the getSftpUtil(). I have also ensured that all the appropriate jars are in the maven project's external libraries and are available in the WEB-INF/lib folder of the project
code
net.sf.opensftp.SftpUtil util = SftpUtilFactory.getSftpUtil();
stacktrace
SftpUtilFactory: Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory - Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory: The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory - The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory: Use the default one.
SftpUtilFactory - Use the default one.
Caused by: java.lang.NoSuchMethodError: com.jcraft.jsch.JSch.setLogger(Lcom/jcraft/jsch/Logger;)V
at net.sf.opensftp.impl.SftpUtil.<clinit>(SftpUtil.java:110)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at net.sf.opensftp.SftpUtilFactory.getSftpUtil(SftpUtilFactory.java:184)
Based on jcraft's change log, setLogger is a method added to JSch.java in jsch-0.1.30. So the jar under your WEB-INF/lib should be an older version.
You can run
mvn dependency:tree
to see which of your dependencies is using the older version, and then exclude it with something like this:
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<exclusions>
<exclusion>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
</exclusion>
</exclusions>
</dependency>
You probably have another dependency refer to a more recent version of jsch, so your problem should be solved at this point. However, if that's not the case, you can add this to pom.xml:
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.50</version>
</dependency>
Well, I guess you are missing this dependency or the proper version:
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.49</version> <!--latest version -->

Categories

Resources