[opencms-dev] Create a scheduled job from jsp

Luis Rodriguez Fernandez luis.rodriguez at fundacionctic.org
Wed Sep 7 09:07:43 CEST 2005


Sorry, this was a mail for a spanish Developer. Problems of the cut and paste!!! I´m going to try to translate it.

 

Thank you. Luis

 

Good mornig. I´m Luis Rodríguez Fernández, from the CTIC Foundation (Spain). I´m trying to develop a newsletter service for OpenCms. To do this, I try to make a scheduled job that sent email's with the news (OpenCms structured contents)

 

I have a class that implements I_CmsScheduledJob. In the launch method I try to load a group of jsp for making the email's. The way to do that is using the export method of the CmsJspLoader. Since this methods needs the request and the response I have put the scheduled job in a jsp, this is the code:

 

 

<%@page import="org.opencms.main.CmsContextInfo,

                         org.opencms.scheduler.CmsScheduledJobInfo,

                         org.opencms.scheduler.CmsScheduleManager,

                         org.opencms.file.CmsObject,

                         org.opencms.jsp.CmsJspBean,

                         java.util.SortedMap,

                         java.util.TreeMap"%>

 

  

 

<%

 

CmsScheduledJobInfo csji = new CmsScheduledJobInfo();

CmsScheduleManager csm = new CmsScheduleManager();

CmsJspBean cjb = new CmsJspBean();

 

cjb.init(pageContext,request,response);

 

CmsObject cmsObj = cjb.getCmsObject();

CmsContextInfo cci = new CmsContextInfo(cjb.getRequestContext());

 

csji.setCronExpression("0 0/1 * * * ?");

 

csji.setClassName("org.fundacionctic.opencms.business.services.NewsLetterCmsScheduledJob");

 

csji.setActive(true);

csji.setContextInfo(cci);

csji.setJobName("boletin");

 

 

 

SortedMap parametros = new TreeMap();

parametros.put("request",request);

parametros.put("response",response);

 

csji.setParameters(parametros);

csm.initialize(cmsObj);

 

csm.scheduleJob(cmsObj,csji);

 

%>

 

 And that´s it! The job is executed every minute. The problem is in the export method form the CmsJspLoader class

 

The launch code is the next:

public String launch(CmsObject arg0, Map arg1) throws Exception {

 

            CmsJspLoader crl = new CmsJspLoader();

     crl.setFlexCache(newCmsFlexCache(newCmsFlexCacheConfiguration()));

            crl.initConfiguration();

 

      

            I_CmsResourceCollector collector = OpenCms.getResourceManager()

 

            .getContentCollector("singleFile");

 

 

 

            List m_collectorResult = collector.getResults(arg0,

"singleFile",

 

                       

> 

"/system/modules/org.opencms.fundacionctic.newsletter/elements/cabeceraBoletin.jsp");

 

            CmsResource e = (CmsResource)m_collectorResult.get(0);

 

 

 

            byte[] contenidoHtml = null;

 

 

 

            HttpServletRequestWrapper hsrw = new

HttpServletRequestWrapper((HttpServletRequest)arg1.get("request"));

 

            HttpServletResponseWrapper hsrew = new

HttpServletResponseWrapper((HttpServletResponse)arg1.get("response"));

 

 

 

            contenidoHtml = crl.export(arg0,e,hsrw,hsrew);

 

            String contenido = new String(contenidoHtml);

 

            System.out.println(contenido);

 

                        

 

return null;

 

}

 

To test I have hardcoded the collector and the structured content I want to load: "singleFile" and " system/modules/org.opencms.fundacionctic.newsletter/elements/cabeceraBoletin.jsp ". The next step was passing them to the class in a form (at the end I am doing the same as the Scheduled Job Manegement). 

 

All seems very clear and correct but executing the export the next exception raise:  

 

 

java.lang.NullPointerException

 

            at

org.apache.coyote.tomcat5.CoyoteRequest.setAttribute(CoyoteRequest.java:1472)

            at

org.apache.coyote.tomcat5.CoyoteRequestFacade.setAttribute(CoyoteRequestFacade.java:351)

            at

javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:283)

            at

javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:283)

            at

javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:283)

            at

javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:283)

            at

org.opencms.flex.CmsFlexController.setController(CmsFlexController.java:277)

 

            at

org.opencms.loader.CmsJspLoader.getController(CmsJspLoader.java:561)

            at 

org.opencms.loader.CmsJspLoader.export(CmsJspLoader.java:245)

            at

org.fundacionctic.opencms.business.services.NewsLetterCmsScheduledJob.launch(NewsLetterCmsScheduledJob.java:376)

            at

org.opencms.scheduler.CmsScheduleManager.execute(CmsScheduleManager.java:171)

            at 

org.quartz.core.JobRunShell.run(JobRunShell.java:191) 

 

 

 

Any idea?

 

 

Thanks and see you. Luis

 

 

_______________________________________________

This mail is send to you from the opencms-dev mailing list

To change your list options, or to unsubscribe from the list, please visit

http://mail.opencms.org/mailman/listinfo/opencms-dev

 

 

 

----------------------------------------------------------------

This message was sent using IMP, the Internet Messaging Program.

 

 

 

_______________________________________________

This mail is send to you from the opencms-dev mailing list

To change your list options, or to unsubscribe from the list, please visit

http://mail.opencms.org/mailman/listinfo/opencms-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20050907/8e0b4777/attachment.htm>


More information about the opencms-dev mailing list