Announcement

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

    Limitation of SmartGWT RestDataSource

    While creating a simple client for a REST service which I have stubbed out, I noticed that smartGWT's RestDataSource class is limited in the type of xml it can understand. All REST resources must respond with XML in the following format..

    Code:
    <response>
      <status>0</status>
      <startRow>0</startRow>
      <endRow>10</endRow>
      <totalRows>50</totalRows>
      <data>
            <record>
                <someField>value</someField>
                <someOtherField>value</someOtherField>
            </record>
            <record>
                <someField>value</someField>
                <someOtherField>value</someOtherField> 
            </record>
            ...
      </data>
    </response>
    .. where the *only variant* is the someField/someOtherField tags.

    This structure, which is little more than name/value pairs, is not going to work for us.

    From the RestDataSource javadoc....

    "If you have a pre-existing REST or WSDL service which is difficult to change, consider adapting Smart GWT to the existing service instead, by starting with a normal{@link com.smartgwt.client.data.DataSource} and using the {@link com.smartgwt.client.docs.ClientDataIntegration 'client-side data integration'} facilities to create a mapping between Smart GWT's {@link com.smartgwt.client.data.DSRequest} and {@link com.smartgwt.client.data.DSResponse} objects and the message formats of your existing services."

    Has anyone out there done this? I am wondering if this approach has been battle-tested or not. I would love to see someone's solution. It sounds like it would require quite a bit of boilerplate code.

    Thanks!

    #2
    It's very common and very simple.

    Comment


      #3
      Thank you sir. This is precisely what I was looking for.

      Comment


        #4
        Is there an example somewhere of how to do a PUT operation on a REST service?

        Comment


          #5
          It can be done. Take a look at the datasource operationBindings. In particular look at the dataProtocol and requestProperties. You likely want postmessage for the protocol and need to add httpMethod of PUT to requestProperties.

          Comment


            #6
            OK getting very close...

            Code:
                DataSource dataSource = new DataSource();
                dataSource.setRecordXPath("//default:Widget");
            		
                // PUT				
                OperationBinding put = new OperationBinding(DSOperationType.ADD,"/SampleServer/widget/");
                put.setDataFormat(DSDataFormat.XML);
                put.setDataProtocol(DSProtocol.POSTXML);
                put.setRecordName("Widget");
            		
                DSRequest putProps = new DSRequest();
                putProps.getUseSimpleHttp();
                putProps.setHttpMethod("PUT");
                put.setRequestProperties(putProps);
            
                // GET
                OperationBinding get = new OperationBinding(DSOperationType.FETCH,"/SampleServer/widget/");		
                
                dataSource.setOperationBindings(put,get);
                
                DataSourceTextField nameField = new DataSourceTextField("Name", "Name");
                DataSourceTextField priceField = new DataSourceTextField("Price", "Price");
                dataSource.setFields(nameField, priceField);
            When attached to a grid this basically works.... the problem is that when performing a PUT the resulting request body looks like this...

            Code:
            <isc_OID_0>  
              <Name>asdfsd</Name>  
              <Price>1234</Price> 
            </isc_OID_0>
            Where my server expects the following...

            Code:
            <Widget>  
              <Name>asdfsd</Name>  
              <Price>1234</Price> 
            </Widget>
            I would have though setRecordName("Widget") would accomplish that, but apparently not.

            Comment


              #7
              recordName is doc'd as being involved in response parsing. The DataSource ID, or alternatively dataSource.tagName, determines what happens on serialization of data.

              Comment

              Working...
              X