I am currently trying to create a Resteasy Client, having to use Version 2.3.10.Final. Unfortunately, I should not use a newer Version. I am very new to this, so I hope I manage to provide all required Information to make this question answerable.
First, the Request is created and finally "PUT". The returned ClientResponse is to be evaluated.
I can successfully call
Response.getStatus()
showing me that the "PUT" has been successful, as the Status is equal to
Response.Status.CREATED.getStatusCode()
However, any attempt to call response.readEntity Returns the error
java.lang.AbstractMethodError: javax.ws.rs.core.Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object;
at blabla.evaluateResponse(MyResteasyClient.java:80)ยด
This is for any attempt to call .readEntity, but for the sake of specificity, let's concentrate on
String entity = Response.readEntity(String.class);
When attempting response.getEntity(), it Returns the following error message:
java.lang.RuntimeException: RESTEASY001555: No type information to extract entity with, use other getEntity() methods
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:337)
at blabla.evaluateResponse(MyResteasyClient.java:81)
Am I even on the right Track? My Goal is to achieve something along the lines of:
List<? extends MyResponse> myResponses = response.readEntity(new GenericType<List<MyResponse>>() {});
Where the class "MyResponse" is an implementation of the Interface
public interface MyPartialResponse {
boolean isSuccessful();
String getMessage();
}
The dependencies within pom.xml are:
<properties>
<version.jackson>2.6.5</version.jackson>
<version.resteasy-client>2.3.10.Final</version.resteasy-client>
</properties>
<dependencies>
(removed a company specific dependency)
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${version.resteasy-client}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>${version.resteasy-client}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
</dependencies>
If anyone happens to land on this question with the same error, let me provide the answer, how I solved my issue:
By adding
BaseClientResponse<?> r = (BaseClientResponse<?>) response;
I could successfully call
r.getEntity(new GenericType<List<MyResponse>>() {});
I think there is a conflicts between Jar files in Maven. Please check your maven dependency hierarchy.
Related
ive been trying to create a cluster using the Emrclient
EmrClient emrClient = EmrClient.builder().
region(Region.US_EAST_1).
credentialsProvider(EnvironmentVariableCredentialsProvider.create()).
build();
when i try to run the code, i get an SDKexception:
Exception in thread "main" software.amazon.awssdk.core.exception.SdkClientException: Unable to load an HTTP implementation from any provider in the chain. You must declare a dependency on an appropriate HTTP implementation or pass in an SdkHttpClient explicitly to the client builder.
at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:98)
at software.amazon.awssdk.core.internal.http.loader.DefaultSdkHttpClientBuilder.lambda$buildWithDefaults$1(DefaultSdkHttpClientBuilder.java:49)
at java.base/java.util.Optional.orElseThrow(Optional.java:408)
at software.amazon.awssdk.core.internal.http.loader.DefaultSdkHttpClientBuilder.buildWithDefaults(DefaultSdkHttpClientBuilder.java:43)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.lambda$resolveSyncHttpClient$5(SdkDefaultClientBuilder.java:269)
at java.base/java.util.Optional.orElseGet(Optional.java:369)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.resolveSyncHttpClient(SdkDefaultClientBuilder.java:269)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.finalizeSyncConfiguration(SdkDefaultClientBuilder.java:220)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.syncClientConfiguration(SdkDefaultClientBuilder.java:153)
at software.amazon.awssdk.services.emr.DefaultEmrClientBuilder.buildClient(DefaultEmrClientBuilder.java:27)
at software.amazon.awssdk.services.emr.DefaultEmrClientBuilder.buildClient(DefaultEmrClientBuilder.java:22)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.build(SdkDefaultClientBuilder.java:124)
at task2.App.main(App.java:27)
after searching online in the aws docs, i found that to create the EMRclient we need to make the builder look like this:
EmrClient emrClient = EmrClient.builder().
region(Region.US_EAST_1).
credentialsProvider(EnvironmentVariableCredentialsProvider.create()).
httpClient(ApacheHttpClient.builder().build()).
build();
but no matter what i do, my IDE doesnt recognize the class ApacheHttpClient,
ive tried to import : import software.amazon.awssdk.http.apache.ApacheHttpClient;
but it doesnt recognize it even though i added it to my POM:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>emr</artifactId>
<version>2.13.23</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ec2</artifactId>
<version>2.13.23</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.13.23</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
<version>2.13.23</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/apache-client -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
<version>2.13.23</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>
was wondering if anyone has encountered this and was able to fix it?
thanks in advance
I'm using auth0-java client library to interact with auth0 v2 service, my codes compile and works fine at my development environment but when I deploy that build in another test environment it throws the following exception:
java.lang.NoSuchMethodError:com.fasterxml.jackson.databind.ObjectMapper.readerFor(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectReader;
at com.auth0.json.mgmt.users.UsersPageDeserializer.getArrayElements(UsersPageDeserializer.java:52)
at com.auth0.json.mgmt.users.UsersPageDeserializer.deserialize(UsersPageDeserializer.java:30)
at com.auth0.json.mgmt.users.UsersPageDeserializer.deserialize(UsersPageDeserializer.java:15)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3562)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2597)
at com.auth0.net.CustomRequest.parseResponse(CustomRequest.java:63)
at com.auth0.net.BaseRequest.execute(BaseRequest.java:37)
at com.myapp.security.Auth0Service.getUserByEmail(Auth0Service.java:246)
at com.myapp.security.Auth0Service.checkForExsistingAuth0Account(Auth0Service.java:266)
at com.myapp.security.AdminUILayout.lambda$launchProgressUpdater$0(AdminUILayout.java:293)
at java.lang.Thread.run(Thread.java:745)
I've already gone through several stackover flow questions like this and tried by cleaning .m2/repository/com/fasterxml folder of that test environment, but cloudn't solve the no such method error
here is my pom file and related codes are given below:
code
public User getUserByEmail(String email){
UserFilter filter = new UserFilter();
filter.withQuery(email);
Request<UsersPage> request = mgmt.users().list(filter);
try {
UsersPage response = request.execute();
for (User u:response.getItems()) {
if (u.getEmail().equals(email)) {
return u;
}
}
} catch (APIException exception) {
// api error
System.out.println("APIException:::::"+exception.getDescription());
} catch (Auth0Exception exception) {
// request error
System.out.println("Auth0Exception:::::"+exception.getMessage());
}catch(Exception ex){
System.out.println("Other exception:::::"+ex.getMessage());
}
return null;
}
pom.xml
<properties>
<jackson.version>2.8.5</jackson.version>
</properties>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0</artifactId>
<version>1.0.0</version>
</dependency>
Update
I've moved those jackson dependencies into <dependencyManagement> section of my pom.xml file,
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
</dependencyManagement>
according to maven documentation ,no matter which version of library jackson-core is requested by a dependency, version ${jackson.version} will always be used, still my codes works in local ,but in that test server
the the exception remains same, even if I deploy my war file in that test server code throws the same exception.
most likely you have compiled your code against a different version of the class, than the one you are using when running it.
Please make sure that on the environment where you run the code there is no any other version of jackson-databind dependency on your classpath.
finally solved the issue , I found that glassfish 4.1.1 has a very old version 2.3.2 of jackson-core jackson-annotation and jackson-databind, so we decided to use Payara server that uses fairly latest version of jackson jackson 2.8.5 and tested the no such method error is solved, the code works fine in that Payara server
Update:
glassfish version 5.0 uses updated version jackson 2.8.9 , I think using that will solve this issue too
Probably one of your other artifacts depends on different version of databind. You can try to exlude it explicitly from each of them to guess
<dependency>
...
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
Please check version.
Screenshot:
For me, I encountered the same exception due to lower version of jackson-databind:
From:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.0</version>
</dependency>
Changed to:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.9</version>
</dependency>
I just update my pom.xml file with higher version of jackson-databind.
Then right-click Project --> Update Maven Project and the exception is resolved.
<!-- faster JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.0</version>
</dependency>
All
I am running into this error in my project when I updated aws library to the latest 1.11.3.
Caused by:
java.lang.NoClassDefFoundError: org/apache/http/conn/SchemePortResolver
at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.<init>(ApacheHttpClientFactory.java:40)
at com.amazonaws.http.AmazonHttpClient.<clinit>(AmazonHttpClient.java:97)
at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:145)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:393)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:373)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:355)
at com.amazonaws.services.s3.AmazonS3Client.<init>(AmazonS3Client.java:339)
in my pom.xml
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-kms</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-encryption-sdk-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Anyone know what I did wrong?
thanks
I had a similar issue with my grails application. In my case the ClassNotFoundException was being thrown from a deploy script. For me the reason SchemePortResolver wasn't being resolved implicitly was because it wasn't required at compile time, it was needed at runtime. Here's what I added to my BuildConfig.groovy to fix it:
runtime 'org.apache.httpcomponents:httpclient:4.5.2' //Required by BeanstalkDeploy.groovy at runtime
Since the OP's question was for Maven, here's the equivalent include:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<scope>runtime</scope>
</dependency>
If you add,
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
,it should work ok as it contains the missing class definitions.
A common cause would be a Maven dependency conflict. In the example below (pom.xml as viewed in Eclipse's Dependency Hierarchy tab), the POM explicitly includes v4.1 of httpclient, which forces Maven to omit the v4.5.5 that aws-java-sdk-core requires (and thus, causes the similar error java.lang.NoClassDefFoundError: org/apache/http/conn/DnsResolver at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory...):
In my case I delete the .meta file in eclipse workplace then import the project again thereafter it work like a charm.
Could not know where the problem exactly.
Before delete .meta I add all files from
aws-java-sdk-1.11.606\third-party\lib
I have the following in my POM.xml
Updated complete pom:
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.19</version>
</dependency>
<!-- <dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.19</version>
</dependency> -->
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>2.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-jdbc-all</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
I wanted to generate an JSON from List<Map<String,String>>. I always end up having MessageBodyWriter not found for media type=application/json, type=class java.util.LinkedHashMap, genericType=jav a.util.Map<String,String>
I even tried with simple map
#GET
#Path("/test")
#Produces(MediaType.APPLICATION_JSON)
public Map<String, String> getMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("some key", "some value");
return map;
}
even this produces the same error message.
UPDATED EXCEPTION STACK TRACE:
Jul 29, 2015 9:23:29 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [CustomerDataService] in context with path [/CustomerDataService] threw exception
[org.glassfish.jersey.server.ContainerException: java.lang.AbstractMethodError: com.fasterxml.jackson.jaxrs.json.Jackson
JaxbJsonProvider.isWriteable(Ljava/lang/Class;Ljava/lang/reflect/Type;[Ljava/lang/annotation/Annotation;Ljavax/ws/rs/cor
e/MediaType;)Z] with root cause
java.lang.AbstractMethodError: com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.isWriteable(Ljava/lang/Class;Lja
va/lang/reflect/Type;[Ljava/lang/annotation/Annotation;Ljavax/ws/rs/core/MediaType;)Z
at org.glassfish.jersey.message.internal.MessageBodyFactory.isWriteable(MessageBodyFactory.java:1158)
at org.glassfish.jersey.message.WriterModel.isWriteable(WriterModel.java:86)
at org.glassfish.jersey.message.internal.MessageBodyFactory._getMessageBodyWriter(MessageBodyFactory.java:798)
at org.glassfish.jersey.message.internal.MessageBodyFactory.getMessageBodyWriter(MessageBodyFactory.java:756)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterc
eptorExecutor.java:241)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInter
ceptor.java:86)
MOXy doesn't handle maps well as it uses JAXB under the hood, and JAXB sucks with Maps. Use Jackson instead. Get rid of the MOXy dependency. MOXy is the default, so if it is on the classpath, it will be used over all others. Once you take it out, Jackson will be used.
UPDATE
So the drill-jdbc-all actually repackages both Jackson 1.x and Jackson 2.x. You can exclude them from the jersey-media-json-jackson depedency, since drill already includes them.
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.19</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-base</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
UPDATE 2
I guess the above still doesn't work. One way I was able to get to work is adding jackson-jaxrs-json-provider (you also need to take out jersey-media-json-jackson and the jersey-media-moxy).
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-jdbc-all</artifactId>
<version>1.1.0</version>
</dependency>
The key to this is that it must be declared before the apache-jdbc-drill. Yea it seems more of a work around that a solution. But the fact that drill packages the dependency is a problem. When Jersey scans, it will will add ours first, and ignore drill's.
You then need to add the provider to your Jersey config
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
</param-value>
</init-param>
I mean I haven't tested this 10,000, but for the 10 to 20 times I did tested, the ordering of the dependencies was the deciding factor for whether or not it would work. Again, like I said, seems like a work-around.
And the add it to the Jersey config
You cannot serialize collections and maps. Create a container class.
For example:
#XmlRootElement
public class Container {
public Map<String, String> data;
}
public Container getMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("some key", "some value");
// wrap content int container object
Container container = new Container();
container.data = map;
return container ;
}
The reason for this issue is, that XML always has to have a single root element.
I am new to Jackson and I was writing some code for practice. I found out the the new version of Jackson library can be found on Fasterxml: Jackson, so I added the below dependencies to my Maven pom file:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.2</version>
</dependency>
I was expecting that I can use the ObjectMapper directly, however after spending a lot of time I found out that to use the ObjectMapper I have to add the old libraries below:
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.2</version>
</dependency>
I am a bit confused. Could someone please tell me why is that?
<properties>
<!-- Use the latest version whenever possible. -->
<jackson.version>2.4.4</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
you have a ObjectMapper (from Jackson Databind package) handy.
if so, you can do:
JsonFactory factory = objectMapper.getFactory();
Source: https://github.com/FasterXML/jackson-core
So, the 3 "fasterxml" dependencies which you already have in u'r pom are enough for ObjectMapper as it includes jackson-databind.
No, you can simply use com.fasterxml.jackson.databind.ObjectMapper.
Most likely you forgot to fix your import-statements, delete all references to codehaus and you're golden.
The package names in Jackson 2.x got changed to com.fasterxml1 from org.codehaus2. So if you just need ObjectMapper, I think Jackson 1.X can satisfy with your needs.
I spent few hours on this.
Even if I had the right dependency the problem was fixed only after I deleted the com.fasterxml.jackson folder in the .m2 repository under C:\Users\username.m2 and updated the project
Apart from fixing the imports, do a fresh maven clean compile -U. Note the -U option, that brings in new dependencies which sometimes the editor has hard time with. Let the compilation fail due to un-imported classes, but at least you have an option to import them after the maven command.
Just doing Maven->Reimport from Intellij did not work for me.