Ben
Ben

Reputation: 62404

java.lang.NoSuchMethodError: javax.ws.rs.ext.MessageBodyWriter.isWriteable

I followed the guide here http://docs.neo4j.org/chunked/milestone/server-java-rest-client-example.html on how to send a POST request. Using the below code I get the error java.lang.NoSuchMethodError: javax.ws.rs.ext.MessageBodyWriter.isWriteable which appears to be an issue with the library I'm using.

public Object getResponse(Object responseClass) {
    Client client = Client.create();

    WebResource webResource = client.resource(getUrl());
    ClientResponse response = webResource
            .type(MediaType.APPLICATION_JSON)
            .entity(responseClass)
            .post(ClientResponse.class);

    if (response.getStatus() != 201)
        return null;

    return response.getEntity(responseClass.getClass());
}

I am unsure if I'm missing a dependency or what...

my pom.xml includes

  <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-jaxrs</artifactId>
      <version>1.9.12</version>
  </dependency>
  <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>2.1.2</version>
  </dependency>

pom.xml

  <dependencies>
      <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.17</version>
      </dependency>
      <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.1.23</version>
      </dependency>
      <dependency>
          <groupId>org.apache.axis</groupId>
          <artifactId>axis</artifactId>
          <version>1.4</version>
      </dependency>
      <dependency>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
          <version>1.1.1</version>
      </dependency>
      <dependency>
          <groupId>commons-discovery</groupId>
          <artifactId>commons-discovery</artifactId>
          <version>0.4</version>
      </dependency>
      <dependency>
          <groupId>javax.xml</groupId>
          <artifactId>jaxrpc-api</artifactId>
          <version>1.1</version>
      </dependency>
      <dependency>
          <groupId>wsdl4j</groupId>
          <artifactId>wsdl4j</artifactId>
          <version>1.6.2</version>
      </dependency>
      <dependency>
          <groupId>javax.mail</groupId>
          <artifactId>mail</artifactId>
          <version>1.4.4</version>
      </dependency>
      <dependency>
          <groupId>javax.activation</groupId>
          <artifactId>activation</artifactId>
          <version>1.1.1</version>
      </dependency>
      <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-lang3</artifactId>
          <version>3.1</version>
      </dependency>
      <dependency>
          <groupId>org.apache.cxf</groupId>
          <artifactId>cxf-rt-frontend-jaxrs</artifactId>
          <version>2.1.2</version>
      </dependency>
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.7.2</version>
      </dependency>

      <!-- Jersey & Jackson -->
      <dependency>
          <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-jaxrs</artifactId>
          <version>1.9.12</version>
      </dependency>
      <dependency>
          <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-xc</artifactId>
          <version>1.9.12</version>
      </dependency>
      <dependency>
          <groupId>com.sun.jersey</groupId>
          <artifactId>jersey-server</artifactId>
          <version>1.17</version>
      </dependency>
      <dependency>
          <groupId>com.sun.jersey</groupId>
          <artifactId>jersey-json</artifactId>
          <version>1.17</version>
      </dependency>
      <dependency>
          <groupId>com.sun.jersey</groupId>
          <artifactId>jersey-servlet</artifactId>
          <version>1.17</version>
      </dependency>
      <dependency>
          <groupId>com.sun.jersey</groupId>
          <artifactId>jersey-grizzly2</artifactId>
          <version>1.17</version>
      </dependency>
      <dependency>
          <groupId>com.sun.jersey</groupId>
          <artifactId>jersey-client</artifactId>
          <version>1.17.1</version>
      </dependency>

      <!-- Spring, Hibernate -->
      <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>4.1.9.Final</version>
      </dependency>
      <dependency>
          <groupId>org.hibernate.javax.persistence</groupId>
          <artifactId>hibernate-jpa-2.0-api</artifactId>
          <version>1.0.1.Final</version>
      </dependency>
      <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>4.1.9.Final</version>
      </dependency>
      <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-annotations</artifactId>
          <version>3.5.6-Final</version>
      </dependency>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>3.2.1.RELEASE</version>
      </dependency>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>3.2.1.RELEASE</version>
      </dependency>
      <dependency>
          <groupId>org.springframework.data</groupId>
          <artifactId>spring-data-jpa</artifactId>
          <version>1.2.0.RELEASE</version>
      </dependency>
  </dependencies>

update removing the below entry fixed it

  <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>2.1.2</version>
  </dependency>

Upvotes: 3

Views: 12326

Answers (1)

longhua
longhua

Reputation: 4252

It seems that you have different javax.ws.rs.ext.MessageBodyWriter classes in your classpath. One is from jsr311-api-0.8.jar and the other one is from jersey-core-1.17.jar. So please manage the dependencies carefully.

By the way, if you use tools, like JFind (find a class in a directory/JAR) and jd-gui (decompile a JAR), you can resolve this kind of issues easily.

The following is my JFind output:

ClassName = javax/ws/rs/ext/MessageBodyWriter.class
JarName = C:\Users\lhuang\.m2\repository\com\sun\jersey\jersey-core\1.17\jersey-core-1.17.jar
----------------
ClassName = javax/ws/rs/ext/MessageBodyWriter.class
JarName = C:\Users\lhuang\.m2\repository\javax\ws\rs\jsr311-api\0.8\jsr311-api-0.8.jar
----------------

Upvotes: 3

Related Questions