@Test
 public void testFileProducer() throws Exception {
   FactoryFinder finder =
       context.getFactoryFinder("META-INF/services/org/apache/camel/component/");
   Class<?> factory = finder.findClass("file", "strategy.factory.");
   assertNotNull("We should find the factory here.", factory);
 }
  /** A strategy method to lazily create the file strategy */
  @SuppressWarnings("unchecked")
  protected GenericFileProcessStrategy<T> createGenericFileStrategy() {
    Class<?> factory = null;
    try {
      FactoryFinder finder =
          getCamelContext().getFactoryFinder("META-INF/services/org/apache/camel/component/");
      factory = finder.findClass(getScheme(), "strategy.factory.");
    } catch (ClassNotFoundException e) {
      if (log.isTraceEnabled()) {
        log.trace("'strategy.factory.class' not found", e);
      }
    } catch (IOException e) {
      if (log.isTraceEnabled()) {
        log.trace(
            "No strategy factory defined in 'META-INF/services/org/apache/camel/component/'", e);
      }
    }

    if (factory == null) {
      // use default
      factory =
          this.getCamelContext().getClassResolver().resolveClass(DEFAULT_STRATEGYFACTORY_CLASS);
      if (factory == null) {
        throw new TypeNotPresentException(DEFAULT_STRATEGYFACTORY_CLASS + " class not found", null);
      }
    }

    try {
      Method factoryMethod =
          factory.getMethod("createGenericFileProcessStrategy", CamelContext.class, Map.class);
      return (GenericFileProcessStrategy<T>)
          ObjectHelper.invokeMethod(factoryMethod, null, getCamelContext(), getParamsAsMap());
    } catch (NoSuchMethodException e) {
      throw new TypeNotPresentException(
          factory.getSimpleName() + ".createGenericFileProcessStrategy method not found", e);
    }
  }
  @Override
  public Producer createProducer() throws Exception {
    RestApiProcessorFactory factory = null;

    RestConfiguration config = getCamelContext().getRestConfiguration(componentName, true);

    // lookup in registry
    Set<RestApiProcessorFactory> factories =
        getCamelContext().getRegistry().findByType(RestApiProcessorFactory.class);
    if (factories != null && factories.size() == 1) {
      factory = factories.iterator().next();
    }

    // lookup on classpath using factory finder to automatic find it (just add camel-swagger-java to
    // classpath etc)
    if (factory == null) {
      String name = apiComponentName != null ? apiComponentName : config.getApiComponent();
      if (name == null) {
        name = DEFAULT_API_COMPONENT_NAME;
      }
      try {
        FactoryFinder finder = getCamelContext().getFactoryFinder(RESOURCE_PATH);
        Object instance = finder.newInstance(name);
        if (instance instanceof RestApiProcessorFactory) {
          factory = (RestApiProcessorFactory) instance;
        }
      } catch (NoFactoryAvailableException e) {
        // ignore
      }
    }

    if (factory != null) {

      // if no explicit port/host configured, then use port from rest configuration
      String host = "";
      int port = 80;

      if (config.getHost() != null) {
        host = config.getHost();
      }
      int num = config.getPort();
      if (num > 0) {
        port = num;
      }

      // if no explicit hostname set then resolve the hostname
      if (ObjectHelper.isEmpty(host)) {
        if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
          host = "0.0.0.0";
        } else if (config.getRestHostNameResolver()
            == RestConfiguration.RestHostNameResolver.localHostName) {
          host = HostUtils.getLocalHostName();
        } else if (config.getRestHostNameResolver()
            == RestConfiguration.RestHostNameResolver.localIp) {
          host = HostUtils.getLocalIp();
        }

        // no host was configured so calculate a host to use
        // there should be no schema in the host (but only port)
        String targetHost = host + (port != 80 ? ":" + port : "");
        getParameters().put("host", targetHost);
      }

      // the base path should start with a leading slash
      String path = getPath();
      if (path != null && !path.startsWith("/")) {
        path = "/" + path;
      }

      // whether listing of the context id's is enabled or not
      boolean contextIdListing = config.isApiContextListing();

      Processor processor =
          factory.createApiProcessor(
              getCamelContext(),
              path,
              getContextIdPattern(),
              contextIdListing,
              config,
              getParameters());
      return new RestApiProducer(this, processor);
    } else {
      throw new IllegalStateException(
          "Cannot find RestApiProcessorFactory in Registry or classpath (such as the camel-swagger-java component)");
    }
  }
 protected Class<?> findLanguageResolver(String name, CamelContext context) throws Exception {
   if (languageResolver == null) {
     languageResolver = context.getFactoryFinder(LANGUAGE_RESOLVER_RESOURCE_PATH);
   }
   return languageResolver.findClass(name);
 }