[
https://issues.apache.org/jira/browse/NIFI-4527?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Pierre Villard resolved NIFI-4527.
----------------------------------
Resolution: Feedback Received
Apache NiFi 1.x is no longer maintained and no new release is planned on the
1.x release line. Marking as resolved as part of a cleanup operation. Please
open a new one with an updated description if this is still relevant for NiFi
2.x.
> unable to get dynamicallyModifiesClasspath for PropertyDescriptor to work
> -------------------------------------------------------------------------
>
> Key: NIFI-4527
> URL: https://issues.apache.org/jira/browse/NIFI-4527
> Project: Apache NiFi
> Issue Type: Bug
> Affects Versions: 1.3.0
> Reporter: Bob Whitehurst
> Priority: Minor
>
> For some reason I cannot get a property that sets
> dynamicallyModifiesClasspath to true to work correctly. I read through the
> code that was dropped for NIFI-2909. Seems like it should work but perhaps I
> have missed something. Seems like someone should have encountered an issue
> before me. There are several other alternative solutions that I can use but
> it would be nice for this to work.
> I created a test case with the following code that is called from the
> OnTrigger method. There may be a typo in this as I cannot cut/paste from my
> development environment: I created my own classloader which will correctly
> load the file.
> ======================================================
> // resource property descriptor
> private static final String EDH_FILE = "edh.yaml";
> private static final String PROP_NAME = "resource_path";
> private static final PropertyDescriptor RESOURCE_DIR = new
> PropertyDescritor.Builder()
> .name(PROP_NAME)
> .defaultValue("some-path")
> .description(" ... ")
> .required(true)
> .addValidator(StandardValidators.NON_EMPT_VALIDATOR)
> .dynamicallyModifiesClasspath(true)
> .build();
> private void loadConfig(final ProcessContext context) {
> final InputStream is = this.getClass.getResourceAsStream(EDH_FILE);
> if (null == is) {
> logger.error("default classloader failed");
> }
> final PropertyValue prop = context.getProperty(PROP_NAME);
> String path = prop.getValue();
> try {
> final URL url = new URL("file://" + EDH_FILE);
> final Classloader clThread =
> Thread.currentThread.getContextClassLoader();
> final Classloader cl = URLClassLoader.newInstance(new URL[] {url},
> clThread);
> InputStream ins = cl.getResourceAsStream(EDH_FILE);
> if (null == ins) {
> logger.error("failed to load from custom classloader");
> } else {
> logger.info("success");
> // read input stream
> }
> } catch (IOException ioe) {
> logger.error("ioe reading config", ioe);
> }
> }
> @Override
> public void onTrigger(ProcessContext context, ProcessSession session) {
> loadConfig(conetxt);
> //... rest of code
> }
--
This message was sent by Atlassian Jira
(v8.20.10#820010)