Is it possible to use a JMS topic as a DataSource? I’ve read client/server integration techniques in the documentation and reviewed some examples on Showcase; I’m still not sure how/if this can be accomplished.
I’m using SmartGWT 2.4 and FireFox 3.6; this is what I have thus far:
client code:
public class DoThis{
public void onModuleLoad(){
ListGrid listGrid = new ListGrid();
listGrid.setWidth100();
listGrid.setHeight(450);
DataSource ds = DataSource.get(“eventDataDMI”);
listGrid.setCanEdit(false);
listGrid.setDataSource(ds);
listGrid.fetchData();
}
)
custom DataSource: eventDataDMI.ds.xml
<DataSource
ID=“eventDataDMI”
serverType=“generic”
dataFormat=“iscServer”
serverConstructor=“com.example.server.MessageDataDMI”
clientOnly="false" >
<fields>
<field name="id" title="Event ID" type="sequence" primaryKey="true" align="left" hidden="false" length="70"/>
<field name="eventDateTime" title="Date - Time" type="text" length="120"/>
<field name="eventText" title="Event Text" type="text" length="300"/>
</fields>
<operationBindings>
<operationBinding operationType="fetch" >
<serverObject className="com.example.server.MessageDataDMI" methodName="executeFetch" />
</operationBinding>
</operationBindings>
</DataSource>
server code:
public class MessageDataDMI extends BasicDataSource {
private static final long serialVersionUID = 1L;
EventData eventData = new EventData();
public DSResponse executeFetch(DSRequest req) throws Exception {
List records = fetchRecords(req.getCriteria());
return new DSResponse(records);
}
public List fetchRecords (Map criteria) {
eventData.subscribeToMessages();
return eventData.getList();
}
}
server sample code to subscribe to JMS Topic:
public class EventData {
Subscription sub = Subscription .Factory.getInstance();
static List list = new ArrayList();
static List getList(){
return list;
}
public List subscribeToMessages() {
SubscriptionCallback<Event> subCallBack = new
SubscriptionCallback<Event>()
public void onReceive(Event theEvent)
{
long id;
Date eventDateTime;
String eventText;
Map map = new HashMap();
map.put("id", id = theEvent.getID());
map.put("eventDateTime", eventDateTime =
theEvent.getTimestamp());
map.put("eventText", eventText = theEvent.getMessage());
list.add(map);
}
};
sub.subscribe(Event.class, subCallBack);
return list;
}
}
web.xml:
<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE web-app
PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd”>
<web-app>
<!–
The DataSourceLoader servlet returns Javascript representations of the
dataSources whose ID’s are passed to it - it is an alternative to
using the <loadDS> JSP tag
–>
<servlet>
<servlet-name>DataSourceLoader</servlet-name>
<servlet-class>com.isomorphic.servlet.DataSourceLoader</servlet-class>
</servlet>
<!-- DataSourceLoader requests -->
<servlet-mapping>
<servlet-name>DataSourceLoader</servlet-name>
<url-pattern>/dothis/sc/DataSourceLoader</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>IDACall</servlet-name>
<servlet-class>com.isomorphic.servlet.IDACall</servlet-class>
</servlet>
<!-- RPCManager uses this URL by default for Built-in DataSource operations –>
<servlet-mapping>
<servlet-name>IDACall</servlet-name>
<url-pattern>/dothis/sc/IDACall/*</url-pattern>
</servlet-mapping>
<!-- Default page to serve –>
<welcome-file-list>
<welcome-file>DoThis.html</welcome-file>
</welcome-file-list>
</web-app>
Root html:
<!doctype html>
<html>
<head>
<meta http-equiv=“content-type” content=“text/html; charset=UTF-8”>
<title>Do This</title>
<link rel=“stylesheet” href=“DoThis.css”>
<script>
var isomorphicDir = “dothis/sc/”;
</script>
<script type=“text/javascript” language=“javascript”
src=“dothis/productdistribution.nocache.js”></script>
<script type=“text/javascript” language=“javascript”
src=“dothis/sc/DataSourceLoader?dataSource=eventDataDMI”></script>
</head>
<body>
<iframe src=“javascript:‘’” id=“__gwt_historyFrame” tabIndex=‘-1’
style=“position: absolute; width: 0; height: 0; border: 0”></iframe>
</body>
</html>
When new messages are published to this topic, the messages should be displayed to the bound ListGrid.
I’m not sure where to go from here.
Any help would be great!