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; }
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()); }
public void testFunctionBehaviour() throws Exception { MuleClient client = new MuleClient(); UMOMessage m = client.send("vm://localhost/groovy.1", "Groovy Test: ", null); assertNotNull(m); assertEquals( "Groovy Test: Received by component 1: Received by component 2:", m.getPayloadAsString()); }
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()); }
public void testClientDispatchAndReceiveOnReplyTo() throws Exception { MuleClient client = new MuleClient(); MuleManager.getConfiguration().setSynchronous(false); Map props = new HashMap(); props.put(JmsConstants.JMS_REPLY_TO, "replyTo.queue"); long start = System.currentTimeMillis(); int i = 0; for (i = 0; i < INTERATIONS; i++) { System.out.println("Sending message " + i); client.dispatch(getDispatchUrl(), "Test Client Dispatch message " + i, props); } long time = System.currentTimeMillis() - start; System.out.println("It took " + time + " ms to send " + i + " messages"); Thread.sleep(5000); start = System.currentTimeMillis(); for (i = 0; i < INTERATIONS; i++) { UMOMessage message = client.receive("jms://replyTo.queue", 5000); assertNotNull("message should not be null from Reply queue", message); System.out.println("Count is " + i); System.out.println("ReplyTo Message is: " + message.getPayloadAsString()); assertTrue(message.getPayloadAsString().startsWith("Received")); } time = System.currentTimeMillis() - start; System.out.println("It took " + time + "ms to receive " + i + " messages"); }
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); } }
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()); }
public void testCorrelation() throws Exception { FilteringOutboundRouter filterRouter = new FilteringOutboundRouter(); UMOSession session = getTestSession(getTestComponent(getTestDescriptor("test", "test"))); UMOMessage message = new MuleMessage(new DefaultMessageAdapter(new StringBuffer())); UMOEndpoint endpoint = getTestEndpoint("test", "sender"); filterRouter.setMessageProperties(session, message, endpoint); assertNotNull(message.getCorrelationId()); }
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()); }
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(); } }
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()); }
public void testAuthenticationFailureNoContext() throws Exception { MuleClient client = new MuleClient(); UMOMessage m = client.send("vm://my.queue", "foo", null); assertNotNull(m); assertNotNull(m.getExceptionPayload()); assertEquals( ExceptionHelper.getErrorCode(CredentialsNotSetException.class), m.getExceptionPayload().getCode()); }
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); }
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()); }
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); }
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; }
public void testRequestResponse() throws Throwable { MuleClient client = new MuleClient(); RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:38100"); try { UMOMessage result = dispatcher.sendRemote( "axis:http://localhost:38104/mule/services/mycomponent2?method=echo", "test", null); assertNotNull(result); assertEquals("test", result.getPayloadAsString()); } finally { client.dispose(); } }
public void testAuthenticationAuthorised() throws Exception { MuleClient client = new MuleClient(); Map props = new HashMap(); UMOEncryptionStrategy strategy = MuleManager.getInstance().getSecurityManager().getEncryptionStrategy("PBE"); String header = MuleCredentials.createHeader("anon", "anon", "PBE", strategy); props.put(MuleProperties.MULE_USER_PROPERTY, header); UMOMessage m = client.send("vm://my.queue", "foo", props); assertNotNull(m); assertNull(m.getExceptionPayload()); }
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")); }
public void testAuthenticationAuthorisedHttp() throws Exception { MuleClient client = new MuleClient(); Map props = new HashMap(); UMOEncryptionStrategy strategy = MuleManager.getInstance().getSecurityManager().getEncryptionStrategy("PBE"); String header = MuleCredentials.createHeader("anon", "anon", "PBE", strategy); props.put(MuleProperties.MULE_USER_PROPERTY, header); UMOMessage m = client.send("http://localhost:4567/index.html", "", props); assertNotNull(m); int status = m.getIntProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1); assertEquals(HttpConstants.SC_OK, status); }
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); }
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); }
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()); } } }
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(); } }
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(); } }
private void setRemoteSync(UMOMessage message, UMOEndpoint endpoint) { if (endpoint.isRemoteSync()) { if (getTransaction() == null) { message.setBooleanProperty(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, true); } else { throw new IllegalStateException( new Message(Messages.CANNOT_USE_TX_AND_REMOTE_SYNC).getMessage()); } } }
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(); } }
public static Map cleanAndAdd(UMOEventContext muleEventContext) { Map props = new HashMap(); UMOMessage currentMessage = muleEventContext.getMessage(); final String SOAP_METHODS = "soapMethods"; for (Iterator iterator = currentMessage.getPropertyNames().iterator(); iterator.hasNext(); ) { String name = (String) iterator.next(); if (!StringUtils.equals(name, SOAP_METHODS) && !StringUtils.equals(name, SoapConstants.SOAP_ACTION_PROPERTY) && !StringUtils.equals(name, MuleProperties.MULE_METHOD_PROPERTY) && (!name.startsWith(MuleProperties.PROPERTY_PREFIX) || StringUtils.equals(name, MuleProperties.MULE_USER_PROPERTY)) && !HttpConstants.ALL_HEADER_NAMES.containsValue(name) && !StringUtils.equals(name, HttpConnector.HTTP_STATUS_PROPERTY)) { props.put(name, currentMessage.getProperty(name)); } } return props; }
protected UMOStreamMessageAdapter sendStream(String uri, UMOStreamMessageAdapter sa) throws UMOException { UMOEndpoint ep = MuleEndpoint.getOrCreateEndpointForUri(uri, UMOEndpoint.ENDPOINT_TYPE_SENDER); ep.setStreaming(true); UMOMessage message = new MuleMessage(sa); UMOEvent event = new MuleEvent(message, ep, RequestContext.getEventContext().getSession(), true); UMOMessage result = ep.send(event); if (result != null) { if (result.getAdapter() instanceof UMOStreamMessageAdapter) { return (UMOStreamMessageAdapter) result.getAdapter(); } else { // TODO i18n (though this case should never happen...) throw new IllegalStateException( "Mismatch of stream states. A stream was used for outbound channel, but a stream was not used for the response"); } } return null; }
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())); }