1

I have a method in my rest interface which looks like this:

@POST
@Path("/path/{param1}/{param2}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
Response updateData(@PathParam("param1") String param1,
                       @PathParam("param2") String param2,
                       String dataPointJson);

I'm trying without success to do a post request, here's my code:

WebTarget path = collect.path("/path/someParam1/" + someParam2);
    Data dp = new Data.Builder()               
    Response post = path.request().post(Entity.json(dp));

Every time I get a 404 response:

ClientResponse{method=POST, uri=http://localhost:9090/collect/path/someParam1/someParam2, status=404, reason=Not Found}

Can someone please suggest what I'm doing wrong? Tried different combinations of "consumes"/"produces", also tried all examples from tutorials which I found on the net.

Ion C
  • 213
  • 3
  • 13
  • 24
  • FYI Path parameters and Query parameters are two different things... – R Dub Aug 09 '16 at 18:46
  • @RDub I would really appreciate if you could explain to a noob in ws what exactly I'm doing wrong. I don't see any difference between pathparam and queryparam in this particular example... – Ion C Aug 09 '16 at 18:49
  • You may need to fix the question title (nothing in your code snippet is a query parameter): http://stackoverflow.com/questions/5579744/what-is-the-difference-between-pathparam-and-queryparam – R Dub Aug 09 '16 at 18:53
  • As for what is going wrong, can you verify that your service is deploying successfully (to jetty?) and that it is under the /collect context? If so, can you create a simple GET endpoint and test access with a browser? – R Dub Aug 09 '16 at 18:54
  • @RDub I already did that, my service is working against GET endpoint – Ion C Aug 09 '16 at 18:58
  • In that case, you may need to set the media type in the request header to be JSON. – R Dub Aug 09 '16 at 19:07
  • @RDub tried that before posting :( path.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(dp)) – Ion C Aug 09 '16 at 19:09
  • Can you post source and configs? – R Dub Aug 09 '16 at 19:13
  • Also in my previous comment I meant content type not media type... So in the POST request header the Content-Type key should have a value application/json. – R Dub Aug 09 '16 at 19:25

0 Answers0