Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire off an internal ServletRequest in Tomcat

I am using Quartz to schedule background tasks for a web application. Some of these tasks just fire off requests against the same web application.

I want to avoid depending on any kind of network settings (for example a request with my own domain name might not be routed properly if made from within the data center). Is there a Java API to fire off a ServletRequest and have it handled by Tomcat internally (without any actual HTTP involved)?

I still want to wrap the work into a Servlet request rather than calling the Java code for the background tasks directly, so that I can go back to regular HTTP request as a configuration option.

Tomcat-specific code is acceptable.

like image 420
Thilo Avatar asked Nov 15 '22 14:11

Thilo


1 Answers

What do you want to get from that scheduled tasks? Standard web-server behavior is to get HTTP request and respond with particular data. I assume that your tasks don't need that, i.e. you want just to perform particular processing which codebase resides within the web-application.

If the assumption above is correct you can just decouple servlet/jsp logic from business-processing logic and call business-logic layer classes directly from your scheduled tasks.

like image 184
denis.zhdanov Avatar answered Dec 17 '22 12:12

denis.zhdanov