3 Replies Latest reply on Apr 4, 2013 2:50 PM by csa

    Help : Errai-Jaxrs Format

    chaluwa

      Sorry to bug you guys again, just to be sure whats goin on in my app. The app is expected to expose services in a REST way, so that other clients (especially a jQuery Mobile cient) can consume the exposed data. Hence I enabled the Jackson JSON format in the app :

       

      private native void setJacksonMarshallingActive(boolean active) /*-{

                   $wnd.erraiJaxRsJacksonMarshallingActive = active;

                }-*/;

       

      which I called with setJacksonMarshallingActive(true);

      And here is a sample output containing some "type" information, so is this the Jackson format :

       

      {"^EncodedType":"java.util.ArrayList","^ObjectID":"1","^Value":[{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Institution","^ObjectID":"2","id" : {"^EncodedType":"java.lang.Long", "^ObjectID": "-1","^NumVal":"9"},"name" : "Benson Idahosa University","shortName" : "BIU","slogan" : "Dummy slogan","schoolType" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.SchoolType","^EnumStringValue":"PrivateUniversity"},"schoolProgrammes" : {"^EncodedType":"org.hibernate.collection.internal.PersistentSet","^ObjectID":"3","^Value":[]},"catchmentAreas" : {"^EncodedType":"org.hibernate.collection.internal.PersistentBag","^ObjectID":"4","^Value":[{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Catchment","^EnumStringValue":"Delta"},{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Catchment","^EnumStringValue":"Edo"}]},"nation" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Nation","^EnumStringValue":"Nigeria"},"region" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Region","^EnumStringValue":"SubSaharanAfrica"}},{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Institution","^ObjectID":"5","id" : {"^EncodedType":"java.lang.Long", "^ObjectID": "-1","^NumVal":"10"},"name" : "Delta State University","shortName" : "DELSU","slogan" : "The Big Heart School","schoolType" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.SchoolType","^EnumStringValue":"StateUniversity"},"schoolProgrammes" : {"^EncodedType":"org.hibernate.collection.internal.PersistentSet","^ObjectID":"6","^Value":[]},"catchmentAreas" : {"^EncodedType":"org.hibernate.collection.internal.PersistentBag","^ObjectID":"7","^Value":[{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Catchment","^EnumStringValue":"Delta"},{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Catchment","^EnumStringValue":"Edo"}]},"nation" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Nation","^EnumStringValue":"Nigeria"},"region" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Region","^EnumStringValue":"SubSaharanAfrica"}},{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Institution","^ObjectID":"8","id" : {"^EncodedType":"java.lang.Long", "^ObjectID": "-1","^NumVal":"7"},"name" : "University of Benin","shortName" : "UniBen","slogan" : "Knowledge for Service","schoolType" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.SchoolType","^EnumStringValue":"FederalUniversity"},"schoolProgrammes" : {"^EncodedType":"org.hibernate.collection.internal.PersistentSet","^ObjectID":"9","^Value":[]},"catchmentAreas" : {"^EncodedType":"org.hibernate.collection.internal.PersistentBag","^ObjectID":"10","^Value":[{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Catchment","^EnumStringValue":"Bayelsa"},{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Catchment","^EnumStringValue":"Delta"},{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Catchment","^EnumStringValue":"Edo"},{"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Catchment","^EnumStringValue":"Lagos"}]},"nation" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Nation","^EnumStringValue":"Nigeria"},"region" : {"^EncodedType":"com.bitrunk.apps.unitalk.client.shared.Region","^EnumStringValue":"SubSaharanAfrica"}}]}

        • 1. Re: Help : Errai-Jaxrs Format
          csa

          Hi Charles,

           

          Setting Jackson marshalling active means that your client will expect and produce Jackson's JSON format. You still have to make sure that your server produces Jackson. In JAX-RS this is done using the corresponding provider. Right now you probably deployed the errai-jaxrs-provider.jar to your server (which will produce Errai JSON). Just remove this provider and make sure your server responds with Jackson generated JSON.

           

          Cheers,

          Christian

          • 2. Re: Help : Errai-Jaxrs Format
            chaluwa

            Thanks Christian for the very prompt response. I also need to clarify something about the Errai-Cordova  Config class for a demo unitalk-mobile app, its generated (by maven) thus:

            public class Config implements Configuration {

                @Override

                public String getRemoteLocation() {

                    return "http://localhost:8080//unitalk-mobile/";

                }

            }

             

            This mobile app is to consume JSON from another Errai app (unitalk) that exposes the "schools" data via a URL like so: http://localhost:8080/unitalk/rest/schools

            Now the question is, do I return http://localhost:8080/unitalk/rest/schools from the getRemoteLocation() method of the mobile app's Config class, or is it somehow possible (I doubt) to call the REST service from the mobile app using the Caller<T> API considerigt that the REST service interface is defined by another application.

             

            Thanks for all the help.

            • 3. Re: Help : Errai-Jaxrs Format
              csa

              Hi Charles,

               

              getRemoteLocation is for specifying the remote bus endpoint. You don't need it for errai-jaxrs. If you need to specify an alternative path for your rest calls (in case the endpoint is not part of the same web app context) you can configure that separately.

               

              See details here:

              https://docs.jboss.org/author/display/ERRAI/Errai+JAX-RS#ErraiJAX-RS-ConfiguringthedefaultrootpathofJAXRSendpoints

               

              Cheers,

              Christian