Java Code Examples for org.apache.camel.util.ObjectHelper#notNull()

The following examples show how to use org.apache.camel.util.ObjectHelper#notNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentProxyComponent.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public ComponentProxyComponent(String componentId, String componentScheme, String componentClass, CamelCatalog catalog) {
    this.componentId = StringHelper.notEmpty(componentId, "componentId");
    this.componentScheme = StringHelper.notEmpty(componentScheme, "componentScheme");
    this.componentSchemeAlias = Optional.empty();
    this.configuredOptions = new HashMap<>();
    this.remainingOptions = new HashMap<>();
    this.catalog = ObjectHelper.notNull(catalog, "catalog");

    if (ObjectHelper.isNotEmpty(componentClass)) {
        this.catalog.addComponent(componentScheme, componentClass);
    }

    try {
        this.definition = ComponentDefinition.forScheme(catalog, componentScheme);
    } catch (IOException e) {
        throw RuntimeCamelException.wrapRuntimeCamelException(e);
    }

    registerExtension(this::getComponentVerifierExtension);
}
 
Example 2
Source File: StepParserSupport.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
public static ProcessorDefinition<?> convertSteps(ProcessorStepParser.Context context, ProcessorDefinition<?> parent, List<Step> steps) {
    ObjectHelper.notNull(context, "step context");
    ObjectHelper.notNull(parent, "parent");

    if (steps == null) {
        return parent;
    }

    ProcessorDefinition<?> current = parent;

    for (Step step : steps) {
        ProcessorDefinition<?> child = ProcessorStepParser.invoke(
            ProcessorStepParser.Context.of(context, current, step.node),
            step.id
        );

        current.addOutput(child);

        if (child instanceof OutputNode && child.getOutputs().isEmpty()) {
            current = child;
        }
    }

    return parent;
}
 
Example 3
Source File: SourceLoader.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
/**
 * Construct an instance of {@link Result} for the given {@link RoutesBuilder}.
 */
static Result on(RoutesBuilder target) {
    ObjectHelper.notNull(target, "target");

    return new Result() {
        @Override
        public Optional<RoutesBuilder> builder() {
            return Optional.of(target);
        }

        @Override
        public Optional<Object> configuration() {
            return Optional.empty();
        }
    };
}
 
Example 4
Source File: SyndesisMetadata.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public static SyndesisMetadata of(DataShape dataShape) {
    ObjectHelper.notNull(dataShape, "DataShape");

    return of(
        new DataShape.Builder().createFrom(dataShape).build(),
        new DataShape.Builder().createFrom(dataShape).build()
    );
}
 
Example 5
Source File: AbstractFilterStepHandler.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> handle(Step step, ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) {
    ObjectHelper.notNull(route, "route");

    final String expression = ObjectHelper.notNull(getFilterExpression(step), "expression");
    final CamelContext context = builder.getContext();
    final Predicate predicate = new JsonSimplePredicate(expression, context);
    final FilterDefinition filter = route.filter(predicate);

    return Optional.of(filter);
}
 
Example 6
Source File: file_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public boolean process(Exchange exchange, AsyncCallback callback) {
    final AtomicExchange result = new AtomicExchange();
    Iterable<ProcessorExchangePair> pairs = null;

    try {
        boolean sync = true;

        pairs = createProcessorExchangePairs(exchange);

        if (isParallelProcessing()) {
            // ensure an executor is set when running in parallel
            ObjectHelper.notNull(executorService, "executorService", this);
            doProcessParallel(exchange, result, pairs, isStreaming(), callback);
        } else {
            sync = doProcessSequential(exchange, result, pairs, callback);
        }

        if (!sync) {
            // the remainder of the multicast will be completed async
            // so we break out now, then the callback will be invoked which then continue routing from where we left here
            return false;
        }
    } catch (Throwable e) {
        exchange.setException(e);
        // unexpected exception was thrown, maybe from iterator etc. so do not regard as exhausted
        // and do the done work
        doDone(exchange, null, pairs, callback, true, false);
        return true;
    }

    // multicasting was processed successfully
    // and do the done work
    Exchange subExchange = result.get() != null ? result.get() : null;
    doDone(exchange, subExchange, pairs, callback, true, true);
    return true;
}
 
Example 7
Source File: ScriptAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
    ObjectHelper.notNull(route, "route");
    ObjectHelper.notNull(engine, "engine");
    ObjectHelper.notNull(language, "language");
    StringHelper.notEmpty(script, "script");

    return Optional.of(route.process(this::process));
}
 
Example 8
Source File: ScriptAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
public void setLanguage(Language language) {
    this.language = ObjectHelper.notNull(language, "language");
    this.engine = new ScriptEngineManager().getEngineByName(language.name());

    if (this.engine == null) {
        throw new IllegalArgumentException("Unable to find a ScriptEngine for language: " + language.name());
    }
}
 
Example 9
Source File: original.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public boolean process(Exchange exchange, AsyncCallback callback) {
    final AtomicExchange result = new AtomicExchange();
    Iterable<ProcessorExchangePair> pairs = null;

    try {
        boolean sync = true;

        pairs = createProcessorExchangePairs(exchange);

        if (isParallelProcessing()) {
            // ensure an executor is set when running in parallel
            ObjectHelper.notNull(executorService, "executorService", this);
            doProcessParallel(exchange, result, pairs, isStreaming(), callback);
        } else {
            sync = doProcessSequential(exchange, result, pairs, callback);
        }

        if (!sync) {
            // the remainder of the multicast will be completed async
            // so we break out now, then the callback will be invoked which then continue routing from where we left here
            return false;
        }
    } catch (Throwable e) {
        exchange.setException(e);
        // unexpected exception was thrown, maybe from iterator etc. so do not regard as exhausted
        // and do the done work
        doDone(exchange, null, pairs, callback, true, false);
        return true;
    }

    // multicasting was processed successfully
    // and do the done work
    Exchange subExchange = result.get() != null ? result.get() : null;
    doDone(exchange, subExchange, pairs, callback, true, true);
    return true;
}
 
Example 10
Source File: AbstractStringToBytesAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
  ObjectHelper.notNull(route, "route");
  ObjectHelper.notNull(charset, "charset");

  return Optional.of(route.process((Exchange exchange) -> {
    exchange.getIn().setBody(exchange.getIn().getBody(String.class).getBytes(charset));
  }));
}
 
Example 11
Source File: file_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public boolean process(Exchange exchange, AsyncCallback callback) {
    final AtomicExchange result = new AtomicExchange();
    Iterable<ProcessorExchangePair> pairs = null;

    try {
        boolean sync = true;

        pairs = createProcessorExchangePairs(exchange);

        if (isParallelProcessing()) {
            // ensure an executor is set when running in parallel
            ObjectHelper.notNull(executorService, "executorService", this);
            doProcessParallel(exchange, result, pairs, isStreaming(), callback);
        } else {
            sync = doProcessSequential(exchange, result, pairs, callback);
        }

        if (!sync) {
            // the remainder of the multicast will be completed async
            // so we break out now, then the callback will be invoked which then continue routing from where we left here
            return false;
        }
    } catch (Throwable e) {
        exchange.setException(e);
        // unexpected exception was thrown, maybe from iterator etc. so do not regard as exhausted
        // and do the done work
        doDone(exchange, null, pairs, callback, true, false);
        return true;
    }

    // multicasting was processed successfully
    // and do the done work
    Exchange subExchange = result.get() != null ? result.get() : null;
    doDone(exchange, subExchange, pairs, callback, true, true);
    return true;
}
 
Example 12
Source File: SetHeaderAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
    ObjectHelper.notNull(route, "route");
    ObjectHelper.notNull(name, "name");
    ObjectHelper.notNull(value, "value");

    route.setHeader(name).constant(value);
    return Optional.empty();
}
 
Example 13
Source File: TemplateStepHandler.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.AvoidReassigningParameters")
@Override
public Optional<ProcessorDefinition<?>> handle(Step step, ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) {
    ObjectHelper.notNull(route, "route");

    Map<String, String> properties = step.getConfiguredProperties();
    String languageId = properties.get(TemplateStepLanguage.LANGUAGE_PROPERTY);
    //
    // If languageId is null then defaults to mustache
    //
    TemplateStepLanguage language = TemplateStepLanguage.stepLanguage(languageId);
    return this.handle(language, step, route, flowIndex, stepIndex);
}
 
Example 14
Source File: ChoiceStepHandler.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"PMD.AvoidReassigningParameters", "PMD.AvoidDeeplyNestedIfStmts"})
@Override
public Optional<ProcessorDefinition<?>> handle(Step step, ProcessorDefinition<?> route, IntegrationRouteBuilder builder, String flowIndex, String stepIndex) {
    ObjectHelper.notNull(route, "route");

    String routingScheme = step.getConfiguredProperties().getOrDefault("routingScheme", "direct");
    String defaultFlow = step.getConfiguredProperties().get("default");
    List<FlowOption> flows = extractFlows(step.getConfiguredProperties().get("flows"));

    if (!flows.isEmpty()) {
        ChoiceDefinition choice = route.choice();

        for (FlowOption flowOption : flows) {
            choice.when(getPredicate(flowOption.getConditionExpression(), builder.getContext()))
                    .description(flowOption.getConditionExpression())
                    .process(new EnrichActivityIdHeader())
                    .to(getEndpointUri(routingScheme, flowOption.getFlow()))
                    .end();
        }

        if (ObjectHelper.isNotEmpty(defaultFlow)) {
            choice.otherwise()
                    .process(new EnrichActivityIdHeader())
                    .to(getEndpointUri(routingScheme, defaultFlow))
                    .end();
        }

        route = choice.end();
    }

    return Optional.of(route);
}
 
Example 15
Source File: StepParser.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
public Context(RouteBuilder builder, ProcessorDefinition<?> processor, ObjectMapper mapper, JsonNode node, Resolver resolver) {
    this.builder = builder;
    this.processor = processor;
    this.mapper = mapper;
    this.node = node;
    this.resolver = ObjectHelper.notNull(resolver, "resolver");
}
 
Example 16
Source File: Base64ToBytesAction.java    From syndesis-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> route, Map<String, Object> parameters) {
  ObjectHelper.notNull(route, "route");

  return Optional.of(route.process((Exchange exchange) -> {
    exchange.getIn().setBody(Base64.decodeBase64(exchange.getIn().getBody(String.class)));
  }));
}
 
Example 17
Source File: QuteEndpoint.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected void onExchange(Exchange exchange) throws Exception {
    String path = getResourceUri();
    ObjectHelper.notNull(path, "resourceUri");

    if (allowTemplateFromHeader) {
        String newResourceUri = exchange.getIn().getHeader(QuteConstants.QUTE_RESOURCE_URI, String.class);
        if (newResourceUri != null) {
            exchange.getIn().removeHeader(QuteConstants.QUTE_RESOURCE_URI);

            log.debug("{} set to {} creating new endpoint to handle exchange", QuteConstants.QUTE_RESOURCE_URI,
                    newResourceUri);
            QuteEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
            newEndpoint.onExchange(exchange);
            return;
        }
    }

    String content = null;
    if (allowTemplateFromHeader) {
        content = exchange.getIn().getHeader(QuteConstants.QUTE_TEMPLATE, String.class);
        if (content != null) {
            // remove the header to avoid it being propagated in the routing
            exchange.getIn().removeHeader(QuteConstants.QUTE_TEMPLATE);
        }
    }

    TemplateInstance instance = null;
    if (allowTemplateFromHeader) {
        instance = exchange.getIn().getHeader(QuteConstants.QUTE_TEMPLATE_INSTANCE, TemplateInstance.class);
    }
    if (instance != null) {
        // use template instance from header
        if (log.isDebugEnabled()) {
            log.debug("Qute template instance is from header {} for endpoint {}", QuteConstants.QUTE_TEMPLATE_INSTANCE,
                    getEndpointUri());
        }
        exchange.getIn().removeHeader(QuteConstants.QUTE_TEMPLATE_INSTANCE);
    } else {
        Template template;
        Engine engine = getQuteEngine();
        if (content == null) {
            template = engine.getTemplate(path);
        } else {
            // This is the first time to parse the content
            template = engine.parse(content);
        }
        instance = template.instance();
    }

    ExchangeHelper.createVariableMap(exchange, isAllowContextMapAll()).forEach(instance::data);

    Map<String, Object> map = exchange.getIn().getHeader(QuteConstants.QUTE_TEMPLATE_DATA, Map.class);
    if (map != null) {
        map.forEach(instance::data);
    }

    exchange.getMessage().setBody(instance.render().trim());
}
 
Example 18
Source File: SyndesisMetadata.java    From syndesis with Apache License 2.0 4 votes vote down vote up
public static SyndesisMetadata outOnly(DataShape dataShape) {
    ObjectHelper.notNull(dataShape, "DataShape");

    return new SyndesisMetadata(Collections.emptyMap(), null, dataShape);
}
 
Example 19
Source File: CamelPropertiesHelper.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the properties on the target bean.
 * <p/>
 * This method uses {@link PropertyBindingSupport} and therefore offers its capabilities such as:
 * <ul>
 *     <li>property placeholders - Keys and values using Camels property placeholder will be resolved</li>
 *     <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
 *     <li>map</li> - Properties can lookup in Map's using map syntax, eg foo[bar] where foo is the name of the property that is a Map instance, and bar is the name of the key.</li>
 *     <li>list</li> - Properties can refer or add to in List's using list syntax, eg foo[0] where foo is the name of the property that is a
 *                     List instance, and 0 is the index. To refer to the last element, then use last as key.</li>
 * </ul>
 * This implementation sets the properties using the following algorithm in the given order:
 * <ul>
 *     <li>reference by bean id - Values can refer to other beans in the registry by prefixing with with # or #bean: eg #myBean or #bean:myBean</li>
 *     <li>reference by type - Values can refer to singleton beans by their type in the registry by prefixing with #type: syntax, eg #type:com.foo.MyClassType</li>
 *     <li>autowire by type - Values can refer to singleton beans by auto wiring by setting the value to #autowired</li>
 *     <li>reference new class - Values can refer to creating new beans by their class name by prefixing with #class, eg #class:com.foo.MyClassType</li>
 *     <li>value as lookup - The value is used as-is (eg like #value) to lookup in the Registry if there is a bean then its set on the target</li>
 * </ul>
 * When an option has been set on the target bean, then its removed from the given properties map. If all the options has been set, then the map will be empty.
 * The implementation ignores case for the property keys.
 *
 * @param context        the CamelContext
 * @param target         the target bean
 * @param properties     the properties
 * @param failIfNotSet   whether to fail if an option either does not exists on the target bean or if the option cannot be due no suitable setter methods with the given type
 * @return <tt>true</tt> if at least one option was configured
 * @throws IllegalArgumentException is thrown if an option cannot be configured on the bean because there is no suitable setter method and failOnNoSet is true.
 * @throws Exception for any other kind of error
 */
public static boolean setCamelProperties(CamelContext context, Object target, Map<String, Object> properties, boolean failIfNotSet) throws Exception {
    ObjectHelper.notNull(context, "context");
    ObjectHelper.notNull(target, "target");
    ObjectHelper.notNull(properties, "properties");
    boolean rc = false;

    PropertyConfigurer configurer = null;
    if (target instanceof Component) {
        // the component needs to be initialized to have the configurer ready
        ServiceHelper.initService(target);
        configurer = ((Component) target).getComponentPropertyConfigurer();
    }

    Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, Object> entry = it.next();
        String name = entry.getKey();
        Object value = entry.getValue();
        String stringValue = value != null ? value.toString() : null;
        boolean hit = false;
        try {
            hit = PropertyBindingSupport.build()
                    .withConfigurer(configurer)
                    .withIgnoreCase(true)
                    .bind(context, target, name, value);
        } catch (PropertyBindingException e) {
            // no we could not and this would be thrown if we attempted to set a value on a property which we cannot do type conversion as
            // then maybe the value refers to a spring bean in the registry so try this
            if (stringValue != null) {
                if (stringValue.startsWith("#")) {
                    stringValue = stringValue.substring(1);
                }
                // use #bean: to lookup
                stringValue = "#bean:" + stringValue;
                hit = PropertyBindingSupport.build().withIgnoreCase(true).bind(context, target, name, stringValue);
            }
        }

        if (hit) {
            // must remove as its a valid option and we could configure it
            it.remove();
            rc = true;
        } else if (failIfNotSet) {
            throw new IllegalArgumentException("Cannot configure option [" + name + "] with value [" + stringValue
                + "] as the bean class [" + ObjectHelper.classCanonicalName(target)
                + "] has no suitable setter method, or not possible to lookup a bean with the id [" + stringValue + "] in Spring Boot registry");
        }
    }

    return rc;
}
 
Example 20
Source File: SyndesisMetadata.java    From syndesis with Apache License 2.0 4 votes vote down vote up
public static SyndesisMetadata of(DataShape inputShape, DataShape outputShape) {
    ObjectHelper.notNull(inputShape, "Input DataShape");
    ObjectHelper.notNull(outputShape, "Output DataShape");

    return new SyndesisMetadata(Collections.emptyMap(), inputShape, outputShape);
}