0

I have a Non Action Class in my Struts2 application where I want to get the HttpServletRequest and HttpServletResponse.

The class is called by a scheduler and I want to execute the job based on what I receive from the from a session.

I ran into the issue while trying to use Async Supported.

Here is my block of code:

  public void executeSync(HttpServletRequest req, HttpServletResponse res) {
    final AsyncContext asyncContext = req.startAsync(req, res);
    asyncContext.start(new Runnable() {
      @Override
      public void run() {
        try {
          // try doing the sync asynchronously ...
        }catch(Exception ex){
            ex.printStackTrace();
        }
        finally {
          asyncContext.complete();
        }
      }
    });

  }

The Issue is how to get the request and response to parse.

I really need help.

Kersy
  • 116
  • 5
  • What do you mean by "get the request and response to parse"? In any case, making anything other than the web interface dependent on web-only artifacts breaks incapsulation; the task may run with data *retrieved* from the session, but it shouldn't rely directly *on* the session. – Dave Newton Mar 13 '19 at 19:06
  • Thanks but that is my point. How do I get data from the session in a class that does not extend a struts2 Action? – Kersy Mar 13 '19 at 19:21
  • You pass it from whatever it is that creates it; if they're completely separated, e.g., you don't create the job from the action, then you'd need to save the data off somewhere and retrieve it in the job. If you're creating it in the action then you just pass it from the action (but pass the data, not the web artifacts). – Dave Newton Mar 13 '19 at 19:25
  • Also see https://stackoverflow.com/a/36655941/573032 – Roman C Apr 09 '19 at 14:24

0 Answers0