I used dsRequest.setOutputs() to set the list of fields to return in the response. However, it made no effect when I used RestDataSource. The 'outputs' attribute does not seem to be included in the rpcRequest.
1. the *complete* SmartGWT or SmartClient version from the lower left-hand corner of the Developer Console (see FAQ for how to open Developer Console), for example, \"v8.2p_2012-04-18/PowerEdition Deployment\"
SmartClient Version: v9.0p_2014-01-09/EVAL Deployment (expires 2014.03.10_09.41.58) Licensed to: Isomorphic Software (#ISC_EVAL_NIGHTLY)
2. browser(s) and version(s) involved
FF v17.0.9
3. for a server-side problem, the *complete* logs generated during processing of the failing request (do *not* trim to just the error message)
=== 2014-03-04 18:47:21,743 [l0-2] DEBUG XML - Parsed XML from (in memory stream): 2ms
=== 2014-03-04 18:47:21,743 [l0-2] DEBUG HttpProxyServlet - HttpProxy - ProxyData is: {
xsi:"http://www.w3.org/2000/10/XMLSchema-instance",
url:"http://localhost:8888/data/sampleData.js",
httpMethod:"POST",
params:{
isc_dataFormat:"json"
},
contentType:"application/json",
requestBody:"{\r \"dataSource\":\"isc_MyRestSample_3_0\", \r \"operationType\":\"fetch\", \r \"startRow\":0, \r \"endRow\":75, \r \"textMatchStyle\":\"substring\", \r \"componentId\":\"isc_ListGrid_0\", \r \"data\":{\r }, \r \"oldValues\":null\r}"
}
=== 2014-03-04 18:47:21,796 [l0-2] INFO HttpProxyServlet - HttpProxy - writing body: {
"dataSource":"isc_MyRestSample_3_0",
"operationType":"fetch",
"startRow":0,
"endRow":75,
"textMatchStyle":"substring",
"componentId":"isc_ListGrid_0",
"data":{
},
"oldValues":null
}
4. for any problem processing a server response, the actual response as shown in the RPC tab in the Developer Console
DSRequest:
{
dataSource:"isc_MyRestSample_3_0",
operationType:"fetch",
componentId:"isc_ListGrid_0",
data:{
isc_metaDataPrefix:"_",
isc_dataFormat:"json"
},
startRow:0,
endRow:75,
textMatchStyle:"substring",
resultSet:[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)],
callback:{
caller:[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)],
methodName:"fetchRemoteDataReply"
},
willHandleError:true,
showPrompt:true,
prompt:"Finding Records that match your criteria...",
requestId:"isc_MyRestSample_3_0$6270",
clientContext:{
requestIndex:1
},
fallbackToEval:false,
lastClientEventThreadCode:"MUP1[E]",
bypassCache:true,
outputs:"col1",
isRestRequest:true,
dataFormat:"json",
useHttpProxy:true
}
RPCRequest:
{
dataSource:"isc_MyRestSample_3_0",
operationType:"fetch",
componentId:"isc_ListGrid_0",
data:{
isc_metaDataPrefix:"_",
isc_dataFormat:"json"
},
startRow:0,
endRow:75,
textMatchStyle:"substring",
resultSet:[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)],
callback:{
caller:[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)],
methodName:"fetchRemoteDataReply"
},
willHandleError:true,
showPrompt:true,
prompt:"Finding Records that match your criteria...",
requestId:"isc_MyRestSample_3_0$6270",
clientContext:{
requestIndex:1
},
fallbackToEval:false,
lastClientEventThreadCode:"MUP1[E]",
bypassCache:true,
outputs:"col1",
isRestRequest:true,
dataFormat:"json",
useHttpProxy:true
}
5. if there is a JavaScript error, the stack trace logged in the Developer Console (see FAQ)
6. sample code if applicable
package com.smartgwt.sample.showcase.client.webservice;
import java.util.HashMap;
import java.util.Map;
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.DataSourceTextFiel d;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.types.DSProtocol;
import com.smartgwt.client.types.SelectionAppearance;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.widgets.Canvas;
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.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.sample.showcase.client.PanelFactory;
import com.smartgwt.sample.showcase.client.ShowcasePanel;
public class MyRestSample extends ShowcasePanel {
private static final String DESCRIPTION = "<p>Smart GWT Server includes an HTTP proxy servlet which "
+ "supports contacting REST and WSDL web services as though they were hosted by a local web server, avoiding"
+ " the \"same origin policy\" restriction which normally prevents web applications from accessing remote services.</p>"
+ "<p>The proxy is used automatically whenever an attempt is made to contact a URL on another host - no special code "
+ "is needed. In this example, a RestDataSource is configured to get/post data, "
+ "with no server-side code or proxy configuration required.</p>"
+ "<p>Configuration files allow for restricting proxying to specific services that users are allowed to contact through your application.</p>";
public static class Factory implements PanelFactory {
private String id;
@Override
public ShowcasePanel create() {
MyRestSample panel = new MyRestSample();
id = panel.getID();
return panel;
}
@Override
public String getID() {
return id;
}
@Override
public String getDescription() {
return DESCRIPTION;
}
}
private ListGrid grid;
@Override
public Canvas getViewPanel() {
VLayout layout = new VLayout(15);
layout.setAutoHeight();
grid = createListGrid();
HLayout hLayout = new HLayout(15);
final IButton addButton = new IButton("Add");
addButton.setWidth(150);
addButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
grid.addData(createRecord("new_row", "new_value"));
}
});
hLayout.addMember(addButton);
final IButton removeButton = new IButton("Remove");
removeButton.setWidth(150);
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ListGridRecord record = new ListGridRecord();
grid.removeData(grid.getSelectedRecord());
}
});
hLayout.addMember(removeButton);
layout.setMembers(grid, hLayout);
return layout;
}
@Override
public String getIntro() {
return DESCRIPTION;
}
private ListGrid createListGrid() {
ListGrid grid = new ListGrid();
grid.setHeight(100);
grid.setDataSource(createRestDataSource());
grid.setAutoFetchData(true);
grid.setSelectionType(SelectionStyle.SINGLE);
grid.setSelectionAppearance(SelectionAppearance.CH ECKBOX);
grid.setCanEdit(true);
return grid;
}
private RestDataSource createRestDataSource() {
RestDataSource ds = new RestDataSource() {
@Override
protected Object transformRequest(DSRequest dsRequest) {
dsRequest.setOutputs("col1");
return super.transformRequest(dsRequest);
}
@Override
protected void transformResponse(DSResponse response,
DSRequest request, Object data) {
super.transformResponse(response, request, data);
}
};
ds.setDataFormat(DSDataFormat.JSON);
ds.setUseHttpProxy(true);
DataSourceTextField col1Field = new DataSourceTextField("col1",
"Column 1");
col1Field.setPrimaryKey(true);
col1Field.setCanEdit(false);
DataSourceTextField col2Field = new DataSourceTextField("col2",
"Column 2");
ds.setFields(col1Field, col2Field);
ds.setFetchDataURL("http://localhost:8888/data/sampleData.js");
ds.setAddDataURL("http://localhost:8888/data/sampleAddData.js");
ds.setRemoveDataURL("http://localhost:8888/data/sampleRemoveData.js");
// ds.setFetchDataURL("data/sampleData.js");
// ds.setAddDataURL("data/sampleAddData.js");
// ds.setRemoveDataURL("data/sampleRemoveData.js");
OperationBinding[] bindings = ds.getOperationBindings();
for (int i = 0; i < bindings.length; i++) {
switch (bindings[i].getOperationType()) {
case FETCH:
bindings[i].setDataProtocol(DSProtocol.POSTMESSAGE);
break;
case ADD:
bindings[i].setDataProtocol(DSProtocol.POSTMESSAGE);
break;
case UPDATE:
bindings[i].setDataProtocol(DSProtocol.POSTMESSAGE);
break;
case REMOVE:
bindings[i].setDataProtocol(DSProtocol.POSTMESSAGE);
break;
default:
}
}
return ds;
}
public ListGridRecord createRecord(String val1, String val2) {
ListGridRecord record = new ListGridRecord();
record.setAttribute("col1", val1);
record.setAttribute("col2", val2);
return record;
}
}
1. the *complete* SmartGWT or SmartClient version from the lower left-hand corner of the Developer Console (see FAQ for how to open Developer Console), for example, \"v8.2p_2012-04-18/PowerEdition Deployment\"
SmartClient Version: v9.0p_2014-01-09/EVAL Deployment (expires 2014.03.10_09.41.58) Licensed to: Isomorphic Software (#ISC_EVAL_NIGHTLY)
2. browser(s) and version(s) involved
FF v17.0.9
3. for a server-side problem, the *complete* logs generated during processing of the failing request (do *not* trim to just the error message)
=== 2014-03-04 18:47:21,743 [l0-2] DEBUG XML - Parsed XML from (in memory stream): 2ms
=== 2014-03-04 18:47:21,743 [l0-2] DEBUG HttpProxyServlet - HttpProxy - ProxyData is: {
xsi:"http://www.w3.org/2000/10/XMLSchema-instance",
url:"http://localhost:8888/data/sampleData.js",
httpMethod:"POST",
params:{
isc_dataFormat:"json"
},
contentType:"application/json",
requestBody:"{\r \"dataSource\":\"isc_MyRestSample_3_0\", \r \"operationType\":\"fetch\", \r \"startRow\":0, \r \"endRow\":75, \r \"textMatchStyle\":\"substring\", \r \"componentId\":\"isc_ListGrid_0\", \r \"data\":{\r }, \r \"oldValues\":null\r}"
}
=== 2014-03-04 18:47:21,796 [l0-2] INFO HttpProxyServlet - HttpProxy - writing body: {
"dataSource":"isc_MyRestSample_3_0",
"operationType":"fetch",
"startRow":0,
"endRow":75,
"textMatchStyle":"substring",
"componentId":"isc_ListGrid_0",
"data":{
},
"oldValues":null
}
4. for any problem processing a server response, the actual response as shown in the RPC tab in the Developer Console
DSRequest:
{
dataSource:"isc_MyRestSample_3_0",
operationType:"fetch",
componentId:"isc_ListGrid_0",
data:{
isc_metaDataPrefix:"_",
isc_dataFormat:"json"
},
startRow:0,
endRow:75,
textMatchStyle:"substring",
resultSet:[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)],
callback:{
caller:[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)],
methodName:"fetchRemoteDataReply"
},
willHandleError:true,
showPrompt:true,
prompt:"Finding Records that match your criteria...",
requestId:"isc_MyRestSample_3_0$6270",
clientContext:{
requestIndex:1
},
fallbackToEval:false,
lastClientEventThreadCode:"MUP1[E]",
bypassCache:true,
outputs:"col1",
isRestRequest:true,
dataFormat:"json",
useHttpProxy:true
}
RPCRequest:
{
dataSource:"isc_MyRestSample_3_0",
operationType:"fetch",
componentId:"isc_ListGrid_0",
data:{
isc_metaDataPrefix:"_",
isc_dataFormat:"json"
},
startRow:0,
endRow:75,
textMatchStyle:"substring",
resultSet:[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)],
callback:{
caller:[ResultSet ID:isc_ResultSet_0 (created by: isc_ListGrid_0)],
methodName:"fetchRemoteDataReply"
},
willHandleError:true,
showPrompt:true,
prompt:"Finding Records that match your criteria...",
requestId:"isc_MyRestSample_3_0$6270",
clientContext:{
requestIndex:1
},
fallbackToEval:false,
lastClientEventThreadCode:"MUP1[E]",
bypassCache:true,
outputs:"col1",
isRestRequest:true,
dataFormat:"json",
useHttpProxy:true
}
5. if there is a JavaScript error, the stack trace logged in the Developer Console (see FAQ)
6. sample code if applicable
package com.smartgwt.sample.showcase.client.webservice;
import java.util.HashMap;
import java.util.Map;
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.DataSourceTextFiel d;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.types.DSProtocol;
import com.smartgwt.client.types.SelectionAppearance;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.widgets.Canvas;
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.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.sample.showcase.client.PanelFactory;
import com.smartgwt.sample.showcase.client.ShowcasePanel;
public class MyRestSample extends ShowcasePanel {
private static final String DESCRIPTION = "<p>Smart GWT Server includes an HTTP proxy servlet which "
+ "supports contacting REST and WSDL web services as though they were hosted by a local web server, avoiding"
+ " the \"same origin policy\" restriction which normally prevents web applications from accessing remote services.</p>"
+ "<p>The proxy is used automatically whenever an attempt is made to contact a URL on another host - no special code "
+ "is needed. In this example, a RestDataSource is configured to get/post data, "
+ "with no server-side code or proxy configuration required.</p>"
+ "<p>Configuration files allow for restricting proxying to specific services that users are allowed to contact through your application.</p>";
public static class Factory implements PanelFactory {
private String id;
@Override
public ShowcasePanel create() {
MyRestSample panel = new MyRestSample();
id = panel.getID();
return panel;
}
@Override
public String getID() {
return id;
}
@Override
public String getDescription() {
return DESCRIPTION;
}
}
private ListGrid grid;
@Override
public Canvas getViewPanel() {
VLayout layout = new VLayout(15);
layout.setAutoHeight();
grid = createListGrid();
HLayout hLayout = new HLayout(15);
final IButton addButton = new IButton("Add");
addButton.setWidth(150);
addButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
grid.addData(createRecord("new_row", "new_value"));
}
});
hLayout.addMember(addButton);
final IButton removeButton = new IButton("Remove");
removeButton.setWidth(150);
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ListGridRecord record = new ListGridRecord();
grid.removeData(grid.getSelectedRecord());
}
});
hLayout.addMember(removeButton);
layout.setMembers(grid, hLayout);
return layout;
}
@Override
public String getIntro() {
return DESCRIPTION;
}
private ListGrid createListGrid() {
ListGrid grid = new ListGrid();
grid.setHeight(100);
grid.setDataSource(createRestDataSource());
grid.setAutoFetchData(true);
grid.setSelectionType(SelectionStyle.SINGLE);
grid.setSelectionAppearance(SelectionAppearance.CH ECKBOX);
grid.setCanEdit(true);
return grid;
}
private RestDataSource createRestDataSource() {
RestDataSource ds = new RestDataSource() {
@Override
protected Object transformRequest(DSRequest dsRequest) {
dsRequest.setOutputs("col1");
return super.transformRequest(dsRequest);
}
@Override
protected void transformResponse(DSResponse response,
DSRequest request, Object data) {
super.transformResponse(response, request, data);
}
};
ds.setDataFormat(DSDataFormat.JSON);
ds.setUseHttpProxy(true);
DataSourceTextField col1Field = new DataSourceTextField("col1",
"Column 1");
col1Field.setPrimaryKey(true);
col1Field.setCanEdit(false);
DataSourceTextField col2Field = new DataSourceTextField("col2",
"Column 2");
ds.setFields(col1Field, col2Field);
ds.setFetchDataURL("http://localhost:8888/data/sampleData.js");
ds.setAddDataURL("http://localhost:8888/data/sampleAddData.js");
ds.setRemoveDataURL("http://localhost:8888/data/sampleRemoveData.js");
// ds.setFetchDataURL("data/sampleData.js");
// ds.setAddDataURL("data/sampleAddData.js");
// ds.setRemoveDataURL("data/sampleRemoveData.js");
OperationBinding[] bindings = ds.getOperationBindings();
for (int i = 0; i < bindings.length; i++) {
switch (bindings[i].getOperationType()) {
case FETCH:
bindings[i].setDataProtocol(DSProtocol.POSTMESSAGE);
break;
case ADD:
bindings[i].setDataProtocol(DSProtocol.POSTMESSAGE);
break;
case UPDATE:
bindings[i].setDataProtocol(DSProtocol.POSTMESSAGE);
break;
case REMOVE:
bindings[i].setDataProtocol(DSProtocol.POSTMESSAGE);
break;
default:
}
}
return ds;
}
public ListGridRecord createRecord(String val1, String val2) {
ListGridRecord record = new ListGridRecord();
record.setAttribute("col1", val1);
record.setAttribute("col2", val2);
return record;
}
}