Can PrettyFaces be used in Quartz job?

Splash Forums PrettyFaces Users Can PrettyFaces be used in Quartz job?

This topic contains 3 replies, has 2 voices, and was last updated by  Christian Kaltepoth 8 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #24779


    I have JavaEE application with Quartz job. The job sometimes sends some emails and i need to generate some URLs to put them into this emails. Quite common issue I suppose.

    Is there way to generate URLs in Quartz job without any HttpRequest?


    That do you mean with “generate URLs”? What’s the exact use case? The typical way to generate pretty URLs from non-pretty URLs is to use HttpServletResponse.encodeURL(), but this won’t be possible from outside of a request.



    I’ve solved it πŸ™‚

    I’m using something like this:

    // request -> HttpServletRequest
    PrettyContext context = PrettyContext.getCurrentInstance(request);
    UrlMapping mapping = context.getConfig().getMappingById(mappingId);
    PrettyURLBuilder builder = new PrettyURLBuilder();
    String targetURL =, false, params);

    I can construct this way URL anywhere in webapp. I’m using Spring and when a job is a bean, i can use this:

    public class SomethingJob extends QuartzJobBean{
        private ServletContext servletContext;
        protected void doExecute(ApplicationContext ctx, JobExecutionContext jobContext){
            MockHttpServletRequest request = new MockHttpServletRequest();
            MockHttpServletResponse response = new MockHttpServletResponse();     
            URL url = ... absolute URL of my application
            PrettyFilter prettyFilter = new PrettyFilter();
            try {
                prettyFilter.init(new MockFilterConfig(servletContext));
                prettyFilter.doFilter(request, response, new MockFilterChain());            
            } catch (Exception ex) {
            // Construct URL by PrettyFaces with code mentioned above
            // Place generated URL to email body and send it

    This workaround is functional, but is there a better way?


    I think the PrettyConfig is available as a servlet context attribute. So something like this could also work:

    ServletContext context = ...;
    PrettyConfig config = context.getAttribute(PrettyContext.CONFIG_KEY);
    UrlMapping mapping = config.getMappingById(mappingId);
    PrettyURLBuilder builder = new PrettyURLBuilder();
    String targetURL =, false, params);

    Perhaps a bit simpler. But I’m not sure if this also works. πŸ™‚

Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.