[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-197323770 @olegz: A sample app would be great. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56446641 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels are
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56596211 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,448 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.lang3.StringUtils; +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + *
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56446243 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-197617908 @olegz : checkstyle fails when I build with your latest commit `` [INFO] --- maven-checkstyle-plugin:2.15:check (check-style) @ nifi-spring-processors --- [WARNING] src/main/java/org/apache/nifi/spring/SpringContextFactory.java[44] (regexp) RegexpSinglelineJava: Line has trailing whitespace. [WARNING] src/main/java/org/apache/nifi/spring/SpringContextFactory.java[51] (regexp) RegexpSinglelineJava: Line has trailing whitespace. [WARNING] src/main/java/org/apache/nifi/spring/SpringContextFactory.java[61] (regexp) RegexpSinglelineJava: Line has trailing whitespace. [WARNING] src/test/java/org/apache/nifi/spring/SpringContextFactoryTests.java[20:15] (imports) UnusedImports: Unused import - org.junit.Assert.assertFalse. `` --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56446675 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-198126926 Also, the Camel example was added for testing here https://github.com/olegz/si-demo .@PuspenduBanerjee if/when you get a chance please check it out. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-198171253 @olegz, I think @joewitt is still looking, but I think the code looks good, I put it through the paces using several applications. I'm +1 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56445529 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels are
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-198134497 @olegz - there are a bunch of trailing whitespace and whitespace on blank lines in the xml and properties files. checkstyle doesn't complain as it checks the java code only, but it did cause warnings when I applied the patch --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user PuspenduBanerjee commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-198245248 @olegz Sorry for the delay in response, I shall look into that during next week. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user asfgit closed the pull request at: https://github.com/apache/nifi/pull/271 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56446521 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels are
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56447125 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels are
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-197434936 @trkurc you can use the simple app here: https://github.com/olegz/si-demo. It has some initial docs and is ready to be used as is after 'mvn clean install', but you can also use it as template and change code. Initial docs are in its README --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56440539 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels are
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-197121747 @trkurc Without knowing how much spring experience you have it's hard to say, but I do have a sample app which I use for testing that I can push to my github and you (anyone) can use to play around. Will do it tomorrow after some other pressing things. Also, I plan to add one minor feature. Will describe it in the next commit message as well as updated docs. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on the pull request: https://github.com/apache/nifi/pull/271#issuecomment-197119997 @oleg: changes look good. do you have a recommendation for building a sample "application" for testing other than adapting what is in the unit tests? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56106623 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/bootstrap/SpringContextDelegate.java --- @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring.bootstrap; + +import java.io.Closeable; +import java.io.IOException; +import java.net.URLClassLoader; +import java.util.Map; + +import org.apache.nifi.spring.SpringDataExchanger; +import org.apache.nifi.spring.SpringNiFiConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.MessageBuilder; + +/** + * Scopes instance of itself to a dedicated {@link ClassLoader}, thus allowing + * Spring Application Context and its class path to be modified and refreshed by + * simply re-starting SpringContextProcessor. Also ensures that there are no + * class path collisions between multiple instances of Spring Context Processor + * which are loaded by the same NAR Class Loader. + */ +/* + * This class is for internal use only and must never be instantiated by the NAR + * Class Loader (hence in a isolated package with nothing referencing it). It is + * loaded by a dedicated CL via byte array that represents it ensuring that this + * class can be loaded multiple times by multiple Class Loaders within a single + * instance of NAR. + */ +final class SpringContextDelegate implements Closeable, SpringDataExchanger { + +private final Logger logger = LoggerFactory.getLogger(SpringContextDelegate.class); + +private final ClassPathXmlApplicationContext applicationContext; + +private final MessageChannel toSpringChannel; + +private final PollableChannel fromSpringChannel; + +/** + * + */ +private SpringContextDelegate(String configName) { +ClassLoader orig = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); +if (logger.isDebugEnabled()) { +logger.debug("Using " + Thread.currentThread().getContextClassLoader() ++ " as context class loader while loading Spring Context '" + configName + "'."); +} +try { +this.applicationContext = new ClassPathXmlApplicationContext(configName); +if (this.applicationContext.containsBean(SpringNiFiConstants.FROM_NIFI)){ +this.toSpringChannel = this.applicationContext.getBean(SpringNiFiConstants.FROM_NIFI, MessageChannel.class); +if (logger.isDebugEnabled()) { +logger.debug("Spring Application Context defined in '" + configName ++ "' is capable of receiving messages from NiFi since 'fromNiFi' channel was discovered."); +} +} else { +this.toSpringChannel = null; +} +if (this.applicationContext.containsBean(SpringNiFiConstants.TO_NIFI)){ +this.fromSpringChannel = this.applicationContext.getBean(SpringNiFiConstants.TO_NIFI, PollableChannel.class); +if (logger.isDebugEnabled()) { +logger.debug("Spring Application Context defined in '" + configName ++ "' is capable of sending messages to " + "NiFi since 'toNiFi' channel was discovered."); +} +} else { +this.fromSpringChannel = null; +} +if (logger.isInfoEnabled() &&
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56106557 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,382 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels are
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user olegz commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56106464 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextFactory.java --- @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Helper class which provides factory method to create and initialize Spring + * Application Context while scoping it within the dedicated Class Loader. + */ +final class SpringContextFactory { + +private static final Logger logger = LoggerFactory.getLogger(SpringContextFactory.class); + +private static final String SC_DELEGATE_NAME = "org.apache.nifi.spring.bootstrap.SpringContextDelegate"; + +/** + * Creates and instance of Spring Application Context scoped within a + * dedicated Class Loader + */ +static SpringDataExchanger createSpringContextDelegate(String classpath, String config) { +System.out.println(SpringContextFactory.class.getClassLoader()); +URL[] urls = gatherAdditionalClassPathUrls(classpath); +SpringContextClassLoader contextCl = new SpringContextClassLoader(urls, +SpringContextFactory.class.getClassLoader()); +try { +InputStream delegateStream = contextCl.getResourceAsStream(SC_DELEGATE_NAME.replace('.', '/') + ".class"); +byte[] delegateBytes = IOUtils.toByteArray(delegateStream); +Class clazz = contextCl.doDefineClass(SC_DELEGATE_NAME, delegateBytes, 0, delegateBytes.length); +Constructor ctr = clazz.getDeclaredConstructor(String.class); +ctr.setAccessible(true); +SpringDataExchanger springDelegate = (SpringDataExchanger) ctr.newInstance(config); +if (logger.isInfoEnabled()) { +logger.info("Successfully instantiated Spring Application Context from '" + config + "'"); +} +return springDelegate; +} catch (Exception e) { +try { +contextCl.close(); +} catch (Exception e2) { +// ignore +} +throw new IllegalStateException("Failed to instantiate Spring Application Context. Config path: '" + config ++ "'; Classpath: " + Arrays.asList(urls), e); +} +} + +/** + * + */ +private static URL[] gatherAdditionalClassPathUrls(String path) { +if (logger.isDebugEnabled()) { +logger.debug("Adding additional resources from '" + path + "' to the classpath."); +} +File libraryDir = new File(path); +if (libraryDir.exists() && libraryDir.isDirectory()) { +String[] cpResourceNames = libraryDir.list(); +try { +URLClassLoader thisCl = (URLClassLoader) SpringContextFactory.class.getClassLoader(); +List urls = new ArrayList<>(); +for (int i = 0; i < cpResourceNames.length; i++) { +if (!isDuplicate(thisCl.getURLs(), cpResourceNames[i])) { +URL url = new File(libraryDir, cpResourceNames[i]).toURI().toURL(); +urls.add(url); +if (logger.isDebugEnabled()) { +logger.debug("Identifying additional resource to the classpath: " + url); +} +} +} +return
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56105950 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/bootstrap/SpringContextDelegate.java --- @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring.bootstrap; + +import java.io.Closeable; +import java.io.IOException; +import java.net.URLClassLoader; +import java.util.Map; + +import org.apache.nifi.spring.SpringDataExchanger; +import org.apache.nifi.spring.SpringNiFiConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.MessageBuilder; + +/** + * Scopes instance of itself to a dedicated {@link ClassLoader}, thus allowing + * Spring Application Context and its class path to be modified and refreshed by + * simply re-starting SpringContextProcessor. Also ensures that there are no + * class path collisions between multiple instances of Spring Context Processor + * which are loaded by the same NAR Class Loader. + */ +/* + * This class is for internal use only and must never be instantiated by the NAR + * Class Loader (hence in a isolated package with nothing referencing it). It is + * loaded by a dedicated CL via byte array that represents it ensuring that this + * class can be loaded multiple times by multiple Class Loaders within a single + * instance of NAR. + */ +final class SpringContextDelegate implements Closeable, SpringDataExchanger { + +private final Logger logger = LoggerFactory.getLogger(SpringContextDelegate.class); + +private final ClassPathXmlApplicationContext applicationContext; + +private final MessageChannel toSpringChannel; + +private final PollableChannel fromSpringChannel; + +/** + * + */ +private SpringContextDelegate(String configName) { +ClassLoader orig = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); +if (logger.isDebugEnabled()) { +logger.debug("Using " + Thread.currentThread().getContextClassLoader() ++ " as context class loader while loading Spring Context '" + configName + "'."); +} +try { +this.applicationContext = new ClassPathXmlApplicationContext(configName); +if (this.applicationContext.containsBean(SpringNiFiConstants.FROM_NIFI)){ +this.toSpringChannel = this.applicationContext.getBean(SpringNiFiConstants.FROM_NIFI, MessageChannel.class); +if (logger.isDebugEnabled()) { +logger.debug("Spring Application Context defined in '" + configName ++ "' is capable of receiving messages from NiFi since 'fromNiFi' channel was discovered."); +} +} else { +this.toSpringChannel = null; +} +if (this.applicationContext.containsBean(SpringNiFiConstants.TO_NIFI)){ +this.fromSpringChannel = this.applicationContext.getBean(SpringNiFiConstants.TO_NIFI, PollableChannel.class); +if (logger.isDebugEnabled()) { +logger.debug("Spring Application Context defined in '" + configName ++ "' is capable of sending messages to " + "NiFi since 'toNiFi' channel was discovered."); +} +} else { +this.fromSpringChannel = null; +} +if (logger.isInfoEnabled() &&
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56105879 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/resources/docs/org.apache.nifi.spring.SpringContextProcessor/additionalDetails.html --- @@ -0,0 +1,94 @@ + + + + + +SpringContextProcessor + + + + + +Description: + +SpringContextProcessor â allows integration of processes encapsulated in Spring Application Context to run as NiFi +processor by becoming a runtime host for an instance of Spring Application Context. + + +Communication between NiFi and process encapsulated within Spring Application Context is accomplished via Spring Messaging +(one of the core modules of Spring Framework) and supports 3 usage modes: + + Headless - no interaction with NiFi, meaning nothing is sent to it and nothing is received from it (i.e., some monitoring app). + In this case NiFi simply plays the role of the runtime host. + One way (NiFi - Spring or Spring - NiFi). - This depends on existence of pre-defined message channel in Spring + Application Context. The name of the channel should be âfromNiFiâ and the type org.springframework.messaging.MessageChannel. + By-directional (NiFi - Spring - Nifi or Spring - NiFi - Spring) - This depends on existence of two channels + in Spring Application Context. One channel receives messages from NiFi with name âfromNiFiâ and type org.springframework.messaging.MessageChanneli> +and another is o receive messages from Spring with name âtoNiFiâ and type org.springframework.messaging.PollableChannel. --- End diff -- another typo: s/ o / to / ? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56104556 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextFactory.java --- @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Helper class which provides factory method to create and initialize Spring + * Application Context while scoping it within the dedicated Class Loader. + */ +final class SpringContextFactory { + +private static final Logger logger = LoggerFactory.getLogger(SpringContextFactory.class); + +private static final String SC_DELEGATE_NAME = "org.apache.nifi.spring.bootstrap.SpringContextDelegate"; + +/** + * Creates and instance of Spring Application Context scoped within a + * dedicated Class Loader + */ +static SpringDataExchanger createSpringContextDelegate(String classpath, String config) { +System.out.println(SpringContextFactory.class.getClassLoader()); +URL[] urls = gatherAdditionalClassPathUrls(classpath); +SpringContextClassLoader contextCl = new SpringContextClassLoader(urls, +SpringContextFactory.class.getClassLoader()); +try { +InputStream delegateStream = contextCl.getResourceAsStream(SC_DELEGATE_NAME.replace('.', '/') + ".class"); +byte[] delegateBytes = IOUtils.toByteArray(delegateStream); +Class clazz = contextCl.doDefineClass(SC_DELEGATE_NAME, delegateBytes, 0, delegateBytes.length); +Constructor ctr = clazz.getDeclaredConstructor(String.class); +ctr.setAccessible(true); +SpringDataExchanger springDelegate = (SpringDataExchanger) ctr.newInstance(config); +if (logger.isInfoEnabled()) { +logger.info("Successfully instantiated Spring Application Context from '" + config + "'"); +} +return springDelegate; +} catch (Exception e) { +try { +contextCl.close(); +} catch (Exception e2) { +// ignore +} +throw new IllegalStateException("Failed to instantiate Spring Application Context. Config path: '" + config ++ "'; Classpath: " + Arrays.asList(urls), e); +} +} + +/** + * + */ +private static URL[] gatherAdditionalClassPathUrls(String path) { +if (logger.isDebugEnabled()) { +logger.debug("Adding additional resources from '" + path + "' to the classpath."); +} +File libraryDir = new File(path); +if (libraryDir.exists() && libraryDir.isDirectory()) { +String[] cpResourceNames = libraryDir.list(); +try { +URLClassLoader thisCl = (URLClassLoader) SpringContextFactory.class.getClassLoader(); +List urls = new ArrayList<>(); +for (int i = 0; i < cpResourceNames.length; i++) { +if (!isDuplicate(thisCl.getURLs(), cpResourceNames[i])) { +URL url = new File(libraryDir, cpResourceNames[i]).toURI().toURL(); +urls.add(url); +if (logger.isDebugEnabled()) { +logger.debug("Identifying additional resource to the classpath: " + url); +} +} +} +return
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user joewitt commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56103524 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/java/org/apache/nifi/spring/SpringContextProcessor.java --- @@ -0,0 +1,382 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.spring; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.annotation.behavior.TriggerWhenEmpty; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.OutputStreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.spring.SpringDataExchanger.SpringResponse; +import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.util.FormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +/** + * Implementation of {@link Processor} capable of sending and receiving data + * from application defined in Spring Application context. It does so via + * predefined in/out {@link MessageChannel}s (see spring-messaging module of + * Spring). Once such channels are defined user is free to implement the rest of + * the application any way they wish (e.g., custom code and/or using frameworks + * such as Spring Integration or Camel). + * + * The requirement and expectations for channel types are: + * + * Input channel must be of type {@link MessageChannel} and named "fromNiFi" + * (see {@link SpringNiFiConstants#FROM_NIFI}) + * Output channel must be of type {@link PollableChannel} and named "toNiFi" + * (see {@link SpringNiFiConstants#TO_NIFI}) + * + * + * Below is the example of sample configuration: + * + * + * ?xml version="1.0" encoding="UTF-8"? + * beans xmlns="http://www.springframework.org/schema/beans; + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + * xmlns:int="http://www.springframework.org/schema/integration; + * xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + * http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd"; + * + * int:channel id="fromNiFi"/ + * + * . . . . . + * + * int:channel id="toNiFi" + * int:queue/ + * /int:channel + * + * /beans + * + * + * Defining {@link MessageChannel} is optional. That's why this processor + * supports 3 modes of interaction with Spring Application Context: + * + * Headless â no channels are
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56103351 --- Diff: nifi-nar-bundles/nifi-spring-bundle/nifi-spring-processors/src/main/resources/docs/org.apache.nifi.spring.SpringContextProcessor/additionalDetails.html --- @@ -0,0 +1,94 @@ + + + + + +SpringContextProcessor + + + + + +Description: + +SpringContextProcessor â allows integration of processes encapsulated in Spring Application Context to run as NiFi +processor by becoming a runtime host for an instance of Spring Application Context. + + +Communication between NiFi and process encapsulated within Spring Application Context is accomplished via Spring Messaging +(one of the core modules of Spring Framework) and supports 3 usage modes: + + Headless - no interaction with NiFi, meaning nothing is sent to it and nothing is received from it (i.e., some monitoring app). + In this case NiFi simply plays the role of the runtime host. + One way (NiFi - Spring or Spring - NiFi). - This depends on existence of pre-defined message channel in Spring + Application Context. The name of the channel should be âfromNiFiâ and the type org.springframework.messaging.MessageChannel. + By-directional (NiFi - Spring - Nifi or Spring - NiFi - Spring) - This depends on existence of two channels + in Spring Application Context. One channel receives messages from NiFi with name âfromNiFiâ and type org.springframework.messaging.MessageChanneli> +and another is o receive messages from Spring with name âtoNiFiâ and type org.springframework.messaging.PollableChannel. + +The example below demonstrates template configuration for bi-directional Spring Application Context configuration: + + +int:channel id=âfromNiFiâ/ + +!â +your custom app configuration to receive messages from âfromNiFiâ channel and optionally send back to NiFi via âtoNiFiâ channel. +It could contain any Spring-based application (i.e., Spring Integration, Apache Camel and/or custom code). All you need to do is inject +channels into your beans and send/receive messages from it. +-- + +int:channel id="toNiFi" + int:queue/ +/int:channel + + + + +The component is based on assumption that user has an existing Spring Application encapsulated in Spring Context that exposes optional in/out +MessagingChannels to allow data to flow to/from ApplicationContext and into/out-of. NiFi. +Such application is realized by having a directory on the file system, which contains contains all required resources for such application to run. +Such resources usually are JAR files to satisfy application's class-path as well as JAR representing the application and its configuration. +Below is the example of what such directory may contain. In this case the 'SI_DEMO-0.0.1-SNAPSHOT.jar' represents the actual application and the rest +of the JARs represent class-path dependency required by an application. + +deps + âââ SI_DEMO-0.0.1-SNAPSHOT.jar + âââ aopalliance-1.0.jar + âââ commons-logging-1.2.jar + âââ spring-aop-4.2.4.RELEASE.jar + âââ spring-beans-4.2.4.RELEASE.jar + âââ spring-context-4.2.4.RELEASE.jar + âââ spring-core-4.2.4.RELEASE.jar + âââ spring-expression-4.2.4.RELEASE.jar + âââ spring-integration-core-4.2.5.RELEASE.jar + âââ spring-messaging-4.2.4.RELEASE.jar + + + +You introduce the processor the usual way and then configure its properties: + +Application Context config path [REQUIRED] - a path to the Application Context configuration. +The path is relative to the class-path of the application defined by the Application Context class path property +Application Context class path [REQUIRED] - a path to a directory on the file system where application dependencies are. +Send Timeout [OPTIONAL] - the wait time for sending messages to Spring Application Context. Only required if NiFi plans to send data o Spring. --- End diff -- Typo: s/ o / to / --- If your project is set up for it, you can reply to
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
Github user trkurc commented on a diff in the pull request: https://github.com/apache/nifi/pull/271#discussion_r56102458 --- Diff: nifi-nar-bundles/pom.xml --- @@ -54,7 +54,8 @@ nifi-scripting-bundle nifi-elasticsearch-bundle nifi-amqp-bundle - nifi-splunk-bundle + nifi-splunk-bundle --- End diff -- something strange is happening with whitespace here. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request: NIFI-1571 initial commit of SpringContext suppo...
GitHub user olegz opened a pull request: https://github.com/apache/nifi/pull/271 NIFI-1571 initial commit of SpringContext support You can merge this pull request into a Git repository by running: $ git pull https://github.com/olegz/nifi NIFI-1571 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/nifi/pull/271.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #271 commit 82bc3ceb16e1f1c237285da227c79fef4441e2f2 Author: Oleg ZhurakouskyDate: 2016-03-02T18:35:26Z NIFI-1571 initial commit of SpringContext support --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---