Exemplo n.º 1
0
  public UMOMessage getResponse(UMOMessage message) throws RoutingException {
    UMOMessage result = null;
    if (routers.size() == 0) {
      result = message;
    } else {
      UMOResponseRouter router = null;
      for (Iterator iterator = getRouters().iterator(); iterator.hasNext(); ) {
        router = (UMOResponseRouter) iterator.next();
        result = router.getResponse(message);
      }

      if (result == null) {
        // Update stats
        if (getStatistics().isEnabled()) {
          getStatistics().incrementNoRoutedMessage();
        }
      }
    }

    if (result != null && transformer != null) {
      try {
        result =
            new MuleMessage(transformer.transform(result.getPayload()), result.getProperties());
      } catch (TransformerException e) {
        throw new RoutingException(result, null);
      }
    }
    return result;
  }
Exemplo n.º 2
0
 public void testUpperCaseString() throws Exception {
   UMOImmutableEndpoint ep =
       new ImmutableMuleEndpoint("jnp://localhost/TestService?method=upperCaseString", false);
   UMOMessage message = ep.send(getTestEvent("hello", ep));
   assertNotNull(message.getPayload());
   assertEquals("HELLO", message.getPayloadAsString());
 }
Exemplo n.º 3
0
 public void testFunctionBehaviour() throws Exception {
   MuleClient client = new MuleClient();
   UMOMessage m = client.send("vm://localhost/groovy.1", "Groovy Test: ", null);
   assertNotNull(m);
   assertEquals(
       "Groovy Test: Received by component 1: Received by component 2:", m.getPayloadAsString());
 }
Exemplo n.º 4
0
  public void testReceivingASubscriptionEvent() throws Exception {
    OrderManagerBean subscriptionBean = (OrderManagerBean) context.getBean("orderManager");
    assertNotNull(subscriptionBean);
    // when an event is received by 'testEventBean1' this callback will be invoked
    EventCallback callback =
        new EventCallback() {
          public void eventReceived(UMOEventContext context, Object o) throws Exception {
            eventCount++;
          }
        };
    subscriptionBean.setEventCallback(callback);

    MuleManager.getConfiguration().setSynchronous(true);
    MuleClient client = new MuleClient();
    Order order = new Order("Sausage and Mash");
    client.send("jms://orders.queue", order, null);
    Thread.sleep(1000);
    assertTrue(eventCount == 1);

    UMOMessage result = client.receive("jms://processed.queue", 10000);
    assertEquals(1, eventCount);
    assertNotNull(result);
    assertEquals(
        "Order 'Sausage and Mash' Processed", ((TextMessage) result.getPayload()).getText());
  }
Exemplo n.º 5
0
  public void testClientDispatchAndReceiveOnReplyTo() throws Exception {
    MuleClient client = new MuleClient();
    MuleManager.getConfiguration().setSynchronous(false);

    Map props = new HashMap();
    props.put(JmsConstants.JMS_REPLY_TO, "replyTo.queue");

    long start = System.currentTimeMillis();
    int i = 0;
    for (i = 0; i < INTERATIONS; i++) {
      System.out.println("Sending message " + i);
      client.dispatch(getDispatchUrl(), "Test Client Dispatch message " + i, props);
    }
    long time = System.currentTimeMillis() - start;
    System.out.println("It took " + time + " ms to send " + i + " messages");

    Thread.sleep(5000);
    start = System.currentTimeMillis();
    for (i = 0; i < INTERATIONS; i++) {
      UMOMessage message = client.receive("jms://replyTo.queue", 5000);
      assertNotNull("message should not be null from Reply queue", message);
      System.out.println("Count is " + i);
      System.out.println("ReplyTo Message is: " + message.getPayloadAsString());
      assertTrue(message.getPayloadAsString().startsWith("Received"));
    }
    time = System.currentTimeMillis() - start;
    System.out.println("It took " + time + "ms to receive " + i + " messages");
  }
Exemplo n.º 6
0
  protected Object receiveAction(AdminNotification action, UMOEventContext context)
      throws UMOException {
    UMOMessage result = null;
    try {
      UMOEndpointURI endpointUri = new MuleEndpointURI(action.getResourceIdentifier());
      UMOEndpoint endpoint =
          MuleEndpoint.getOrCreateEndpointForUri(endpointUri, UMOEndpoint.ENDPOINT_TYPE_SENDER);

      UMOMessageDispatcher dispatcher = endpoint.getConnector().getDispatcher(endpoint);
      long timeout =
          MapUtils.getLongValue(
              action.getProperties(),
              MuleProperties.MULE_EVENT_TIMEOUT_PROPERTY,
              MuleManager.getConfiguration().getSynchronousEventTimeout());

      UMOEndpointURI ep = new MuleEndpointURI(action.getResourceIdentifier());
      result = dispatcher.receive(ep, timeout);
      if (result != null) {
        // See if there is a default transformer on the connector
        UMOTransformer trans =
            ((AbstractConnector) endpoint.getConnector()).getDefaultInboundTransformer();
        if (trans != null) {
          Object payload = trans.transform(result.getPayload());
          result = new MuleMessage(payload, result);
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wireFormat.write(out, result);
        return out.toByteArray();
      } else {
        return null;
      }
    } catch (Exception e) {
      return handleException(result, e);
    }
  }
Exemplo n.º 7
0
  public void testSendComplex() throws Throwable {
    UMOConnector c = ConnectorFactory.getConnectorByProtocol(getProtocol());
    assertNotNull(c);
    UMOMessageDispatcher dispatcher = c.getDispatcher("ANY");
    UMOEndpoint endpoint =
        new MuleEndpoint(
            "test",
            new MuleEndpointURI(getSendReceiveComplexEndpoint1()),
            c,
            null,
            UMOEndpoint.ENDPOINT_TYPE_SENDER,
            0,
            null);
    UMOEvent event = getTestEvent(new Person("Ross", "Mason"), endpoint);

    UMOMessage result = dispatcher.send(event);
    assertNull(result);

    // lets get our newly added person
    result = dispatcher.receive(new MuleEndpointURI(getSendReceiveComplexEndpoint2()), 0);
    assertNotNull(result);
    assertTrue(result.getPayload() instanceof Person);
    assertEquals("Ross", ((Person) result.getPayload()).getFirstName());
    assertEquals("Mason", ((Person) result.getPayload()).getLastName());
  }
Exemplo n.º 8
0
 public void testCorrelation() throws Exception {
   FilteringOutboundRouter filterRouter = new FilteringOutboundRouter();
   UMOSession session = getTestSession(getTestComponent(getTestDescriptor("test", "test")));
   UMOMessage message = new MuleMessage(new DefaultMessageAdapter(new StringBuffer()));
   UMOEndpoint endpoint = getTestEndpoint("test", "sender");
   filterRouter.setMessageProperties(session, message, endpoint);
   assertNotNull(message.getCorrelationId());
 }
Exemplo n.º 9
0
 public void testNoArgsCallWrapper() throws Exception {
   MuleClient client = new MuleClient();
   client.dispatch("vm://invoke", "test", null);
   UMOMessage reply = client.receive("vm://out", RECEIVE_TIMEOUT);
   assertNotNull(reply);
   assertNull(reply.getExceptionPayload());
   assertEquals("Just an apple.", reply.getPayload());
 }
Exemplo n.º 10
0
 protected Object getErrorMessagePayload(UMOMessage message) {
   try {
     return message.getPayloadAsString();
   } catch (Exception e) {
     logException(e);
     logger.info("Failed to read message payload as string, using raw payload");
     return message.getPayload();
   }
 }
Exemplo n.º 11
0
 public void testWithInjectedDelegate() throws Exception {
   MuleClient client = new MuleClient();
   client.dispatch("vm://invokeWithInjected", "test", null);
   UMOMessage reply = client.receive("vm://outWithInjected", RECEIVE_TIMEOUT);
   assertNotNull(reply);
   assertNull(reply.getExceptionPayload());
   // same as original input
   assertEquals("test", reply.getPayload());
 }
Exemplo n.º 12
0
 public void testAuthenticationFailureNoContext() throws Exception {
   MuleClient client = new MuleClient();
   UMOMessage m = client.send("vm://my.queue", "foo", null);
   assertNotNull(m);
   assertNotNull(m.getExceptionPayload());
   assertEquals(
       ExceptionHelper.getErrorCode(CredentialsNotSetException.class),
       m.getExceptionPayload().getCode());
 }
Exemplo n.º 13
0
 public void testReceive() throws Throwable {
   UMOConnector c = ConnectorFactory.getConnectorByProtocol(getProtocol());
   assertNotNull(c);
   UMOMessageDispatcher dispatcher = c.getDispatcher("ANY");
   UMOMessage result = dispatcher.receive(new MuleEndpointURI(getReceiveEndpoint()), 0);
   assertNotNull(result);
   assertNotNull(result.getPayload());
   assertTrue(result.getPayload().toString().length() > 0);
 }
Exemplo n.º 14
0
 public void testReceiveComplex() throws Throwable {
   UMOConnector c = ConnectorFactory.getConnectorByProtocol(getProtocol());
   assertNotNull(c);
   UMOMessageDispatcher dispatcher = c.getDispatcher("ANY");
   UMOMessage result = dispatcher.receive(new MuleEndpointURI(getReceiveComplexEndpoint()), 0);
   assertNotNull(result);
   assertTrue(result.getPayload() instanceof Person);
   assertEquals("Fred", ((Person) result.getPayload()).getFirstName());
   assertEquals("Flintstone", ((Person) result.getPayload()).getLastName());
 }
Exemplo n.º 15
0
 public void testReceiveComplexCollection() throws Throwable {
   UMOConnector c = ConnectorFactory.getConnectorByProtocol(getProtocol());
   assertNotNull(c);
   UMOMessageDispatcher dispatcher = c.getDispatcher("ANY");
   UMOMessage result =
       dispatcher.receive(new MuleEndpointURI(getReceiveComplexCollectionEndpoint()), 0);
   assertNotNull(result);
   assertTrue(result.getPayload() instanceof Person[]);
   assertEquals(3, ((Person[]) result.getPayload()).length);
 }
Exemplo n.º 16
0
 public List requestSend(int number, String endpoint) throws Exception {
   List results = new ArrayList(number);
   UMOMessage result;
   for (int i = 0; i < number; i++) {
     result = client.send(endpoint, createRequest(), null);
     if (result != null) {
       results.add(result.getPayload());
     }
   }
   return results;
 }
Exemplo n.º 17
0
 public void testRequestResponse() throws Throwable {
   MuleClient client = new MuleClient();
   RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:38100");
   try {
     UMOMessage result =
         dispatcher.sendRemote(
             "axis:http://localhost:38104/mule/services/mycomponent2?method=echo", "test", null);
     assertNotNull(result);
     assertEquals("test", result.getPayloadAsString());
   } finally {
     client.dispose();
   }
 }
Exemplo n.º 18
0
  public void testAuthenticationAuthorised() throws Exception {
    MuleClient client = new MuleClient();

    Map props = new HashMap();
    UMOEncryptionStrategy strategy =
        MuleManager.getInstance().getSecurityManager().getEncryptionStrategy("PBE");
    String header = MuleCredentials.createHeader("anon", "anon", "PBE", strategy);
    props.put(MuleProperties.MULE_USER_PROPERTY, header);

    UMOMessage m = client.send("vm://my.queue", "foo", props);
    assertNotNull(m);
    assertNull(m.getExceptionPayload());
  }
Exemplo n.º 19
0
  public void testCaseBadPassword() throws Exception {
    MuleClient client = new MuleClient();
    Map props = new HashMap();
    UMOEncryptionStrategy strategy =
        MuleManager.getInstance().getSecurityManager().getEncryptionStrategy("PBE");
    String header = MuleCredentials.createHeader("Marie.Rizzo", "evil", "PBE", strategy);
    props.put(MuleProperties.MULE_USER_PROPERTY, header);
    UMOMessage m = client.send("vm://test", "Test", props);

    assertNotNull(m);
    assertTrue(m.getPayload() instanceof String);
    assertFalse(m.getPayloadAsString().equals("Test Received"));
  }
Exemplo n.º 20
0
  public void testAuthenticationAuthorisedHttp() throws Exception {
    MuleClient client = new MuleClient();

    Map props = new HashMap();
    UMOEncryptionStrategy strategy =
        MuleManager.getInstance().getSecurityManager().getEncryptionStrategy("PBE");
    String header = MuleCredentials.createHeader("anon", "anon", "PBE", strategy);
    props.put(MuleProperties.MULE_USER_PROPERTY, header);

    UMOMessage m = client.send("http://localhost:4567/index.html", "", props);
    assertNotNull(m);
    int status = m.getIntProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
    assertEquals(HttpConstants.SC_OK, status);
  }
Exemplo n.º 21
0
  public void testExceptionStrategyForTransformerExceptionAsync() throws Exception {
    MuleClient client = new MuleClient();

    UMOMessage message = client.receive("vm://error.queue", 2000);
    assertNull(message);

    client.dispatch("vm://component.in", "test", null);

    message = client.receive("vm://component.out", 2000);
    assertNull(message);

    message = client.receive("vm://error.queue", 2000);
    assertNotNull(message);
    Object payload = message.getPayload();
    assertTrue(payload instanceof ExceptionMessage);
  }
Exemplo n.º 22
0
    public void handleMessagingException(UMOMessage message, Throwable t) {
      System.out.println("@@@@ ExceptionHandler Called @@@@");
      if (t instanceof MessageRedeliveredException) {
        countDown.countDown();
        try {
          // MessageRedeliveredException mre =
          // (MessageRedeliveredException)t;
          Message msg = (Message) message.getPayload();

          assertNotNull(msg);
          assertTrue(msg.getJMSRedelivered());
          assertTrue(msg instanceof TextMessage);
          // No need to commit transaction as the Tx template will
          // auto
          // matically commit by default
          super.handleMessagingException(message, t);
        } catch (Exception e) {
          fail(e.getMessage());
        }
      } else {
        t.printStackTrace();
        fail(t.getMessage());
      }
      super.handleMessagingException(message, t);
    }
Exemplo n.º 23
0
 public void request(LoanRequest request, boolean sync) throws Exception {
   if (!sync) {
     client.dispatch("vm://LoanBrokerRequests", request, null);
     System.out.println("Sent Async request");
     // let the request catch up
     Thread.sleep(1500);
   } else {
     UMOMessage result = client.send("vm://LoanBrokerRequests", request, null);
     if (result == null) {
       System.out.println(
           "A result was not received, an error must have occurred. Check the logs.");
     } else {
       System.out.println("Loan Consumer received a Quote: " + result.getPayload());
     }
   }
 }
Exemplo n.º 24
0
  public void testRequestResponseComplex2() throws Exception {
    MuleClient client = new MuleClient();
    RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:38100");
    try {
      String[] args = new String[] {"Betty", "Rubble"};
      UMOMessage result =
          dispatcher.sendRemote(
              "axis:http://localhost:38104/mule/services/mycomponent3?method=addPerson",
              args,
              null);
      assertNotNull(result);
      assertTrue(result.getPayload() instanceof Person);
      assertEquals("Betty", ((Person) result.getPayload()).getFirstName());
      assertEquals("Rubble", ((Person) result.getPayload()).getLastName());

      // do a receive
      result =
          client.send(
              "axis:http://localhost:38104/mule/services/mycomponent3?method=getPerson",
              "Betty",
              null);
      assertNotNull(result);
      assertTrue(result.getPayload() instanceof Person);
      assertEquals("Betty", ((Person) result.getPayload()).getFirstName());
      assertEquals("Rubble", ((Person) result.getPayload()).getLastName());
    } finally {
      client.dispose();
    }
  }
Exemplo n.º 25
0
 public void testRequestResponseComplex() throws Exception {
   MuleClient client = new MuleClient();
   RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:38100");
   try {
     UMOMessage result =
         dispatcher.sendRemote(
             "axis:http://localhost:38104/mule/services/mycomponent3?method=getPerson",
             "Fred",
             null);
     assertNotNull(result);
     System.out.println(result.getPayload());
     assertTrue(result.getPayload() instanceof Person);
     assertEquals("Fred", ((Person) result.getPayload()).getFirstName());
     assertEquals("Flintstone", ((Person) result.getPayload()).getLastName());
   } finally {
     client.dispose();
   }
 }
Exemplo n.º 26
0
 private void setRemoteSync(UMOMessage message, UMOEndpoint endpoint) {
   if (endpoint.isRemoteSync()) {
     if (getTransaction() == null) {
       message.setBooleanProperty(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, true);
     } else {
       throw new IllegalStateException(
           new Message(Messages.CANNOT_USE_TX_AND_REMOTE_SYNC).getMessage());
     }
   }
 }
Exemplo n.º 27
0
 public Object transform(UMOMessage message, String outputEncoding) throws TransformerException {
   UMOMessage result = message;
   Object temp = message;
   UMOTransformer lastTransformer = null;
   for (Iterator iterator = transformers.iterator(); iterator.hasNext(); ) {
     lastTransformer = (UMOTransformer) iterator.next();
     temp = lastTransformer.transform(temp);
     if (temp instanceof UMOMessage) {
       result = (UMOMessage) temp;
     } else {
       result.setPayload(temp);
     }
   }
   if (lastTransformer != null && lastTransformer.getReturnClass().equals(UMOMessage.class)) {
     return result;
   } else {
     return result.getPayload();
   }
 }
Exemplo n.º 28
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;
  }
Exemplo n.º 29
0
  protected UMOStreamMessageAdapter sendStream(String uri, UMOStreamMessageAdapter sa)
      throws UMOException {

    UMOEndpoint ep = MuleEndpoint.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;
  }
Exemplo n.º 30
0
  public void testReceiveAsWebService() throws Exception {
    MuleClient client = new MuleClient();
    OrderManagerBean orderManager = (OrderManagerBean) context.getBean("orderManager");
    assertNotNull(orderManager);
    EventCallback callback =
        new EventCallback() {
          public void eventReceived(UMOEventContext context, Object o) throws Exception {
            eventCount++;
          }
        };
    orderManager.setEventCallback(callback);

    Order order = new Order("Sausage and Mash");
    UMOMessage result =
        client.send(
            "axis:http://localhost:44444/mule/orderManager?method=processOrder", order, null);

    assertNotNull(result);
    assertEquals("Order 'Sausage and Mash' Processed", (result.getPayload()));
  }