/**
   * Creates an uninitialied connector from the provided MuleEndpointURI. The scheme is used to
   * determine what kind of connector to create. Any params set on the uri can be used to initialise
   * bean properties on the created connector.
   *
   * <p>Note that the initalise method will need to be called on the connector returned. This is so
   * that developers can control when the connector initialisation takes place as this is likely to
   * initialse all connecotr resources.
   *
   * @param url the MuleEndpointURI url to create the connector with
   * @return a new Connector
   * @throws TransportFactoryException
   */
  public Connector createConnector(EndpointURI url) throws TransportFactoryException {

    try {
      Connector connector;
      String scheme = url.getFullScheme();

      TransportServiceDescriptor sd =
          (TransportServiceDescriptor)
              muleContext
                  .getRegistry()
                  .lookupServiceDescriptor(ServiceType.TRANSPORT, scheme, null);
      if (sd == null) {
        throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme));
      }

      connector = sd.createConnector();
      if (connector != null) {
        if (connector instanceof AbstractConnector) {
          ((AbstractConnector) connector).initialiseFromUrl(url);
        }
      } else {
        throw new TransportFactoryException(
            CoreMessages.objectNotSetInService("Connector", scheme));
      }

      connector.setName(new ObjectNameHelper(muleContext).getConnectorName(connector));

      return connector;
    } catch (Exception e) {
      throw new TransportFactoryException(
          CoreMessages.failedToCreateObjectWith("Endpoint", url), e);
    }
  }
示例#2
0
  protected void connectListeners() throws MuleException {
    @SuppressWarnings("unchecked")
    List<InboundEndpoint> endpoints = getIncomingEndpoints();

    for (InboundEndpoint endpoint : endpoints) {
      AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
      MessageReceiver receiver = connector.getReceiver(this, endpoint);
      if (receiver != null && connector.isConnected()) {
        try {
          receiver.connect();
        } catch (Exception e) {
          throw new ModelException(
              MessageFactory.createStaticMessage(
                  "Failed to connect listener " + receiver + " for endpoint " + endpoint.getName()),
              e);
        }
      }
    }
  }
示例#3
0
  protected void connectListeners() throws MuleException {
    InboundEndpoint endpoint;
    List endpoints = getIncomingEndpoints();

    for (Iterator it = endpoints.iterator(); it.hasNext(); ) {
      endpoint = (InboundEndpoint) it.next();
      AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
      MessageReceiver receiver = connector.getReceiver(this, endpoint);
      if (receiver != null && connector.isConnected()) {
        try {
          receiver.connect();
        } catch (Exception e) {
          throw new ModelException(
              MessageFactory.createStaticMessage(
                  "Failed to connect listener " + receiver + " for endpoint " + endpoint.getName()),
              e);
        }
      }
    }
  }
示例#4
0
  /**
   * Creates an uninitialied connector from the provided MuleEndpointURI. The scheme is used to
   * determine what kind of connector to create. Any params set on the uri can be used to initialise
   * bean properties on the created connector.
   *
   * <p>Note that the initalise method will need to be called on the connector returned. This is so
   * that developers can control when the connector initialisation takes place as this is likely to
   * initialse all connecotr resources.
   *
   * @param url the MuleEndpointURI url to create the connector with
   * @return a new Connector
   * @throws TransportFactoryException
   */
  public static Connector createConnector(EndpointURI url, MuleContext muleContext)
      throws TransportFactoryException {

    try {
      Connector connector;
      String scheme = url.getSchemeMetaInfo();

      TransportServiceDescriptor sd =
          (TransportServiceDescriptor)
              muleContext
                  .getRegistry()
                  .lookupServiceDescriptor(
                      ServiceDescriptorFactory.TRANSPORT_SERVICE_TYPE, scheme, null);
      if (sd == null) {
        throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme));
      }

      connector = sd.createConnector();
      if (connector != null) {
        connector.setMuleContext(muleContext);
        if (connector instanceof AbstractConnector) {
          ((AbstractConnector) connector).initialiseFromUrl(url);
        }
      } else {
        throw new TransportFactoryException(
            CoreMessages.objectNotSetInService("Connector", scheme));
      }

      connector.setName(ObjectNameHelper.getConnectorName(connector));

      // TODO Do we still need to support this for 2.x?
      // set any manager default properties for the connector
      // these are set on the Manager with a protocol i.e.
      // jms.specification=1.1
      //            Map props = new HashMap();
      //
      // PropertiesUtils.getPropertiesWithPrefix(RegistryContext.getRegistry().lookupProperties(),
      //                connector.getProtocol().toLowerCase(), props);
      //            if (props.size() > 0)
      //            {
      //                props = PropertiesUtils.removeNamespaces(props);
      //                BeanUtils.populateWithoutFail(connector, props, true);
      //            }

      return connector;
    } catch (Exception e) {
      throw new TransportFactoryException(
          CoreMessages.failedToCreateObjectWith("Endpoint", url), e);
    }
  }