History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: QUARTZ-89
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: James House
Reporter: Sean Owen
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Quartz Scheduler

JobSchedulingDataProcessor causes exception for files not in classpath

Created: 01/Nov/04 12:48 PM   Updated: 30/Dec/04 01:34 PM
Component/s: Core
Affects Version/s: 1.4.2
Fix Version/s: 1.4.3

Environment: JDK 1.4.2_05 on RH9 Linux
Issue Links:
Related
This issue relates to:
QUARTZ-68 JobInitializationPlugin: jobs.xml in ... Major Closed
This issue is related to:
QUARTZ-105 (reopen) JobSchedulingDataProcessor c... Major Closed


 Description  « Hide
JobSchedulingDataProcessor.processFileAndScheduleJobs(String, Scheduler, boolean) appears to only work correctly when the named file can be located as a resource in the classpath. When it can't, the user gets an unhelpful exception from the underlying XML parser.

I think that either:

1) the documentation for it should be fixed (incidentally, looks like the javadoc for this method was copied without modification from its overloaded sibling -- refers to "xml file in the *default* location"), and the code changed to catch and report this case more meaningfully, or

2) the code should be changed to handle files outside the classpath


To elaborate...

processFileAndScheduleJobs() calls processFile(), which ultimately accesses the file by calling ClassLoader.getResourceAsStream(). I believe this only returns a non-null value when the file is available in the classpath. If it's not, it returns null, and this null InputStream is given to InputSource. No exception is generated at that point. But, since systemId is set to null on the InputSource in this case too, when parsing starts one gets an unhelpful exception from the XML parser (an NPE from Crimson; a MalformedURLException from Xerces).

At least, I think that Quartz should catch the case where getResourceAsStream() returns null and handle it more meaningfully. The documentation should also be updated.

This can be worked around, however, by replacing a call to...

processor.processFileAndScheduleJobs(fileName, scheduler, true);

with...

processor.processFile(fileName, fileName);
processor.scheduleJobs(processor.getScheduledJobs(), scheduler, true);

That is, pass the file name as the "systemId" as well. It is a bit of a hack but it works, since the parser will load the file indicated by the systemId if the InputSource provides no valid InputStream -- it uses "new URL("file://...").openStream()" in the case of Crimson.

It seems possible to incorporate this into Quartz as well, so as to load both from the classpath and, failing that, the file system.

 All   Comments   Change History      Sort Order:
Sean Owen - [01/Nov/04 12:53 PM ]
Hmm, actually it appears to me that JobSchedulingDataProcessor does *not* check the file system. Well, these issues concern the same particular part of Quartz at least.

Paul Stephenson - [02/Dec/04 08:12 AM ]
Hi, I've just started using Quartz for an in house project running on weblogic, using it essentially as a cron replacement, and I've found it very good - thanks for all your hard work on it.

I really needed to be able to specify a file outside the classpath - due to struct code and configuration separation based on directory trees. I made the following small change to org.quartz.xmlzJobSchedulingDataProcessor.getInputStream (as implied in the first comment above), which seems to work fine, though files need to be specified as eg d:\jobs.xml as opposed to file:///d:/jobs.xml

protected InputStream getInputStream(String fileName) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();

InputStream is = cl.getResourceAsStream(fileName);
        if (is == null) {
            try {
                is = new FileInputStream(fileName);
            } catch (FileNotFoundException e) {
                getLog().info("Cannot find file "+fileName+"in JobSchedulingdataProcessor.getInputStream");
            }
        }
        return is;
    }

Sean Owen - [30/Dec/04 01:28 PM ]
This issue has not been fixed in the latest release, I don't think. It continues to experience the problem described above. In fact I only see one line of code changed in JobSchedulingDataProcessor.java between 1.4.2 and 1.4.3 and it is not related.