1 Reply Latest reply on Jan 2, 2014 9:55 AM by jfuerth

    JSONException in Errai RemoteService REST

    shut_desert

      Hi,tell me please.I used for errai: 3.0.0.20131101-M2. I have a problem with the current task:

       

      public class SimpleInterceptor implements RestClientInterceptor {    
              @Override    
             public void aroundInvoke(final RestCallContext context) {    
                  context.proceed(new ResponseCallback() {    
                      @Override    
                      public void callback(Response response) {    
                          int statusCode = response.getStatusCode();    
                          if (statusCode == 200) {    
                              GWT.log("it's ok");    
                              context.setResult(Marshalling.fromJSON(response.getText()));  
                          }    
                          if (statusCode == 404) {    
                              GWT.log("Error 404");    
                              // to do something    
                          }    
                      }    
                  });    
              }    
          }   
      

       

      remoteService.call(new RemoteCallback<ServerMessage>() {  
                         @Override  
                         public void callback(ServerMessage response) {  
                             Window.alert(response.getText()+" called in HeaderController");  
                         }  
                     }).getMessage();  
      


      public class ServerMessage {
         private String text;
         private Date time;
         public ServerMessage() {
         }
         public ServerMessage(String text, Date time) {
         this.text = text;
         this.time = time;
         }
         getters and setters..
      }
      

      When I call the service, there is an error: JSONException (JSONParse). What am I doing wrong?

        • 1. Re: JSONException in Errai RemoteService REST
          jfuerth

          Hi Yernar,

           

          It's hard to say for sure without seeing the stack trace that comes with the JSONException, but my first guess would be that you forgot to annotate your ServerMessage DTO with @Portable.

           

          My second guess is that your REST client is getting an HTML error page of some sort instead of the JSON data it was expecting (possibly an Internal Server Error page, or a Not Found page with a status code of 200 rather than 404).

           

          If you could follow up with the following information, we can probably help you pinpoint the exact issue:

           

          • The full Dev Mode stack trace associated with the JSONException
          • A dump of the HTTP request that the REST client made, and the response from the server. You can obtain this from the developer tooling in your browser (in Chrome, View -> Developer -> Developer Tools, then click on the Network tab)
          • All log messages generated on the server side while it was processing the REST request

           

          Thanks,

          Jonathan