Ejemplo n.º 1
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());
  }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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());
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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);
    }
  }
Ejemplo n.º 6
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;
  }
Ejemplo n.º 7
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());
 }
Ejemplo n.º 8
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());
  }
Ejemplo n.º 9
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);
    }
Ejemplo n.º 10
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());
 }
Ejemplo n.º 11
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();
   }
 }
Ejemplo n.º 12
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());
 }
Ejemplo n.º 13
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();
   }
 }
Ejemplo n.º 14
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;
 }
Ejemplo n.º 15
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();
    }
  }
Ejemplo n.º 16
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"));
  }
Ejemplo n.º 17
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);
  }
Ejemplo n.º 18
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());
     }
   }
 }
Ejemplo n.º 19
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();
   }
 }
Ejemplo n.º 20
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()));
  }
Ejemplo n.º 21
0
  public void testGoodUserNameEncrypted() throws Exception {
    MuleClient client = new MuleClient();
    Properties props = new Properties();

    // Action to perform : user token
    props.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
    // User name to send
    props.setProperty(WSHandlerConstants.USER, "mulealias");
    // Callback used to retrive password for given user.
    props.setProperty(
        WSHandlerConstants.PW_CALLBACK_CLASS,
        "org.mule.extras.wssecurity.callbackhandlers.MuleWsSecurityCallbackHandler");
    // Property file containing the Encryption properties
    props.setProperty(WSHandlerConstants.ENC_PROP_FILE, "out-encrypted-security.properties");

    UMOMessage m =
        client.send("axis:http://localhost:8282/MySecuredUMO?method=echo", "Test", props);
    assertNotNull(m);
    assertTrue(m.getPayload() instanceof String);
    assertTrue(m.getPayload().equals("Test"));
  }
Ejemplo n.º 22
0
 public void testDownloadSpeed() throws Exception {
   MuleClient client = new MuleClient();
   long now = System.currentTimeMillis();
   UMOMessage result = client.send(endpoint, "request", null);
   assertNotNull(result);
   assertNotNull(result.getPayload());
   assertEquals(InputStreamSource.SIZE, result.getPayloadAsBytes().length);
   long then = System.currentTimeMillis();
   double speed =
       InputStreamSource.SIZE
           / (double) (then - now)
           * 1000
           / AbstractStreamingCapacityTestCase.ONE_MB;
   logger.info(
       "Transfer speed "
           + speed
           + " MB/s ("
           + InputStreamSource.SIZE
           + " B in "
           + (then - now)
           + " ms)");
 }
Ejemplo n.º 23
0
 public boolean accept(UMOMessage obj) {
   return accept(obj.getPayload());
 }
Ejemplo n.º 24
0
  public Object transform(UMOMessage message, String outputEncoding) throws TransformerException {
    Object src = message.getPayload();

    String data = src.toString();
    if (src instanceof InputStream) {
      InputStream is = (InputStream) src;
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      try {
        try {
          IOUtils.copy(is, bos);
        } finally {
          is.close();
        }
      } catch (IOException e) {
        throw new TransformerException(this, e);
      }

      src = bos.toByteArray();
    }

    if (src instanceof byte[]) {
      try {
        data = new String((byte[]) src, outputEncoding);
      } catch (UnsupportedEncodingException e) {
        throw new TransformerException(this, e);
      }
      // Data is already Xml
      if (data.startsWith("<") || data.startsWith("&lt;")) {
        return data;
      }
    }

    String httpMethod = message.getStringProperty("http.method", "GET");
    String request = message.getStringProperty("http.request", null);

    int i = request.indexOf('?');
    String query = request.substring(i + 1);
    Properties p = PropertiesUtils.getPropertiesFromQueryString(query);

    String method = (String) p.remove(MuleProperties.MULE_METHOD_PROPERTY);
    if (method == null) {
      throw new TransformerException(
          CoreMessages.propertiesNotSet(MuleProperties.MULE_METHOD_PROPERTY), this);
    }

    if (httpMethod.equals("POST")) {
      p.setProperty(method, data);
    }

    StringBuffer result = new StringBuffer(8192);
    String header =
        StringMessageUtils.getFormattedMessage(SOAP_HEADER, new Object[] {outputEncoding});

    result.append(header);
    result.append('<').append(method).append(" xmlns=\"");
    result.append(DEFAULT_NAMESPACE).append("\">");
    for (Iterator iterator = p.entrySet().iterator(); iterator.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iterator.next();
      result.append('<').append(entry.getKey()).append('>');
      result.append(entry.getValue());
      result.append("</").append(entry.getKey()).append('>');
    }
    result.append("</").append(method).append('>');
    result.append(SOAP_FOOTER);

    return result.toString();
  }
Ejemplo n.º 25
0
 public boolean accept(UMOMessage message) {
   return accept(message.getPayload());
 }