5 Replies Latest reply on Mar 9, 2013 8:21 AM by t.gruen2

    Rest in Errai without JAX-RS?

    t.gruen2

      Hello,

       

      I just came across Errai and am very curious to find out if we can/should use it for our project. One thing I’m very interested in is calling rest services as backend. We have a running server component and I have to reuse that instead of any new protocol or using the bus system (which is really nice).

      My problem is that most rest services I can think of are written using the Class javax.ws.rs.core.Response as result or are written in some other technology. Because of that I can’t use the JAX-RS interface as described in the Errai documentation.

       

      My question here is: What would you use to access such rest services in Errai? Can I reuse some things like marshaling framework? Or should I stick to GWT request builder or any other frameowork (restyGWT?) Maybe I could at least reuse the transfer objects from the server’s code base.

       

      I would appreciate any help and advice on that topic.

       

      Kind regards

      Tom

        • 1. Re: Rest in Errai without JAX-RS?
          csa

          Hi Tom,

           

          The JAX-RS interface can just be a client-side interface. You don't have to implement it on the server, if you don't need to. In this case the client-side interface would just describe the HTTP interaction with the existing endpoints.

           

          Also, javax.ws.rs.core.Response can be used in an JAX-RS interface that is used by Errai on the client. You can use the ResponseCallback to get a GWT Response object for it, see https://docs.jboss.org/author/display/ERRAI/Errai+JAX-RS#ErraiJAX-RS-HandlingResponses.

           

          The advantage of still using a JAX-RS interface and therefore using Errai JAX-RS is that your interactions with the server are declarative and in one place. Plus you can use Errai's marshalling system (for your shared transfer objects).

           

          On the server, you can either deploy the errai-jaxrs-provider, so your endpoint generates Errai's json or configure it to use Jackson.

           

          We could add an additional client API that does not rely on JAX-RS annotations but I am not sure what the benefits would be. For instance, we could add suppport for the new client API  of JAX-RS 2.0. What do you think?

           

          Cheers,

          Christian

          1 of 1 people found this helpful
          • 2. Re: Rest in Errai without JAX-RS?
            t.gruen2

            Hi Christian,

             

            Thanks for your fast support.

            So in case I use the interface just in the client, I have to write java classes exactly matching the JSON format right? I think this can be challenging (still I like this solution the most at that moment).

            I read about the client response object, but I didn’t figure out if I’m able to use any demarshalling framework. Can I use an util that converts the text from the response to objects?

             

            Kind regards

            Tom

            • 3. Re: Rest in Errai without JAX-RS?
              csa

              Hi,

               

              Yes you can call into MarshallingWrapper.fromJson(response.getText(), MyType.class), where MyType is a @Portable type. But like I said this will only work if your JSON is either Errai's JSON or Jackson.

               

              Cheers,

              Christian

              • 4. Re: Rest in Errai without JAX-RS?
                t.gruen2

                Hi,

                 

                that's perfect. Thanks a lot. As the first service I want to call uses Jersey I will give Errai a shot.

                 

                Beside of that I found this tutorial covering JSON in GWT: https://developers.google.com/web-toolkit/doc/latest/tutorial/JSON. If the Marshalling doesn't work I try creating overlays and use Errai UI.

                 

                Cheers,

                Tom

                • 5. Re: Rest in Errai without JAX-RS?
                  t.gruen2

                  Short feedback: works like a charm!

                  I set up Jackson marshaling and used Chrome developer tools to find out the correct base URLs. And I reuse the beans from server code.

                   

                  Cheers

                  Tom