0

I have a simple REST client with GET POST and DELETE methods.

Weird things is that only GET methods work, neither POST nor DELETE doesn't even get hit and response is "404 Not Found" of course.

Here's my REST service and the client:

Interface:

public interface MyInterface {
    @GET
    @Path("/content")
    @Produces(MediaType.APPLICATION_JSON)
    Response getAirports();

    @DELETE
    @Path("/content/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    Response deleteAirport(@PathParam("id") String id);
}

Implementation:

@Path("/source")
public class SourceService extends AbstractService implements MyInterface {

@Override
    public Response getContent() {
        DBCollection collection = getDBCollection("content");

        DBCursor cursor = collection.find();
        String serialize = JSON.serialize(cursor);

        return Response.status(Response.Status.OK).entity(serialize).build();
    }

    @Override
    public Response deleteContent(@PathParam("id") Integer id) {
        DBCollection collection = getDBCollection("content");

        BasicDBObject query = new BasicDBObject();
        query.append("id", id);

        collection.remove(query);

        return Response.status(Response.Status.OK).build();
    }
}

Client:

// This is working
public void getContent() {
        WebTarget path = collect.path("/content");
        Response response = path.request().get();
        LOGGER.info("collect.ping: " + response.readEntity(String.class) + "\n");
    }

// This is not working
public void deleteContent(Integer id) {
        WebTarget path = collect.path("/content/"+id);
        Response response = path.request(MediaType.APPLICATION_JSON).delete();
        System.out.println("object deleted:"+response);
    }

I've tried requesting with jersey or apache clients but all of them return 404 and I'm like hopeless now.

Hope you can give me a direction.

neocorp
  • 569
  • 7
  • 20
  • Try reducing your problem a little. Make the implementation just immediately return an OK response. – Chill May 30 '16 at 20:34
  • @Chill Just tried removing the PathParam and it get hit and returned OK. How about that? Am I sending the path parameter in a wrong way? – neocorp May 30 '16 at 20:39
  • try just changing it to a string... such as "airport" Also, you are passing a parameter in the client as this: public void deleteAirport(String iata) { But you don't use "iata" in your client code... – CA Martin May 30 '16 at 20:42
  • @Chill tried that too again its not hitting... It only hits when no PathParam exists. Should I handle PathParam differently? – neocorp May 30 '16 at 20:46
  • please comment on my answer. – CA Martin May 30 '16 at 20:47

2 Answers2

2

This looks like a possible duplicate of Inheritance with JAX-RS. Have you tried replicating all annotations in the subclass or none, means do not use @PathParam in the implementation class at all?

Community
  • 1
  • 1
  • woow! I've been pulling my hair all day on this and you just saved it... Thank you very much I really appreciate this!! – neocorp May 30 '16 at 20:56
0

If you actually can debug your client and you are indeed able to "Step through" the client code?

If you place a break-point within your server code and you never actually "break" on it? Then the problem is with the way you are exposing your web service and how you are then trying to consume it.

Try to change the parameter type expected by the Server and the type you pass from your client.

If you can change it on the server and client to a simpler type.. i.e.. an integer.. and then you can actually capture a breakpoint in both client and server, then you know that the problem is in your types.

I hope you can understand what I'm saying? You really need to simplify your parameters and/or try it without parameters first.

When you get something simpler working, then you can extend it to something else.

try just changing it to a string... such as "airport" Also, you are passing a parameter in the client as this:

            public void deleteAirport(String iata) { 

But you don't use "iata" in your client code...

CA Martin
  • 307
  • 2
  • 7
  • just tried and it works without any PathParam but when add anything as a PathParam it doesn't work again... What can I do? that method is just a client test method, tried using the parameter and without but no luck... – neocorp May 30 '16 at 20:48
  • are you able to set break-points? in the server or client? or both? – CA Martin May 30 '16 at 20:54
  • Now OP changed line to this: // This is not working public void deleteContent(Integer id) { Therefore my original suggestion doesn't make sense any longer :) Still seems the debugging suggestions may help someone else.... – CA Martin May 31 '16 at 19:50