Reply To: Can PrettyFaces be used in Quartz job?

Splash Forums PrettyFaces Users Can PrettyFaces be used in Quartz job? Reply To: Can PrettyFaces be used in Quartz job?

#24792

Extak
Participant

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 = builder.build(mapping, 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{
    @Inject
    private ServletContext servletContext;

    @Override
    protected void doExecute(ApplicationContext ctx, JobExecutionContext jobContext){
        ...
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();     

        URL url = ... absolute URL of my application
 
        request.setRemoteAddr(url.getHost());
        request.setServerName(url.getHost());
        request.setRemotePort(url.getPort());
        request.setServerPort(url.getPort());

        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?