public String withCamelContext(String body, CamelContext camel) {
   assertNotNull(body);
   assertNotNull(camel);
   assertNotNull(camel.getRegistry().lookupByName("foo"));
   assertEquals("Hello", body);
   return "CamelContext";
 }
Exemple #2
0
 public ControlChannel(
     final CamelContext hostContext, final Tracer tracer, final Configuration config) {
   this(
       hostContext,
       tracer,
       config,
       hostContext.getRegistry().lookup(Environment.SHUTDOWN_CHANNEL_ID, ShutdownChannel.class));
 }
Exemple #3
0
  public static ParameterMappingStrategy createParameterMappingStrategy(CamelContext camelContext) {
    // lookup in registry first if there is a user define strategy
    Registry registry = camelContext.getRegistry();
    ParameterMappingStrategy answer =
        registry.lookupByNameAndType(
            BeanConstants.BEAN_PARAMETER_MAPPING_STRATEGY, ParameterMappingStrategy.class);
    if (answer == null) {
      // no then use the default one
      answer = new DefaultParameterMappingStrategy();
    }

    return answer;
  }
 private void notifyListeners(
     CamelContext context, org.switchyard.Exchange exchange, Throwable exception) {
   Map<String, ErrorListener> listeners = context.getRegistry().lookupByType(ErrorListener.class);
   if (listeners != null && listeners.size() > 0) {
     for (Entry<String, ErrorListener> entry : listeners.entrySet()) {
       try {
         entry.getValue().notify(exchange, exception);
       } catch (Exception e) {
         LOG.error(
             "Error listener "
                 + entry.getKey()
                 + " failed to handle exception "
                 + exception.getClass());
       }
     }
   }
 }
  @SuppressWarnings("unchecked")
  public Language resolveLanguage(String name, CamelContext context) {
    // lookup in registry first
    Object bean = null;
    try {
      bean = context.getRegistry().lookup(name);
      if (bean != null && getLog().isDebugEnabled()) {
        getLog().debug("Found language: " + name + " in registry: " + bean);
      }
    } catch (Exception e) {
      if (getLog().isDebugEnabled()) {
        getLog().debug("Ignored error looking up bean: " + name + ". Error: " + e);
      }
    }
    if (bean != null) {
      if (bean instanceof Language) {
        return (Language) bean;
      }
      // we do not throw the exception here and try to auto create a Language from META-INF
    }

    Class type = null;
    try {
      type = findLanguage(name, context);
    } catch (NoFactoryAvailableException e) {
      // ignore
    } catch (Exception e) {
      throw new IllegalArgumentException(
          "Invalid URI, no Language registered for scheme: " + name, e);
    }

    if (type != null) {
      if (Language.class.isAssignableFrom(type)) {
        return (Language) context.getInjector().newInstance(type);
      } else {
        throw new IllegalArgumentException(
            "Resolving language: "
                + name
                + " detected type conflict: Not a Language implementation. Found: "
                + type.getName());
      }
    } else {
      // no specific language found then try fallback
      return noSpecificLanguageFound(name, context);
    }
  }
  public SpringAMQPComponent(CamelContext context) {
    super(context);

    // Attempt to load a connection factory from the registry
    if (this.connectionFactory == null) {
      this.connectionFactory = context.getRegistry().findByTypeWithName(ConnectionFactory.class);
      if (this.connectionFactory != null && !this.connectionFactory.isEmpty()) {
        for (Map.Entry<String, ConnectionFactory> connection : this.connectionFactory.entrySet()) {
          LOG.info(
              "Found AMQP ConnectionFactory in registry for {}", connection.getValue().getHost());
        }
      }
    }

    if (this.connectionFactory == null) {
      LOG.error("Cannot find a connection factory!");
    }
  }