Bob Whitehurst created NIFI-4527:
------------------------------------
Summary: 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
(v6.4.14#64029)