4 Replies Latest reply on Nov 7, 2014 1:56 PM by Phillip Nakaska

    DataService is called with null parameter;

    Phillip Nakaska Newbie

      The DataService is failing to receive the parameter passed from the client.

      The parameter received by the service method implementation only gets null for 'value'

       

      -------------------

      // The Main Page uses call() to send request:

          @EventHandler("searchButton")

          public void onSearchButtonPress(ClickEvent e) {

                String discarded = dataService.call(searchCallback).search( "thisIsAParamValue");

                // I know dataService does not return ant values b.c.it is asynchronous, response arrives via the callback, thus named 'discarded'

          }

      -------------------

      // The callback, then,  should receive response:

      final ResponseCallback searchCallback = new ResponseCallback() {

        @Override

        public void callback(Response response) {

             Window.alert("HTTP status code: " + response.getStatusCode());

       

      // The response value 'A String result' is received by this callback, as sent by the service as the response.

             Window.alert("HTTP response body: " + response.getText());

        }

      };

       

      -------------------

      A basic data service to receive some queries; currently it receives only a 'String' value as a parameter:

      @Path("search")

      public interface DataService {

         @POST

         @Produces({"application/json"})

         public String search (String queryString);

      }

       

      -------------------

      // The implementation attempts to show the parameter 'value'

      // but the 'value' is null, It's value should be 'thisIsAParamValue'.

      // The callback does properly return the string result 'A String result' back to the client.

       

      public class DataServiceImpl implements DataService

      {

           @Override

           public String search (String value) {

             if (value != null) {

                       System.out.println("DataServiceImpl:dummySearch:received: value="+value);

                  } else {

                       System.out.println("DataServiceImpl:dummySearch:null value received");

                  }

                  return "A String result";

              }

      ...

      }

       

      The POM is based on the errai-jaxrs-demo-crud. But it is eventually got to work with Elastic search and a few other things, so there are some additional dependencies in the POM.

      I've included the POM. Could some of the dependencies included be interfering with the JAXRS marshaling, somehow?

      At runtime, there are no errors that I can detect during the request.

        • 1. Re: DataService is called with null parameter;
          Christian Sadilek Master

          HI Phillip,

           

          I've copied your code into the Errai tutorial (https://github.com/errai/errai-tutorial) and it worked fine. I've seen that you have Jackson dependencies, specifically the resteasy-jackson-provider, in your pom.xml. Did you configure your REST endpoint to return and expect Jackson based JSON?

           

          If so, you have to configure Errai to use Jackson instead of its own JSON format:

          http://docs.jboss.org/errai/3.0.3.Final/errai/reference/html_single/#sid-19398997_ErraiJAX-RS-Configuration

           

          Cheers,

          Christian

          • 2. Re: DataService is called with null parameter;
            Phillip Nakaska Newbie

            Thanks for looking at that, Christian. I found the Index.html had the erraiJaxRsJacksonMarshallingActive=true, and 

            the App class (marked as @EntryPoint) had the setApplicationRoot.

            I moved the setJacksonMarshallingActive to the App as well., to no effect:


            PostConstruct:

            @EntryPoint

            public class App {

                  @PostConstruct

                      private void init() {

                            RestClient.setApplicationRoot("/esindexview/service");

                             RestClient.setJacksonMarshallingActive(true);

                   }

            }

             

            Although now the search service call receives an empty String rather than just null...


            Also, cutting out a -lot- of redundant errai dependencies in the POM, matching better to the POM in the errai-jaxrs-demo-crud after did not effect anything.

             

            if I use the url: http://localhost:8080/esindexview/service/search I can see the result showing up in the browser (The string 'This is the result', as received by the ResponseCallback

            How would the URL look with the parameter appended? it's not http://localhost:8080/esindexview/service/search?"this is a parameter value" how can I emulate that parameter in the URL?


            Given the question 'Did you configure your REST endpoint to return and expect Jackson based JSON?' Are you referring to the annotations on the service methods (@Produces("application/json")) or is there something else?

             

            What should the JaxRSApplicationConfig @ApplicationPath be set to? currently I've got @ApplicationPath("/service")?

            • 3. Re: DataService is called with null parameter;
              Christian Sadilek Master

              Your /search request is a POST request which is why passing the queryString as URL parameter doesn't work (it needs to be in the request body). The correct syntax for a GET request would be /search?queryString=value (so you're missing the parameter name).

               

              Since you're deploying the RestEasy Jackson Provider you have in fact configured your server to use a Jackson based format, so you will need to activate Jackson marshalling in Errai (which you've already done now).

               

              I would try the following: Add @Consumes("text/plain") and @Produces("text/plain") to your search method. Then execute and inspect a request in your browser's network tab to see what is sent to and returned from the server. After that switch to ("application/json") and do the same. Happy to help more if you can share your findings here.

               

              Cheers,

              Christian

              • 4. Re: DataService is called with null parameter;
                Phillip Nakaska Newbie

                Solved this by modifying the @Path (adding '{message}')

                and adding the PathParam to map the parameter. In the DataServiceImpl:

                 

                @Path("/search/{message}")

                public interface DataService {

                  @GET

                  @Produces("application/json")

                  public String search(@PathParam("message") String value);

                }

                 

                now the service receives the value of the parameter correctly, and the URL:

                http://localhost:8080/esindexview/service/search/message

                 

                shows the parameter value was appended to the result string returned to the callback:

                (Browser output:)

                this is the result:'message'

                 

                 

                Thanks for looking at this!