aspose file tools*
The moose likes Security and the fly likes Exception: Server redirected too many  times (20) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "Exception: Server redirected too many  times (20)" Watch "Exception: Server redirected too many  times (20)" New topic
Author

Exception: Server redirected too many times (20)

Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
Hi all,

I am working on a standalone application which reads the data from a web page with the help of URL and automatically writes it to an Excel sheet at regular intervals.
This application is helped by another single sign-on application and requires a pair of username/password for accessing webpage's details.
But I am getting the exception: "java.net.ProtocolException: Server redirected too many times (20)"
What is the meaning of this exception?wheather it is showing an authentication problem or something else?I have googled it lots of time but I havn't got any satisfactory answer for this problem!
Also tell me how it can be removed?Does it requires code changes at server side also?
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
Check you server program if it is properly coded. There could be loops or non-properly-terminated http request methods. If the code is small, you can post it here.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
The most likely reason is that one of the involved servers sets cookies, and the other one doesn't receive them. That's no surprise, as the code you posted doesn't handle cookies at all. See this article for how to do that.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
thanks for replies,Ulf and Jesus......
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
Hi Jesus and Ulf,
I am pasting here server side code.There are total four classes in server side code(three servlets,one java class).main servlets of server side code are RedirectToIdpServlet and RedirectToSpServlet,As their names are telling I am suspecting some loop or redirection in code but exactly not getting "where this loop is and how it would be removed",as I am not aware of server side appliaction,seeing it first time.I am pasting the codes for "RedirectToIdpServlet" and "RedirectToSpServlet" here.The only thing I can tell is, "The client request first goes to RedirectToSpServlet".
Please see these code snippets and tell if any suspected thing is found and how it can be resolved.

RedirectToIdpServlet



RedirectToSpServlet


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
I am pasting the codes for "RedirectToIdpServlet" ... here.

Not yet.

What is "registerPrincipalURL" - is that a destination that's under your control?

Have you used an HTTP monitor (like the Firefox extension LiveHttpHeaders, or WireShark) to investigate what's going on?
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
I think I have posted the code.I am not aware about the functionality of this cod, somebody else has developed this code.
From the code of "RedirectToSpServlet",I guess, it should be part of redirected URL(Originally requested URL from user's side+registerPrincipalURL).
I havn't used any of the tools.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
I think I have posted the code.

You posted a class called "RequestHack" which is not a servlet.

I am not aware about the functionality of this cod, somebody else has developed this code.

Have you been in touch with that person yet? That would seem the logical first step.

I havn't used any of the tools.

Then I advise to start with that so you get a better understanding of what's going on at runtime, like which URL redirects to which other one in which sequence.

From the code of "RedirectToSpServlet",I guess, it should be part of redirected URL

That much is obvious. But unless you know which piece of code can redirect to *where* under *which* circumstances, AND you know what is exactly happening at runtime, there's not much chance of this getting resolved, certainly not by anyone in this forum who doesn't have access to any of that information.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
Sorry for inconvenience Ulf,The code for RedirectToIdpServlet has been given below-



I am not in touch with concerned person at present.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
OK. We still don't know what the values of "idpURL" and "registerPrincipalURL" are, and we don't know which URLs these two servlets are mapped to, though. Be sure to let us know the values of the query parameters as well, since those are used to determine to where the redirect should happen.

We also don't know between which URLs the redirects occurs, but I'm assuming you're working on finding that out. Should be easy using the tools I mentioned; the Firefox extension is quite simple to use.

Let us know once you have all this information, and we can take it from there.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
thanks Ulf,Surely I'll notify as I finish.
Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 126
    
    5

Thanks for this posting. I recently had the same error suddenly occur reading a website I have been reading for years. The suggestion about the CookieManager resolved the error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception: Server redirected too many times (20)