Search code examples
jax-rsresteasy

JAX-RS/RestEasy Client and JSON-P


In a REST client written using JAX-RS and RestEasy as implementation I'm trying the send a JsonObject via POST to a WebService. The project uses the reference implementation of JSON-P, org.glassfish.javax.json.

When I'm trying the send the request I get the following exception:

javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type application/json type: org.glassfish.json.JsonObjectBuilderImpl$JsonObjectImpl

The following artifacts are present in the pom.xml:

<dependency>
   <groupId>javax.json</groupId>
   <artifactId>javax.json-api</artifactId>
   <version>1.1.4</version>
</dependency>
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1.4</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.6.3.SP1</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.6.3.SP1</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-json-p-provider</artifactId>
    <version>3.6.3.SP1</version>
</dependency>

From what I've read in the documentation that should be all necessary.

The request in invoked as follows:

final JsonObjectBuilder credentialsBuilder = Json.createObjectBuilder();
credentialsBuilder.add("username", configuration.getServiceUser());
credentialsBuilder.add("password", configuration.getServicePassword());

final Entity<JsonObject> credentials = Entity
    .json(credentialsBuilder.build());
final Response response = ClientBuilder
    .newClient()
    .target("http://www.example.org/some/url")
    .request(MediaType.APPLICATION_JSON)
    .post(credentials);

What I'm missing?


Solution

  • It seems like your provider is not being registered; depending on how/where you're using Resteasy, you might need to do additional configuration to make sure it picks up that kind of stuff for you (http://docs.jboss.org/resteasy/docs/3.6.3.Final/userguide/html_single).

    For example, if you're using servlet configuration, you might need to use resteasy-servlet-initializer, or add in a spring helper, etc.

    Note that you can most likely explicitly register the JSON-P provider to the Client, Target, or Request itself when you're building it out if you wanted to (or are just testing)