Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible to detect timeouts upon forwarding requests?

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the code I included will not work in Struts 2, what is the proper way to do a forward? - Dave
 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic