Coverage Report - org.mule.transport.quartz.jobs.ScheduledDispatchJob
 
Classes in this File Line Coverage Branch Coverage Complexity
ScheduledDispatchJob
0%
0/19
0%
0/6
7
 
 1  
 /*
 2  
  * $Id: ScheduledDispatchJob.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.quartz.jobs;
 12  
 
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.module.client.MuleClient;
 15  
 import org.mule.transport.NullPayload;
 16  
 import org.mule.transport.quartz.QuartzConnector;
 17  
 import org.mule.transport.quartz.i18n.QuartzMessages;
 18  
 
 19  
 import java.io.Serializable;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 import org.quartz.Job;
 24  
 import org.quartz.JobDataMap;
 25  
 import org.quartz.JobExecutionContext;
 26  
 import org.quartz.JobExecutionException;
 27  
 
 28  
 /**
 29  
  * Will dispatch the current message to a Mule endpoint at a later time.
 30  
  * This job can be used to fire time based events.
 31  
  */
 32  0
 public class ScheduledDispatchJob implements Job, Serializable
 33  
 {
 34  
     /**
 35  
      * The logger used for this class
 36  
      */
 37  0
     protected transient Log logger = LogFactory.getLog(getClass());
 38  
 
 39  
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
 40  
     {
 41  0
         JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
 42  0
         Object payload = jobDataMap.get(QuartzConnector.PROPERTY_PAYLOAD);
 43  
 
 44  0
         if (payload == null)
 45  
         {
 46  0
             payload = NullPayload.getInstance();
 47  
         }
 48  
 
 49  0
         ScheduledDispatchJobConfig config = (ScheduledDispatchJobConfig) jobDataMap.get(QuartzConnector.PROPERTY_JOB_CONFIG);
 50  0
         if (config == null)
 51  
         {
 52  0
             throw new JobExecutionException(
 53  
                 QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_CONFIG).getMessage());
 54  
         }
 55  
 
 56  
         try
 57  
         {
 58  0
             MuleClient client = new MuleClient(config.getMuleContext());
 59  
 
 60  0
             String endpointRef = config.getEndpointRef();
 61  0
             if (jobDataMap.containsKey("endpointRef")) 
 62  
             {
 63  0
                 endpointRef = (String) jobDataMap.get("endpointRef");
 64  
             }
 65  
 
 66  0
             logger.debug("Dispatching payload on: " + config.getEndpointRef());
 67  
 
 68  0
             client.dispatch(endpointRef, payload, jobDataMap);
 69  
         }
 70  0
         catch (MuleException e)
 71  
         {
 72  0
             throw new JobExecutionException(e);
 73  0
         }
 74  0
     }
 75  
 }