I have this DataSource class:
<code>
public abstract class BasicRestDataSource extends RestDataSource {
protected abstract void bindFields();
public BasicRestDataSource() {
createAndInitRestDatasource();
bindFields();
}
protected void createAndInitRestDatasource() {
setDataFormat(DSDataFormat.JSON);
}
protected void setUpOperationBindings() {
// set up FETCH to use GET requests
OperationBinding fetch = new OperationBinding();
fetch.setOperationType(DSOperationType.FETCH);
fetch.setDataProtocol(DSProtocol.GETPARAMS);
DSRequest fetchProps = new DSRequest();
fetchProps.setHttpMethod("GET");
fetch.setRequestProperties(fetchProps);
// set up ADD to use POST requests
OperationBinding add = new OperationBinding();
add.setOperationType(DSOperationType.ADD);
add.setDataProtocol(DSProtocol.POSTMESSAGE);
DSRequest addProps = new DSRequest();
addProps.setHttpMethod("POST");
addProps.setContentType("application/json");
add.setRequestProperties(addProps);
// set up UPDATE to use PUT
OperationBinding update = new OperationBinding();
update.setOperationType(DSOperationType.UPDATE);
update.setDataProtocol(DSProtocol.POSTMESSAGE);
DSRequest updateProps = new DSRequest();
updateProps.setHttpMethod("POST");
updateProps.setContentType("application/json");
update.setRequestProperties(updateProps);
// set up REMOVE to use DELETE
OperationBinding remove = new OperationBinding();
remove.setOperationType(DSOperationType.REMOVE);
remove.setDataProtocol(DSProtocol.POSTMESSAGE);
DSRequest removeProps = new DSRequest();
removeProps.setHttpMethod("DELETE");
remove.setRequestProperties(removeProps);
// apply all the operational bindings
setOperationBindings(fetch, add, update, remove);
}
}
</code>
I have this Impl Class for my BasicRestDataSource
<code>
public class TestDataSource extends BasicRestDataSource {
@Override
protected void createAndInitRestDatasource() {
super.createAndInitRestDatasource();
setUpOperationBindings();
}
@Override
protected void bindFields() {
DataSourceTextField cityClinicSystemId = new DataSourceTextField("CityClinicSystemId", "City Clinic System ID");
cityClinicSystemId.setPrimaryKey(true);
cityClinicSystemId.setCanEdit(false);
DataSourceTextField stateClinicSystemId = new DataSourceTextField("stateClinicSystemId", "State Clinic System ID");
DataSourceTextField activityStatus = new DataSourceTextField("activityStatus", "Activity Status");
DataSourceDateField dateitem = new DataSourceDateField("dateitem","Date of Inception");
setFields(stateClinicSystemId,activityStatus,dateitem);
setFetchDataURL("http://localhost:4567/fetchData");
setAddDataURL("http://localhost:4567/saveData");
setUpdateDataURL("http://localhost:4567/saveData");
}
}
</code>
I have tested the rest resources using curl and they all work fine. No issues. 100% perfect. Not to worry there at all
Now in my GWT Module. I have a code which simple creates a form like as follows:
<code>
private DynamicForm createDynamicForm() {
DynamicForm dynaForm = new DynamicForm();
dynaForm.setNumCols(2);
dynaForm.setColWidths("230,*");
dynaForm.setWidth(401);
dynaForm.setAutoDraw(false);
dynaForm.setDataSource(new TestDataSource());
return dynaForm;
}
</code>
and then I have a two buttons. Button for fetch and Button for save. Very Simple. No complications
<code>
Button fd = new Button("fetch");
Button sd = new Button("save");
vStack.addMember(fd);
vStack.addMember(sd);
fd.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
dynaForm.fetchData();
}
});
sd.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
dynaForm.saveData();
}
});
</code>
when I click the fetch button. I get response from the rest and dynaFOrm happily loads the data and i am happy. But when I press save button. I get this error
<code>
=== 2013-09-07 17:48:37,628 [l0-2] DEBUG RPCDMI - rpc returned RPCResponse
=== 2013-09-07 17:48:37,628 [l0-2] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
=== 2013-09-07 18:03:50,893 [l0-2] DEBUG XML - Parsed XML from (in memory stream): 2ms
=== 2013-09-07 18:03:50,895 [l0-2] DEBUG HttpProxyServlet - HttpProxy - ProxyData is: {
xsi:"http://www.w3.org/2000/10/XMLSchema-instance",
url:"http://localhost:4567/saveData",
httpMethod:"POST",
params:{
isc_dataFormat:"json"
},
contentType:"application/json",
requestBody:"{\r \"dataSource\":\"isc_TestDataSource_0\", \r \"operationType\":\"update\", \r \"componentId\":\"isc_DynamicForm_0\", \r \"data\":{\r \"stateClinicSystemId\":\"100\", \r \"activityStatus\":\"Active\", \r \"dateitem\":\"2013-09-04\", \r \"ownerType\":\"Public\"\r }, \r \"oldValues\":{\r \"stateClinicSystemId\":\"100\", \r \"activityStatus\":\"Active\", \r \"dateitem\":\"2013-09-04\", \r \"ownerType\":\"Public\"\r }\r}"
}
=== 2013-09-07 18:03:50,895 [l0-2] ERROR XML - XML parser fatal error: file '(in memory stream)' line 1: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
=== 2013-09-07 18:03:50,895 [l0-2] DEBUG XML - Exception thrown during XML parsing
=== 2013-09-07 18:03:50,896 [l0-2] ERROR HttpProxyServlet - HttpProxy - Top-level servlet error:
com.isomorphic.xml.XMLParsingException: [
"XML parser fatal error: file '(in memory stream)' line 1: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog."
]
at com.isomorphic.xml.XML.parseXML(XML.java:206)
at com.isomorphic.xml.XML.parseXML(XML.java:125)
at com.isomorphic.servlet.HttpProxyServlet.doPost(HttpProxyServlet.java:495)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
</code>
The debug console gives this as a trace
DSRequest Tab output of RPC TAB
<code>
{
dataSource:"isc_TestDataSource_0",
operationType:"update",
componentId:"isc_DynamicForm_0",
data:"{\r \"dataSource\":\"isc_TestDataSource_0\", \r \"operationType\":\"update\", \r \"componentId\":\"isc_DynamicForm_0\", \r \"data\":{\r \"stateClinicSystemId\":\"100\", \r \"activityStatus\":\"Active\", \r \"dateitem\":\"2013-09-04\", \r \"ownerType\":\"Public\"\r }, \r \"oldValues\":{\r \"stateClinicSystemId\":\"100\", \r \"activityStatus\":\"Active\", \r \"dateitem\":\"2013-09-04\", \r \"ownerType\":\"Public\"\r }\r}",
callback:{
target:[DynamicForm ID:isc_DynamicForm_0],
methodName:"saveEditorReply"
},
showPrompt:true,
prompt:"Saving form...",
oldValues:{
stateClinicSystemId:"100",
activityStatus:"Active",
dateitem:"2013-09-04",
ownerType:"Public"
},
requestId:"isc_TestDataSource_0$6272",
clientContext:{
},
fallbackToEval:false,
afterFlowCallback:"isc_DynamicForm_0.$49z(dsRequest, dsResponse, data)",
editor:[DynamicForm ID:isc_DynamicForm_0],
lastClientEventThreadCode:"MUP0",
httpMethod:"POST",
contentType:"application/json",
bypassCache:true,
isRestRequest:true,
dataFormat:"json"
}
</code>
I DONOT understand. The payload is JSON then whcy do I get an XML Parsing error, that too from the http Proxy. The call does not even
get to the REST resource.
I am using licensed version of smart gwt SmartClient Version: v9.0p_2013-09-04/Pro Deployment (built 2013-09-04)
<code>
public abstract class BasicRestDataSource extends RestDataSource {
protected abstract void bindFields();
public BasicRestDataSource() {
createAndInitRestDatasource();
bindFields();
}
protected void createAndInitRestDatasource() {
setDataFormat(DSDataFormat.JSON);
}
protected void setUpOperationBindings() {
// set up FETCH to use GET requests
OperationBinding fetch = new OperationBinding();
fetch.setOperationType(DSOperationType.FETCH);
fetch.setDataProtocol(DSProtocol.GETPARAMS);
DSRequest fetchProps = new DSRequest();
fetchProps.setHttpMethod("GET");
fetch.setRequestProperties(fetchProps);
// set up ADD to use POST requests
OperationBinding add = new OperationBinding();
add.setOperationType(DSOperationType.ADD);
add.setDataProtocol(DSProtocol.POSTMESSAGE);
DSRequest addProps = new DSRequest();
addProps.setHttpMethod("POST");
addProps.setContentType("application/json");
add.setRequestProperties(addProps);
// set up UPDATE to use PUT
OperationBinding update = new OperationBinding();
update.setOperationType(DSOperationType.UPDATE);
update.setDataProtocol(DSProtocol.POSTMESSAGE);
DSRequest updateProps = new DSRequest();
updateProps.setHttpMethod("POST");
updateProps.setContentType("application/json");
update.setRequestProperties(updateProps);
// set up REMOVE to use DELETE
OperationBinding remove = new OperationBinding();
remove.setOperationType(DSOperationType.REMOVE);
remove.setDataProtocol(DSProtocol.POSTMESSAGE);
DSRequest removeProps = new DSRequest();
removeProps.setHttpMethod("DELETE");
remove.setRequestProperties(removeProps);
// apply all the operational bindings
setOperationBindings(fetch, add, update, remove);
}
}
</code>
I have this Impl Class for my BasicRestDataSource
<code>
public class TestDataSource extends BasicRestDataSource {
@Override
protected void createAndInitRestDatasource() {
super.createAndInitRestDatasource();
setUpOperationBindings();
}
@Override
protected void bindFields() {
DataSourceTextField cityClinicSystemId = new DataSourceTextField("CityClinicSystemId", "City Clinic System ID");
cityClinicSystemId.setPrimaryKey(true);
cityClinicSystemId.setCanEdit(false);
DataSourceTextField stateClinicSystemId = new DataSourceTextField("stateClinicSystemId", "State Clinic System ID");
DataSourceTextField activityStatus = new DataSourceTextField("activityStatus", "Activity Status");
DataSourceDateField dateitem = new DataSourceDateField("dateitem","Date of Inception");
setFields(stateClinicSystemId,activityStatus,dateitem);
setFetchDataURL("http://localhost:4567/fetchData");
setAddDataURL("http://localhost:4567/saveData");
setUpdateDataURL("http://localhost:4567/saveData");
}
}
</code>
I have tested the rest resources using curl and they all work fine. No issues. 100% perfect. Not to worry there at all
Now in my GWT Module. I have a code which simple creates a form like as follows:
<code>
private DynamicForm createDynamicForm() {
DynamicForm dynaForm = new DynamicForm();
dynaForm.setNumCols(2);
dynaForm.setColWidths("230,*");
dynaForm.setWidth(401);
dynaForm.setAutoDraw(false);
dynaForm.setDataSource(new TestDataSource());
return dynaForm;
}
</code>
and then I have a two buttons. Button for fetch and Button for save. Very Simple. No complications
<code>
Button fd = new Button("fetch");
Button sd = new Button("save");
vStack.addMember(fd);
vStack.addMember(sd);
fd.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
dynaForm.fetchData();
}
});
sd.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
dynaForm.saveData();
}
});
</code>
when I click the fetch button. I get response from the rest and dynaFOrm happily loads the data and i am happy. But when I press save button. I get this error
<code>
=== 2013-09-07 17:48:37,628 [l0-2] DEBUG RPCDMI - rpc returned RPCResponse
=== 2013-09-07 17:48:37,628 [l0-2] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
=== 2013-09-07 18:03:50,893 [l0-2] DEBUG XML - Parsed XML from (in memory stream): 2ms
=== 2013-09-07 18:03:50,895 [l0-2] DEBUG HttpProxyServlet - HttpProxy - ProxyData is: {
xsi:"http://www.w3.org/2000/10/XMLSchema-instance",
url:"http://localhost:4567/saveData",
httpMethod:"POST",
params:{
isc_dataFormat:"json"
},
contentType:"application/json",
requestBody:"{\r \"dataSource\":\"isc_TestDataSource_0\", \r \"operationType\":\"update\", \r \"componentId\":\"isc_DynamicForm_0\", \r \"data\":{\r \"stateClinicSystemId\":\"100\", \r \"activityStatus\":\"Active\", \r \"dateitem\":\"2013-09-04\", \r \"ownerType\":\"Public\"\r }, \r \"oldValues\":{\r \"stateClinicSystemId\":\"100\", \r \"activityStatus\":\"Active\", \r \"dateitem\":\"2013-09-04\", \r \"ownerType\":\"Public\"\r }\r}"
}
=== 2013-09-07 18:03:50,895 [l0-2] ERROR XML - XML parser fatal error: file '(in memory stream)' line 1: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
=== 2013-09-07 18:03:50,895 [l0-2] DEBUG XML - Exception thrown during XML parsing
=== 2013-09-07 18:03:50,896 [l0-2] ERROR HttpProxyServlet - HttpProxy - Top-level servlet error:
com.isomorphic.xml.XMLParsingException: [
"XML parser fatal error: file '(in memory stream)' line 1: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog."
]
at com.isomorphic.xml.XML.parseXML(XML.java:206)
at com.isomorphic.xml.XML.parseXML(XML.java:125)
at com.isomorphic.servlet.HttpProxyServlet.doPost(HttpProxyServlet.java:495)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
</code>
The debug console gives this as a trace
DSRequest Tab output of RPC TAB
<code>
{
dataSource:"isc_TestDataSource_0",
operationType:"update",
componentId:"isc_DynamicForm_0",
data:"{\r \"dataSource\":\"isc_TestDataSource_0\", \r \"operationType\":\"update\", \r \"componentId\":\"isc_DynamicForm_0\", \r \"data\":{\r \"stateClinicSystemId\":\"100\", \r \"activityStatus\":\"Active\", \r \"dateitem\":\"2013-09-04\", \r \"ownerType\":\"Public\"\r }, \r \"oldValues\":{\r \"stateClinicSystemId\":\"100\", \r \"activityStatus\":\"Active\", \r \"dateitem\":\"2013-09-04\", \r \"ownerType\":\"Public\"\r }\r}",
callback:{
target:[DynamicForm ID:isc_DynamicForm_0],
methodName:"saveEditorReply"
},
showPrompt:true,
prompt:"Saving form...",
oldValues:{
stateClinicSystemId:"100",
activityStatus:"Active",
dateitem:"2013-09-04",
ownerType:"Public"
},
requestId:"isc_TestDataSource_0$6272",
clientContext:{
},
fallbackToEval:false,
afterFlowCallback:"isc_DynamicForm_0.$49z(dsRequest, dsResponse, data)",
editor:[DynamicForm ID:isc_DynamicForm_0],
lastClientEventThreadCode:"MUP0",
httpMethod:"POST",
contentType:"application/json",
bypassCache:true,
isRestRequest:true,
dataFormat:"json"
}
</code>
I DONOT understand. The payload is JSON then whcy do I get an XML Parsing error, that too from the http Proxy. The call does not even
get to the REST resource.
I am using licensed version of smart gwt SmartClient Version: v9.0p_2013-09-04/Pro Deployment (built 2013-09-04)
Comment