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); } }
if (ObjectHelper.isEmpty(contextId)) { BeanDefinition definition = parser.parse(childElement, parserContext); String id = childElement.getAttribute("id"); if (ObjectHelper.isNotEmpty(id)) { parserContext.registerComponent(new BeanComponentDefinition(definition, id));
/** * Apply additional configuration to the context */ protected void configure(SpringCamelContext ctx) { try { // allow any custom configuration, such as when running in camel-spring-boot if (applicationContext.containsBean("xmlCamelContextConfigurer")) { XmlCamelContextConfigurer configurer = applicationContext.getBean("xmlCamelContextConfigurer", XmlCamelContextConfigurer.class); if (configurer != null) { configurer.configure(applicationContext, ctx); } } } catch (Exception e) { // error during configuration throw ObjectHelper.wrapRuntimeCamelException(e); } }
@Bean(name = "tokenize-language") @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @ConditionalOnMissingBean(TokenizeLanguage.class) IntrospectionSupport.getProperties(configuration, parameters, null, false); CamelPropertiesHelper.setCamelProperties(camelContext, language, parameters, false); if (ObjectHelper.isNotEmpty(customizers)) { for (LanguageCustomizer<TokenizeLanguage> customizer : customizers) { boolean useCustomizer = (customizer instanceof HasId) ? HierarchicalPropertiesEvaluator.evaluate( applicationContext.getEnvironment(), "camel.language.customizer", "camel.language.tokenize.customizer", ((HasId) customizer).getId()) : HierarchicalPropertiesEvaluator.evaluate( applicationContext.getEnvironment(), "camel.language.customizer", "camel.language.tokenize.customizer");
private void restoreDroplet(Exchange exchange) throws Exception { if (ObjectHelper.isEmpty(exchange.getIn().getHeader(DigitalOceanHeaders.IMAGE_ID))) { throw new IllegalArgumentException(DigitalOceanHeaders.IMAGE_ID + " must be specified"); } Action action = getEndpoint().getDigitalOceanClient().restoreDroplet(dropletId, exchange.getIn().getHeader(DigitalOceanHeaders.IMAGE_ID, Integer.class)); LOG.trace("DropletAction Restore [{}] ", action); exchange.getOut().setBody(action); }
public static String getLocalPath(DropboxConfiguration configuration, Exchange exchange) { return ObjectHelper.isNotEmpty( exchange.getIn().getHeader(DropboxConstants.HEADER_LOCAL_PATH)) ? exchange.getIn().getHeader(DropboxConstants.HEADER_LOCAL_PATH, String.class) : configuration.getLocalPath(); }
private void compare(long expected, Exchange exchange) { long update = exchange.getIn().getBody(Long.class); if (ObjectHelper.isEmpty(expected)) { throw new IllegalArgumentException("Expected value must be specified"); } exchange.getOut().setBody(this.atomicnumber.compareAndSet(expected, update)); }
@SuppressWarnings("unchecked") public ExecCommand readInput(Exchange exchange, ExecEndpoint endpoint) { ObjectHelper.notNull(exchange, "exchange"); ObjectHelper.notNull(endpoint, "endpoint"); // do not convert args as we do that manually later Object args = exchange.getIn().removeHeader(EXEC_COMMAND_ARGS); String cmd = getAndRemoveHeader(exchange.getIn(), EXEC_COMMAND_EXECUTABLE, endpoint.getExecutable(), String.class); String dir = getAndRemoveHeader(exchange.getIn(), EXEC_COMMAND_WORKING_DIR, endpoint.getWorkingDir(), String.class); long timeout = getAndRemoveHeader(exchange.getIn(), EXEC_COMMAND_TIMEOUT, endpoint.getTimeout(), Long.class); String outFilePath = getAndRemoveHeader(exchange.getIn(), EXEC_COMMAND_OUT_FILE, endpoint.getOutFile(), String.class); boolean useStderrOnEmptyStdout = getAndRemoveHeader(exchange.getIn(), EXEC_USE_STDERR_ON_EMPTY_STDOUT, endpoint.isUseStderrOnEmptyStdout(), Boolean.class); InputStream input = exchange.getIn().getBody(InputStream.class); // If the args is a list of strings already.. List<String> argsList = null; if (isListOfStrings(args)) { argsList = (List<String>) args; } if (argsList == null) { // no we could not do that, then parse it as a string to a list String s = endpoint.getArgs(); if (args != null) { // use args from header instead from endpoint s = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, args); } LOG.debug("Parsing argument String to a List: {}", s); argsList = splitToWhiteSpaceSeparatedTokens(s); } File outFile = outFilePath == null ? null : new File(outFilePath); return new ExecCommand(cmd, argsList, dir, timeout, input, outFile, useStderrOnEmptyStdout); }
public void onApplicationEvent(ApplicationEvent event) { Exchange exchange = createExchange(); exchange.getIn().setBody(event); try { getLoadBalancer().process(exchange); } catch (Exception e) { throw wrapRuntimeCamelException(e); } }
public Object evaluate(Exchange exchange, Class asType) { Object answer = exchange.getIn().getBody(type); if (answer == null) { Object defaultValue = exchange.getIn().getBody(); if (defaultValue != null) { throw ObjectHelper.wrapRuntimeCamelException(new NoTypeConversionAvailableException(defaultValue, type)); } // if we don't have a body then // lets instantiate and inject a new instance answer = exchange.getContext().getInjector().newInstance(type); } return answer; } };
/** * QUERY map with a sql like syntax (see http://www.hazelcast.com/) */ private void query(String query, Exchange exchange) { Collection<Object> result; if (ObjectHelper.isNotEmpty(query)) { result = this.cache.values(new SqlPredicate(query)); } else { result = this.cache.values(); } exchange.getOut().setBody(result); }
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { Class<?> unmarshallType = exchange.getIn().getHeader(UNMARSHALL_CLASS, Class.class); if (unmarshallType == null) { unmarshallType = getUnmarshallClass(); } ObjectHelper.notNull(unmarshallType, "unmarshallClass or CamelJibxUnmarshallClass header"); IBindingFactory bindingFactory = createBindingFactory(unmarshallType, bindingName); IUnmarshallingContext unmarshallingContext = bindingFactory.createUnmarshallingContext(); return unmarshallingContext.unmarshalDocument(stream, null); }
protected Class<?> getBeanClass(Element element) { ErrorHandlerType type = ErrorHandlerType.DefaultErrorHandler; if (ObjectHelper.isNotEmpty(element.getAttribute("type"))) { type = ErrorHandlerType.valueOf(element.getAttribute("type")); } return type.getTypeAsClass(); }
@Override @SuppressWarnings("unchecked") protected String convertPathToActualDestination(String path, Map<String, Object> parameters) { // support ActiveMQ destination options using the destination. prefix // http://activemq.apache.org/destination-options.html Map options = IntrospectionSupport.extractProperties(parameters, "destination."); String query; try { query = URISupport.createQueryString(options); } catch (URISyntaxException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } // if we have destination options then append them to the destination name if (ObjectHelper.isNotEmpty(query)) { return path + "?" + query; } else { return path; } }
@Override public void afterPropertiesSet() { if (endpoint == null) { if (ObjectHelper.isNotEmpty(camelContextId)) { camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId); endpoint = camelContext.getRegistry().lookupByNameAndType(getServiceRef(), Endpoint.class); } else { endpoint = camelContext.getEndpoint(getServiceUrl()); producer = endpoint.createProducer(); camelContext.addService(producer, true, true); serviceProxy = ProxyHelper.createProxy(endpoint, bind, producer, getServiceInterface()); } catch (Exception e) {
/** * Creates an HBase {@link Delete} on a specific row, using a collection of values (family/column/value pairs). */ private Delete createDeleteRow(HBaseRow hRow) throws Exception { ObjectHelper.notNull(hRow, "HBase row"); ObjectHelper.notNull(hRow.getId(), "HBase row id"); return new Delete(endpoint.getCamelContext().getTypeConverter().convertTo(byte[].class, hRow.getId())); }
@Override public void putState(Channel channel, NettyCamelState state) { // grab the correlation id Object body = state.getExchange().getMessage().getBody(); // the correlation id is the first part of the message String cid = getRequestCorrelationId(body); if (ObjectHelper.isEmpty(cid)) { throw new IllegalArgumentException("CorrelationID is missing"); } LOG.debug("putState({}) on channel: {}", cid, channel.id()); map.put(cid, state, timeout); }
@PostConstruct public void addRouteDefinitions() throws Exception { if (ObjectHelper.isNotEmpty(definitions)) { context.addRouteDefinitions(definitions); } } }
@InvokeOnHeader("REMOVE") boolean onRemove(Message message, AsyncCallback callback) throws Exception { final DistributedSet<Object> set = getResource(message); final Object value = message.getHeader(RESOURCE_VALUE, message::getBody, Object.class); ObjectHelper.notNull(value, RESOURCE_VALUE); set.remove(value).thenAccept( result -> processResult(message, callback, result) ); return false; }
public Producer createProducer() throws Exception { ObjectHelper.notNull(applicationContext, "applicationContext"); return new DefaultProducer(this) { public void process(Exchange exchange) throws Exception { ApplicationEvent event = toApplicationEvent(exchange); applicationContext.publishEvent(event); } }; }