Beispiel #1
0
  public void initialise() throws InitialisationException {
    if (wireFormat == null) {
      wireFormat = new SerializationWireFormat();
    }

    try {
      if (StringUtils.isEmpty(serverUri)) {
        // no serverUrl specified, warn a user
        logger.warn(
            "No serverUriUrl specified, MuleAdminAgent will not start. E.g. use "
                + "<mule:admin-agent serverUri=\"tcp://example.com:60504\"/> ");

        // abort the agent registration process
        managementContext.getRegistry().unregisterAgent(this.getName());

        return;
      }

      // Check for override
      if (ModelHelper.isComponentRegistered(MuleManagerComponent.MANAGER_COMPONENT_NAME)) {
        logger.info("Mule manager component has already been initialised, ignoring server url");
      } else {
        if (managementContext.getRegistry().lookupConnector(DEFAULT_MANAGER_ENDPOINT) != null) {
          throw new AlreadyInitialisedException("Server Components", this);
        }

        MuleEndpoint writableEndpoint;
        // Check to see if we have an endpoint identifier
        UMOImmutableEndpoint endpoint = managementContext.getRegistry().lookupEndpoint(serverUri);
        if (endpoint == null) {
          UMOEndpointURI endpointUri = new MuleEndpointURI(serverUri);
          UMOConnector connector = TransportFactory.getOrCreateConnectorByProtocol(endpointUri);
          // If this connector has already been initialised i.e. it's a
          // pre-existing connector don't reinit
          if (managementContext.getRegistry().lookupConnector(connector.getName()) == null) {
            connector.setName(DEFAULT_MANAGER_ENDPOINT);
            connector.initialise();
            managementContext.getRegistry().registerConnector(connector);
          }
          writableEndpoint = new MuleEndpoint();
          writableEndpoint.setConnector(connector);
          writableEndpoint.setEndpointURI(endpointUri);
        } else {
          writableEndpoint = new MuleEndpoint(endpoint);
        }

        logger.info("Registering Admin listener on: " + serverUri);
        UMODescriptor descriptor =
            MuleManagerComponent.getDescriptor(
                writableEndpoint,
                wireFormat,
                RegistryContext.getConfiguration().getDefaultEncoding(),
                RegistryContext.getConfiguration().getDefaultSynchronousEventTimeout());

        ModelHelper.registerSystemComponent(descriptor);
      }
    } catch (UMOException e) {
      throw new InitialisationException(e, this);
    }
  }
Beispiel #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);
    }
  }
Beispiel #3
0
 /**
  * Configure Spring by passing an in-memory XML Spring config.
  *
  * @param configurationXmlAsString XML config contents
  * @throws ContainerException in case of any error
  */
 public void configure(String configurationXmlAsString) throws ContainerException {
   final String encoding = RegistryContext.getConfiguration().getDefaultEncoding();
   try {
     BeanFactory bf = new XmlBeanFactory(new CachedResource(configurationXmlAsString, encoding));
     setExternalBeanFactory(bf);
   } catch (UnsupportedEncodingException e) {
     throw new ContainerException(CoreMessages.failedToConvertStringUsingEncoding(encoding), e);
   }
 }
Beispiel #4
0
 protected void doSetUp() throws Exception {
   // Make sure we are running synchronously
   RegistryContext.getConfiguration().setDefaultSynchronousEndpoints(true);
   SedaModel model = new SedaModel();
   model.setName("main");
   model.getPoolingProfile().setInitialisationPolicy(PoolingProfile.INITIALISE_ONE);
   muleContext.getRegistry().registerModel(model);
   // Create and register connector
   connector = createConnector();
   muleContext.getRegistry().registerConnector(connector);
   // Empty table
   emptyTable();
 }
Beispiel #5
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);
    }
  }
Beispiel #6
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;
 }
Beispiel #7
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"));
 }
Beispiel #8
0
  public final synchronized void dispose() {
    // TODO lifecycleManager.checkPhase(Disposable.PHASE_NAME);

    if (isDisposed()) {
      return;
    }

    try {
      doDispose();
      lifecycleManager.firePhase(getManagementContext(), Disposable.PHASE_NAME);
      if (getParent() != null) {
        parent.dispose();
      } else {
        // remove this referenceonce there is no one else left to dispose
        RegistryContext.setRegistry(null);
      }
    } catch (UMOException e) {
      // TO-DO
      logger.error("Failed to cleanly dispose: " + e.getMessage(), e);
    }
  }
Beispiel #9
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;
  }
Beispiel #10
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;
   }
 }
Beispiel #11
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;
  }
Beispiel #12
0
  public static TransientRegistry createNew() throws UMOException {
    // Use the default server lifecycleManager
    // UMOLifecycleManager lifecycleManager = new DefaultLifecycleManager();
    UMOLifecycleManager lifecycleManager = new GenericLifecycleManager();

    lifecycleManager.registerLifecycle(
        new ContainerManagedLifecyclePhase(
            Initialisable.PHASE_NAME, Initialisable.class, Disposable.PHASE_NAME));
    lifecycleManager.registerLifecycle(new ManagementContextStartPhase());
    lifecycleManager.registerLifecycle(new ManagementContextStopPhase());
    lifecycleManager.registerLifecycle(
        new ContainerManagedLifecyclePhase(
            Disposable.PHASE_NAME, Disposable.class, Initialisable.PHASE_NAME));

    // Create the registry
    TransientRegistry registry = new TransientRegistry();

    RegistryContext.setRegistry(registry);

    MuleConfiguration config = new MuleConfiguration();

    registry.setConfiguration(config);

    QueueManager queueManager = new TransactionalQueueManager();
    queueManager.setPersistenceStrategy(
        new CachingPersistenceStrategy(new MemoryPersistenceStrategy()));

    ThreadingProfile tp = config.getDefaultThreadingProfile();
    UMOWorkManager workManager = new MuleWorkManager(tp, "MuleServer");

    ServerNotificationManager notificationManager = new ServerNotificationManager();
    notificationManager.registerEventType(
        ManagerNotificationListener.class, ManagerNotification.class);
    notificationManager.registerEventType(ModelNotificationListener.class, ModelNotification.class);
    notificationManager.registerEventType(
        ComponentNotificationListener.class, ComponentNotification.class);
    notificationManager.registerEventType(
        SecurityNotificationListener.class, SecurityNotification.class);
    notificationManager.registerEventType(
        ManagementNotificationListener.class, ManagementNotification.class);
    notificationManager.registerEventType(AdminNotificationListener.class, AdminNotification.class);
    notificationManager.registerEventType(
        CustomNotificationListener.class, CustomNotification.class);
    notificationManager.registerEventType(
        ConnectionNotificationListener.class, ConnectionNotification.class);
    notificationManager.registerEventType(
        RegistryNotificationListener.class, RegistryNotification.class);
    notificationManager.registerEventType(
        ExceptionNotificationListener.class, ExceptionNotification.class);
    notificationManager.registerEventType(
        TransactionNotificationListener.class, TransactionNotification.class);

    UMOSecurityManager securityManager = new MuleSecurityManager();

    UMOManagementContext context = new ManagementContext(lifecycleManager);
    context.setId(UUID.getUUID());

    registry.registerObject(
        UMOManagementContext.class, MuleProperties.OBJECT_MANAGMENT_CONTEXT, context);
    registry.registerObject(
        ObjectProcessor.class,
        MuleProperties.OBJECT_MANAGMENT_CONTEXT_PROCESSOR,
        new ManagementContextDependencyProcessor(context));

    // Register objects so we get lifecycle management
    registry.registerObject(MuleProperties.OBJECT_SECURITY_MANAGER, securityManager);
    registry.registerObject(MuleProperties.OBJECT_WORK_MANAGER, workManager);
    registry.registerObject(MuleProperties.OBJECT_NOTIFICATION_MANAGER, notificationManager);
    registry.registerObject(MuleProperties.OBJECT_QUEUE_MANAGER, queueManager);

    // Set the object explicitly on the ManagementContext
    context.setWorkManager(workManager);
    context.setSecurityManager(securityManager);
    context.setNotificationManager(notificationManager);
    context.setQueueManager(queueManager);

    // Register the system Model
    ModelServiceDescriptor sd =
        (ModelServiceDescriptor)
            registry.lookupServiceDescriptor(
                ServiceDescriptorFactory.MODEL_SERVICE_TYPE, config.getSystemModelType(), null);

    UMOModel model = sd.createModel();
    model.setName(MuleProperties.OBJECT_SYSTEM_MODEL);
    registry.registerModel(model);
    registry.initialise();
    return registry;
  }