Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1684

"Arguments must not be null" when sending a null JSON object with ResteasyWebTarget

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.24.Final, 3.1.4.Final
    • 3.0.23.Final, 3.1.3.Final
    • None
    • None
    • Hide

      Package and deploy the resteasy-test.zip into EAP 7. Then execute the client application that uses resteasy-client to connect to the deployed WS.

      mvn test
      mvn exec:java -Dexec.args=http://${host}:${port}
      Hello world!
      Hello null!
      Hello world!
      [WARNING] 
      java.lang.IllegalArgumentException: Arguments must not be null.
      	at javax.ws.rs.core.GenericEntity.<init>(GenericEntity.java:148)
      	at org.jboss.resteasy.client.jaxrs.internal.proxy.processors.invocation.MessageBodyParameterProcessor.process(MessageBodyParameterProcessor.java:35)
      	...
      

      The simple client requests using jax-rs and proxy way. First two executions show the jax-rs way and they work ok, with and without object. The second two executions show that resteasy proxy works with an object but not with null (the client throws the exception at client side).

      Show
      Package and deploy the resteasy-test.zip into EAP 7. Then execute the client application that uses resteasy-client to connect to the deployed WS. mvn test mvn exec:java -Dexec.args=http: //${host}:${port} Hello world! Hello null ! Hello world! [WARNING] java.lang.IllegalArgumentException: Arguments must not be null . at javax.ws.rs.core.GenericEntity.<init>(GenericEntity.java:148) at org.jboss.resteasy.client.jaxrs.internal.proxy.processors.invocation.MessageBodyParameterProcessor.process(MessageBodyParameterProcessor.java:35) ... The simple client requests using jax-rs and proxy way. First two executions show the jax-rs way and they work ok, with and without object. The second two executions show that resteasy proxy works with an object but not with null (the client throws the exception at client side).

      Having a very simple WS application with a REST endpoint that consumes a JSON object:

      @Path("hello")
      public class HelloWorld {
          @POST
          @Path("entity")
          @Produces({MediaType.APPLICATION_JSON})
          @Consumes({MediaType.APPLICATION_JSON})
          public Greeting helloEntity(Greeter greeter) {
              return new Greeting(greeter);
          }
      }
      

      If the resteasy-client with the the ResteasyWebTarget proxy is used:

              System.out.println(
                      ((ResteasyWebTarget)
                      ClientBuilder.newClient()
                      .target("http://jboss.sample.com:8080")
                      .path("resteasy-test")
                      .path("ws")
                      .path("hello"))
                      .proxy(HelloWorldInterface.class)
                      .helloEntity(null));
      

      The following exception is thrown at client side (no data is sent):

      java.lang.IllegalArgumentException: Arguments must not be null.
          at javax.ws.rs.core.GenericEntity.<init>(GenericEntity.java:148)
          at org.jboss.resteasy.client.jaxrs.internal.proxy.processors.invocation.MessageBodyParameterProcessor.process(MessageBodyParameterProcessor.java:35)
          at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.createRequest(ClientInvoker.java:135)
          at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:101)
          at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:64)
          at com.sun.proxy.$Proxy39.helloEntity(Unknown Source)
          at com.redhat.sample.test.Client.main(Client.java:63)
      

      You can send a null using the standard jax-rs methods:

              System.out.println(ClientBuilder.newClient()
                      .target("http://jboss.sample.com:8080")
                      .path("resteasy-test")
                      .path("ws")
                      .path("hello")
                      .path("entity")
                      .request(MediaType.APPLICATION_JSON)
                      .accept(MediaType.APPLICATION_JSON)
                      .post(Entity.entity(null, MediaType.APPLICATION_JSON))
                      .readEntity(Greeting.class));
      

              rhn-support-rmartinc Ricardo Martin Camarero
              chaowan@redhat.com Chao Wang
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: