Example #1
1
  public void doTestRegisterListener(
      String component, String endpoint, boolean canSendWithoutReceiver) throws Exception {
    MuleClient client = new MuleClient();

    if (!canSendWithoutReceiver) {
      try {
        client.send(endpoint, "Test Client Send message", null);
        fail("There is no receiver for this endpointUri");
      } catch (Exception e) {
        assertTrue(e.getCause() instanceof NoReceiverForEndpointException);
      }
    }

    Service c = muleContext.getRegistry().lookupService(component);
    c.start();

    MuleMessage message = client.send(endpoint, "Test Client Send message", null);
    assertNotNull(message);
    assertEquals("Received: Test Client Send message", message.getPayloadAsString());

    // The SpringRegistry is read-only so we can't unregister the service!
    // muleContext.getRegistry().unregisterComponent("vmComponent");
    c.stop();

    if (!canSendWithoutReceiver) {
      try {
        message = client.send(endpoint, "Test Client Send message", null);
        fail("There is no receiver for this endpointUri");
      } catch (Exception e) {
        assertTrue(e.getCause() instanceof NoReceiverForEndpointException);
      }
    }
  }
  @Test
  public void testDisableTemporaryReplyOnTheConnector() throws MuleException {
    MuleClient muleClient = new MuleClient(muleContext);
    MuleMessage response = muleClient.send("vm://in3", TEST_MESSAGE, null);

    assertEquals(NullPayload.getInstance(), response.getPayload());
  }
 @Test
 public void testExplicitReplyToAsyncSet() throws MuleException {
   MuleClient muleClient = new MuleClient(muleContext);
   MuleMessage response = muleClient.send("vm://in4", TEST_MESSAGE, null);
   // We get the original message back, not the result from the remote component
   assertEquals(TEST_MESSAGE + " TestService1", response.getPayload());
 }
  @Override
  public Object transformMessage(MuleMessage message, String outputEncoding)
      throws TransformerException {
    UPCSubGroupTableServiceCreateRequest req = new UPCSubGroupTableServiceCreateRequest();
    Division division = ((PartnerProfile) message.getPayload()).getCompany().getCpDivision().get(0);
    SubstitutionGroup substitutionGroup = division.getProducts().get(0).getSubstGrp();
    AxdUPCSubGroupTable upcSubGroupTable = new AxdUPCSubGroupTable();

    AxdEntityBhnUPCSubGroupTable1 bhnUPCSubGroupTable1 = new AxdEntityBhnUPCSubGroupTable1();
    bhnUPCSubGroupTable1.setBhnDivisionCode(division.getDivisionCode());
    bhnUPCSubGroupTable1.setCardDisplayDesc(substitutionGroup.getSubstitutionCardDisplayDesc());
    bhnUPCSubGroupTable1.setName("DEFAULT");
    bhnUPCSubGroupTable1.setPartnerProfileId(
        message.getProperty("partnerProfileId", PropertyScope.SESSION).toString());
    bhnUPCSubGroupTable1.setPOGCategory1(substitutionGroup.getSubstitutionPOG1Category());
    bhnUPCSubGroupTable1.setPOGCategory2(substitutionGroup.getSubstitutionPOG2Category());
    bhnUPCSubGroupTable1.setPOGCategory3(substitutionGroup.getSubstitutionPOG3Category());
    bhnUPCSubGroupTable1.setPOGDimension(substitutionGroup.getSubstitutionPOGDimension());
    bhnUPCSubGroupTable1.setPortalDisplayName(substitutionGroup.getSubstitutionPortalDisplayName());
    bhnUPCSubGroupTable1.setShipperUPC(
        AxdEnumNoYes
            .NO); // TODO currently defaulted to NO as per spec. Will have to revisit it once we get
    // JSON sample value.
    bhnUPCSubGroupTable1.setSubGroupId("DEFAULT");
    bhnUPCSubGroupTable1.setClazz("entity");

    upcSubGroupTable.getBhnUPCSubGroupTable1().add(bhnUPCSubGroupTable1);
    req.setUPCSubGroupTable(upcSubGroupTable);
    return req;
  }
Example #5
0
 // This method is used when the service invoked synchronously. It should really
 // be used independantly of if the service is invoked synchronously when we are
 // using an out-only outbound message exchange pattern
 protected MuleMessage sendToOutboundRouter(MuleEvent event, MuleMessage result)
     throws MessagingException {
   if (event.isStopFurtherProcessing()) {
     logger.debug(
         "MuleEvent stop further processing has been set, no outbound routing will be performed.");
   }
   if (result != null
       && !event.isStopFurtherProcessing()
       && !(result.getPayload() instanceof NullPayload)) {
     if (getOutboundRouter().hasEndpoints()) {
       // Here we need to use a copy of the message instance because there
       // is an inbound response so that transformers executed as part of
       // the outbound phase do not affect the inbound response. MULE-3307
       if (stats.isEnabled()) {
         stats.incSentEventSync();
       }
       MuleMessage outboundReturnMessage =
           getOutboundRouter()
               .route(new DefaultMuleMessage(result.getPayload(), result), event.getSession());
       if (outboundReturnMessage != null) {
         result = outboundReturnMessage;
       }
     } else {
       logger.debug(
           "Outbound router on service '"
               + getName()
               + "' doesn't have any endpoints configured.");
     }
   }
   return result;
 }
 @Override
 public Object transformMessage(final MuleMessage message, String outputEncoding)
     throws TransformerException {
   try {
     if (wildcardAttachmentNameEvaluator.hasWildcards()) {
       try {
         wildcardAttachmentNameEvaluator.processValues(
             message.getInboundAttachmentNames(),
             new WildcardAttributeEvaluator.MatchCallback() {
               @Override
               public void processMatch(String matchedValue) {
                 try {
                   message.addOutboundAttachment(
                       matchedValue, message.getInboundAttachment(matchedValue));
                 } catch (Exception e) {
                   throw new MuleRuntimeException(e);
                 }
               }
             });
       } catch (Exception e) {
         throw new TransformerException(this, e);
       }
     } else {
       String attachmentName = attachmentNameEvaluator.resolveValue(message).toString();
       DataHandler inboundAttachment = message.getInboundAttachment(attachmentName);
       message.addOutboundAttachment(attachmentName, inboundAttachment);
     }
   } catch (Exception e) {
     throw new TransformerException(this, e);
   }
   return message;
 }
Example #7
0
  // //@Override
  protected void initialise(MuleMessage message) {
    if (message.getPayload() instanceof List) {
      // get a copy of the list
      List payload = new LinkedList((List) message.getPayload());
      payloadContext.set(payload);

      if (enableCorrelation != ENABLE_CORRELATION_NEVER) {
        // always set correlation group size, even if correlation id
        // has already been set (usually you don't have group size yet
        // by this point.
        final int groupSize = payload.size();
        message.setCorrelationGroupSize(groupSize);
        if (logger.isDebugEnabled()) {
          logger.debug(
              "java.util.List payload detected, setting correlation group size to " + groupSize);
        }
      }
    } else {
      throw new IllegalArgumentException(
          "The payload for this router must be of type java.util.List");
    }

    // Cache the properties here because for some message types getting the
    // properties can be expensive
    Map props = new HashMap();
    for (Iterator iterator = message.getPropertyNames().iterator(); iterator.hasNext(); ) {
      String propertyKey = (String) iterator.next();
      props.put(propertyKey, message.getProperty(propertyKey));
    }

    propertiesContext.set(props);
  }
 protected String renderMessageAsString(final MuleMessage message) {
   try {
     return message.getPayloadAsString();
   } catch (final Exception e) {
     return message.toString();
   }
 }
Example #9
0
  public void testDispatchReceiveSimple() throws Exception {
    MuleClient client = new MuleClient();
    client.dispatch("endpoint1", TEST_MESSAGE, null);

    MuleMessage result = client.request("vm://middle", 5000L);
    assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
  }
 public static void handle(String service, MuleMessage responseMessage, BaseMessage request) {
   BaseMessage reply = null;
   if (responseMessage.getExceptionPayload() == null) {
     reply = (BaseMessage) responseMessage.getPayload();
   } else {
     Throwable t = responseMessage.getExceptionPayload().getException();
     t = (t.getCause() == null) ? t : t.getCause();
     reply = new EucalyptusErrorMessageType(service, request, t.getMessage());
   }
   String corrId = reply.getCorrelationId();
   EventRecord.here(
           EuareReplyQueue.class,
           EventType.MSG_REPLY,
           reply.getCorrelationId(),
           reply.getClass().getSimpleName())
       .debug();
   try {
     Context context = Contexts.lookup(corrId);
     Channel channel = context.getChannel();
     Channels.write(channel, reply);
     Contexts.clear(context);
   } catch (NoSuchContextException e) {
     LOG.trace(e, e);
   }
 }
 private Object process(String flowName, MuleEvent event) throws Exception {
   MuleMessage result = lookupFlowConstruct(flowName).process(event).getMessage();
   if (result.getExceptionPayload() != null) {
     throw (Exception) result.getExceptionPayload().getException();
   }
   return result.getPayload();
 }
  @Override
  public Object transformMessage(final MuleMessage message, final String outputEncoding)
      throws TransformerException {

    BaseNodeRq nodeRq = null;

    // create the context.
    TransformContext context = new TransformContext();
    message.setProperty("txContext", context, PropertyScope.SESSION);

    String contentType = message.getInboundProperty("Content-Type");
    if (contentType != null && contentType.contains("multipart/form-data")) {

      // transform the multipart request to node
      Node node = httpMultipartTransformer.transformMessage(message);

      // run the transform.
      nodeRq = this.httpRqToNodeRq.transform(context, node);

    } else if (message.getProperty("http.request", PropertyScope.INBOUND) != null) {

      // adapt the http request
      String muleQueryString = (String) message.getProperty("http.request", PropertyScope.INBOUND);
      HttpRequestAdapter httpRequest = new HttpRequestAdapter(muleQueryString);

      // run the transform.
      nodeRq = this.httpRqToNodeRq.transform(context, httpRequest);
    }

    return nodeRq;
  }
Example #13
0
 public void testServerWithEcho() throws Exception {
   MuleClient client = new MuleClient();
   MuleMessage result = client.send("http://localhost:63081/services/Echo", msg, null);
   String resString = result.getPayloadAsString();
   //        System.out.println(resString);
   assertTrue(resString.indexOf("<test xmlns=\"http://foo\"> foo </test>") != -1);
 }
Example #14
0
 public void run() {
   int i = 0;
   try {
     Thread.sleep(2000);
     MuleClient client = new MuleClient();
     MuleMessage result = null;
     for (i = 0; i < numberOfRequests; i++) {
       try {
         result = client.request("CustomerResponses", getDelay());
       } catch (MuleException e) {
         exListener.exceptionThrown(e);
         break;
       }
       // System.out.println("Received: " + i);
       assertNotNull("Result is null", result);
       assertFalse("Result is null", result.getPayload() instanceof NullPayload);
       assertTrue(
           "Result should be LoanQuote but is " + result.getPayload().getClass().getName(),
           result.getPayload() instanceof LoanQuote);
       LoanQuote quote = (LoanQuote) result.getPayload();
       assertTrue(quote.getInterestRate() > 0);
     }
   } catch (Throwable e) {
     // e.printStackTrace();
     System.out.println(StringMessageUtils.getBoilerPlate("Processed Messages=" + i));
     if (e instanceof Error) {
       // throw (Error)e;
       exListener.exceptionThrown(new Exception(e));
     } else {
       exListener.exceptionThrown((Exception) e);
     }
   } finally {
     latch.countDown();
   }
 }
  @Override
  protected MuleEvent aggregateEvents(EventGroup events) throws AggregationException {
    StringBuilder aggregateResponse = new StringBuilder();
    MuleEvent event = null;

    try {
      for (Iterator<MuleEvent> iterator = events.iterator(); iterator.hasNext(); ) {
        event = iterator.next();
        try {
          MuleMessage message = event.getMessage();
          System.out.println(
              "//TODO: HOUSSOU message => " + message + "type => " + message.getClass());
          doAggregate(aggregateResponse, message);
        } catch (Exception e) {
          throw new AggregationException(events, null, e);
        }
      }
      System.out.println("//TODO: HOUSSOU aggregateResponse => " + aggregateResponse);
      return new DefaultMuleEvent(
          new DefaultMuleMessage(aggregateResponse, events.toMessageCollection().getMuleContext()),
          events.getMessageCollectionEvent());
    } catch (ObjectStoreException e) {
      throw new AggregationException(events, null);
    }
  }
Example #16
0
 public void testDelegateClass() throws Exception {
   MuleClient client = new MuleClient();
   client.dispatch(INPUT_DC_QUEUE_NAME, "test", null);
   MuleMessage message = client.request(OUTPUT_DC_QUEUE_NAME, TIMEOUT);
   assertNotNull(message);
   assertEquals(message.getPayload(), DEFUALT_OUTPUT_MESSAGE);
   client.dispose();
 }
Example #17
0
 protected MuleMessage receiveMessage() throws Exception {
   MuleMessage result = client.request(DEFAULT_OUTPUT_MULE_QUEUE_NAME, TIMEOUT);
   assertNotNull(result);
   assertNotNull(result.getPayload());
   assertNull(result.getExceptionPayload());
   assertEquals(DEFAULT_OUTPUT_MESSAGE, result.getPayload());
   return result;
 }
  @Override
  public MuleEvent process(MuleEvent event) throws MuleException {

    MuleMessage message = event.getMessage();
    List messageList = (List) message.getPayload();
    logger.info("message.getPayload() => {}", messageList);
    return event;
  }
 public void doTestXml(String endpoint, String xml) throws Exception {
   MuleClient client = muleContext.getClient();
   client.dispatch("in", xml, null);
   MuleMessage response = client.request(endpoint, TIMEOUT * 2);
   assertNotNull(response);
   assertNotNull(response.getPayload());
   assertEquals(xml, response.getPayloadAsString());
 }
 @Test
 public void testFlowRefHandlingException() throws Exception {
   LocalMuleClient client = muleContext.getClient();
   MuleMessage response =
       client.send("vm://inEnricherExceptionFlow", new DefaultMuleMessage("payload", muleContext));
   assertThat(ErrorProcessor.handled, not(nullValue()));
   assertThat(response.getExceptionPayload(), nullValue());
 }
 @Test
 public void testCorrelation() throws Exception {
   FilteringOutboundRouter filterRouter = new FilteringOutboundRouter();
   MuleMessage message = new DefaultMuleMessage(new StringBuilder(), muleContext);
   OutboundEndpoint endpoint = getTestOutboundEndpoint("test");
   filterRouter.setMessageProperties(getTestService(), message, endpoint);
   assertNotNull(message.getCorrelationId());
 }
 @Test
 public void testThrough() throws Exception {
   MuleMessage message = new MuleClient(muleContext).send("vm://chained", OUTBOUND_MESSAGE, null);
   assertNotNull(message);
   assertEquals(
       StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE) + " Received",
       message.getPayloadAsString());
 }
Example #23
0
 public void testWithInjectedDelegate() throws Exception {
   MuleClient client = new MuleClient();
   client.dispatch(INPUT_DI_QUEUE_NAME, DEFAULT_INPUT_MESSAGE, null);
   MuleMessage reply = client.request(OUTPUT_DI_QUEUE_NAME, TIMEOUT);
   assertNotNull(reply);
   assertNull(reply.getExceptionPayload());
   // same as original input
   assertEquals(DEFAULT_INPUT_MESSAGE, reply.getPayload());
 }
Example #24
0
 public void testInvokeBinding() throws Exception {
   MuleClient client = new MuleClient();
   MuleMessage response = client.send("vm://invoker.in", TEST_MESSAGE, null);
   assertNotNull(response);
   assertNull(response.getExceptionPayload());
   assertTrue(response.getBooleanProperty(PROCESSED, false));
   String expected = "Hello " + TEST_MESSAGE + " " + MAGIC_NUMBER;
   assertEquals(expected, response.getPayload());
 }
Example #25
0
  public Object transform(MuleMessage message, String outputEncoding) throws TransformerException {
    HttpRequestMessageAdapter messageAdapter = (HttpRequestMessageAdapter) message.getAdapter();

    String payloadParam =
        messageAdapter.getStringProperty(
            AbstractReceiverServlet.PAYLOAD_PARAMETER_NAME,
            AbstractReceiverServlet.DEFAULT_PAYLOAD_PARAMETER_NAME);

    String payload = messageAdapter.getStringProperty(payloadParam, null);
    if (payload == null) {
      // Plain text
      if (messageAdapter.getContentType() == null
          || messageAdapter.getContentType().startsWith("text/")) {
        try {
          InputStream is = (InputStream) message.getPayload();
          BufferedReader reader;
          if (messageAdapter.getCharacterEncoding() != null) {
            reader =
                new BufferedReader(
                    new InputStreamReader(is, messageAdapter.getCharacterEncoding()));
          } else {
            reader = new BufferedReader(new InputStreamReader(is));
          }
          StringBuffer buffer = new StringBuffer(8192);
          String line = reader.readLine();
          while (line != null) {
            buffer.append(line);
            line = reader.readLine();
            if (line != null) buffer.append(SystemUtils.LINE_SEPARATOR);
          }
          payload = buffer.toString();
        } catch (IOException e) {
          throw new TransformerException(this, e);
        }
      }

      // HTTP Form
      else if (messageAdapter.getContentType().equals("application/x-www-form-urlencoded")) {
        InputStream is = (InputStream) message.getPayload();
        Properties props = new Properties();
        try {
          props.load(is);
        } catch (IOException e) {
          throw new TransformerException(this, e);
        } finally {
          try {
            is.close();
          } catch (IOException e2) {
            throw new TransformerException(this, e2);
          }
        }
        return props.get(payloadParam);
      }
    }

    return payload;
  }
  @Test
  public void testEndpointAuthenticated() throws Exception {
    MuleClient client = new MuleClient(muleContext);

    client.dispatch("jms:/messages.in", DECRYPTED_MESSAGE, null);
    MuleMessage result = client.request("jms:/messages.out", 15000);
    assertThat(result.getPayload(), is(not(instanceOf(ExceptionPayload.class))));
    assertThat(result.getPayloadAsString(), equalTo(DECRYPTED_MESSAGE));
  }
  @Test
  public void testEncryptDecrypt() throws Exception {
    String payload = "this is a super simple test. Hope it works!!!";
    MuleClient client = muleContext.getClient();

    client.send("vm://in", new DefaultMuleMessage(payload, muleContext));
    MuleMessage message = client.request("vm://out", 5000);
    assertEquals(payload, message.getPayloadAsString());
  }
 @Test
 public void testSimple() throws Exception {
   MuleClient client = muleContext.getClient();
   MuleMessage message = client.send("vm://simple", OUTBOUND_MESSAGE, null);
   assertNotNull(message);
   assertEquals(
       StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE) + " Received",
       message.getPayloadAsString());
 }
 protected Object request(MuleClient client, String endpoint, Class<?> clazz)
     throws MuleException {
   MuleMessage message = client.request(endpoint, TIMEOUT);
   assertNotNull(message);
   assertNotNull(message.getPayload());
   assertTrue(
       message.getPayload().getClass().getName(),
       clazz.isAssignableFrom(message.getPayload().getClass()));
   return message.getPayload();
 }
 @Test
 public void testNotXml() throws Exception {
   logger.debug("not xml");
   MuleClient client = muleContext.getClient();
   client.dispatch("in", STRING_MESSAGE, null);
   MuleMessage response = client.request("notxml", TIMEOUT);
   assertNotNull(response);
   assertNotNull(response.getPayload());
   assertEquals(STRING_MESSAGE, response.getPayloadAsString());
 }