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 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 void onMessage(MessageExchange messageExchange) throws MessagingException { try { UMOMessageDispatcher dispatcher = endpoint.getConnector().getDispatcher(endpoint.getEndpointURI().getAddress()); NormalizedMessage out = getOutMessage(messageExchange); UMOMessage message = JbiUtils.createMessage(out); UMOEvent event = new MuleEvent(message, endpoint, new MuleSession(), endpoint.isSynchronous()); if (endpoint.isSynchronous()) { UMOMessage result = dispatcher.send(event); // todo send result back } else { dispatcher.dispatch(event); } } catch (Exception e) { error(messageExchange, e); } }
public void testException() throws Throwable { UMOConnector c = ConnectorFactory.getConnectorByProtocol(getProtocol()); assertNotNull(c); UMOMessageDispatcher dispatcher = c.getDispatcher("ANY"); UMOEndpoint endpoint = new MuleEndpoint( "test", new MuleEndpointURI(getTestExceptionEndpoint()), c, null, UMOEndpoint.ENDPOINT_TYPE_SENDER, 0, null); UMOEvent event = getTestEvent(new Person("Nodet", "Guillaume"), endpoint); try { dispatcher.send(event); fail("An Fault should have been raised"); } catch (Exception f) { // This is ok } }