Dark Knight
Dark Knight

Reputation: 503

Unable to invoke request (REST call)

I'm currently using Jersey/Jackson in order to make a REST call from client to server.

Client side:

ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://localhost:8080/TrustBasedRecommendation/restservice/adduser");     
Response responseTo = target.request().post(Entity.entity(json, MediaType.TEXT_HTML));
if (responseTo.getStatus() != 200) {
throw new Exception("Failed : HTTP error code : " + responseTo.getStatus() +" "+ responseTo.readEntity(String.class) );

SERVER SIDE - Just a test to print my String

@POST
@Path("/adduser")
@Consumes(MediaType.TEXT_HTML)
public Response addUser(String user)
{
    System.out.println("Inside add user "+user);
    String failedMessage = "failed to add user";
    String successMessage = "user successfully added";

I'm getting the following exception:

javax.ws.rs.ProcessingException: Unable to invoke request

Caused by: javax.ws.rs.ProcessingException: could not find writer for content-type text/html type: java.lang.String at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)

I'm trying to send a "String" (JSON) from my client to server.

Please kindly help.

Upvotes: 0

Views: 14504

Answers (1)

dgm
dgm

Reputation: 2333

I am not sure which jar you have used for "jersey". But I have faced this kind of problem whenever I used following dependency

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.9.1</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.9.1</version>
        </dependency>

Then I have moved to jersey bundle and it was working fine.

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-bundle</artifactId>
    <version>1.18.1</version>
</dependency>

You can also have a try.

Upvotes: 4

Related Questions