Example #1
0
  public void testExceptionChaining() {
    String rootMsg = "Root Test Exception Message";
    String msg = "Test Exception Message";

    Exception e =
        new ManagerException(
            MessageFactory.createStaticMessage(msg),
            new MuleException(MessageFactory.createStaticMessage(rootMsg)));

    assertEquals(rootMsg, e.getCause().getMessage());
    assertEquals(msg, e.getMessage());
    assertEquals(e.getClass().getName() + ": " + msg, e.toString());
  }
Example #2
0
  protected void doInitialise() throws InitialisationException {
    try {
      if (bpms == null) {
        if (bpmsClass != null) {
          logger.info("Instantiating BPMS from the default constructor for " + bpmsClass);
          bpms = (BPMS) ClassUtils.instanciateClass(bpmsClass, new Object[0]);
        } else {
          throw new ConfigurationException(
              MessageFactory.createStaticMessage(
                  "Either the bpms or bpmsClass property must be set for this connector."));
        }
      }

      // Set a callback so that the BPMS may generate messages within Mule.
      bpms.setMessageService(this);

      // The MuleClient is used as a global dispatcher.
      // TODO MULE-1221 It would be cleaner to use something like the dynamic:// transport
      if ((allowGlobalDispatcher == true) && (muleClient == null)) {
        muleClient = new MuleClient(false);
      }
    } catch (Exception e) {
      throw new InitialisationException(e, this);
    }
  }
Example #3
0
  protected void doInitialise() throws InitialisationException {
    try {
      if (bpms == null) {
        bpms = createBpms();
      }
      if (bpms == null) {
        throw new ConfigurationException(
            MessageFactory.createStaticMessage(
                "The bpms property must be set for this connector."));
      }

      if (bpms instanceof Initialisable) {
        ((Initialisable) bpms).initialise();
      }

      // Set a callback so that the BPMS may generate messages within Mule.
      bpms.setMessageService(this);

      // The MuleClient is used as a global dispatcher.
      // TODO MULE-1221 It would be cleaner to use something like the dynamic:// transport
      if ((allowGlobalDispatcher == true) && (muleClient == null)) {
        muleClient = new MuleClient(muleContext);
      }
    } catch (Exception e) {
      throw new InitialisationException(e, this);
    }
  }
Example #4
0
  public MuleMessage generateMessage(
      String endpoint, Object payloadObject, Map messageProperties, boolean synchronous)
      throws Exception {
    String processName = (String) messageProperties.get(ProcessConnector.PROPERTY_PROCESS_TYPE);
    Object processId = messageProperties.get(ProcessConnector.PROPERTY_PROCESS_ID);

    // Look up a receiver for this process.
    ProcessMessageReceiver receiver = lookupReceiver(processName, processId);
    if (receiver == null) {
      throw new ConfigurationException(
          MessageFactory.createStaticMessage(
              "No corresponding receiver found for processName = "
                  + processName
                  + ", processId = "
                  + processId));
    }

    logger.debug(
        "Generating Mule message for process name = "
            + processName
            + " id = "
            + processId
            + ", synchronous = "
            + synchronous);

    if (synchronous) {
      // Send the process-generated Mule message synchronously.
      return receiver.generateSynchronousEvent(endpoint, payloadObject, messageProperties);
    } else {
      // Dispatch the process-generated Mule message asynchronously.
      receiver.generateAsynchronousEvent(endpoint, payloadObject, messageProperties);
      return null;
    }
  }
Example #5
0
 protected void setMessage(String message) {
   initialise();
   this.message = message;
   if (i18nMessage == null) {
     i18nMessage = MessageFactory.createStaticMessage(message);
   }
 }
  public final void initialise() throws InitialisationException {
    if (flowConstruct == null) {
      throw new InitialisationException(
          MessageFactory.createStaticMessage(
              "Component has not been initialized properly, no flow constuct."),
          this);
    }

    lifecycleManager.fireInitialisePhase(
        new LifecycleCallback<Component>() {
          public void onTransition(String phaseName, Component object) throws MuleException {
            DefaultMessageProcessorChainBuilder chainBuilder =
                new DefaultMessageProcessorChainBuilder(flowConstruct);
            chainBuilder.setName("Component interceptor processor chain for :" + getName());
            for (Interceptor interceptor : interceptors) {
              chainBuilder.chain(interceptor);
            }
            chainBuilder.chain(
                new MessageProcessor() {
                  public MuleEvent process(MuleEvent event) throws MuleException {
                    return invokeInternal(event);
                  }
                });

            interceptorChain = chainBuilder.build();
            if (interceptorChain instanceof MuleContextAware) {
              ((MuleContextAware) interceptorChain).setMuleContext(muleContext);
            }
            if (interceptorChain instanceof Initialisable) {
              ((Initialisable) interceptorChain).initialise();
            }
            doInitialise();
          }
        });
  }
Example #7
0
 public int getQueueSize() {
   if (queue == null) {
     logger.warn(
         new InitialisationException(
             MessageFactory.createStaticMessage("Queue not created for service " + name), this));
     return -1;
   }
   return queue.size();
 }
Example #8
0
 protected void enqueue(MuleEvent event) throws Exception {
   if (queue == null) {
     throw new InitialisationException(
         MessageFactory.createStaticMessage("Queue not created for service " + name), this);
   }
   if (logger.isDebugEnabled()) {
     logger.debug(
         MessageFormat.format(
             "Service {0} putting event on queue {1}: {2}", name, queue.getName(), event));
   }
   queue.put(event);
 }
Example #9
0
  /**
   * Initialise the service. The service will first create a Mule UMO from the UMODescriptor and
   * then initialise a pool based on the attributes in the UMODescriptor.
   *
   * @throws org.mule.api.lifecycle.InitialisationException if the service fails to initialise
   * @see org.mule.api.UMODescriptor
   */
  protected synchronized void doInitialise() throws InitialisationException {
    MuleConfiguration config = muleContext.getConfiguration();
    if (threadingProfile == null) {
      // TODO MULE-2102 This should be configured in the default template.
      threadingProfile = muleContext.getDefaultComponentThreadingProfile();
    }
    // Create thread pool
    workManager = threadingProfile.createWorkManager(getName());

    if (queueProfile == null) {
      // TODO MULE-2102 This should be configured in the default template.
      queueProfile = ((SedaModel) model).getQueueProfile();
    }

    if (queueTimeout == null) {
      // TODO MULE-2102 This should be configured in the default template.
      setQueueTimeout(new Integer(((SedaModel) model).getQueueTimeout()));
    }

    try {
      if (name == null) {
        throw new InitialisationException(
            MessageFactory.createStaticMessage("Service has no name to identify it"), this);
      }
      // Setup event Queue (used for VM execution).  The queue has the same name as the service.
      queueProfile.configureQueue(name, muleContext.getQueueManager());
      queue = muleContext.getQueueManager().getQueueSession().getQueue(name);
      if (queue == null) {
        throw new InitialisationException(
            MessageFactory.createStaticMessage(
                "Queue " + name + " not created for service " + name),
            this);
      }
    } catch (InitialisationException e) {
      throw e;
    } catch (Throwable e) {
      throw new InitialisationException(
          CoreMessages.objectFailedToInitialise("Service Queue"), e, this);
    }
  }
Example #10
0
 protected void enqueue(MuleEvent event) throws Exception {
   QueueSession session = muleContext.getQueueManager().getQueueSession();
   Queue queue = session.getQueue(name);
   if (queue == null) {
     throw new InitialisationException(
         MessageFactory.createStaticMessage("Queue " + name + " not created for service " + name),
         this);
   }
   if (logger.isDebugEnabled()) {
     logger.debug("Service " + name + " putting event on queue " + name + ": " + event);
   }
   queue.put(event);
 }
Example #11
0
 public MuleException(Throwable cause) {
   super(
       (cause instanceof InvocationTargetException
           ? ((InvocationTargetException) cause).getTargetException()
           : cause));
   if (cause != null) {
     setMessage(
         MessageFactory.createStaticMessage(
             cause.getMessage() + " (" + cause.getClass().getName() + ")"));
   } else {
     initialise();
   }
 }
Example #12
0
 public int getQueueSize() {
   QueueSession session = muleContext.getQueueManager().getQueueSession();
   Queue queue = session.getQueue(name);
   if (queue == null) {
     logger.warn(
         new InitialisationException(
             MessageFactory.createStaticMessage(
                 "Queue " + name + " not created for service " + name),
             this));
     return -1;
   }
   return queue.size();
 }
Example #13
0
  protected void doInitialise() throws InitialisationException {
    createMultipleTransactedReceivers = false;

    if (dataSource == null) {
      throw new InitialisationException(
          MessageFactory.createStaticMessage("Missing data source"), this);
    }
    if (resultSetHandler == null) {
      resultSetHandler = new org.apache.commons.dbutils.handlers.MapListHandler();
    }
    if (queryRunner == null) {
      queryRunner = new QueryRunner();
    }
  }
Example #14
0
  public void initialise() throws InitialisationException {
    if (objectClass == null && objectClassName == null) {
      throw new InitialisationException(
          MessageFactory.createStaticMessage("Object factory has not been initialized."), this);
    }

    if (objectClass == null && objectClassName != null) {
      try {
        objectClass = ClassUtils.getClass(objectClassName);
      } catch (ClassNotFoundException e) {
        throw new InitialisationException(e, this);
      }
    }
  }
Example #15
0
 // moved here from connection wrapper
 public boolean enlistResource(XAResource resource) throws TransactionException {
   TransactionManager txManager = muleContext.getTransactionManager();
   try {
     Transaction jtaTransaction = txManager.getTransaction();
     if (jtaTransaction == null) {
       throw new TransactionException(MessageFactory.createStaticMessage("XATransaction is null"));
     }
     return jtaTransaction.enlistResource(resource);
   } catch (RollbackException e) {
     throw new TransactionException(e);
   } catch (SystemException e) {
     throw new TransactionException(e);
   }
 }
Example #16
0
 protected void doConnect() throws Exception {
   if (transport == null) {
     try {
       transport = castConnector().getSessionDetails(endpoint).newTransport();
       EndpointURI uri = endpoint.getEndpointURI();
       transport.connect(uri.getHost(), uri.getPort(), uri.getUser(), uri.getPassword());
     } catch (Exception e) {
       throw new EndpointException(
           org.mule.config.i18n.MessageFactory.createStaticMessage(
               "Unable to connect to mail transport."),
           e);
     }
   }
 }
Example #17
0
  @Override
  public <T> T lookupObject(Class<T> type) throws RegistrationException {
    // Accumulate objects from all registries.
    Collection<T> objects = lookupObjects(type);

    if (objects.size() == 1) {
      return objects.iterator().next();
    } else if (objects.size() > 1) {
      throw new RegistrationException(
          MessageFactory.createStaticMessage(
              "More than one object of type " + type + " registered but only one expected."));
    } else {
      return null;
    }
  }
Example #18
0
  /** Creates an initialized object instance based on the class and sets any properties. */
  public Object getInstance() throws Exception {
    if (objectClass == null) {
      throw new InitialisationException(
          MessageFactory.createStaticMessage("Object factory has not been initialized."), this);
    }

    Object object = ClassUtils.instanciateClass(objectClass, ClassUtils.NO_ARGS);

    if (properties != null) {
      BeanUtils.populate(object, properties);
    }

    fireInitialisationCallbacks(object);

    return object;
  }
Example #19
0
 protected MuleEvent dequeue() throws Exception {
   if (queue == null) {
     throw new InitialisationException(
         MessageFactory.createStaticMessage("Queue not created for service " + name), this);
   }
   if (logger.isDebugEnabled()) {
     logger.debug(
         MessageFormat.format(
             "Service {0} polling queue {1}, timeout = {2}", name, queue.getName(), queueTimeout));
   }
   if (getQueueTimeout() == null) {
     throw new InitialisationException(CoreMessages.noServiceQueueTimeoutSet(this), this);
   } else {
     return (MuleEvent) queue.poll(getQueueTimeout());
   }
 }
Example #20
0
  /**
   * Creates a component based on its descriptor.
   *
   * @param descriptor the descriptor to create the component from
   * @return The newly created component
   * @throws UMOException
   */
  public static Object createService(UMODescriptor descriptor) throws UMOException {
    Object component;
    try {
      component = descriptor.getServiceFactory().create();

      // TODO MULE-1933 Would be nice to remove this eventually.
      BeanUtils.populate(component, descriptor.getProperties());
    } catch (Exception e) {
      throw new LifecycleException(
          MessageFactory.createStaticMessage("Unable to create component"), e, descriptor);
    }

    // Call any custom initialisers
    if (descriptor instanceof MuleDescriptor) {
      ((MuleDescriptor) descriptor).fireInitialisationCallbacks(component);
    }

    return component;
  }
Example #21
0
  protected void connectListeners() throws MuleException {
    @SuppressWarnings("unchecked")
    List<InboundEndpoint> endpoints = getIncomingEndpoints();

    for (InboundEndpoint endpoint : endpoints) {
      AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
      MessageReceiver receiver = connector.getReceiver(this, endpoint);
      if (receiver != null && connector.isConnected()) {
        try {
          receiver.connect();
        } catch (Exception e) {
          throw new ModelException(
              MessageFactory.createStaticMessage(
                  "Failed to connect listener " + receiver + " for endpoint " + endpoint.getName()),
              e);
        }
      }
    }
  }
Example #22
0
  public Object transform(MuleMessage message, String encoding) throws TransformerException {
    Object src = message.getPayload();
    try {
      XMLStreamReader xsr = XMLUtils.toXMLStreamReader(getXMLInputFactory(), src);
      if (xsr == null) {
        throw new TransformerException(
            MessageFactory.createStaticMessage(
                "Unable to convert " + src.getClass() + " to XMLStreamReader."));
      }

      if (reversible && !(xsr instanceof ReversibleXMLStreamReader)) {
        return new ReversibleXMLStreamReader(xsr);
      } else {
        return xsr;
      }
    } catch (XMLStreamException e) {
      throw new TransformerException(this, e);
    }
  }
Example #23
0
  protected void connectListeners() throws MuleException {
    InboundEndpoint endpoint;
    List endpoints = getIncomingEndpoints();

    for (Iterator it = endpoints.iterator(); it.hasNext(); ) {
      endpoint = (InboundEndpoint) it.next();
      MessageReceiver receiver =
          ((AbstractConnector) endpoint.getConnector()).getReceiver(this, endpoint);
      if (receiver != null) {
        try {
          receiver.connect();
        } catch (Exception e) {
          throw new ModelException(
              MessageFactory.createStaticMessage(
                  "Failed to connect listener " + receiver + " for endpoint " + endpoint.getName()),
              e);
        }
      }
    }
  }
Example #24
0
  protected void doConfigure(MuleContext muleContext) throws Exception {
    Registry registry;

    if (parentContext != null) {
      if (appContext instanceof ConfigurableApplicationContext) {
        registry = new SpringRegistry((ConfigurableApplicationContext) appContext, parentContext);
      } else {
        throw new ConfigurationException(
            MessageFactory.createStaticMessage(
                "Cannot set a parent context if the ApplicationContext does not implement ConfigurableApplicationContext"));
      }
    } else {
      registry = new SpringRegistry(appContext);
    }

    // Note: The SpringRegistry must be created before applicationContext.refresh() gets called
    // because
    // some beans may try to look up other beans via the Registry during preInstantiateSingletons().
    muleContext.addRegistry(registry);
    registry.initialise();
  }
Example #25
0
 /**
  * @param message
  * @param cause
  */
 public BusinessException(String message, Throwable cause) {
   super(MessageFactory.createStaticMessage(message), cause);
 }
Example #26
0
 protected static String getString(String bundlePath, String code) {
   return MessageFactory.getString(bundlePath, Integer.parseInt(code));
 }