Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-11860

[GSS](7.2.z) "Arguments must not be null" when sending a null JSON object with ResteasyWebTarget

    XMLWordPrintable

Details

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

      Attachments

        Issue Links

          Activity

            People

              rpelisse@redhat.com Romain Pelisse
              rhn-support-rmartinc Ricardo Martin Camarero
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: