Java Reference
In-Depth Information
The JmsTemplate is finally injected into the ReportingDelegate , which is invoked by the
page controller that handles the report generation request. The implementation class
ReportingDelegateImpl follows the Business Delegate pattern and handles the JMS-related
details, as shown in Listing 5-25.
Listing 5-25.
public class ReportingDelegateImpl implements ReportingDelegate{
private JmsTemplate jmsTemplate;
public long triggerReportGeneration(Map reportDataMap) {
long reportId = ReportUtil.generateReportId(reportDataMap);
this.jmsTemplate.send(new ReportMessageCreatorImpl(reportDataMap));
return reportId;
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
The report ID is passed to the page controller so that it can display this token to the
user for future reference. The user can search with this ID to find the status of the report
generation that he has triggered. Note that I have also altered the workflow of the
JmsTemplate class by passing a custom implementation of the MessageCreator interface in
the form of ReportMessageCreatorImpl , as shown in Listing 5-26. This class is responsible
for transforming the incoming message into a form compatible with the JMS API.
Listing 5-26.
public class ReportMessageCreatorImpl implements MessageCreator{
private Map reportData;
public ReportMessageCreatorImpl(Map reportData){
this.reportData = reportData;
public Message createMessage(Session jmsSession) throws JMSException {
MapMessage message = jmsSession.createMapMessage();
message.setObject("REPORT_DATA", reportData.get("REPORT_DATA"));
return message;
Search WWH ::

Custom Search