Exemplo n.º 1
0
  public void testSendTransactedRollback() throws Exception {
    final int countDownInitialCount = 2;
    final CountDownLatch countDown = new CountDownLatch(countDownInitialCount);

    // This exception strategy will be invoked when a message is redelivered
    // after a rollback

    // setup the component and start Mule
    UMODescriptor descriptor =
        getDescriptor("testComponent", FunctionalTestComponent.class.getName());

    EventCallback callback =
        new EventCallback() {
          public void eventReceived(UMOEventContext context, Object Component) throws Exception {
            callbackCalled = true;
            currentTx = context.getCurrentTransaction();
            assertNotNull(currentTx);
            assertTrue(currentTx.isBegun());
            System.out.println("@@@@ Rolling back transaction @@@@");
            currentTx.setRollbackOnly();
            countDown.countDown();
          }
        };

    initialiseComponent(descriptor, UMOTransactionConfig.ACTION_ALWAYS_BEGIN, callback);
    UMOManager manager = MuleManager.getInstance();
    addResultListener(getOutDest().getAddress(), countDown);

    UMOConnector umoCnn = manager.lookupConnector(CONNECTOR_NAME);
    // Set the test Exception strategy
    umoCnn.setExceptionListener(new RollbackExceptionListener(countDown));

    // Start the server
    manager.start();

    // Send a test message firstso that it is there when the component is
    // started
    send(DEFAULT_MESSAGE, false, Session.AUTO_ACKNOWLEDGE);

    afterInitialise();
    countDown.tryLock(LOCK_WAIT, TimeUnit.MILLISECONDS);
    assertTrue(
        "Only "
            + (countDownInitialCount - countDown.getCount())
            + " of "
            + countDownInitialCount
            + " checkpoints hit",
        countDown.tryLock());

    // Sleep a while to allow transaction to be rolled back
    afterInitialise();

    assertNull(currentMsg);
    assertTrue(callbackCalled);
    assertTrue(currentTx.isRolledBack());

    // Make sure the message isn't on the queue
    assertNull(receive(getInDest().getAddress(), 2000));
  }
Exemplo n.º 2
0
  protected void setUp() throws Exception {
    super.setUp();
    if (MuleManager.isInstanciated()) {
      MuleManager.getInstance().dispose();
    }
    UMOManager manager = MuleManager.getInstance();
    MuleManager.getConfiguration().setSynchronous(true);
    MuleManager.getConfiguration()
        .getPoolingProfile()
        .setInitialisationPolicy(PoolingProfile.POOL_INITIALISE_ONE_COMPONENT);
    manager.setModel(new SedaModel());

    MuleDescriptor descriptor = createInDescriptor("httpIn", EchoComponent.class.getName());
    manager.getModel().registerComponent(descriptor);
    manager.start();
  }
Exemplo n.º 3
0
 public UMOEndpoint registerEndpoint(String uri, String name, boolean inbound)
     throws UMOException {
   UMOEndpoint ep = createEndpoint(uri, name, inbound);
   ep.initialise();
   manager.registerEndpoint(ep);
   return ep;
 }
Exemplo n.º 4
0
 protected UMOModel getModel() throws UMOException {
   if (model == null) {
     model = new SedaModel();
     model.setName("main");
     manager.registerModel(model);
   }
   return model;
 }
Exemplo n.º 5
0
 public UMOEndpoint registerEndpoint(String uri, String name, boolean inbound, Map properties)
     throws UMOException {
   UMOEndpoint ep = createEndpoint(uri, name, inbound);
   ep.getProperties().putAll(properties);
   ep.initialise();
   manager.registerEndpoint(ep);
   return ep;
 }
Exemplo n.º 6
0
 public UMOManager configure(ReaderResource[] configResources, Properties startupProperties)
     throws ConfigurationException {
   try {
     manager.start();
   } catch (UMOException e) {
     throw new ConfigurationException(e);
   }
   return manager;
 }
Exemplo n.º 7
0
 public void disableAdminAgent() {
   MuleManager.getConfiguration().setServerUrl(StringUtils.EMPTY);
   if (manager != null) {
     try {
       manager.unregisterAgent(MuleAdminAgent.AGENT_NAME);
     } catch (UMOException e) {
       // TODO MULE-863: fix API or handle
     }
   }
 }
Exemplo n.º 8
0
  /**
   * Configures a started manager. This method will throw InitialisationException if the current
   * manager is already started
   *
   * @param synchronous whether to start the manager in synchronous mode
   * @param serverUrl the url used to receive client requests, or null if the server listening
   *     components should not be set up
   * @return the configured manager
   * @throws UMOException if the manager is already started or it fails to start
   */
  public UMOManager createStartedManager(boolean synchronous, String serverUrl, String modeltype)
      throws UMOException {
    if (manager.isStarted()) {
      throw new InitialisationException(new Message(Messages.MANAGER_ALREADY_STARTED), this);
    }
    if (serverUrl == null) {
      serverUrl = "";
    }
    MuleManager.getConfiguration().setServerUrl(serverUrl);
    MuleManager.getConfiguration().setSynchronous(synchronous);
    if (!MODEL_NOT_SET.equals(modeltype)) {
      model = ModelFactory.createModel(modeltype);
    } else {
      model = ModelFactory.createModel("seda");
    }
    manager.registerModel(model);

    manager.start();
    return manager;
  }
Exemplo n.º 9
0
 public UMOEndpoint registerEndpoint(
     String uri, String name, boolean inbound, Map properties, UMOFilter filter)
     throws UMOException {
   UMOEndpoint ep = createEndpoint(uri, name, inbound);
   if (properties != null) {
     ep.getProperties().putAll(properties);
   }
   if (filter != null) {
     ep.setFilter(filter);
   }
   ep.initialise();
   manager.registerEndpoint(ep);
   return ep;
 }
Exemplo n.º 10
0
 public UMOComponent registerComponent(
     String implementation,
     String name,
     String inboundEndpoint,
     String outboundEndpoint,
     Map properties)
     throws UMOException {
   UMOEndpoint inEndpoint = null;
   UMOEndpoint outEndpoint = null;
   if (inboundEndpoint != null) {
     inEndpoint = manager.lookupEndpoint(inboundEndpoint);
     if (inEndpoint == null) {
       inEndpoint = createEndpoint(inboundEndpoint, null, true);
     }
   }
   if (outboundEndpoint != null) {
     outEndpoint = manager.lookupEndpoint(outboundEndpoint);
     if (outEndpoint == null) {
       outEndpoint = createEndpoint(outboundEndpoint, null, false);
     }
   }
   UMODescriptor d = createDescriptor(implementation, name, inEndpoint, outEndpoint, properties);
   return registerComponent(d);
 }
Exemplo n.º 11
0
  /**
   * Configures a started manager. This method will throw InitialisationException if the current
   * manager is already started
   *
   * @param synchronous whether to start the manager in synchronous mode
   * @param serverUrl the url used to receive client requests, or null if the server listening
   *     components should not be set up
   * @param serverConnector The server connector to use for the serverUrl
   * @return the configured manager
   * @throws UMOException if the manager is already started or it fails to start
   */
  public UMOManager createStartedManager(
      boolean synchronous, String serverUrl, UMOConnector serverConnector) throws UMOException {
    if (serverConnector != null) {
      manager.registerConnector(serverConnector);
    } else {
      throw new IllegalArgumentException("Cannot create started manager from null serverConnector");
    }

    // set the connector on the endpointUri
    int param = serverUrl.indexOf('?');
    if (param == -1) {
      serverUrl += '?';
    } else {
      serverUrl += '&';
    }

    serverUrl += UMOEndpointURI.PROPERTY_CREATE_CONNECTOR + "=" + serverConnector.getName();
    return createStartedManager(synchronous, serverUrl);
  }
Exemplo n.º 12
0
  protected void initMule() {
    try {
      // endpointsCache.clear();
      // See if there has been a discriptor explicitly configured
      if (applicationContext.containsBean(EVENT_MULTICASTER_DESCRIPTOR_NAME)) {
        descriptor = (UMODescriptor) applicationContext.getBean(EVENT_MULTICASTER_DESCRIPTOR_NAME);
      }
      // If the mule manager has been initialised in the contain
      // there is not need to do anything here
      if (applicationContext.containsBean("muleManager")) {
        // Register the multicaster descriptor
        registerMulticasterDescriptor();
        return;
      }
      UMOManager manager = MuleManager.getInstance();
      Map map = applicationContext.getBeansOfType(MuleConfiguration.class);
      if (map != null && map.size() > 0) {
        MuleManager.setConfiguration((MuleConfiguration) map.values().iterator().next());
      }
      if (!manager.isStarted()) {
        MuleManager.getConfiguration().setSynchronous(!asynchronous);
        // register any endpointUri mappings
        registerEndpointMappings();
      }
      // tell mule to load component definitions from spring
      SpringContainerContext containerContext = new SpringContainerContext();
      containerContext.setBeanFactory(applicationContext);
      manager.setContainerContext(null);
      manager.setContainerContext(containerContext);

      // see if there are any UMOConnectors to register
      registerConnectors();

      // Next see if there are any UMOTransformers to register
      registerTransformers();

      registerGlobalEndpoints();

      // Register the multicaster descriptor
      registerMulticasterDescriptor();

      if (!manager.isStarted()) {
        manager.start();
      }
    } catch (UMOException e) {
      throw new MuleRuntimeException(SpringMessages.failedToReinitMule(), e);
    }
  }
Exemplo n.º 13
0
  public void testTransactedRedeliveryToDLDestination() throws Exception {
    // there are 2 check points for each message delivered, so
    // the message will be delivered twice before this countdown will release
    final int countDownInitialCount = 4;
    final CountDownLatch countDown = new CountDownLatch(countDownInitialCount);

    // setup the component and start Mule
    UMODescriptor descriptor =
        getDescriptor("testComponent", FunctionalTestComponent.class.getName());

    EventCallback callback =
        new EventCallback() {
          public void eventReceived(UMOEventContext context, Object Component) throws Exception {
            callbackCalled = true;
            currentTx = context.getCurrentTransaction();
            assertNotNull(currentTx);
            assertTrue(currentTx.isBegun());
            System.out.println("@@@@ Rolling back transaction @@@@");
            currentTx.setRollbackOnly();
            countDown.countDown();
          }
        };

    initialiseComponent(descriptor, UMOTransactionConfig.ACTION_ALWAYS_BEGIN, callback);
    UMOManager manager = MuleManager.getInstance();
    addResultListener(getDLDest().getAddress(), countDown);

    JmsConnector umoCnn = (JmsConnector) manager.lookupConnector(CONNECTOR_NAME);

    // After redelivery retry the message and then fail
    umoCnn.setMaxRedelivery(1);

    // Set the test Exception strategy
    umoCnn.setExceptionListener(new RollbackExceptionListener(countDown, getDLDest()));

    // Start the server
    manager.start();

    // Send a test message firstso that it is there when the component is
    // started
    send(DEFAULT_MESSAGE, false, Session.AUTO_ACKNOWLEDGE);

    afterInitialise();
    countDown.tryLock(LOCK_WAIT, TimeUnit.MILLISECONDS);
    assertTrue(
        "Only "
            + (countDownInitialCount - countDown.getCount())
            + " of "
            + countDownInitialCount
            + " checkpoints hit",
        countDown.tryLock());

    assertNotNull(currentMsg);
    System.out.println(currentMsg);
    String dest = currentMsg.getStringProperty(MuleProperties.MULE_ENDPOINT_PROPERTY);
    assertNotNull(dest);
    assertEquals(getDLDest().getUri().toString(), dest);
    assertTrue(callbackCalled);

    // Make sure the message isn't on the queue
    assertNull(receive(getInDest().getAddress(), 2000));
  }
Exemplo n.º 14
0
 public void registerModel(String modelType, String name) throws UMOException {
   UMOModel model = ModelFactory.createModel(modelType);
   model.setName(name);
   manager.registerModel(model);
 }
Exemplo n.º 15
0
 public void registerModel(UMOModel model) throws UMOException {
   this.model = model;
   manager.registerModel(model);
 }
Exemplo n.º 16
0
 /**
  * Sets the component resolver on the model. Component resolver is used to look up components in
  * an external container such as Spring or Pico
  *
  * @param ctx
  * @throws UMOException
  */
 public void setContainerContext(UMOContainerContext ctx) throws UMOException {
   manager.setContainerContext(ctx);
 }