How to put parameters in RESTful POST with JerseyFramework

Let’s assume that I have simple class:

   public class Test
    {
       @Path("/test")
       @POST
       @Produces(APPLICATION_JSON)
       @Consumes(APPLICATION_JSON)
       public TestResponse post(TestResponse request, @HeaderParam("text") String text)
       {
          return new TestResponse(request.getData());
       }
    }

and I want to test this class. So how I can param in code like this:

 Entity<TestRequest> requestEntity = Entity.entity(request, MediaType.APPLICATION_JSON);
 final TestResponse response =  target("test").request().post(requestEntity, TestResponse.class);

Answer

target("test").request().header("text", "value").post(...);

When you call request(). You get back an Invocation.Builder. You can take a look at the other methods. For the most part they all return the same Invocation.Builder, so can just chain the calls.

Leave a Reply

Your email address will not be published. Required fields are marked *