@Override
 public MuleEvent handleException(Exception ex, MuleEvent event) {
   doHandleException(ex, event);
   DefaultMuleMessage message = new DefaultMuleMessage(NullPayload.getInstance(), muleContext);
   message.setExceptionPayload(
       new DefaultExceptionPayload(
           new MessagingException(event, new RuntimeException("Bad news!"))));
   return new DefaultMuleEvent(message, event);
 }
Example #2
0
  public void testConstructors() throws Exception {
    Apple payload = new Apple();
    // Ensure that the MuleMessage is unwrapped correctly
    DefaultMuleMessage message =
        new DefaultMuleMessage(new DefaultMuleMessage(payload, muleContext), muleContext);
    assertEquals(message.getPayload(), payload);

    DefaultMessageAdapter adapter = new DefaultMessageAdapter(payload);

    message = new DefaultMuleMessage(adapter, new HashMap(), muleContext);
    assertEquals(message.getPayload(), payload);
  }
Example #3
0
  public void testDelete() throws Exception {
    MessagePropertiesTransformer t = new MessagePropertiesTransformer();
    t.setDeleteProperties(Collections.singletonList("badProperty"));
    t.setMuleContext(muleContext);

    DefaultMuleMessage msg = new DefaultMuleMessage("message", (Map) null);
    msg.setProperty("badProperty", "badValue");
    DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg, null);
    assertSame(msg, transformed);
    assertEquals(msg.getUniqueId(), transformed.getUniqueId());
    assertEquals(msg.getPayload(), transformed.getPayload());
    assertEquals(msg.getPropertyNames(), transformed.getPropertyNames());
    assertFalse(transformed.getPropertyNames().contains("badValue"));
  }
  @Override
  protected void addProperties(DefaultMuleMessage message, Object transportMessage)
      throws Exception {
    super.addProperties(message, transportMessage);

    if (transportMessage instanceof OpenSpacesQueueObject) {
      OpenSpacesQueueObject queueObject = (OpenSpacesQueueObject) transportMessage;

      if (queueObject.getPayloadMetaData() != null)
        message.addProperties(queueObject.getPayloadMetaData());

      String correlationId = queueObject.getCorrelationID();

      if (correlationId != null) message.setCorrelationId(correlationId);
    }
  }
Example #5
0
  public void testRenameProperties() throws Exception {
    MessagePropertiesTransformer t = new MessagePropertiesTransformer();
    Map add = new HashMap();
    add.put("Foo", "Baz");
    t.setRenameProperties(add);
    t.setMuleContext(muleContext);

    DefaultMuleMessage msg = new DefaultMuleMessage("message", (Map) null);
    msg.setProperty("Foo", "Bar");
    DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg, null);
    assertSame(msg, transformed);
    assertEquals(msg.getUniqueId(), transformed.getUniqueId());
    assertEquals(msg.getPayload(), transformed.getPayload());
    assertEquals(msg.getPropertyNames(), transformed.getPropertyNames());

    assertEquals("Bar", transformed.getProperty("Baz"));
  }
Example #6
0
    protected void preRouteMuleMessage(final DefaultMuleMessage message) throws Exception {
      super.preRouteMuleMessage(message);

      final SocketAddress clientAddress = socket.getRemoteSocketAddress();
      if (clientAddress != null) {
        message.setProperty(MuleProperties.MULE_REMOTE_CLIENT_ADDRESS, clientAddress.toString());
      }
    }
Example #7
0
  public void testOverwriteFalsePreservesOriginal() throws Exception {
    MessagePropertiesTransformer t = new MessagePropertiesTransformer();
    Map add = new HashMap();
    add.put("addedProperty", "overwrittenValue");
    t.setAddProperties(add);
    t.setOverwrite(false);
    t.setMuleContext(muleContext);

    DefaultMuleMessage msg = new DefaultMuleMessage("message", (Map) null);
    msg.setProperty("addedProperty", "originalValue");
    DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg, null);
    assertSame(msg, transformed);
    assertEquals(msg.getUniqueId(), transformed.getUniqueId());
    assertEquals(msg.getPayload(), transformed.getPayload());
    assertEquals(msg.getPropertyNames(), transformed.getPropertyNames());

    assertEquals("originalValue", transformed.getProperty("addedProperty"));
  }
Example #8
0
  public void testOverwriteFlagEnabledByDefault() throws Exception {
    MessagePropertiesTransformer t = new MessagePropertiesTransformer();
    Map add = new HashMap();
    add.put("addedProperty", "overwrittenValue");
    t.setAddProperties(add);
    t.setMuleContext(muleContext);

    MuleMessage msg = new DefaultMuleMessage("message", (Map) null);
    msg.setProperty("addedProperty", "originalValue");
    MuleEventContext ctx = getTestEventContext(msg);
    // context clones message
    msg = ctx.getMessage();
    DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg, null);
    assertSame(msg, transformed);
    assertEquals(msg.getUniqueId(), transformed.getUniqueId());
    assertEquals(msg.getPayload(), transformed.getPayload());
    // property values will be different
    assertEquals(msg.getPropertyNames(), transformed.getPropertyNames());

    assertEquals("overwrittenValue", transformed.getProperty("addedProperty"));
  }
 protected MuleEvent createResultEvent(MuleEvent event, Object result) throws MuleException {
   if (result instanceof MuleMessage) {
     return new DefaultMuleEvent((MuleMessage) result, event);
   } else if (result instanceof VoidResult) {
     return event;
   } else if (result != null) {
     event
         .getMessage()
         .applyTransformers(
             event,
             Collections.<Transformer>singletonList(
                 new TransformerTemplate(
                     new TransformerTemplate.OverwitePayloadCallback(result))));
     return event;
   } else {
     DefaultMuleMessage emptyMessage =
         new DefaultMuleMessage(NullPayload.getInstance(), muleContext);
     emptyMessage.propagateRootId(event.getMessage());
     return new DefaultMuleEvent(emptyMessage, event);
   }
 }