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); } } }
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); }
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()); }
protected String renderMessageAsString(final MuleMessage message) { try { return message.getPayloadAsString(); } catch (final Exception e) { return message.toString(); } }
@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()); }
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 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()); }
@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()); }
public void testTransformersOnProtocol() throws Exception { MuleClient client = new MuleClient(); client.dispatch("protocolTransformerClient", msg, null); MuleMessage result = client.request("vm://in", 3000); assertNotNull(result); String resString = result.getPayloadAsString(); System.out.println(resString); assertTrue(resString.indexOf("<transformed xmlns=\"http://foo\"><soap:Envelope") != -1); }
@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()); }
@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()); }
@Test public void testCanProxyMessages() throws Exception { String order = FileUtils.readFileToString(new File("src/test/resources/order.xml")); Map properties = new HashMap(); properties.put("Authorization", "Basic am9objpqb2hu"); MuleMessage response = muleContext.getClient().send("http://localhost:8080", order, properties); assertNotNull(response); assertEquals("SUCCESS", response.getPayloadAsString()); }
public void testRequestResponse() throws Throwable { MuleClient client = new MuleClient(); MuleMessage result = client.send( getSoapProvider() + ":http://localhost:38104/mule/services/mycomponent2?method=echo", "test", null); assertNotNull(result); assertEquals("test", result.getPayloadAsString()); }
public void testServerClientProxy() throws Exception { String msg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body> <test xmlns=\"http://foo\"></test>" + "</soap:Body>" + "</soap:Envelope>"; MuleClient client = new MuleClient(); MuleMessage result = client.send("http://localhost:63081/services/proxy", msg, null); String resString = result.getPayloadAsString(); assertTrue(resString.indexOf("<test xmlns=\"http://foo\"") != -1); }
public void testProxyWithDatabinding() throws Exception { String msg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body><greetMe xmlns=\"http://apache.org/hello_world_soap_http/types\"><requestType>Dan</requestType></greetMe>" + "</soap:Body>" + "</soap:Envelope>"; MuleClient client = new MuleClient(); MuleMessage result = client.send("http://localhost:63081/services/greeterProxy", msg, null); String resString = result.getPayloadAsString(); assertTrue(resString.indexOf("greetMeResponse") != -1); }
private void doAggregate(StringBuilder aggregateResponse, MuleMessage message) throws Exception { String payloadAsString = null; if (message instanceof MuleMessageCollection) { for (MuleMessage payload : ((MuleMessageCollection) message).getMessagesAsArray()) { doAggregate(aggregateResponse, payload); } } else { if (message.getPayload() instanceof List) { for (Object payload : message.getPayload(List.class)) { payloadAsString = /*(payload == null || payload instanceof NullPayload) ? null :*/ message.getPayloadAsString(); aggregateResponse.append(payloadAsString == null ? "" : payloadAsString); } } else { Object payload = message.getPayload(); payloadAsString = /*(payload == null || payload instanceof NullPayload) ? null :*/ message.getPayloadAsString(); aggregateResponse.append(payloadAsString == null ? "" : payloadAsString); } } }
@Test public void testHttpResponseMove() throws Exception { MuleClient client = new MuleClient(muleContext); DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, muleContext); MuleMessage response = client.send("http://localhost:" + dynamicPort.getNumber() + "/resources/move", muleMessage); assertEquals(HTTP_BODY, response.getPayloadAsString()); assertEquals( "" + HttpConstants.SC_MOVED_PERMANENTLY, response.getInboundProperty("http.status")); assertEquals( "http://localhost:9090/resources/moved", response.<Object>getInboundProperty("Location")); }
public void testGetEcho() throws Exception { // CXF has built in support for understanding GET requests. They are of the form: // http://host/service/OPERATION/PARAM_NAME/PARAM_VALUE MuleClient client = new MuleClient(); Map<String, String> props = new HashMap<String, String>(); props.put("http.method", "GET"); MuleMessage result = client.send("http://localhost:65082/services/EchoUMO/echo/text/hello", "", props); assertNotNull(result); assertFalse(result.getPayload() instanceof NullPayload); XMLAssert.assertXMLEqual(expectedGetResponse, result.getPayloadAsString()); }
public void testSendAndRequest() throws Exception { MuleClient client = new MuleClient(); MuleMessage message = client.send( "tcp://localhost:65432", new DefaultMuleMessage( new DefaultMessageAdapter(new ByteArrayInputStream(TEST_MESSAGE.getBytes())))); assertNotNull(message); Object payload = message.getPayload(); assertTrue(payload instanceof InputStream); assertEquals("Some value - set to make test ok", message.getPayloadAsString()); }
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()); }
@Override public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { try { ProcessInstance processInstance = new ProcessInstance(); Map<String, Object> rootAsMap = this.getMapper().readValue(message.getPayloadAsString(), Map.class); BeanUtils.populateWithoutFail(processInstance, rootAsMap, false); return processInstance; } catch (Exception e) { throw new TransformerException(ActivitiMessages.failToProcessJson(), e); } }
@Test public void testGetTest2() throws Exception { MuleClient client = muleContext.getClient(); MuleMessage result = client.request("http://127.0.0.1:8081/test2", 1000); assertThat(result, is(notNullValue())); Object parsedJson = JSON.parse(result.getPayloadAsString()); assertTrue(parsedJson instanceof Object[]); Object[] array = (Object[]) parsedJson; assertEquals(1, array.length); assertTrue(array[0] instanceof Map); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) array[0]; assertEquals("hello2", map.get("var1")); assertEquals("goodbye2", map.get("var2")); }
@Test public void testHttpResponseError() throws Exception { MuleClient client = new MuleClient(muleContext); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("errorMessage", "ERROR !!!! "); DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, properties, muleContext); MuleMessage response = client.send( "http://localhost:" + dynamicPort.getNumber() + "/resources/error", muleMessage, properties); assertTrue(response.getPayloadAsString().contains("ERROR !!!!")); assertEquals( "" + HttpConstants.SC_INTERNAL_SERVER_ERROR, response.getInboundProperty("http.status")); }
@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()); }
@Test public void testHttpResponseAll() throws Exception { MuleClient client = new MuleClient(muleContext); DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, muleContext); MuleMessage response = client.send("http://localhost:" + dynamicPort.getNumber() + "/resources/all", muleMessage); assertEquals("Custom body", response.getPayloadAsString()); assertEquals("" + HttpConstants.SC_NOT_FOUND, response.getInboundProperty("http.status")); assertEquals( "public,no-cache,must-revalidate,max-age=3600,no-transform", response.getInboundProperty("Cache-Control")); assertEquals("Thu, 01 Dec 2014 16:00:00 GMT", response.getInboundProperty("Expires")); assertEquals("http://localhost:9090", response.getInboundProperty("Location")); assertEquals("value1", response.getInboundProperty("header1")); Cookie[] cookies = (Cookie[]) response.getInboundProperty("Set-Cookie"); assertEquals(2, cookies.length); validateCookie(cookies[0]); validateCookie(cookies[1]); }
public void testSoapActionRouting() throws Exception { String msg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body> <test xmlns=\"http://foo\"></test>" + "</soap:Body>" + "</soap:Envelope>"; Map<String, Object> httpHeaders = new HashMap<String, Object>(); Map<String, Object> props = new HashMap<String, Object>(); props.put(HttpConnector.HTTP_CUSTOM_HEADERS_MAP_PROPERTY, httpHeaders); props.put("SOAPAction", "http://acme.com/transform"); MuleClient client = new MuleClient(); MuleMessage result = client.send("http://localhost:63081/services/routeBasedOnSoapAction", msg, props); String resString = result.getPayloadAsString(); System.out.println(resString); assertTrue(resString.indexOf("<transformed xmlns=\"http://foo\">") != -1); }
@Test public void vmDemoTest() throws Exception { MuleClient client = new MuleClient(muleContext); final String content = "Hi_JeeConf"; MuleMessage receivedMessage = client.send( "vm://process.message.outbound", "/ftp/myFile/Hi_JeeConf", new HashMap<String, Object>()); Thread.sleep(5000); Assert.assertNotNull(receivedMessage); Assert.assertEquals(content, receivedMessage.getPayloadAsString()); client.dispose(); }
protected void doTest(String path, Object payload, String result, Map properties) throws Exception { MuleClient client = new MuleClient(); MuleMessage response = client.send("vm://" + path, payload, properties); assertEquals(result, response.getPayloadAsString()); }