[opencms-dev] Scheduled job, that I created programmatically, is causing problems (manual creation works fine though)

Mathias Lin mail at mathiaslin.com
Fri Jul 13 07:48:52 CEST 2012


I try to create a scheduled job, which worked fine so far when I created it
manually, in code. Idea is that I want the scheduled job to be created
automatically when a module is being imported and initialized, using the
Module Action class. (OpenCms 8.0.3)

The problem that I encounter though is that the programmatically created
scheduled job appears fine in the Opencms workplace / job administration.
And the configuration of all it's fields looks exactly the same in the
OpenCms workplace admin.
Here's a screenshot of the config:
http://imageshack.us/photo/my-images/10/ocmsjobconfig.jpg/

But: it throws some exception when it's being executed (NullPointer on
OpenCms core code level), and also I cannot modify the job anymore. When I
try to modify the job via OpenCms workplace, I get some error message ("The
following errors occurred when validating the form: Adding text to an XML
document must not be null"); marked red in the screenshot above.

Below is the code that I use to create the scheduled job.


            SortedMap<String, String> parameters = new
java.util.TreeMap<java.lang.String, java.lang.String>();
            parameters.put("workshopsRootFolder",
"/sites/mysite/de/de/SomeFolder");
            parameters.put("wsUrl", wsUrlLocations);

            try {
                Context initCtx = new InitialContext();
                String wsUrlLocations = (String)
initCtx.lookup("java:comp/env/env/OCMS_WEBSERVICE_LOCATIONS");
                parameters.put("wsUrl", wsUrlLocations);
            } catch (NamingException ne) {
                ne.printStackTrace();
            }

            CmsContextInfo contextInfo = new CmsContextInfo("Admin");
            contextInfo.setProjectName("Offline");
            contextInfo.setLocaleName("de_DE");
            contextInfo.setEncoding(null);
            contextInfo.setRemoteAddr(null);

            // doesn't matter what I put here, it won't show in the created
scheduled job!
            // I tried "/" and "/some/path/" already, but it won't show in
the OpenCms workplace administration.
            contextInfo.setSiteRoot(null);

            contextInfo.setRequestedUri(null);
            contextInfo.setOuFqn("/");

            CmsScheduledJobInfo jobInfo = new CmsScheduledJobInfo(
                    null,
                    "CreateWorkshopPagesJob",
                    "com.uv.smp.ocms.jobs.CreateWorkshopPagesJob",
                    contextInfo,
                    "0 0/30 * * * ?",
                    true,
                    true,
                    parameters
            );

            OpenCms.getScheduleManager().scheduleJob(cmsObject, jobInfo);


I noticed the following problems:

1) As you can see in my comment in my code above, I tried to set the
siteRoot of the contextInfo to something other than null, i.e. "/" or some
other path, but this is not reflected in the OpenCms workplace / admin
section when looking into the job configuration after it's been created.
The siteRoot field will always remain empty there, regardless of what I had
put in my code, which created the job.

2) I cannot modify the job in the workplace after it's automatic creation.
I get an error "The following errors occurred when validating the form:
Adding text to an XML document must not be null", as shown in above
screenshot.
When I hit the 'save' button a second time, I get a detailed log which
shows me the following error message - which actually makes me wonder:
where are the scheduled jobs stored actually? I couldn't find them in the
DB nor in any of the config files.

java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap.clear(Collections.java:1351)
at
org.opencms.workplace.CmsWidgetDialogParameter.prepareCommit(CmsWidgetDialogParameter.java:626)
at
org.opencms.workplace.CmsWidgetDialog.commitWidgetValues(CmsWidgetDialog.java:842)
at
org.opencms.workplace.CmsWidgetDialog.initWorkplaceRequestValues(CmsWidgetDialog.java:1516)
at
org.opencms.workplace.tools.scheduler.CmsEditScheduledJobInfoDialog.initWorkplaceRequestValues(CmsEditScheduledJobInfoDialog.java:477)
at
org.opencms.workplace.CmsWorkplace.initWorkplaceMembers(CmsWorkplace.java:1959)
at org.opencms.workplace.CmsWorkplace.<init>(CmsWorkplace.java:252)
at org.opencms.workplace.tools.CmsToolDialog.<init>(CmsToolDialog.java:93)
at org.opencms.workplace.CmsDialog.<init>(CmsDialog.java:260)
at org.opencms.workplace.CmsWidgetDialog.<init>(CmsWidgetDialog.java:146)
at
org.opencms.workplace.tools.scheduler.CmsEditScheduledJobInfoDialog.<init>(CmsEditScheduledJobInfoDialog.java:103)
at
org.opencms.workplace.tools.scheduler.CmsEditScheduledJobInfoDialog.<init>(CmsEditScheduledJobInfoDialog.java:115)
at
org.apache.jsp.WEB_002dINF.jsp.offline.system.workplace.admin.scheduler.edit_jsp._jspService(edit_jsp.java:65)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at org.opencms.loader.CmsJspLoader.load(CmsJspLoader.java:514)
at
org.opencms.loader.CmsResourceManager.loadResource(CmsResourceManager.java:1062)
at org.opencms.main.OpenCmsCore.showResource(OpenCmsCore.java:1598)
at org.opencms.main.OpenCmsServlet.doGet(OpenCmsServlet.java:153)
at org.opencms.main.OpenCmsServlet.doPost(OpenCmsServlet.java:166)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:279)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

3) Finally, when the job is tried to being executed, I see the following
error in the log:

        java.lang.NullPointerException
        at
org.opencms.file.CmsRequestContext.setSiteRoot(CmsRequestContext.java:571)
        at
org.opencms.file.CmsRequestContext.<init>(CmsRequestContext.java:132)
        at org.opencms.main.OpenCmsCore.initCmsObject(OpenCmsCore.java:2151)
        at org.opencms.main.OpenCmsCore.initCmsObject(OpenCmsCore.java:855)
        at org.opencms.main.OpenCms.initCmsObject(OpenCms.java:589)
        at
org.opencms.scheduler.CmsScheduleManager.execute(CmsScheduleManager.java:165)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
        at
org.opencms.scheduler.CmsSchedulerThread.run(CmsSchedulerThread.java:115)

which leads me to the following code section in OpenCms 8.0.3:

https://github.com/alkacon/opencms-core/blob/build_8_0_3/src/org/opencms/file/CmsRequestContext.java#L571

    public void setSiteRoot(String root) {
        // site roots must never end with a "/"
        if (root.endsWith("/")) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20120713/93b93c5d/attachment.htm>


More information about the opencms-dev mailing list