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)<div>
<br></div><div>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.</div>
<div>Here's a screenshot of the config: <a href="http://imageshack.us/photo/my-images/10/ocmsjobconfig.jpg/">http://imageshack.us/photo/my-images/10/ocmsjobconfig.jpg/</a></div><div><br></div><div>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.</div>
<div><br></div><div>Below is the code that I use to create the scheduled job. </div><div><br></div><div><br></div><div><div><font face="courier new, monospace" size="1"> SortedMap<String, String> parameters = new java.util.TreeMap<java.lang.String, java.lang.String>();</font></div>
<div><font face="courier new, monospace" size="1"> parameters.put("workshopsRootFolder", "/sites/mysite/de/de/SomeFolder");</font></div><div><font face="courier new, monospace" size="1"> parameters.put("wsUrl", wsUrlLocations);</font></div>
<div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1"> try {</font></div><div><font face="courier new, monospace" size="1"> Context initCtx = new InitialContext();</font></div>
<div><font face="courier new, monospace" size="1"> String wsUrlLocations = (String) initCtx.lookup("java:comp/env/env/OCMS_WEBSERVICE_LOCATIONS");</font></div><div><font face="courier new, monospace" size="1"> parameters.put("wsUrl", wsUrlLocations);</font></div>
<div><font face="courier new, monospace" size="1"> } catch (NamingException ne) {</font></div><div><font face="courier new, monospace" size="1"> ne.printStackTrace();</font></div><div><font face="courier new, monospace" size="1"> }</font></div>
<div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1"> CmsContextInfo contextInfo = new CmsContextInfo("Admin");</font></div><div><font face="courier new, monospace" size="1"> contextInfo.setProjectName("Offline");</font></div>
<div><font face="courier new, monospace" size="1"> contextInfo.setLocaleName("de_DE");</font></div><div><font face="courier new, monospace" size="1"> contextInfo.setEncoding(null);</font></div>
<div><font face="courier new, monospace" size="1"> contextInfo.setRemoteAddr(null);</font></div><div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1"> // doesn't matter what I put here, it won't show in the created scheduled job!</font></div>
<div><font face="courier new, monospace" size="1"> // I tried "/" and "/some/path/" already, but it won't show in the OpenCms workplace administration.</font></div><div><font face="courier new, monospace" size="1"> contextInfo.setSiteRoot(null);</font></div>
<div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1"> contextInfo.setRequestedUri(null);</font></div><div><font face="courier new, monospace" size="1"> contextInfo.setOuFqn("/");</font></div>
<div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1"> CmsScheduledJobInfo jobInfo = new CmsScheduledJobInfo(</font></div><div><font face="courier new, monospace" size="1"> null,</font></div>
<div><font face="courier new, monospace" size="1"> "CreateWorkshopPagesJob",</font></div><div><font face="courier new, monospace" size="1"> "com.uv.smp.ocms.jobs.CreateWorkshopPagesJob",</font></div>
<div><font face="courier new, monospace" size="1"> contextInfo,</font></div><div><font face="courier new, monospace" size="1"> "0 0/30 * * * ?",</font></div><div><font face="courier new, monospace" size="1"> true,</font></div>
<div><font face="courier new, monospace" size="1"> true,</font></div><div><font face="courier new, monospace" size="1"> parameters</font></div><div><font face="courier new, monospace" size="1"> );</font></div>
<div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1"> OpenCms.getScheduleManager().scheduleJob(cmsObject, jobInfo);</font></div></div><div><br></div>
<div><br></div><div>I noticed the following problems:</div><div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div>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.</div>
<div><br></div><div><div><font face="courier new, monospace" size="1">java.lang.UnsupportedOperationException</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at java.util.Collections$UnmodifiableMap.clear(Collections.java:1351)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.CmsWidgetDialogParameter.prepareCommit(CmsWidgetDialogParameter.java:626)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.CmsWidgetDialog.commitWidgetValues(CmsWidgetDialog.java:842)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.CmsWidgetDialog.initWorkplaceRequestValues(CmsWidgetDialog.java:1516)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.tools.scheduler.CmsEditScheduledJobInfoDialog.initWorkplaceRequestValues(CmsEditScheduledJobInfoDialog.java:477)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.CmsWorkplace.initWorkplaceMembers(CmsWorkplace.java:1959)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.CmsWorkplace.<init>(CmsWorkplace.java:252)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.tools.CmsToolDialog.<init>(CmsToolDialog.java:93)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.CmsDialog.<init>(CmsDialog.java:260)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.CmsWidgetDialog.<init>(CmsWidgetDialog.java:146)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.tools.scheduler.CmsEditScheduledJobInfoDialog.<init>(CmsEditScheduledJobInfoDialog.java:103)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.workplace.tools.scheduler.CmsEditScheduledJobInfoDialog.<init>(CmsEditScheduledJobInfoDialog.java:115)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.jsp.WEB_002dINF.jsp.offline.system.workplace.admin.scheduler.edit_jsp._jspService(edit_jsp.java:65)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)</font></div><div>
<font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.loader.CmsJspLoader.load(CmsJspLoader.java:514)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.loader.CmsResourceManager.loadResource(CmsResourceManager.java:1062)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.main.OpenCmsCore.showResource(OpenCmsCore.java:1598)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.main.OpenCmsServlet.doGet(OpenCmsServlet.java:153)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.opencms.main.OpenCmsServlet.doPost(OpenCmsServlet.java:166)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)</font></div><div>
<font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:279)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)</font></div>
<div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)</font></div><div><font face="courier new, monospace" size="1"><span class="Apple-tab-span" style="white-space:pre"> </span>at java.lang.Thread.run(Thread.java:722)</font></div>
</div><div><br></div><div>3) Finally, when the job is tried to being executed, I see the following error in the log:</div><div><br></div><div><div><font face="courier new, monospace" size="1"> java.lang.NullPointerException</font></div>
<div><font face="courier new, monospace" size="1"> at org.opencms.file.CmsRequestContext.setSiteRoot(CmsRequestContext.java:571)</font></div><div><font face="courier new, monospace" size="1"> at org.opencms.file.CmsRequestContext.<init>(CmsRequestContext.java:132)</font></div>
<div><font face="courier new, monospace" size="1"> at org.opencms.main.OpenCmsCore.initCmsObject(OpenCmsCore.java:2151)</font></div><div><font face="courier new, monospace" size="1"> at org.opencms.main.OpenCmsCore.initCmsObject(OpenCmsCore.java:855)</font></div>
<div><font face="courier new, monospace" size="1"> at org.opencms.main.OpenCms.initCmsObject(OpenCms.java:589)</font></div><div><font face="courier new, monospace" size="1"> at org.opencms.scheduler.CmsScheduleManager.execute(CmsScheduleManager.java:165)</font></div>
<div><font face="courier new, monospace" size="1"> at org.quartz.core.JobRunShell.run(JobRunShell.java:203)</font></div><div><font face="courier new, monospace" size="1"> at org.opencms.scheduler.CmsSchedulerThread.run(CmsSchedulerThread.java:115)</font></div>
</div><div><br></div><div>which leads me to the following code section in OpenCms 8.0.3:</div><div><br></div><div><div><a href="https://github.com/alkacon/opencms-core/blob/build_8_0_3/src/org/opencms/file/CmsRequestContext.java#L571">https://github.com/alkacon/opencms-core/blob/build_8_0_3/src/org/opencms/file/CmsRequestContext.java#L571</a></div>
<div><br></div><div><font face="courier new, monospace" size="1"> public void setSiteRoot(String root) {</font></div><div><font face="courier new, monospace" size="1"> // site roots must never end with a "/"</font></div>
<div><font face="courier new, monospace" size="1"> if (root.endsWith("/")) {</font></div></div><div><font face="courier new, monospace" size="1"><br></font></div><div><br></div><div><br></div>