@Test public void testThrough() throws Exception { MuleClient client = muleContext.getClient(); MuleMessage message = client.send("vm://chained", OUTBOUND_MESSAGE, null); assertNotNull(message); assertEquals( StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE) + " Received", message.getPayloadAsString()); }
@Override public void testSendRequestResponseInbound() throws Exception { MuleClient client = muleContext.getClient(); try { client.send("vm://requestresponse-in", "a", null); fail("Exception expected"); } catch (Exception e) { } }
@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 testSyncResponse() throws Exception { MuleClient client = muleContext.getClient(); String payload = "payload"; client.send("tcp://localhost:4444", payload, null); MuleMessage msg = client.request("file://temp/tests/mule", 10000); assertNotNull(msg); assertEquals(payload, msg.getPayloadAsString()); }
@Override public void testSendToOneWayTx() throws Exception { MuleClient client = muleContext.getClient(); try { client.send("vm://oneway-tx-in", "a", null); fail("Exception expected"); } catch (Exception e) { TransactionCoordination.getInstance().getTransaction().rollback(); } }
@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()); }
@Test public void testTcpTcpRemoteSync() throws Exception { MuleClient client = muleContext.getClient(); Map<String, Object> props = new HashMap<String, Object>(); // must notify the client to wait for a response from the server props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, Boolean.TRUE); MuleMessage reply = client.send( ((InboundEndpoint) muleContext.getRegistry().lookupObject("echoInTcp")).getAddress(), new DefaultMuleMessage(message, muleContext), props); assertNotNull(reply); assertNotNull(reply.getPayload()); assertEquals("Received: " + message, reply.getPayloadAsString()); }
@Override public Object onCall(MuleEventContext eventContext) throws Exception { logger.info("Entering onCall ....."); MuleMessage message = eventContext.getMessage(); List messageList = (List) message.getPayload(); logger.info("message.getPayload() => {}", messageList); MuleClient client = context.getClient(); StringBuilder aggregated = new StringBuilder("AGGREGATED ["); for (int i = 0; i < messageList.size(); i++) { String messageType = (String) messageList.get(i); MuleMessage muleMessage = new DefaultMuleMessage(messageType, context); StringBuilder muleURL = new StringBuilder(); muleMessage.setOutboundProperty("X", messageType); client.dispatch("jms://queue1", muleMessage); MuleMessage muleMessage2 = new DefaultMuleMessage(messageType, context); muleMessage2.setOutboundProperty("X", messageType); MuleMessage result = client.send("jms://queue2", muleMessage2); aggregated.append(result.getPayload()).append(","); } aggregated.append("]"); logger.info("Aggregated response {}", aggregated); return eventContext; }
public Object send(String url, Object payload) throws MuleException { return muleClient.send(url, payload, null).getPayload(); }