예제 #1
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);
    }
  }
예제 #2
0
  /**
   * Creates an uninitialied connector from the provided MuleEndpointURI. The scheme is used to
   * determine what kind of connector to create. Any params set on the uri can be used to initialise
   * bean properties on the created connector.
   *
   * <p>Note that the initalise method will need to be called on the connector returned. This is so
   * that developers can control when the connector initialisation takes place as this is likely to
   * initialse all connecotr resources.
   *
   * @param url the MuleEndpointURI url to create the connector with
   * @return a new Connector
   * @throws TransportFactoryException
   */
  public static Connector createConnector(EndpointURI url, MuleContext muleContext)
      throws TransportFactoryException {

    try {
      Connector connector;
      String scheme = url.getSchemeMetaInfo();

      TransportServiceDescriptor sd =
          (TransportServiceDescriptor)
              RegistryContext.getRegistry()
                  .lookupServiceDescriptor(
                      ServiceDescriptorFactory.PROVIDER_SERVICE_TYPE, scheme, null);
      if (sd == null) {
        throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme));
      }

      connector = sd.createConnector();
      if (connector != null) {
        if (connector instanceof AbstractConnector) {
          ((AbstractConnector) connector).initialiseFromUrl(url);
        }
      } else {
        throw new TransportFactoryException(
            CoreMessages.objectNotSetInService("Connector", scheme));
      }

      connector.setName(ObjectNameHelper.getConnectorName(connector));

      // TODO Do we still need to support this for 2.x?
      // set any manager default properties for the connector
      // these are set on the Manager with a protocol i.e.
      // jms.specification=1.1
      //            Map props = new HashMap();
      //
      // PropertiesUtils.getPropertiesWithPrefix(RegistryContext.getRegistry().lookupProperties(),
      //                connector.getProtocol().toLowerCase(), props);
      //            if (props.size() > 0)
      //            {
      //                props = PropertiesUtils.removeNamespaces(props);
      //                BeanUtils.populateWithoutFail(connector, props, true);
      //            }

      return connector;
    } catch (Exception e) {
      throw new TransportFactoryException(
          CoreMessages.failedToCreateObjectWith("Endpoint", url), e);
    }
  }
예제 #3
0
 public static Connector getConnectorByProtocol(String protocol) {
   Connector connector;
   Connector resultConnector = null;
   Collection connectors = RegistryContext.getRegistry().getConnectors();
   for (Iterator iterator = connectors.iterator(); iterator.hasNext(); ) {
     connector = (Connector) iterator.next();
     if (connector.supportsProtocol(protocol)) {
       if (resultConnector == null) {
         resultConnector = connector;
       } else {
         throw new IllegalStateException(
             CoreMessages.moreThanOneConnectorWithProtocol(protocol).getMessage());
       }
     }
   }
   return resultConnector;
 }
예제 #4
0
 public void testTransformerConfig() throws Exception {
   MessagePropertiesTransformer transformer =
       (MessagePropertiesTransformer)
           RegistryContext.getRegistry().lookupTransformer("testTransformer");
   transformer.setMuleContext(muleContext);
   assertNotNull(transformer);
   assertNotNull(transformer.getAddProperties());
   assertNotNull(transformer.getDeleteProperties());
   assertEquals(2, transformer.getAddProperties().size());
   assertEquals(2, transformer.getDeleteProperties().size());
   assertEquals(1, transformer.getRenameProperties().size());
   assertTrue(transformer.isOverwrite());
   assertEquals("text/baz;charset=UTF-16BE", transformer.getAddProperties().get("Content-Type"));
   assertEquals("value", transformer.getAddProperties().get("key"));
   assertEquals("test-property1", transformer.getDeleteProperties().get(0));
   assertEquals("test-property2", transformer.getDeleteProperties().get(1));
   assertEquals("Faz", transformer.getRenameProperties().get("Foo"));
 }
예제 #5
0
  protected UMOStreamMessageAdapter sendStream(String uri, UMOStreamMessageAdapter sa)
      throws UMOException {

    UMOEndpoint ep =
        RegistryContext.getRegistry()
            .getOrCreateEndpointForUri(uri, UMOEndpoint.ENDPOINT_TYPE_SENDER);
    ep.setStreaming(true);
    UMOMessage message = new MuleMessage(sa);
    UMOEvent event =
        new MuleEvent(message, ep, RequestContext.getEventContext().getSession(), true);
    UMOMessage result = ep.send(event);
    if (result != null) {
      if (result.getAdapter() instanceof UMOStreamMessageAdapter) {
        return (UMOStreamMessageAdapter) result.getAdapter();
      } else {
        // TODO i18n (though this case should never happen...)
        throw new IllegalStateException(
            "Mismatch of stream states. A stream was used for outbound channel, but a stream was not used for the response");
      }
    }
    return null;
  }
예제 #6
0
 public static Connector getConnectorByProtocol(String protocol) {
   Connector connector;
   List<Connector> results = new ArrayList<Connector>();
   Collection connectors = RegistryContext.getRegistry().lookupObjects(Connector.class);
   for (Iterator iterator = connectors.iterator(); iterator.hasNext(); ) {
     connector = (Connector) iterator.next();
     if (connector.supportsProtocol(protocol)) {
       results.add(connector);
     }
   }
   if (results.size() > 1) {
     StringBuffer buf = new StringBuffer();
     for (Connector result : results) {
       buf.append(result.getName()).append(", ");
     }
     throw new IllegalStateException(
         CoreMessages.moreThanOneConnectorWithProtocol(protocol, buf.toString()).getMessage());
   } else if (results.size() == 1) {
     return results.get(0);
   } else {
     return null;
   }
 }
예제 #7
0
  /** Returns an initialized connector. */
  public static Connector getOrCreateConnectorByProtocol(EndpointURI uri, MuleContext muleContext)
      throws TransportFactoryException {
    String connectorName = uri.getConnectorName();
    if (null != connectorName) {
      // TODO this lookup fails currently on Mule 2.x! MuleAdminAgentTestCase
      Connector connector = RegistryContext.getRegistry().lookupConnector(connectorName);
      if (connector != null) {
        return connector;
      }
    }

    Connector connector = getConnectorByProtocol(uri.getFullScheme());
    if (connector == null) {
      connector = createConnector(uri, muleContext);
      try {
        BeanUtils.populate(connector, uri.getParams());
        connector.setMuleContext(muleContext);
        muleContext.getRegistry().registerConnector(connector);
      } catch (Exception e) {
        throw new TransportFactoryException(e);
      }
    }
    return connector;
  }