Hi Isomorphic,
second parameter of DynamicDSGenerator.getDataSource() is "DSRequest dsRequest" (Docs: ...This will be null if the DataSource is not needed in the context of a DSRequest).
Please take a look at this test case (using v12.0p_2019-04-03/PowerEdition Deployment (built 2019-04-03)).
web.xml
LMSRESTHandler.java
RegisterDS.java
animals.ds.xml
Animals.java
Call:
If you set a breakpoint in both places where I wrote in the comments, after execution of
in Animals.java, "animalsGenerator" is called again but "dsRequest" is null. I don't see a reason why "dsRequest" is null at this point so this could be a bug.
My actual case is a way more complicated but I hope you see the problem.
Best regards
Pavo
second parameter of DynamicDSGenerator.getDataSource() is "DSRequest dsRequest" (Docs: ...This will be null if the DataSource is not needed in the context of a DSRequest).
Please take a look at this test case (using v12.0p_2019-04-03/PowerEdition Deployment (built 2019-04-03)).
web.xml
Code:
<!-- Rewrite default definiton with this one --> <servlet> <servlet-name>RESTHandler</servlet-name> <servlet-class>com.smartgwt.sample.server.listener.LMSRESTHandler</servlet-class> <init-param> <param-name>defaultDataFormat</param-name> <param-value>json</param-value> </init-param> </servlet> <servlet> <servlet-name>RegisterDS</servlet-name> <servlet-class>com.smartgwt.sample.server.listener.RegisterDS</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
Code:
package com.smartgwt.sample.server.listener; import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DSResponse; import com.isomorphic.datasource.DataSource; import com.isomorphic.rpc.RPCManager; import com.isomorphic.servlet.RESTHandler; import com.isomorphic.servlet.RequestContext; public class LMSRESTHandler extends RESTHandler { private static final long serialVersionUID = -1L; @Override public void processRestTransaction(RPCManager rpcManager, RequestContext requestContext) throws Exception { super.processRestTransaction(rpcManager, requestContext); } @Override public DSResponse handleDSRequest(DSRequest dsRequest, RPCManager rpcManager, RequestContext requestContext) throws Exception { DSRequest request = new DSRequest("animals", DataSource.OP_FETCH, rpcManager); DSResponse returnResponse = request.execute(); return returnResponse; } }
Code:
package com.smartgwt.sample.server.listener; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DataSource; import com.isomorphic.datasource.DynamicDSGenerator; public class RegisterDS extends HttpServlet { private static final long serialVersionUID = 7849924835392267735L; @Override public void init() throws ServletException { final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DynamicDSGenerator animalsGenerator = new DynamicDSGenerator() { @Override public DataSource getDataSource(String id, DSRequest dsRequest) { DataSource ds = null; try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); // Document doc = documentBuilder // .parse(getServletContext().getResourceAsStream("war\\ds\\animals.ds.xml")); Document doc = documentBuilder .parse("C:\\Users\\Pavo\\eclipse-workspace\\lib\\smartgwtpower-12.0p\\samples\\built-in-ds\\war\\ds\\animals.ds.xml"); //Set a breakpoint on the next line of the code ds = DataSource.fromXML(doc); } catch (Exception ex) { ex.printStackTrace(); } return ds; } }; DataSource.addDynamicDSGenerator(animalsGenerator, "animals"); } }
Code:
<DataSource ID="animals" serverType="sql" tableName="animals" testFileName="animals.data.xml" > <fields> <field name="commonName" title="Animal" type="text"/> <field name="scientificName" title="Scientific Name" type="text" primaryKey="true" required="true"/> <field name="lifeSpan" title="Life Span" type="integer"/> <field name="status" title="Endangered Status" type="text"> <valueMap> <value>Threatened</value> <value>Endangered</value> <value>Not Endangered</value> <value>Not currently listed</value> <value>May become threatened</value> <value>Protected</value> </valueMap> </field> <field name="diet" title="Diet" type="text"/> <field name="information" title="Interesting Facts" type="text" length="1000"/> <field name="picture" title="Picture" type="image" detail="true" imageURLPrefix="/isomorphic/system/reference/inlineExamples/tiles/images/"/> </fields> <serverObject lookupStyle="new" className="com.smartgwt.sample.server.listener.Animals" /> </DataSource>
Code:
package com.smartgwt.sample.server.listener; import javax.servlet.http.HttpServletRequest; import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DSResponse; import com.isomorphic.datasource.DataSource; import com.isomorphic.tools.DataImport; public class Animals { public DSResponse fetch(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception { DataImport dataImporter = new DataImport(); dataImporter.setPopulateDisplayFields(true); DSRequest addRequest = new DSRequest("animals", DataSource.OP_ADD, dsRequest.getRPCManager()); //Set a breakpoint on the next line of the code addRequest.setValues(dataImporter.importDataSourceRecord(dsRequest.getValues(), dsRequest.getDataSourceName())); DSResponse addResponse = addRequest.execute(); return addResponse; } }
Code:
http://127.0.0.1:8888/builtinds/sc/RESTHandler/employees
Code:
addRequest.setValues (dataImporter.importDataSourceRecord (dsRequest.getValues (), dsRequest.getDataSourceName ()));
My actual case is a way more complicated but I hope you see the problem.
Best regards
Pavo
Comment