Example #1
0
  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);
    }
  }
Example #2
0
  /**
   * Depending on the session state this methods either Passes an event synchronously to the next
   * available Mule UMO in the pool or via the endpointUri configured for the event
   *
   * @param message the event message payload to send
   * @param endpointUri The endpointUri to disptch the event through
   * @return the return Message from the call or null if there was no result
   * @throws org.mule.umo.UMOException if the event fails to be processed by the component or the
   *     transport for the endpointUri
   */
  public UMOMessage sendEvent(UMOMessage message, UMOEndpointURI endpointUri) throws UMOException {
    UMOEndpoint endpoint =
        MuleEndpoint.getOrCreateEndpointForUri(endpointUri, UMOEndpoint.ENDPOINT_TYPE_SENDER);

    // If synchronous receive has not been explicitly set, default it to
    // true
    setRemoteSync(message, endpoint);
    return session.sendEvent(message, endpoint);
  }
Example #3
0
  /**
   * Will dispatch an application event through Mule
   *
   * @param applicationEvent the Spring event to be dispatched
   * @throws ApplicationEventException if the event cannot be dispatched i.e. if the underlying
   *     transport throws an exception
   */
  protected void dispatchEvent(MuleApplicationEvent applicationEvent)
      throws ApplicationEventException {
    UMOEndpoint endpoint = null;
    try {
      endpoint =
          MuleEndpoint.getOrCreateEndpointForUri(
              applicationEvent.getEndpoint(), UMOEndpoint.ENDPOINT_TYPE_SENDER);
    } catch (UMOException e) {
      throw new ApplicationEventException(
          "Failed to get endpoint for endpointUri: " + applicationEvent.getEndpoint(), e);
    }
    if (endpoint != null) {
      try {
        // if (applicationEvent.getEndpoint() != null) {
        // endpoint.setEndpointURI(applicationEvent.getEndpoint());
        // }

        MuleMessage message =
            new MuleMessage(applicationEvent.getSource(), applicationEvent.getProperties());
        // has dispatch been triggered using beanFactory.publish()
        // without a current event
        if (applicationEvent.getMuleEventContext() != null) {
          // tell mule not to try and route this event itself
          applicationEvent.getMuleEventContext().setStopFurtherProcessing(true);
          applicationEvent.getMuleEventContext().dispatchEvent(message, endpoint);
        } else {
          UMOSession session =
              new MuleSession(
                  message,
                  ((AbstractConnector) endpoint.getConnector()).getSessionHandler(),
                  component);
          RequestContext.setEvent(new MuleEvent(message, endpoint, session, false));
          // transform if necessary
          if (endpoint.getTransformer() != null) {
            message =
                new MuleMessage(
                    endpoint.getTransformer().transform(applicationEvent.getSource()),
                    applicationEvent.getProperties());
          }
          endpoint.dispatch(new MuleEvent(message, endpoint, session, false));
        }
      } catch (Exception e1) {
        throw new ApplicationEventException("Failed to dispatch event: " + e1.getMessage(), e1);
      }
    } else {
      throw new ApplicationEventException(
          "Failed endpoint using name: " + applicationEvent.getEndpoint());
    }
  }
Example #4
0
  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;
  }
Example #5
0
  protected UMODescriptor getDefaultDescriptor() throws UMOException {
    // When the the beanFactory is refreshed all the beans get
    // reloaded so we need to unregister the component from Mule
    UMOModel model = MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL);
    if (model == null) {
      model = new SedaModel();
      model.setName(ModelHelper.SYSTEM_MODEL);
      MuleManager.getInstance().registerModel(model);
    }
    UMODescriptor descriptor = model.getDescriptor(EVENT_MULTICASTER_DESCRIPTOR_NAME);
    if (descriptor != null) {
      model.unregisterComponent(descriptor);
    }
    descriptor = new MuleDescriptor(EVENT_MULTICASTER_DESCRIPTOR_NAME);
    if (subscriptions == null) {
      logger.info("No receive endpoints have been set, using default '*'");
      descriptor.setInboundEndpoint(new MuleEndpoint("vm://*", true));
    } else {
      // Set multiple inbound subscriptions on the descriptor
      UMOInboundRouterCollection messageRouter = descriptor.getInboundRouter();

      for (int i = 0; i < subscriptions.length; i++) {
        String subscription = subscriptions[i];
        UMOEndpointURI endpointUri = new MuleEndpointURI(subscription);
        UMOEndpoint endpoint =
            MuleEndpoint.getOrCreateEndpointForUri(endpointUri, UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
        if (!asynchronous) {
          endpoint.setSynchronous(true);
        }
        messageRouter.addEndpoint(endpoint);
      }
    }
    // set the implementation name to this bean so Mule will manage it
    descriptor.setImplementation(
        AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME);
    return descriptor;
  }
Example #6
0
 /**
  * Requests a synchronous receive of an event on the component
  *
  * @param endpointUri the endpointUri on which the event will be received
  * @param timeout time in milliseconds before the request timesout
  * @return The requested event or null if the request times out
  * @throws org.mule.umo.UMOException if the request operation fails
  */
 public UMOMessage receiveEvent(UMOEndpointURI endpointUri, long timeout) throws UMOException {
   UMOEndpoint endpoint =
       MuleEndpoint.getOrCreateEndpointForUri(endpointUri, UMOEndpoint.ENDPOINT_TYPE_SENDER);
   return session.receiveEvent(endpoint, timeout);
 }
Example #7
0
 /**
  * Depending on the session state this methods either Passes an event asynchronously to the next
  * available Mule UMO in the pool or via the endpointUri configured for the event
  *
  * @param message the event message payload to send
  * @param endpointUri the endpointUri to dispatc the event to first on the component configuration
  *     and then on the mule manager configuration
  * @throws org.mule.umo.UMOException if the event fails to be processed by the component or the
  *     transport for the endpointUri
  */
 public void dispatchEvent(UMOMessage message, UMOEndpointURI endpointUri) throws UMOException {
   UMOEndpoint endpoint =
       MuleEndpoint.getOrCreateEndpointForUri(endpointUri, UMOEndpoint.ENDPOINT_TYPE_SENDER);
   session.dispatchEvent(message, endpoint);
 }