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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 3.0.23.Final, 3.1.3.Final
    • Fix Version/s: 3.0.24.Final, 3.1.4.Final
    • Component/s: None
    • Labels:
      None
    • Steps to Reproduce:
      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).

      Description

      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));
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  rhn-support-rmartinc Ricardo Martin Camarero
                  Reporter:
                  soul2zimate Chao Wang
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  7 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: