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

Mathias Lin mail at mathiaslin.com
Mon Jul 16 20:18:14 CEST 2012


I got it working now programmatically, although I don't know exactly why I
need to do it this way:

Instead of setting the following attributes to null, I had to set some kind
of value for them, so that I'm not getting an error. Not quite sure why they
are necessary, since creating the job via workplace/admin just looks
identical to as if I would set everything to null. 
And it seems that setting site root to '' (empty string) or to null does
make a different, however, both ways are represented in the same way in the
workplace admin (if I set site root to '' (empty string), I do not see an
empty input field though in the workplace/admin/job config, but not input
field at all, just the same way as if I had set the null value). Very
strange.

contextInfo.setRemoteAddr("localhost");
contextInfo.setSiteRoot("/");
contextInfo.setRequestedUri("/");




Mathias Lin wrote:
> 
> Hi Deiverson,
> 
> thanks for your reply, but: yes, I saw that comment in the code, but it
> shouldn't matter, because that's what OpenCms takes care of by itself.
> That's what the code section is for in the ContextInfo - it's cutting off
> the trailing.
> My problem is though that root is already null, and I can't figure out why
> it's null, but I also don't understand the difference yet between my
> manually created scheduled jobs (where I did not set any siteRoot in the
> job config either), and my automatically created job through code, where I
> get a NullPointerException for the root being null.
> 
> I will give it a try and leave the / out, but I doubt it will help.
> 
> 
>         // site roots must never end with a "/"
>         if (root.endsWith("/")) {
>             m_siteRoot = root.substring(0, root.length() - 1);
>         } else {
>             m_siteRoot = root;
>         }
> 
> 
> On Fri, Jul 13, 2012 at 8:38 PM, Deiverson Silveira <
> deiverson at solutioncms.com> wrote:
> 
>> Hi Marthias,
>>
>> In documentation, you see the method:
>> // site roots must never end with a "/"
>>
>> Try put "/some/path", not "/some/path/". do not put the "/" at the end.
>>
>> Good luck,
>>
>> Deiverson
>>
>>
>> 2012/7/13 Mathias Lin <mail at mathiaslin.com>
>>
>>> 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("/")) {
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> This mail is sent to you from the opencms-dev mailing list
>>> To change your list options, or to unsubscribe from the list, please
>>> visit
>>> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>>>
>>>
>>>
>>>
>>>
>>
>>
>> --
>> *
>> www.solutioncms.com
>>  The Brazilian
>> Official Provider OpenCms
>>
>> *
>>
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, please
>> visit
>> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>>
>>
>>
>>
>>
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
> 
> 
> 
> 
> 
-- 
View this message in context: http://old.nabble.com/Scheduled-job%2C-that-I-created-programmatically%2C-is-causing-problems-%28manual-creation-works-fine-though%29-tp34154578p34169447.html
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.




More information about the opencms-dev mailing list