Failed to instantiate MessageBodyReader error

First of all, I have to say that I am new to Maven, even thought I didn't think Maven had anything to do with this error. I am using Eclipse 4.2.1 with m2e
I have this code I got from ckan4j developer

Client c = ClientBuilder.newBuilder().register(MultiPartFeature.class).build();
WebTarget wt = c.target("192.168.1.2/action").path("resource_update");
Builder b = wt.request();
b.header("authorization", "fa0499d1-ffda-4590-82b3-4afdb9c91576");
FileDataBodyPart filePart = new FileDataBodyPart("upload", new File("/home/ilias/Downloads/OdtUtils.java"));
FormDataMultiPart multipart = (FormDataMultiPart) new FormDataMultiPart().field("id","test2").bodyPart(filePart);
String response_string = b.post(Entity.entity(multipart, multipart.getMediaType())).readEntity(String.class);       
System.out.println(response_string);

      

this is my pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>ckanTest2</groupId>
  <artifactId>ckanConn2</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>CkanConnectTest</name>     

   <dependencies>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-client</artifactId>
        <version>3.0.2.Final</version>
    </dependency>       
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-multipart-provider</artifactId>
        <version>3.0.11.Final</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.5.2</version>
    </dependency> 

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>2.18</version>
    </dependency>
  </dependencies>
</project>

      

I'm not 100% sure about the dependencies, but I just looked for the error I was getting during compilation and added the results here until I got any errors. Now when I build maven (using generate-sources

) I get this

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".  
SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J:  
See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.  
[INFO] Scanning for projects...   
[INFO]            
[INFO]-----------------------------------------------------------------------  
[INFO] Building CkanConnectTest 0.0.1-SNAPSHOT  
[INFO]------------------------------------------------------------------------  
[INFO]------------------------------------------------------------------------  
[INFO] BUILD SUCCESS  
[INFO]------------------------------------------------------------------------    [INFO] Total time: 0.298s  
[INFO] Finished at: Wed Jun 24 19:50:57 EEST 2015  
[INFO] Final Memory: 6M/58M  
[INFO]------------------------------------------------------------------------

      

who even thought he was complaining about the registrar, I don't really want to decide now. other than that it seems to be okay.

When trying to execute java file I get this

Exception in thread "main" java.lang.RuntimeException: Unable to instantiate MessageBodyReader   
    at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1371)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1310)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1232)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.register(ResteasyProviderFactory.java:2364)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.register(ResteasyProviderFactory.java:97)
    at org.jboss.resteasy.util.FeatureContextDelegate.register(FeatureContextDelegate.java:37)
    at org.jboss.resteasy.util.FeatureContextDelegate.register(FeatureContextDelegate.java:12)
    at org.glassfish.jersey.media.multipart.MultiPartFeature.configure(MultiPartFeature.java:65)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1673)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1310)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1232)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.register(ResteasyProviderFactory.java:2364)
    at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.register(ResteasyClientBuilder.java:361)
    at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.register(ResteasyClientBuilder.java:48)
    at cKanTest.CkanAlpha.main(CkanAlpha.java:17)  

Caused by: java.lang.IllegalArgumentException: Unable to find a public constructor for provider class  
  org.glassfish.jersey.media.multipart.internal.MultiPartReaderServerSide
    at org.jboss.resteasy.spi.ResteasyProviderFactory.createConstructorInjector(ResteasyProviderFactory.java:2184)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.createProviderInstance(ResteasyProviderFactory.java:2173)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.addMessageBodyReader(ResteasyProviderFactory.java:748)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1366)
    ... 14 more

      

I used the xml tag just to make the xml more readable

+3


source to share


1 answer


I had the same problem caused by a combination of RestEasy and Jersey (org.glassfish.jersey.media):

ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
ResteasyProviderFactory.pushContext(javax.ws.rs.ext.Providers.class, factory);

      



Another hint is to use the jersey-media-multipart dependency rather than jersey-multipart

0


source







All Articles