RestDatasource not processing the xml response when xmlns present

SmartGWT version : 2.5
Browser version : IE 8

I’m facing problem while using the RestDatasource. The xml content received from the spring Rest service is not being processed by the DS. The issue that I observed is that if there are xmlns & xsl present in XML, then the UI is not processing the result and repeatedly invokes the Rest service infinitely.

The java code for processing the RestDataSource and databinding is as follows.

package com.test.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.data.OperationBinding;
import com.smartgwt.client.data.RestDataSource;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.DSOperationType;
import com.smartgwt.client.types.DSProtocol;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Gwt2 implements EntryPoint {

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
      VLayout layout = new VLayout(15);
      layout.setAutoHeight();

      //overrides here are for illustration purposes only
      RestDataSource studentDS = new RestDataSource() {
          @Override
          protected Object transformRequest(DSRequest dsRequest) {
              return super.transformRequest(dsRequest);
          }
          @Override
          protected void transformResponse(DSResponse response, DSRequest request, Object data) {
              super.transformResponse(response, request, data);
          }
      };
      DataSourceTextField studentId = new DataSourceTextField("id", "id");
      OperationBinding fetch = new OperationBinding();
      fetch.setOperationType(DSOperationType.FETCH);
      fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
      studentDS.setOperationBindings(fetch);

      DataSourceTextField studentName = new DataSourceTextField("name", "name");
      studentDS.setFields(studentId, studentName);

      //studentDS.setFetchDataURL("app/students");    //-- This is the Rest Service call
      studentDS.setFetchDataURL("data/students.xml");

      final ListGrid studentGrid = new ListGrid();
      studentGrid.setWidth(500);
      studentGrid.setHeight(224);
      studentGrid.setDataSource(studentDS);
      studentGrid.setEmptyCellValue("--");


      ListGridField idField = new ListGridField("id");
      ListGridField nameField = new ListGridField("name");
      studentGrid.setFields(idField, nameField);
      studentGrid.setSortField(0);
      studentGrid.setDataPageSize(50);
      //studentGrid.setAutoFetchData(true);

      layout.addMember(studentGrid);

      HLayout hLayout = new HLayout(15);

      final IButton fetchButton = new IButton("Fetch");
      fetchButton.setWidth(150);
      fetchButton.addClickHandler(new ClickHandler() {
          public void onClick(ClickEvent event) {
        	  studentGrid.fetchData();
          }
      });
      hLayout.addMember(fetchButton);

      layout.addMember(hLayout);

      layout.draw();
  }
}

The data received from the Rest Service is as below:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<response>
	<data>
		<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="student">
			<id>1</id> 
			<name>Student One</name> 
		</record>
		<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="student">
			<id>2</id> 
			<name>Student Two</name> 
		</record>
		<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="student">
			<id>3</id> 
			<name>Student Three</name> 
		</record>
		<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="student">
			<id>4</id> 
			<name>Student Four</name> 
		</record>
		<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="student">
			<id>5</id> 
			<name>Student Five</name> 
		</record>
		<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="student">
			<id>6</id> 
			<name>Student Six</name> 
		</record>
	</data>
	<endRow>6</endRow> 
	<startRow>0</startRow> 
	<status>0</status> 
	<totalRows>6</totalRows> 
</response>

For testing purpose, I created a sample xml by removing the namespaces and pointed the fetchURL to the static xml (which is given below). It works fine and provides the result in the grid.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<response>
	<data>
		<record>
			<id>1</id> 
			<name>Student One</name> 
		</record>
		<record>
			<id>2</id> 
			<name>Student Two</name> 
		</record>
		<record>
			<id>3</id> 
			<name>Student Three</name> 
		</record>
		<record>
			<id>4</id> 
			<name>Student Four</name> 
		</record>
		<record>
			<id>5</id> 
			<name>Student Five</name> 
		</record>
		<record>
			<id>6</id> 
			<name>Student Six</name> 
		</record>
	</data>
	<endRow>6</endRow> 
	<startRow>0</startRow> 
	<status>0</status> 
	<totalRows>6</totalRows> 
</response>

Adding to this, I extended my testing by just adding the namespace for only one record. The grid displayed all the data except the one which has the namespace and however it again started hitting the server repeatedly when I add the namspace.

I don’t know whether I’m missing to handle the namespace in the client code.

Please help me to resolve this issue.

Thanks
Thiruppathy.R

The best solution is to avoid writing out those attributes. They are a waste of bytes and can only have a negative effect like this. However if you grab a nightly of 2.5.x, you should find that they are now ignored by default.

Thank you for providing this fix in the latest build.

I agree that avoiding those namespaces will reduce the size of the messages a lot. Thank you for the suggestion too. :slight_smile: