Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Bas TransformResponse and correct JSON being reported as bad

    Be sure your post includes:
    1. SmartClient Version: v9.0_2013-07-03/LGPL Development Only (built 2013-07-03)

    2. Firefox 24.0

    Error:
    Code:
    15:04:20.592 [ERROR] [SoccerAdmin] 15:04:20.590:XRP7:WARN:RestDataSource:restLoginDS:RestDataSouce transformResponse(): JSON response text does not appear to be in standard response format.
    
    com.smartgwt.client.core.JsObject$SGWT_WARN: 15:04:20.590:XRP7:WARN:RestDataSource:restLoginDS:RestDataSouce transformResponse(): JSON response text does not appear to be in standard response format.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:299)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
        at com.smartgwt.client.data.DataSource.transformResponse(DataSource.java)
        at com.companyname.products.soccer.admin.client.datasource.LoginDataSource.transformResponse(LoginDataSource.java:273)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
        at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
        at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
        at java.lang.Thread.run(Thread.java:662)
    I had another two previously working SmartGWT apps which called RESTful SpringMVC controllers. They received JSON and sent JSON databack successfully, and SmartGWT at one point was happy to receive this properly formatted custom data. However, now this new app is broken, and the old apps seem broken also, but I can't find what the issue is.

    The back-end SpringMVC controller is Unit Tested and works. It uses the Jackson 2.0 mapper to translate from objects to JSON and back again. The controller is sending back a UserEntity which looks like:

    Code:
    {
            "userId":1, 
            "username":"tholmes", 
            "password":"password", 
            "active":true, 
            "fullname":"Thomas Holmes", 
            "birthdate":"1960-01-01", 
            "email":"tom@tomholmes.net", 
            "cellPhone":"111-222-1234", 
            "updatedBy":1, 
            "updatedDate":"2013-01-01", 
            "createdBy":1, 
            "createdDate":"2013-01-01", 
            "securityQuestion1":"first car", 
            "securityAnswer1":"prius"
        }
    I have unit tested this JSON with Jackson Mapper 2.0 from a JSON String to UserEntity to UserDTO to String and back again. This all looks like it works. I also used the JSON.encode to translate from a JavaScriptObject to a String and that JSON string data can also be translated into an object. Finally, I tested this JSON data against several online JSON validators to make sure that the JSON was correct.

    In the RestDataSource I double-checked that the dataSourc field names match those in the JSON.
    Code:
     protected void init()
        {
            System.out.println("init: START");
    
            setDataFormat(DSDataFormat.JSON);
            setJsonRecordXPath("/");
    
            // set the values for the datasource
            userIdField = new DataSourceIntegerField("userId", Constants.TITLE_USER_ID);
            userIdField.setPrimaryKey(true);
            userIdField.setCanEdit(false);
    
            usernameField = new DataSourceTextField("username", Constants.TITLE_USER_USERNAME);
            usernameField.setCanEdit(false);
    
            passwordField = new DataSourceTextField("password", Constants.TITLE_USER_PASSWORD);
            passwordField.setCanEdit(false);
    
            userActiveField = new DataSourceBooleanField("active", Constants.TITLE_USER_ACTIVE);
    
            fullnameField = new DataSourceTextField("fullname", Constants.TITLE_USER_FULLNAME);
    
            birthdateField = new DataSourceDateField("birthdate", Constants.TITLE_USER_BIRTHDATE);
    
            emailField = new DataSourceTextField("email", Constants.TITLE_USER_EMAIL);
    
            cellPhoneField = new DataSourceTextField("cellPhone", Constants.TITLE_USER_CELL_PHONE);
    
            securityQuestion1Field = new DataSourceTextField("securityQuestion1", Constants.TITLE_USER_SECURITY_QUESTION_1);
            securityAnswer1Field = new DataSourceTextField("securityAnswer1", Constants.TITLE_USER_SECURITY_ANSWER_1);
    
            updatedByField = new DataSourceIntegerField("updatedBy", Constants.TITLE_USER_UPDATED_BY);
            updatedDateField = new DataSourceDateField("updatedDate", Constants.TITLE_USER_UPDATED_DATE);
            createdByField = new DataSourceIntegerField("createdBy", Constants.TITLE_USER_CREATED_BY);
            createdDateField = new DataSourceDateField("createdDate", Constants.TITLE_USER_CREATED_DATE);
    
            System.out.println("init: FINISH");
            setFields(userIdField, usernameField, passwordField, userActiveField, emailField, cellPhoneField,
                fullnameField, birthdateField, securityQuestion1Field, securityAnswer1Field, updatedByField,
                updatedDateField, createdByField, createdDateField);
    
            // setFetchDataURL(getServiceRoot() + "/userId/{id}");
            // setFetchDataURL(getServiceRoot() + "/contactId/{id}");
            setAddDataURL(getServiceRoot() + "/create");
            setUpdateDataURL(getServiceRoot() + "/update");
            setRemoveDataURL(getServiceRoot() + "/remove/{id}");
        }
    As for the DSReponse itself, within the transformResponse itself I have the following:
    Code:
    @Override
        protected void transformResponse(DSResponse response, DSRequest request, Object jsonData)
        {
            System.out.println("LoginDataSource: transformResponse: START");
            JavaScriptObject jsObj = (JavaScriptObject) jsonData;
            String jsoText1 = JSON.encode(jsObj);
            System.out.println("LoginDataSource: transformResponse: jsoText1=" + jsoText1);
    
            System.out.println("LoginDataSource: transformResponse: jsonData=" + jsonData.getClass());
    
            for (String attr : response.getAttributes())
            {
                System.out.println("LoginDataSource: transformResponse: attr=" + attr + " value="
                    + response.getAttribute(attr));
            }
            super.transformResponse(response, request, jsonData);
        }
    I am looking at the data for the response, which I don't think I have any control over. I thought the RestDataSource created that correctly, and this is what I can is there:
    Code:
    LoginDataSource: transformResponse: jsonData=class com.google.gwt.core.client.JavaScriptObject$
    LoginDataSource: transformResponse: attr=data value=[object Object]
    LoginDataSource: transformResponse: attr=startRow value=0
    LoginDataSource: transformResponse: attr=status value=0
    LoginDataSource: transformResponse: attr=endRow value=1
    LoginDataSource: transformResponse: attr=totalRows value=1
    LoginDataSource: transformResponse: attr=httpResponseCode value=200
    LoginDataSource: transformResponse: attr=transactionNum value=0
    LoginDataSource: transformResponse: attr=clientContext value=null
    LoginDataSource: transformResponse: attr=httpHeaders value=[object Object]
    LoginDataSource: transformResponse: attr=context value=[object Object]
    So, if the response should be correct because I have no control over it, and if my JSON is correct, then I am at a loss as to what the issue is.

    I have installed the SmartClient Developer Tools, and I pulled it up. I did turn on the tracking of RPC's and unfortunately, this tracking is not getting called, and I am not able to see the request/response at all.

    I think I've done my due diligence here, and I have researched this, even comparing my current code to other previously working projects. However, this projects are now reporting the same error with their JSON data, and I have checked to make sure that JSON is correct also.

    Any help would be much appreciated. Thanks!

    #2
    RestDataSource transformResponse is broken

    Well ... I doubt Isomophic will admit it, but it seems that the transformResponse of a RestDataSource is broken.

    Here is a simple test app:
    Code:
    public class TestApp implements EntryPoint
    {
        private DataSourceIntegerField userIdField;
    
        public void onModuleLoad()
        {
        RestDataSource dataSource = new RestDataSource();
        dataSource.setDataFormat(DSDataFormat.JSON);
        dataSource.setDataURL("data/single_user.json");
    
        // set the values for the datasource
        userIdField = new DataSourceIntegerField("userId", "User Id");
        userIdField.setPrimaryKey(true);
        userIdField.setCanEdit(false);
    
        dataSource.setFields(userIdField);
    
        ListGrid grid = new ListGrid();
        grid.setDataSource(dataSource);
        grid.setWidth100();
        grid.setHeight(150);
        grid.setAutoFetchData(true);
        grid.draw();
        }
    }
    The single_user.json looks like:
    {"userId":1} or {"userId":"1"}
    This is as simple as it gets, and this is corect JSON.

    The error message that I reported comes up again:
    Code:
    15:35:40.181 [ERROR] [SoccerAdmin]
    15:35:40.179:XRP7:WARN:RestDataSource:restUserDS:RestDataSource
    transformResponse(): JSON response text is incorrectly formatted as an Array rather than a simple response object.
    
    com.smartgwt.client.core.JsObject$SGWT_WARN: 
    15:35:40.179:XRP7:WARN:RestDataSource:restUserDS:RestDataSource
    transformResponse(): JSON response text is incorrectly formatted as an Array rather than a simple response object.
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
    Method)
         at
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
         at
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
         at
    com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
         at
    com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
         at
    com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
         at
    com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
         at
    com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
         at
    com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
         at
    com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
         at
    com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:299)
         at
    com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
         at
    com.smartgwt.client.data.DataSource.transformResponse(DataSource.java)
         at
    com.medenasoft.products.soccer.admin.client.datasource.UserDataSource.transformResponse(UserDataSource.java:211)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at
    com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
         at
    com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
         at
    com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
         at
    com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
         at
    com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
         at
    com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
         at
    com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
         at
    com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
         at
    com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
         at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
         at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
         at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
         at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at
    com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
         at
    com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
         at
    com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
         at
    com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
         at
    com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
         at
    com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
         at java.lang.Thread.run(Thread.java:662)
    The break is always in the super.transformResponse line. The fix was to change this to a regular "DataSource" and that fixed my issue.

    I am using Spring MVC 3.2, and I know my controllers are well tested and always return JSON. My springmvc-servlet.xml uses the com.fasterxml.jackson.core 2.2.3 to automatically transform anything coming from my controller to JSON. I know this is valid JSON and I have several use cass where this JSON is converted back into an Object on the SmartGWT client-side.

    Just an FYI, I had a previous basic application which worked great with super.transformResponse in a RestDataSource. I copied this configuration over to a new app, and presumed it would work the same, but it didn't. Then I went back to the original app, re-compiled and re-ran, and realized I was getting the same error.

    I hope this helps someone else fix this issue.

    Comment

    Working...
    X