示例#1
0
  protected void setSubscriptionsOnDescriptor(MuleDescriptor descriptor) throws UMOException {
    List endpoints = new ArrayList();
    for (Iterator iterator = listeners.iterator(); iterator.hasNext(); ) {
      ApplicationListener listener = (ApplicationListener) iterator.next();
      if (listener instanceof AsynchronousEventListener) {
        listener = ((AsynchronousEventListener) listener).getListener();
      }
      if (listener instanceof MuleSubscriptionEventListener) {
        String[] subscriptions = ((MuleSubscriptionEventListener) listener).getSubscriptions();
        for (int i = 0; i < subscriptions.length; i++) {
          if (subscriptions[i].indexOf("*") == -1 && MuleEndpointURI.isMuleUri(subscriptions[i])) {
            boolean isSoap = registerAsSoap(subscriptions[i], listener);

            if (!isSoap) {
              endpoints.add(subscriptions[i]);
            }
          }
        }
      }
    }
    if (endpoints.size() > 0) {
      for (Iterator iterator = endpoints.iterator(); iterator.hasNext(); ) {
        String endpoint = (String) iterator.next();
        MuleEndpoint ep = new MuleEndpoint(endpoint, true);

        // check whether the endpoint has already been set on the MuleEventMulticastor
        if (descriptor.getInboundRouter().getEndpoint(ep.getName()) == null) {
          descriptor.getInboundRouter().addEndpoint(ep);
        }
      }
    }
  }
示例#2
0
  public void initialise() throws InitialisationException {
    if (wireFormat == null) {
      wireFormat = new SerializationWireFormat();
    }

    try {
      if (StringUtils.isEmpty(serverUri)) {
        // no serverUrl specified, warn a user
        logger.warn(
            "No serverUriUrl specified, MuleAdminAgent will not start. E.g. use "
                + "<mule:admin-agent serverUri=\"tcp://example.com:60504\"/> ");

        // abort the agent registration process
        managementContext.getRegistry().unregisterAgent(this.getName());

        return;
      }

      // Check for override
      if (ModelHelper.isComponentRegistered(MuleManagerComponent.MANAGER_COMPONENT_NAME)) {
        logger.info("Mule manager component has already been initialised, ignoring server url");
      } else {
        if (managementContext.getRegistry().lookupConnector(DEFAULT_MANAGER_ENDPOINT) != null) {
          throw new AlreadyInitialisedException("Server Components", this);
        }

        MuleEndpoint writableEndpoint;
        // Check to see if we have an endpoint identifier
        UMOImmutableEndpoint endpoint = managementContext.getRegistry().lookupEndpoint(serverUri);
        if (endpoint == null) {
          UMOEndpointURI endpointUri = new MuleEndpointURI(serverUri);
          UMOConnector connector = TransportFactory.getOrCreateConnectorByProtocol(endpointUri);
          // If this connector has already been initialised i.e. it's a
          // pre-existing connector don't reinit
          if (managementContext.getRegistry().lookupConnector(connector.getName()) == null) {
            connector.setName(DEFAULT_MANAGER_ENDPOINT);
            connector.initialise();
            managementContext.getRegistry().registerConnector(connector);
          }
          writableEndpoint = new MuleEndpoint();
          writableEndpoint.setConnector(connector);
          writableEndpoint.setEndpointURI(endpointUri);
        } else {
          writableEndpoint = new MuleEndpoint(endpoint);
        }

        logger.info("Registering Admin listener on: " + serverUri);
        UMODescriptor descriptor =
            MuleManagerComponent.getDescriptor(
                writableEndpoint,
                wireFormat,
                RegistryContext.getConfiguration().getDefaultEncoding(),
                RegistryContext.getConfiguration().getDefaultSynchronousEventTimeout());

        ModelHelper.registerSystemComponent(descriptor);
      }
    } catch (UMOException e) {
      throw new InitialisationException(e, this);
    }
  }
示例#3
0
 private MuleEndpoint buildEndpoint(String urlStr)
     throws EndpointException, MalformedEndpointException, UMOException {
   MuleEndpoint endpoint = new MuleEndpoint();
   endpoint.setEndpointURI(new MuleEndpointURI(urlStr));
   endpoint.setType(UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
   endpoint.setFilter(new NotFilter(new WildcardFilter("*xyz*")));
   // endpoint.setTransformer(new HttpRequestToString());
   endpoint.setConnector(buildConnector(urlStr));
   return endpoint;
 }
示例#4
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);
    }
  }
示例#5
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);
  }
示例#6
0
 public RollbackExceptionListener(CountDownLatch countDown, UMOEndpointURI deadLetter)
     throws UMOException {
   this.countDown = countDown;
   UMOEndpoint ep =
       MuleEndpoint.createEndpointFromUri(deadLetter, UMOEndpoint.ENDPOINT_TYPE_SENDER);
   // lets include dispatch to the deadLetter queue in the sme tx.
   ep.setTransactionConfig(new MuleTransactionConfig());
   ep.getTransactionConfig().setAction(UMOTransactionConfig.ACTION_JOIN_IF_POSSIBLE);
   super.addEndpoint(ep);
 }
示例#7
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());
    }
  }
示例#8
0
 public UMOEndpoint createEndpoint(
     String uri, String name, boolean inbound, String transformers, UMOFilter filter)
     throws UMOException {
   UMOEndpoint ep =
       MuleEndpoint.createEndpointFromUri(
           new MuleEndpointURI(uri),
           (inbound ? UMOEndpoint.ENDPOINT_TYPE_RECEIVER : UMOEndpoint.ENDPOINT_TYPE_SENDER));
   ep.setName(name);
   if (transformers != null) {
     String delim = (transformers.indexOf(",") > -1 ? "," : " ");
     ep.setTransformer(MuleObjectHelper.getTransformer(transformers, delim));
   }
   ep.setFilter(filter);
   return ep;
 }
示例#9
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;
  }
示例#10
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;
  }
示例#11
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);
 }
示例#12
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);
 }