@Override protected void doStart() throws Exception { super.doStart(); if (engineRef != null && engine == null) { engine = CamelContextHelper.mandatoryLookup(getCamelContext(), engineRef, Engine.class); } synchronized (getComponent()) { if (managed != null && managed) { if (!(engine.isStarting() || engine.isRunning())) { engine.startup(); autoStarted = true; } } if (!(engine.isStarting() || engine.isRunning())) { throw new SpongeException("Sponge engine is not starting or running"); } configureEngine(); } }
@Override protected DataFormat createDataFormat(RouteContext routeContext) { DataFormat cryptoFormat = super.createDataFormat(routeContext); if (ObjectHelper.isNotEmpty(keyRef)) { Key key = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), keyRef, Key.class); setProperty(routeContext.getCamelContext(), cryptoFormat, "key", key); } if (ObjectHelper.isNotEmpty(algorithmParameterRef)) { AlgorithmParameterSpec spec = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), algorithmParameterRef, AlgorithmParameterSpec.class); setProperty(routeContext.getCamelContext(), cryptoFormat, "AlgorithmParameterSpec", spec); } if (ObjectHelper.isNotEmpty(initVectorRef)) { byte[] iv = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), initVectorRef, byte[].class); setProperty(routeContext.getCamelContext(), cryptoFormat, "InitializationVector", iv); } return cryptoFormat; }
protected Processor createCompositeProcessor(RouteContext routeContext, List<Processor> list) throws Exception { final AggregationStrategy strategy = createAggregationStrategy(routeContext); boolean isParallelProcessing = getParallelProcessing() != null && getParallelProcessing(); boolean isShareUnitOfWork = getShareUnitOfWork() != null && getShareUnitOfWork(); boolean isStreaming = getStreaming() != null && getStreaming(); boolean isStopOnException = getStopOnException() != null && getStopOnException(); boolean isParallelAggregate = getParallelAggregate() != null && getParallelAggregate(); boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing); ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "Multicast", this, isParallelProcessing); long timeout = getTimeout() != null ? getTimeout() : 0; if (timeout > 0 && !isParallelProcessing) { throw new IllegalArgumentException("Timeout is used but ParallelProcessing has not been enabled."); } if (onPrepareRef != null) { onPrepare = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onPrepareRef, Processor.class); } MulticastProcessor answer = new MulticastProcessor(routeContext.getCamelContext(), list, strategy, isParallelProcessing, threadPool, shutdownThreadPool, isStreaming, isStopOnException, timeout, onPrepare, isShareUnitOfWork, isParallelAggregate); return answer; }
/** * Allows an exception handler to create a new redelivery policy for this exception type * * @param context the camel context * @param parentPolicy the current redelivery policy, is newer <tt>null</tt> * @return a newly created redelivery policy, or return the original policy if no customization is required * for this exception handler. */ public RedeliveryPolicy createRedeliveryPolicy(CamelContext context, RedeliveryPolicy parentPolicy) { if (redeliveryPolicy != null) { return redeliveryPolicy; } else if (redeliveryPolicyRef != null) { return CamelContextHelper.mandatoryLookup(context, redeliveryPolicyRef, RedeliveryPolicy.class); } else if (redeliveryPolicyType != null) { return redeliveryPolicyType.createRedeliveryPolicy(context, parentPolicy); } else if (!outputs.isEmpty() && parentPolicy.getMaximumRedeliveries() != 0) { // if we have outputs, then do not inherit parent maximumRedeliveries // as you would have to explicit configure maximumRedeliveries on this onException to use it // this is the behavior Camel has always had RedeliveryPolicy answer = parentPolicy.copy(); answer.setMaximumRedeliveries(0); return answer; } else { return parentPolicy; } }
public TabularData listEips() throws Exception { try { // find all EIPs Map<String, Properties> eips = context.findEips(); TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listEipsTabularType()); // gather EIP detail for each eip for (Map.Entry<String, Properties> entry : eips.entrySet()) { String name = entry.getKey(); String title = (String) entry.getValue().get("title"); String description = (String) entry.getValue().get("description"); String label = (String) entry.getValue().get("label"); String type = (String) entry.getValue().get("class"); String status = CamelContextHelper.isEipInUse(context, name) ? "in use" : "on classpath"; CompositeType ct = CamelOpenMBeanTypes.listEipsCompositeType(); CompositeData data = new CompositeDataSupport(ct, new String[]{"name", "title", "description", "label", "status", "type"}, new Object[]{name, title, description, label, status, type}); answer.put(data); } return answer; } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
public String getEipParameterJsonSchema(String eipName) throws IOException { // the eip json schema may be in some of the sub-packages so look until we find it String[] subPackages = new String[]{"", "/config", "/dataformat", "/language", "/loadbalancer", "/rest"}; for (String sub : subPackages) { String path = CamelContextHelper.MODEL_DOCUMENTATION_PREFIX + sub + "/" + eipName + ".json"; ClassResolver resolver = getClassResolver(); InputStream inputStream = resolver.loadResourceAsStream(path); if (inputStream != null) { log.debug("Loading eip JSON Schema for: {} using class resolver: {} -> {}", new Object[]{eipName, resolver, inputStream}); try { return IOHelper.loadText(inputStream); } finally { IOHelper.close(inputStream); } } } return null; }
protected ServiceCallLoadBalancer configureLoadBalancer(C conf, RouteContext routeContext, ServiceCallDefinition sd) throws Exception { ServiceCallLoadBalancer lb = null; String ref; if (sd != null) { lb = sd.getLoadBalancer(); ref = sd.getLoadBalancerRef(); if (lb == null && ref != null) { lb = builtInLoadBalancer( conf, ref) .orElseGet(() -> CamelContextHelper.mandatoryLookup( routeContext.getCamelContext(), ref, ServiceCallLoadBalancer.class) ); } } return lb; }
protected ServiceCallServerListStrategy configureServerListStrategy(C conf, RouteContext routeContext, ServiceCallDefinition sd) throws Exception { ServiceCallServerListStrategy sl = null; String ref; if (sd != null) { sl = sd.getServerListStrategy(); ref = sd.getServerListStrategyRef(); if (sl == null && ref != null) { sl = builtInServerListStrategy( conf, ref) .orElseGet(() -> CamelContextHelper.mandatoryLookup( routeContext.getCamelContext(), ref, ServiceCallServerListStrategy.class) ); } } return sl; }
protected ServiceCallServerListStrategy configureServerListStrategy(C conf, RouteContext routeContext, ServiceCallConfigurationDefinition config) throws Exception { ServiceCallServerListStrategy sl = config.getServerListStrategy(); String ref = config.getServerListStrategyRef(); if (sl == null && ref != null) { sl = builtInServerListStrategy( conf, ref) .orElseGet(() -> CamelContextHelper.mandatoryLookup( routeContext.getCamelContext(), ref, ServiceCallServerListStrategy.class) ); } return sl; }
@Override protected void doStart() throws Exception { if (binding == null) { binding = CamelContextHelper.mandatoryLookup(getCamelContext(), bindingName, Binding.class); } if (delegate == null) { delegate = getMandatoryEndpoint(getCamelContext(), delegateUri); } // inject CamelContext if (binding instanceof CamelContextAware) { ((CamelContextAware) binding).setCamelContext(getCamelContext()); } ServiceHelper.startServices(delegate, binding); super.doStart(); }
@Test public void testComponentDiscovery() throws Exception { CamelContext context = new DefaultCamelContext(); SortedMap<String, Properties> map = CamelContextHelper.findComponents(context); assertNotNull("Should never return null", map); assertTrue("Component map should never be empty", !map.isEmpty()); String[] expectedComponentNames = {"file", "vm"}; for (String expectedName : expectedComponentNames) { Properties properties = map.get(expectedName); assertTrue("Component map contain component: " + expectedName, properties != null); } Set<Map.Entry<String, Properties>> entries = map.entrySet(); for (Map.Entry<String, Properties> entry : entries) { LOG.info("Found component " + entry.getKey() + " with properties: " + entry.getValue()); } }
@Override public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate, String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters) throws Exception { // just use a seda endpoint for testing purpose String id; if (uriTemplate != null) { id = ActiveMQUuidGenerator.generateSanitizedId(basePath + uriTemplate); } else { id = ActiveMQUuidGenerator.generateSanitizedId(basePath); } // remove leading dash as we add that ourselves if (id.startsWith("-")) { id = id.substring(1); } if (configuration.getConsumerProperties() != null) { String ref = (String) configuration.getConsumerProperties().get("dummy"); if (ref != null) { dummy = CamelContextHelper.mandatoryLookup(camelContext, ref.substring(1)); } } SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class); return seda.createConsumer(processor); }
@Override public void process(Exchange exchange) throws Exception { JobParameters jobParameters = prepareJobParameters(exchange.getIn().getHeaders()); String messageJobName = jobParameters.getString(SpringBatchConstants.JOB_NAME); Job job2run = this.job; if (messageJobName != null) { job2run = CamelContextHelper.mandatoryLookup(getEndpoint().getCamelContext(), messageJobName, Job.class); } if (job2run == null) { exchange.setException(new CamelExchangeException("jobName was not specified in the endpoint construction " + " and header " + SpringBatchConstants.JOB_NAME + " could not be found", exchange)); return; } JobExecution jobExecution = jobLauncher.run(job2run, jobParameters); exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); exchange.getOut().setBody(jobExecution); }
protected TrustManagersParameters createInstance() throws Exception { TrustManagersParameters newInstance = new TrustManagersParameters(); newInstance.setAlgorithm(algorithm); if (getKeyStore() != null) { getKeyStore().setCamelContext(getCamelContext()); newInstance.setKeyStore(getKeyStore().getObject()); } newInstance.setProvider(provider); newInstance.setCamelContext(getCamelContext()); if (trustManager != null) { TrustManager tm = CamelContextHelper.mandatoryLookup(getCamelContext(), trustManager, TrustManager.class); newInstance.setTrustManager(tm); } return newInstance; }
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { DataSource dataSource; String dataSourceRef; if (this.dataSource != null) { // prefer to use datasource set by setter dataSource = this.dataSource; dataSourceRef = "component"; } else { dataSource = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, DataSource.class); dataSourceRef = remaining; } Map<String, Object> params = IntrospectionSupport.extractProperties(parameters, "statement."); JdbcEndpoint jdbc = new JdbcEndpoint(uri, this, dataSource); jdbc.setDataSourceName(dataSourceRef); jdbc.setParameters(params); setProperties(jdbc, parameters); return jdbc; }
public static String getComponentDocumentation(BundleContext bundleContext, CamelContext camelContext, String componentName) throws IOException { String path = CamelContextHelper.COMPONENT_DOCUMENTATION_PREFIX + componentName + ".html"; Bundle[] bundles = bundleContext.getBundles(); for (Bundle bundle : bundles) { URL resource = bundle.getResource(path); if (resource != null) { InputStream inputStream = resource.openStream(); if (inputStream != null) { return IOHelper.loadText(inputStream); } } } return null; }
public void afterPropertiesSet() throws Exception { // lets bind the URI to a pojo notNull(uri, "uri"); // Always resolve the camel context by using the camelContextID if (ObjectHelper.isNotEmpty(camelContextId)) { camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId); } notNull(camelContext, "camelContext"); if (serviceRef != null && getService() == null && applicationContext != null) { setService(applicationContext.getBean(serviceRef)); } Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(camelContext, uri); notNull(getService(), "service"); Object proxy = getProxyForService(); try { // need to start endpoint before we create consumer ServiceHelper.startService(endpoint); consumer = endpoint.createConsumer(new BeanProcessor(proxy, camelContext)); // add and start consumer camelContext.addService(consumer, true, true); } catch (Exception e) { throw new FailedToCreateConsumerException(endpoint, e); } }
@Override protected DataFormat createDataFormat(RouteContext routeContext) { if ("json".equals(this.driver)) { setProperty(routeContext.getCamelContext(), this, "dataFormatName", "json-xstream"); } DataFormat answer = super.createDataFormat(routeContext); // need to lookup the reference for the xstreamDriver if (ObjectHelper.isNotEmpty(driverRef)) { setProperty(routeContext.getCamelContext(), answer, "xstreamDriver", CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), driverRef)); } return answer; }
@Override protected DataFormat createDataFormat(RouteContext routeContext) { DataFormat flatpack = super.createDataFormat(routeContext); if (ObjectHelper.isNotEmpty(parserFactoryRef)) { Object parserFactory = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), parserFactoryRef); setProperty(routeContext.getCamelContext(), flatpack, "parserFactory", parserFactory); } return flatpack; }
public boolean isAsyncDelayedRedelivery(CamelContext context) { if (getAsyncDelayedRedelivery() == null) { return false; } try { return CamelContextHelper.parseBoolean(context, getAsyncDelayedRedelivery()); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
@Override public Processor createProcessor(RouteContext routeContext) throws Exception { Processor childProcessor = this.createChildProcessor(routeContext, true); aggregationStrategy = createAggregationStrategy(routeContext); boolean isParallelProcessing = getParallelProcessing() != null && getParallelProcessing(); boolean isStreaming = getStreaming() != null && getStreaming(); boolean isShareUnitOfWork = getShareUnitOfWork() != null && getShareUnitOfWork(); boolean isParallelAggregate = getParallelAggregate() != null && getParallelAggregate(); boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing); ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "Split", this, isParallelProcessing); long timeout = getTimeout() != null ? getTimeout() : 0; if (timeout > 0 && !isParallelProcessing) { throw new IllegalArgumentException("Timeout is used but ParallelProcessing has not been enabled."); } if (onPrepareRef != null) { onPrepare = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onPrepareRef, Processor.class); } Expression exp = getExpression().createExpression(routeContext); Splitter answer = new Splitter(routeContext.getCamelContext(), exp, childProcessor, aggregationStrategy, isParallelProcessing, threadPool, shutdownThreadPool, isStreaming, isStopOnException(), timeout, onPrepare, isShareUnitOfWork, isParallelAggregate); return answer; }
@Override protected LoadBalancer createLoadBalancer(RouteContext routeContext) { if (loadBalancer != null) { return loadBalancer; } ObjectHelper.notEmpty(ref, "ref", this); return CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), ref, LoadBalancer.class); }
/** * Lookup the routes from the {@link RouteContextRefDefinition}. * <p/> * This implementation must be used to lookup the routes as it performs a deep clone of the routes * as a {@link RouteContextRefDefinition} can be re-used with multiple {@link ModelCamelContext} and each * context should have their own instances of the routes. This is to ensure no side-effects and sharing * of instances between the contexts. For example such as property placeholders may be context specific * so the routes should not use placeholders from another {@link ModelCamelContext}. * * @param camelContext the CamelContext * @param ref the id of the {@link RouteContextRefDefinition} to lookup and get the routes. * @return the routes. */ @SuppressWarnings("unchecked") public static synchronized List<RouteDefinition> lookupRoutes(ModelCamelContext camelContext, String ref) { ObjectHelper.notNull(camelContext, "camelContext"); ObjectHelper.notNull(ref, "ref"); List<RouteDefinition> answer = CamelContextHelper.lookup(camelContext, ref, List.class); if (answer == null) { throw new IllegalArgumentException("Cannot find RouteContext with id " + ref); } // must clone the route definitions as they can be reused with multiple CamelContexts // and they would need their own instances of the definitions to not have side effects among // the CamelContext - for example property placeholder resolutions etc. List<RouteDefinition> clones = new ArrayList<RouteDefinition>(answer.size()); try { JAXBContext jaxb = getOrCreateJAXBContext(camelContext); for (RouteDefinition def : answer) { RouteDefinition clone = cloneRouteDefinition(jaxb, def); if (clone != null) { clones.add(clone); } } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } return clones; }
/** * Creates a {@link StreamResequencer} instance applying the given <code>config</code>. * * @param routeContext route context. * @param config stream resequencer configuration. * @return the configured stream resequencer. * @throws Exception can be thrwon */ protected StreamResequencer createStreamResequencer(RouteContext routeContext, StreamResequencerConfig config) throws Exception { Processor processor = this.createChildProcessor(routeContext, true); Expression expression = getExpression().createExpression(routeContext); CamelInternalProcessor internal = new CamelInternalProcessor(processor); internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeContext)); ObjectHelper.notNull(config, "config", this); ObjectHelper.notNull(expression, "expression", this); ExpressionResultComparator comparator; if (config.getComparatorRef() != null) { comparator = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), config.getComparatorRef(), ExpressionResultComparator.class); } else { comparator = config.getComparator(); } comparator.setExpression(expression); StreamResequencer resequencer = new StreamResequencer(routeContext.getCamelContext(), internal, comparator, expression); resequencer.setTimeout(config.getTimeout()); resequencer.setCapacity(config.getCapacity()); resequencer.setRejectOld(config.getRejectOld()); if (config.getIgnoreInvalidExchanges() != null) { resequencer.setIgnoreInvalidExchanges(config.getIgnoreInvalidExchanges()); } return resequencer; }
private void setOnRedeliveryFromRedeliveryRef(RouteContext routeContext) { // lookup onRedelivery if ref is provided if (ObjectHelper.isNotEmpty(onRedeliveryRef)) { // if ref is provided then use mandatory lookup to fail if not found Processor onRedelivery = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onRedeliveryRef, Processor.class); setOnRedelivery(onRedelivery); } }
private void setOnExceptionOccurredFromOnExceptionOccurredRef(RouteContext routeContext) { // lookup onRedelivery if ref is provided if (ObjectHelper.isNotEmpty(onExceptionbOccurredRef)) { // if ref is provided then use mandatory lookup to fail if not found Processor onExceptionOccurred = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onExceptionbOccurredRef, Processor.class); setOnExceptionOccurred(onExceptionOccurred); } }
/** * Lookup the rests from the {@link org.apache.camel.model.RestContextRefDefinition}. * <p/> * This implementation must be used to lookup the rests as it performs a deep clone of the rests * as a {@link org.apache.camel.model.RestContextRefDefinition} can be re-used with multiple {@link org.apache.camel.model.ModelCamelContext} and each * context should have their own instances of the routes. This is to ensure no side-effects and sharing * of instances between the contexts. For example such as property placeholders may be context specific * so the routes should not use placeholders from another {@link org.apache.camel.model.ModelCamelContext}. * * @param camelContext the CamelContext * @param ref the id of the {@link org.apache.camel.model.RestContextRefDefinition} to lookup and get the routes. * @return the rests. */ @SuppressWarnings("unchecked") public static synchronized List<RestDefinition> lookupRests(ModelCamelContext camelContext, String ref) { ObjectHelper.notNull(camelContext, "camelContext"); ObjectHelper.notNull(ref, "ref"); List<RestDefinition> answer = CamelContextHelper.lookup(camelContext, ref, List.class); if (answer == null) { throw new IllegalArgumentException("Cannot find RestContext with id " + ref); } // must clone the rest definitions as they can be reused with multiple CamelContexts // and they would need their own instances of the definitions to not have side effects among // the CamelContext - for example property placeholder resolutions etc. List<RestDefinition> clones = new ArrayList<RestDefinition>(answer.size()); try { JAXBContext jaxb = getOrCreateJAXBContext(camelContext); for (RestDefinition def : answer) { RestDefinition clone = cloneRestDefinition(jaxb, def); if (clone != null) { clones.add(clone); } } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } return clones; }
/** * Determines if redelivery is enabled by checking if any of the redelivery policy * settings may allow redeliveries. * * @return <tt>true</tt> if redelivery is possible, <tt>false</tt> otherwise * @throws Exception can be thrown */ private boolean determineIfRedeliveryIsEnabled() throws Exception { // determine if redeliver is enabled either on error handler if (getRedeliveryPolicy().getMaximumRedeliveries() != 0) { // must check for != 0 as (-1 means redeliver forever) return true; } if (retryWhilePolicy != null) { return true; } // or on the exception policies if (!exceptionPolicies.isEmpty()) { // walk them to see if any of them have a maximum redeliveries > 0 or retry until set for (OnExceptionDefinition def : exceptionPolicies.values()) { String ref = def.getRedeliveryPolicyRef(); if (ref != null) { // lookup in registry if ref provided RedeliveryPolicy policy = CamelContextHelper.mandatoryLookup(camelContext, ref, RedeliveryPolicy.class); if (policy.getMaximumRedeliveries() != 0) { // must check for != 0 as (-1 means redeliver forever) return true; } } else if (def.getRedeliveryPolicy() != null) { Integer max = CamelContextHelper.parseInteger(camelContext, def.getRedeliveryPolicy().getMaximumRedeliveries()); if (max != null && max != 0) { // must check for != 0 as (-1 means redeliver forever) return true; } } if (def.getRetryWhilePolicy() != null || def.getRetryWhile() != null) { return true; } } } return false; }
public DefaultEndpointRegistry(CamelContext context) { // do not stop on eviction, as the endpoint may still be in use super(CamelContextHelper.getMaximumEndpointCacheSize(context), CamelContextHelper.getMaximumEndpointCacheSize(context), false); // static map to hold endpoints we do not want to be evicted this.staticMap = new ConcurrentHashMap<EndpointKey, Endpoint>(); this.context = context; }
/** * Gets the parameter and remove it from the parameter map. This method doesn't resolve * reference parameters in the registry. * * @param parameters the parameters * @param key the key * @param type the requested type to convert the value from the parameter * @param defaultValue use this default value if the parameter does not contain the key * @return the converted value parameter * @see #resolveAndRemoveReferenceParameter(Map, String, Class, Object) */ public <T> T getAndRemoveParameter(Map<String, Object> parameters, String key, Class<T> type, T defaultValue) { Object value = parameters.remove(key); if (value == null) { value = defaultValue; } if (value == null) { return null; } return CamelContextHelper.convertTo(getCamelContext(), type, value); }
public String resolveComponentDefaultName(String javaType) { // special for some components // TODO: ActiveMQ 5.11 will include this out of the box, so not needed when its released if ("org.apache.activemq.camel.component.ActiveMQComponent".equals(javaType)) { return "jms"; } // try to find the component by its java type from the in-use components if (javaType != null) { // find all the components which will include the default component name try { Map<String, Properties> all = CamelContextHelper.findComponents(this); for (Map.Entry<String, Properties> entry : all.entrySet()) { String fqn = (String) entry.getValue().get("class"); if (javaType.equals(fqn)) { // is there component docs for that name? String name = entry.getKey(); String json = getComponentParameterJsonSchema(name); if (json != null) { return name; } } } } catch (Exception e) { // ignore return null; } } // could not find a component with that name return null; }
public Object getInjectionPropertyValue(Class<?> type, String propertyName, String propertyDefaultValue, String injectionPointName, Object bean, String beanName) { try { // enforce a properties component to be created if none existed CamelContextHelper.lookupPropertiesComponent(getCamelContext(), true); String key; String prefix = getCamelContext().getPropertyPrefixToken(); String suffix = getCamelContext().getPropertySuffixToken(); if (!propertyName.contains(prefix)) { // must enclose the property name with prefix/suffix to have it resolved key = prefix + propertyName + suffix; } else { // key has already prefix/suffix so use it as-is as it may be a compound key key = propertyName; } String value = getCamelContext().resolvePropertyPlaceholders(key); if (value != null) { return getCamelContext().getTypeConverter().mandatoryConvertTo(type, value); } else { return null; } } catch (Exception e) { if (ObjectHelper.isNotEmpty(propertyDefaultValue)) { try { return getCamelContext().getTypeConverter().mandatoryConvertTo(type, propertyDefaultValue); } catch (Exception e2) { throw ObjectHelper.wrapRuntimeCamelException(e2); } } throw ObjectHelper.wrapRuntimeCamelException(e); } }
public Object getInjectionBeanValue(Class<?> type, String name) { if (ObjectHelper.isEmpty(name)) { Set<?> found = getCamelContext().getRegistry().findByType(type); if (found == null || found.isEmpty()) { throw new NoSuchBeanException(name, type.getName()); } else if (found.size() > 1) { throw new NoSuchBeanException("Found " + found.size() + " beans of type: " + type + ". Only one bean expected."); } else { // we found only one return found.iterator().next(); } } else { return CamelContextHelper.mandatoryLookup(getCamelContext(), name, type); } }
protected void doStart() throws Exception { if (extendedStatistics) { int max = maxCacheSize == 0 ? CamelContextHelper.getMaximumCachePoolSize(camelContext) : maxCacheSize; statistics = new DefaultEndpointUtilizationStatistics(max); } ServiceHelper.startServices(producers.values()); ServiceHelper.startServices(statistics, pool); }
protected ServiceCallLoadBalancer configureLoadBalancer(C conf, RouteContext routeContext, ServiceCallConfigurationDefinition config) throws Exception { ServiceCallLoadBalancer lb = config.getLoadBalancer(); String ref = config.getLoadBalancerRef(); if (lb == null && ref != null) { lb = builtInLoadBalancer( conf, ref) .orElseGet(() ->CamelContextHelper.mandatoryLookup( routeContext.getCamelContext(), ref, ServiceCallLoadBalancer.class) ); } return lb; }
protected void doStart() throws Exception { if (extendedStatistics) { int max = maxCacheSize == 0 ? CamelContextHelper.getMaximumCachePoolSize(camelContext) : maxCacheSize; statistics = new DefaultEndpointUtilizationStatistics(max); } ServiceHelper.startServices(consumers.values()); }
@Override protected void doStart() throws Exception { endpoint = CamelContextHelper.mandatoryLookup(getCamelContext(), name, Endpoint.class); // add the endpoint to the endpoint registry getCamelContext().addEndpoint(endpoint.getEndpointUri(), endpoint); super.doStart(); }
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { Long timeout = getAndRemoveParameter(parameters, "timeout", Long.class); TestEndpoint answer = new TestEndpoint(uri, this); if (timeout != null) { answer.setTimeout(timeout); } setProperties(answer, parameters); // from the rest create a new uri with those parameters String endpointUri = URISupport.appendParametersToURI(remaining, parameters); Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(getCamelContext(), endpointUri); answer.setExpectedMessageEndpoint(endpoint); return answer; }
public void testGetEndpointNoScheme() throws Exception { DefaultCamelContext ctx = new DefaultCamelContext(); ctx.disableJMX(); try { CamelContextHelper.getMandatoryEndpoint(ctx, "log.foo"); fail("Should have thrown a NoSuchEndpointException"); } catch (NoSuchEndpointException e) { // expected } }
@Override protected void doStart() throws Exception { if (jobLauncher == null) { jobLauncher = resolveJobLauncher(); } if (job == null && jobName != null && jobFromHeader == null) { job = CamelContextHelper.mandatoryLookup(getCamelContext(), jobName, Job.class); } }