コード例 #1
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);
  }
コード例 #2
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();
   }
 }
コード例 #3
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;
 }
コード例 #4
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;
 }
コード例 #5
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;
  }
 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();
 }
コード例 #7
0
  public void testDispatchReceiveComplexObjects() throws Exception {
    MuleClient client = new MuleClient();
    FruitBowl bowl = new FruitBowl(new Apple(), new Banana());
    bowl.getApple().setWashed(true);
    client.dispatch("endpoint2", bowl, null);

    MuleMessage result = client.request("vm://middle2", 5000L);
    assertTrue(result.getPayload() instanceof FruitBowl);
    assertTrue(((FruitBowl) result.getPayload()).hasApple());
    assertTrue(((FruitBowl) result.getPayload()).getApple().isWashed());
    assertTrue(((FruitBowl) result.getPayload()).hasBanana());
  }
コード例 #8
0
 private void doSelectOnOutbound(String endpoint) throws Exception {
   MuleClient client = new MuleClient();
   MuleMessage reply = client.send(endpoint, new DefaultMuleMessage(NullPayload.getInstance()));
   assertNotNull(reply.getPayload());
   assertTrue(reply.getPayload() instanceof List);
   List resultList = (List) reply.getPayload();
   assertTrue(resultList.size() == 1);
   assertTrue(resultList.get(0) instanceof Map);
   Map resultMap = (Map) resultList.get(0);
   assertEquals(new Integer(1), resultMap.get("TYPE"));
   assertEquals(TEST_VALUES[0], resultMap.get("DATA"));
 }
コード例 #9
0
 @Override
 protected MuleMessage handleUnacceptedFilter(MuleMessage message) {
   super.handleUnacceptedFilter(message);
   if (message.getPayload() instanceof Message) {
     Message msg = (Message) message.getPayload();
     try {
       msg.setFlag(Flags.Flag.DELETED, endpoint.isDeleteUnacceptedMessages());
     } catch (MessagingException e) {
       logger.error("failed to set message deleted: " + e.getMessage(), e);
     }
   }
   return message;
 }
コード例 #10
0
 public void testSelectOnOutboundByExpression() throws Exception {
   MuleClient client = new MuleClient();
   MyMessage payload = new MyMessage(2);
   MuleMessage reply = client.send("vm://terra", new DefaultMuleMessage(payload));
   assertNotNull(reply.getPayload());
   assertTrue(reply.getPayload() instanceof List);
   List resultList = (List) reply.getPayload();
   assertTrue(resultList.size() == 1);
   assertTrue(resultList.get(0) instanceof Map);
   Map resultMap = (Map) resultList.get(0);
   assertEquals(new Integer(2), resultMap.get("TYPE"));
   assertEquals(TEST_VALUES[1], resultMap.get("DATA"));
 }
コード例 #11
0
 public boolean accept(MuleMessage obj) {
   if (obj.getPayload() instanceof byte[]) {
     try {
       return accept(obj.getPayloadAsString());
     } catch (Exception e) {
       logger.warn(
           "JxPath filter rejected message because it could not convert from byte[] to String"
               + e.getMessage(),
           e);
       return false;
     }
   }
   return accept(obj.getPayload());
 }
コード例 #12
0
  public void testRequestResponseComplex() throws Exception {
    MuleClient client = new MuleClient();

    MuleMessage result =
        client.send(
            getSoapProvider()
                + ":http://localhost:38104/mule/services/mycomponent3?method=getPerson",
            "Fred",
            null);
    assertNotNull(result);
    logger.debug(result.getPayload());
    assertTrue(result.getPayload() instanceof Person);
    assertEquals("Fred", ((Person) result.getPayload()).getFirstName());
    assertEquals("Flintstone", ((Person) result.getPayload()).getLastName());
  }
コード例 #13
0
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  public Object hostTransform(final MuleMessage esbMessage, final String encoding)
      throws TransformerException {

    try {

      Object src = esbMessage.getPayload();

      if (src instanceof byte[]) {
        return getBindingTransformers().toJava((byte[]) src, getHostCharset(esbMessage));

      } else if (src instanceof InputStream) {
        return getBindingTransformers()
            .toJava(IOUtils.toByteArray((InputStream) src), getHostCharset(esbMessage));

      } else if (src instanceof Map) {
        return toJava((Map<String, byte[]>) src, getHostCharset(esbMessage));

      } else {
        return null;
      }

    } catch (HostTransformException e) {
      throw new TransformerException(getI18NMessages().hostTransformFailure(), this, e);
    } catch (Exception e) {
      throw new TransformerException(getI18NMessages().hostTransformFailure(), this, e);
    }
  }
コード例 #14
0
 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);
   }
 }
コード例 #15
0
 @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());
 }
コード例 #16
0
  @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());
  }
  @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;
  }
コード例 #18
0
  /**
   * Transform, using XSLT, a XML String to another String.
   *
   * @return The result in the type specified by the user
   */
  @Override
  public Object transformMessage(MuleMessage message, String putputEncoding)
      throws TransformerException {
    Object src = message.getPayload();
    try {
      Source sourceDoc = XMLUtils.toXmlSource(getXMLInputFactory(), isUseStaxSource(), src);
      if (sourceDoc == null) {
        return null;
      }

      ResultHolder holder = getResultHolder(returnType.getType());

      // If the users hasn't specified a class, lets return the same type they gave us
      if (holder == null) {
        holder = getResultHolder(src.getClass());
      }

      // If we still don't have a result type, lets fall back to using a DelayedResult
      // as it is the most efficient.
      if (holder == null || DelayedResult.class.equals(returnType.getType())) {
        return getDelayedResult(message, putputEncoding, sourceDoc);
      }

      doTransform(message, putputEncoding, sourceDoc, holder.getResult());

      return holder.getResultObject();
    } catch (Exception e) {
      throw new TransformerException(this, e);
    }
  }
コード例 #19
0
 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();
 }
コード例 #20
0
  @Test
  public void tcpTest() throws Exception {
    MuleClient client = muleContext.getClient();
    MuleMessage result = client.send("tcpendpoint", new DataObject(1234), null);

    assertNotNull(result);
    assertNull(result.getExceptionPayload());
    assertFalse(result.getPayload() instanceof NullPayload);

    // Assert that the expected payload has been received.
    assertTrue(result.getPayload() instanceof DataObject);

    DataObject dataObject = (DataObject) result.getPayload();

    // Assert id returned as expected (note: Echo increments id by 1)
    assertEquals(1235, (int) dataObject.getId());
  }
コード例 #21
0
  @Test
  public void testTransformer() throws Exception {
    InputStream in = getClass().getResourceAsStream("/transformer-input-message.xml");

    MuleClient client = new MuleClient(muleContext);
    MuleMessage reply =
        client.send("vm://messageInput", new DefaultMuleMessage(in, client.getMuleContext()));

    assertNotNull(reply);
    assertNotNull(reply.getPayload());
    assertFalse(
        "The payload is a NullPayload",
        "<org.mule.transport.NullPayload></org.mule.transport.NullPayload>"
            .equals(reply.getPayload()));

    assertTrue(reportFile.exists());
  }
コード例 #22
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();
 }
コード例 #23
0
  public void testSingleLoanRequest() throws Exception {
    MuleClient client = new MuleClient();
    Customer c = new Customer("Ross Mason", 1234);
    CustomerQuoteRequest request = new CustomerQuoteRequest(c, 100000, 48);
    // Send asynchronous request
    client.dispatch("CustomerRequests", request, null);

    // Wait for asynchronous response
    MuleMessage result = client.request("CustomerResponses", getDelay());
    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);
  }
コード例 #24
0
 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());
 }
コード例 #25
0
  @Override
  public MuleEvent process(MuleEvent event) throws MuleException {

    MuleMessage message = event.getMessage();
    List messageList = (List) message.getPayload();
    logger.info("message.getPayload() => {}", messageList);
    return event;
  }
コード例 #26
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());
 }
コード例 #27
0
  @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));
  }
コード例 #28
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());
 }
コード例 #29
0
 public void testRoundTrip() throws Exception {
   if (this.getRoundTripTransformer() != null) {
     Transformer trans = this.getTransformer();
     Transformer trans2 = this.getRoundTripTransformer();
     MuleMessage message = new DefaultMuleMessage(getTestData(), muleContext);
     message.applyTransformers(Arrays.asList(new Transformer[] {trans, trans2}));
     Object result = message.getPayload();
     this.compareRoundtripResults(this.getTestData(), result);
   }
 }
コード例 #30
0
 @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());
 }