This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Possible to detect timeouts upon forwarding requests? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Possible to detect timeouts upon forwarding requests?" Watch "Possible to detect timeouts upon forwarding requests?" New topic
Author

Possible to detect timeouts upon forwarding requests?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using Struts 2. I have this line in my execute method ...

return new ActionForward(redirect);

Where redirect is a URL to a site potentially different than that of my server. Is it possible to detect a timeout from that site and if so, redirect the user to a page of my choosing? If it is possible, how can I set the timeout wait period?

Thanks, - Dave
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

ActionForwards are from Struts 1. That code won't have meaning.

Forwards and redirects are very different things: forwards include the content of another webapp resource in the current response; AFAIK they have to be local to the webapp. Redirects instruct the browser to request another resource, which may be local or remote.

If you're actually talking about redirects, then timeouts are detected by the *client*, not the server. In order for the *server* to detect a timeout it would have to create its own request (through, for example, an HttpClient). If you're actually talking about a forward, then I'm not sure if it's possible; I've never tried to forward to a non-local resource.

But the bottom line is that at some point you have to decide if you're using Struts 1 or Struts 2.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
If the code I included will not work in Struts 2, what is the proper way to do a forward? - Dave
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Struts or no, it sounds like you want to do a redirect. At least if you're sending the request off to another URL which isn't in your application, you're going to have to do a redirect. And as David Newton, said, what happens when you do that is that you reply to the browser with a code which says "Go to this other URL instead". Once you reply, that's it. Your code is finished. The browser may or may not be able to connect to that other URL, but there's nothing your code could do about it. Doesn't matter what version of Struts you're using or even if you're not using Struts at all.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The correct way to do a "forward" is to define a "dispatcher" result type in your action's configuration (XML- or annotation-based). You can include parameters in your result configuration, see here for general result configuration, and here for more information on parameter usage.

Again, I do not believe this will work with non-webapp resources, but maybe it will.

Do you have a working S2 application using ActionForwards?!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possible to detect timeouts upon forwarding requests?