Beispiel #1
0
 public FunctionalTestNotification(UMOEventContext context, Object replyMessage, int action)
     throws TransformerException {
   super(context.getTransformedMessage(), action);
   resourceIdentifier = context.getComponentDescriptor().getName();
   this.replyMessage = replyMessage;
   this.eventContext = context;
 }
Beispiel #2
0
 MuleApplicationEvent(Object message, UMOEventContext context, ApplicationContext appContext)
     throws MalformedEndpointException {
   super(message);
   this.context = context;
   setEndpoint(context.getEndpointURI().toString());
   applicationContext = appContext;
 }
Beispiel #3
0
 protected String getParam(UMOEventContext context, String name) throws NullPointerException {
   String value = context.getMessage().getStringProperty(name, null);
   if (value == null) {
     throw new IllegalArgumentException("Parameter '" + name + "' must be set on the request");
   }
   return value;
 }
Beispiel #4
0
 /**
  * Passes the context to the listener
  *
  * @param context the context ot process
  * @return Object this object can be anything. When the <code>UMOLifecycleAdapter</code> for the
  *     components receives this object it will first see if the Object is an <code>UMOEvent</code>
  *     if not and the Object is not null a new context will be created using the returned object
  *     as the payload. This new context will then get published to the configured outbound
  *     endpoint if-
  *     <ol>
  *       <li>One has been configured for the UMO.
  *       <li>the <code>setStopFurtherProcessing(true)</code> wasn't called on the previous
  *           context.
  *     </ol>
  *
  * @throws Exception if the context fails to process properly. If exceptions aren't handled by the
  *     implementation they will be handled by the exceptionListener associated with the components
  */
 public Object onCall(UMOEventContext context) throws Exception {
   if (methodName.equals(DEFAULT_METHOD_NAME)) {
     return component.invokeMethod(getMethodName(), context);
   } else {
     Object msg = context.getTransformedMessage();
     return component.invokeMethod(getMethodName(), msg);
   }
 }
Beispiel #5
0
  protected Object invokeAction(AdminNotification action, UMOEventContext context)
      throws UMOException {
    String destComponent = null;
    UMOMessage result = null;
    String endpoint = action.getResourceIdentifier();
    if (action.getResourceIdentifier().startsWith("mule:")) {
      destComponent = endpoint.substring(endpoint.lastIndexOf("/") + 1);
    } else {
      destComponent = endpoint;
    }

    if (destComponent != null) {
      UMOSession session = MuleManager.getInstance().getModel().getComponentSession(destComponent);
      // Need to do this otherise when the event is invoked the
      // transformer associated with the Mule Admin queue will be invoked, but
      // the
      // message will not be of expected type
      UMOEndpoint ep = new MuleEndpoint(RequestContext.getEvent().getEndpoint());
      ep.setTransformer(null);
      UMOEvent event =
          new MuleEvent(action.getMessage(), ep, context.getSession(), context.isSynchronous());
      RequestContext.setEvent(event);

      if (context.isSynchronous()) {
        result = session.getComponent().sendEvent(event);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wireFormat.write(out, result);
        return out.toByteArray();
      } else {
        session.getComponent().dispatchEvent(event);
        return null;
      }
    } else {
      return handleException(
          result,
          new MuleException(
              new Message(
                  Messages.COULD_NOT_DETERMINE_DESTINATION_COMPONENT_FROM_ENDPOINT_X, endpoint)));
    }
  }
Beispiel #6
0
  public Object onCall(UMOEventContext context) throws Exception {
    String contents = context.getTransformedMessageAsString();
    String msg =
        StringMessageUtils.getBoilerPlate(
            "Message Received in component: "
                + context.getComponentDescriptor().getName()
                + ". Content is: "
                + StringMessageUtils.truncate(contents, 100, true),
            '*',
            80);

    logger.info(msg);

    if (eventCallback != null) {
      eventCallback.eventReceived(context, this);
    }

    Object replyMessage;
    if (returnMessage != null) {
      replyMessage = returnMessage;
    } else {
      replyMessage =
          contents
              + " Received"
              + (appendComponentName ? " " + context.getComponentDescriptor().getName() : "");
    }

    MuleManager.getInstance()
        .fireNotification(
            new FunctionalTestNotification(
                context, replyMessage, FunctionalTestNotification.EVENT_RECEIVED));

    if (throwException) {
      throw new MuleException(Message.createStaticMessage("Functional Test Component Exception"));
    }

    return replyMessage;
  }
Beispiel #7
0
  public Object onCall(UMOEventContext context) throws Exception {
    String contents = context.getMessageAsString();
    String msg = null;
    msg =
        StringMessageHelper.getBoilerPlate(
            "Message Received in component: "
                + context.getComponentDescriptor().getName()
                + ". Content is: "
                + StringMessageHelper.truncate(contents, 100, true),
            '*',
            80);
    logger.info(msg);

    if (eventCallback != null) {
      eventCallback.eventReceived(context, this);
    }
    if (returnMessage != null) {
      return returnMessage;
    } else {
      contents += " Received";
      return contents;
    }
  }
Beispiel #8
0
  /**
   * Routes the current exception to an error endpoint such as a Dead Letter Queue (jms) This method
   * is only invoked if there is a UMOMassage available to dispatch. The message dispatched from
   * this method will be an <code>ExceptionMessage</code> which contains the exception thrown the
   * UMOMessage and any context information.
   *
   * @param message the UMOMessage being processed when the exception occurred
   * @param failedEndpoint optional; the endpoint being dispatched or recieved on when the error
   *     occurred. This is NOT the endpoint that the message will be disptched on and is only
   *     supplied to this method for logging purposes
   * @param t the exception thrown. This will be sent with the ExceptionMessage
   * @see ExceptionMessage
   */
  protected void routeException(UMOMessage message, UMOEndpoint failedEndpoint, Throwable t) {
    UMOEndpoint endpoint = getEndpoint(t);
    if (endpoint != null) {
      try {
        logger.error(
            "Message being processed is: " + (message == null ? "null" : message.toString()));
        UMOEventContext ctx = RequestContext.getEventContext();
        ExceptionMessage msg = null;
        if (failedEndpoint != null) {
          msg = new ExceptionMessage(getErrorMessagePayload(message), endpoint, t, ctx);
        } else {
          msg = new ExceptionMessage(getErrorMessagePayload(message), t, ctx);
        }

        ctx.sendEvent(new MuleMessage(msg, null), endpoint);
        logger.debug("routed Exception message via " + endpoint);

      } catch (UMOException e) {
        logFatal(message, e);
      }
    } else {
      markTransactionForRollback();
    }
  }
Beispiel #9
0
  protected Object sendAction(AdminNotification action, UMOEventContext context)
      throws UMOException {
    UMOMessage result = null;
    try {
      UMOEndpoint endpoint = new MuleEndpoint(action.getResourceIdentifier(), false);

      if (AdminNotification.ACTION_DISPATCH == action.getAction()) {
        context.dispatchEvent(action.getMessage(), endpoint);
        return null;
      } else {
        endpoint.setRemoteSync(true);
        result = context.sendEvent(action.getMessage(), endpoint);
        if (result == null) {
          return null;
        } else {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          wireFormat.write(out, result);
          return out.toByteArray();
        }
      }
    } catch (Exception e) {
      return handleException(result, e);
    }
  }
Beispiel #10
0
  public Object onCall(UMOEventContext context) throws Exception {
    logger.debug("org.mule.test.usecases.props.PropsComponent");

    if ("component1".equals(context.getComponent().getName())) {
      logger.debug("Adding: " + context.getComponent().getName());
      Map props = new HashMap();
      props.put("stringParam", "param1");
      props.put("objectParam", testObjectProperty);
      UMOMessage msg = new MuleMessage(context.getMessageAsString(), props);
      logger.debug("Adding done: " + context.getComponent().getName());
      return msg;
    } else {
      logger.debug("Verifying: " + context.getComponent().getName());
      assertEquals("param1", context.getMessage().getProperty("stringParam"));
      assertEquals(testObjectProperty, context.getMessage().getProperty("objectParam"));
      logger.debug("Verifying done: " + context.getComponent().getName());
    }

    return context;
  }
Beispiel #11
0
  public static Map cleanAndAdd(UMOEventContext muleEventContext) {

    Map props = new HashMap();
    UMOMessage currentMessage = muleEventContext.getMessage();
    final String SOAP_METHODS = "soapMethods";

    for (Iterator iterator = currentMessage.getPropertyNames().iterator(); iterator.hasNext(); ) {
      String name = (String) iterator.next();
      if (!StringUtils.equals(name, SOAP_METHODS)
          && !StringUtils.equals(name, SoapConstants.SOAP_ACTION_PROPERTY)
          && !StringUtils.equals(name, MuleProperties.MULE_METHOD_PROPERTY)
          && (!name.startsWith(MuleProperties.PROPERTY_PREFIX)
              || StringUtils.equals(name, MuleProperties.MULE_USER_PROPERTY))
          && !HttpConstants.ALL_HEADER_NAMES.containsValue(name)
          && !StringUtils.equals(name, HttpConnector.HTTP_STATUS_PROPERTY)) {
        props.put(name, currentMessage.getProperty(name));
      }
    }
    return props;
  }
Beispiel #12
0
 public Object onCall(UMOEventContext context) throws Exception {
   Object result;
   logger.debug("Message received by MuleManagerComponent");
   ByteArrayInputStream in = new ByteArrayInputStream(context.getTransformedMessageAsBytes());
   AdminNotification action = (AdminNotification) wireFormat.read(in);
   if (AdminNotification.ACTION_INVOKE == action.getAction()) {
     result = invokeAction(action, context);
   } else if (AdminNotification.ACTION_SEND == action.getAction()) {
     result = sendAction(action, context);
   } else if (AdminNotification.ACTION_DISPATCH == action.getAction()) {
     result = sendAction(action, context);
   } else if (AdminNotification.ACTION_RECEIVE == action.getAction()) {
     result = receiveAction(action, context);
   } else {
     result =
         handleException(
             null,
             new MuleException(
                 new Message(
                     Messages.EVENT_TYPE_X_NOT_RECOGNISED,
                     "AdminNotification:" + action.getAction())));
   }
   return result;
 }
Beispiel #13
0
  /*
   * (non-Javadoc)
   *
   * @see org.mule.transformers.AbstractTransformer#doTransform(java.lang.Object)
   */
  public Object transform(Object src, UMOEventContext context) throws TransformerException {
    String endpointAddress = endpoint.getEndpointURI().getAddress();
    SmtpConnector connector = (SmtpConnector) endpoint.getConnector();
    String to = context.getStringProperty(MailProperties.TO_ADDRESSES_PROPERTY, endpointAddress);
    String cc =
        context.getStringProperty(MailProperties.CC_ADDRESSES_PROPERTY, connector.getCcAddresses());
    String bcc =
        context.getStringProperty(
            MailProperties.BCC_ADDRESSES_PROPERTY, connector.getBccAddresses());
    String from =
        context.getStringProperty(MailProperties.FROM_ADDRESS_PROPERTY, connector.getFromAddress());
    String replyTo =
        context.getStringProperty(
            MailProperties.REPLY_TO_ADDRESSES_PROPERTY, connector.getReplyToAddresses());
    String subject =
        context.getStringProperty(MailProperties.SUBJECT_PROPERTY, connector.getSubject());

    String contentType =
        context.getStringProperty(MailProperties.CONTENT_TYPE_PROPERTY, connector.getContentType());

    Properties headers = new Properties();
    if (connector.getCustomHeaders() != null) headers.putAll(connector.getCustomHeaders());
    Properties otherHeaders =
        (Properties) context.getProperty(MailProperties.CUSTOM_HEADERS_MAP_PROPERTY);
    if (otherHeaders != null) {
      Map props = new HashMap(MuleManager.getInstance().getProperties());
      props.putAll(context.getProperties());
      headers.putAll(templateParser.parse(props, otherHeaders));
    }

    if (logger.isDebugEnabled()) {
      StringBuffer buf = new StringBuffer();
      buf.append("Constucting email using:\n");
      buf.append("To: ").append(to);
      buf.append("From: ").append(from);
      buf.append("CC: ").append(cc);
      buf.append("BCC: ").append(bcc);
      buf.append("Subject: ").append(subject);
      buf.append("ReplyTo: ").append(replyTo);
      buf.append("Content type: ").append(contentType);
      buf.append("Payload type: ").append(src.getClass().getName());
      buf.append("Custom Headers: ").append(PropertiesHelper.propertiesToString(headers, false));
      logger.debug(buf.toString());
    }

    try {
      Message msg =
          new MimeMessage(
              (Session)
                  endpoint.getConnector().getDispatcher(endpointAddress).getDelegateSession());

      msg.setRecipients(Message.RecipientType.TO, MailUtils.stringToInternetAddresses(to));

      // sent date
      msg.setSentDate(Calendar.getInstance().getTime());

      if (from != null && !Utility.EMPTY_STRING.equals(from)) {
        msg.setFrom(MailUtils.stringToInternetAddresses(from)[0]);
      }

      if (cc != null && !Utility.EMPTY_STRING.equals(cc)) {
        msg.setRecipients(Message.RecipientType.CC, MailUtils.stringToInternetAddresses(cc));
      }

      if (bcc != null && !Utility.EMPTY_STRING.equals(bcc)) {
        msg.setRecipients(Message.RecipientType.BCC, MailUtils.stringToInternetAddresses(bcc));
      }

      if (replyTo != null && !Utility.EMPTY_STRING.equals(replyTo)) {
        msg.setReplyTo(MailUtils.stringToInternetAddresses(replyTo));
      }

      msg.setSubject(subject);

      Map.Entry entry;
      for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext(); ) {
        entry = (Map.Entry) iterator.next();
        msg.setHeader(entry.getKey().toString(), entry.getValue().toString());
      }

      setContent(src, msg, contentType, context);

      return msg;
    } catch (Exception e) {
      throw new TransformerException(this, e);
    }
  }
Beispiel #14
0
 /**
  * This is the callback method used by Mule to give Mule events to this Multicaster
  *
  * @param context the context received by Mule
  */
 public void onMuleEvent(UMOEventContext context)
     throws TransformerException, MalformedEndpointException {
   multicastEvent(
       new MuleApplicationEvent(context.getTransformedMessage(), context, applicationContext));
   context.setStopFurtherProcessing(true);
 }
Beispiel #15
0
 public Object onCall(UMOEventContext context) throws Exception {
   throw new UnsupportedOperationException(
       "A bridge should not ever receive an event, instead the event should be directly dispatched from the inbound endpoint to the outbound router. Component is: "
           + context.getComponent().getName());
 }
Beispiel #16
0
  /*
   * (non-Javadoc)
   *
   * @see org.mule.transformers.AbstractEventAwareTransformer#transform(java.lang.Object,
   *      java.lang.String, org.mule.umo.UMOEventContext)
   */
  public Object transform(Object src, String encoding, UMOEventContext context)
      throws TransformerException {

    String endpointAddress = endpoint.getEndpointURI().getAddress();
    SmtpConnector connector = (SmtpConnector) endpoint.getConnector();
    UMOMessage eventMsg = context.getMessage();

    String to = eventMsg.getStringProperty(MailProperties.TO_ADDRESSES_PROPERTY, endpointAddress);
    String cc =
        eventMsg.getStringProperty(
            MailProperties.CC_ADDRESSES_PROPERTY, connector.getCcAddresses());
    String bcc =
        eventMsg.getStringProperty(
            MailProperties.BCC_ADDRESSES_PROPERTY, connector.getBccAddresses());
    String from =
        eventMsg.getStringProperty(
            MailProperties.FROM_ADDRESS_PROPERTY, connector.getFromAddress());
    String replyTo =
        eventMsg.getStringProperty(
            MailProperties.REPLY_TO_ADDRESSES_PROPERTY, connector.getReplyToAddresses());
    String subject =
        eventMsg.getStringProperty(MailProperties.SUBJECT_PROPERTY, connector.getSubject());
    String contentType =
        eventMsg.getStringProperty(
            MailProperties.CONTENT_TYPE_PROPERTY, connector.getContentType());

    Properties headers = new Properties();
    Properties customHeaders = connector.getCustomHeaders();

    if (customHeaders != null && !customHeaders.isEmpty()) {
      headers.putAll(customHeaders);
    }

    Properties otherHeaders =
        (Properties) eventMsg.getProperty(MailProperties.CUSTOM_HEADERS_MAP_PROPERTY);
    if (otherHeaders != null && !otherHeaders.isEmpty()) {
      Map props = new HashMap(MuleManager.getInstance().getProperties());
      for (Iterator iterator = eventMsg.getPropertyNames().iterator(); iterator.hasNext(); ) {
        String propertyKey = (String) iterator.next();
        props.put(propertyKey, eventMsg.getProperty(propertyKey));
      }
      headers.putAll(templateParser.parse(props, otherHeaders));
    }

    if (logger.isDebugEnabled()) {
      StringBuffer buf = new StringBuffer(256);
      buf.append("Constructing email using:\n");
      buf.append("To: ").append(to);
      buf.append("From: ").append(from);
      buf.append("CC: ").append(cc);
      buf.append("BCC: ").append(bcc);
      buf.append("Subject: ").append(subject);
      buf.append("ReplyTo: ").append(replyTo);
      buf.append("Content type: ").append(contentType);
      buf.append("Payload type: ").append(src.getClass().getName());
      buf.append("Custom Headers: ").append(PropertiesUtils.propertiesToString(headers, false));
      logger.debug(buf.toString());
    }

    try {
      Message email =
          new MimeMessage(
              (Session) endpoint.getConnector().getDispatcher(endpoint).getDelegateSession());

      // set mail details
      email.setRecipients(Message.RecipientType.TO, MailUtils.stringToInternetAddresses(to));
      email.setSentDate(Calendar.getInstance().getTime());
      if (StringUtils.isNotBlank(from)) {
        email.setFrom(MailUtils.stringToInternetAddresses(from)[0]);
      }
      if (StringUtils.isNotBlank(cc)) {
        email.setRecipients(Message.RecipientType.CC, MailUtils.stringToInternetAddresses(cc));
      }
      if (StringUtils.isNotBlank(bcc)) {
        email.setRecipients(Message.RecipientType.BCC, MailUtils.stringToInternetAddresses(bcc));
      }
      if (StringUtils.isNotBlank(replyTo)) {
        email.setReplyTo(MailUtils.stringToInternetAddresses(replyTo));
      }
      email.setSubject(subject);

      for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iterator.next();
        email.setHeader(entry.getKey().toString(), entry.getValue().toString());
      }

      // Create Multipart to put BodyParts in
      Multipart multipart = new MimeMultipart();

      // Create Text Message
      BodyPart messageBodyPart = new MimeBodyPart();
      messageBodyPart.setText("My Text");
      multipart.addBodyPart(messageBodyPart);

      // Create Attachment
      messageBodyPart = new MimeBodyPart();
      DataHandler dataHandler = (DataHandler) src;
      messageBodyPart.setDataHandler(dataHandler);
      messageBodyPart.setFileName(dataHandler.getName());
      multipart.addBodyPart(messageBodyPart);

      email.setContent(multipart);

      return email;
    } catch (Exception e) {
      throw new TransformerException(this, e);
    }
  }