Ejemplo n.º 1
0
  public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    JobDataMap map = jobExecutionContext.getJobDetail().getJobDataMap();
    AbstractMessageReceiver receiver =
        (AbstractMessageReceiver) map.get(QuartzMessageReceiver.QUARTZ_RECEIVER_PROPERTY);
    Object payload =
        jobExecutionContext.getJobDetail().getJobDataMap().get(QuartzConnector.PROPERTY_PAYLOAD);

    try {
      if (payload == null) {
        String ref =
            jobExecutionContext
                .getJobDetail()
                .getJobDataMap()
                .getString(QuartzConnector.PROPERTY_PAYLOAD_REFERENCE);
        // for backward compatibility check the old payload Class property too
        if (ref == null) {
          ref =
              jobExecutionContext
                  .getJobDetail()
                  .getJobDataMap()
                  .getString(QuartzConnector.PROPERTY_PAYLOAD_CLASS_NAME);
        }
        try {
          payload = MuleManager.getInstance().getContainerContext().getComponent(ref);
        } catch (ObjectNotFoundException e) {
          logger.warn("There is no payload attached to this quartz job. Sending Null payload");
          payload = new NullPayload();
        }
      }
      receiver.routeMessage(new MuleMessage(receiver.getConnector().getMessageAdapter(payload)));
    } catch (Exception e) {
      receiver.handleException(e);
    }
  }
Ejemplo n.º 2
0
  public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    JobDataMap map = jobExecutionContext.getJobDetail().getJobDataMap();

    String receiverKey = (String) map.get(QuartzMessageReceiver.QUARTZ_RECEIVER_PROPERTY);
    if (receiverKey == null)
      throw new JobExecutionException(QuartzMessages.receiverNotInJobDataMap().getMessage());

    String connectorName = (String) map.get(QuartzMessageReceiver.QUARTZ_CONNECTOR_PROPERTY);
    if (connectorName == null)
      throw new JobExecutionException(QuartzMessages.connectorNotInJobDataMap().getMessage());

    AbstractConnector connector =
        (AbstractConnector) RegistryContext.getRegistry().lookupConnector(connectorName);
    if (connector == null)
      throw new JobExecutionException(QuartzMessages.noConnectorFound(connectorName).getMessage());

    AbstractMessageReceiver receiver =
        (AbstractMessageReceiver) connector.lookupReceiver(receiverKey);
    if (receiver == null)
      throw new JobExecutionException(
          QuartzMessages.noReceiverInConnector(receiverKey, connectorName).getMessage());

    Object payload =
        jobExecutionContext.getJobDetail().getJobDataMap().get(QuartzConnector.PROPERTY_PAYLOAD);

    try {
      if (payload == null) {
        String ref =
            jobExecutionContext
                .getJobDetail()
                .getJobDataMap()
                .getString(QuartzConnector.PROPERTY_PAYLOAD_REFERENCE);
        // for backward compatibility check the old payload Class property
        // too
        if (ref == null) {
          ref =
              jobExecutionContext
                  .getJobDetail()
                  .getJobDataMap()
                  .getString(QuartzConnector.PROPERTY_PAYLOAD_CLASS_NAME);
        }
        if (ref == null) {
          payload = NullPayload.getInstance();
        } else {
          payload = RegistryContext.getRegistry().lookupObject(ref);
        }

        if (payload == null) {
          logger.warn("There is no payload attached to this quartz job. Sending Null payload");
          payload = NullPayload.getInstance();
        }
      }
      receiver.routeMessage(new MuleMessage(receiver.getConnector().getMessageAdapter(payload)));
    } catch (Exception e) {
      receiver.handleException(e);
    }
  }