Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

"Server redirected too many times (20)" problem

Posted on 2006-07-10
22
7,314 Views
Last Modified: 2011-04-14
I'm trying to open a URL using HttpsURLConnection, but once in a while I got this message: "Server redirected too many times (20)". What can I do about this? Is this usually something wrong with the java code or the website setup?

Thanks in advance for the help
0
Comment
Question by:rnicholus
  • 7
  • 5
  • 5
  • +2
22 Comments
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 150 total points
ID: 17075332
Usually happens when you are missing some of cookies server needs.
Try using jakarta-httpclient, it has cookie handling
http://jakarta.apache.org/commons/httpclient/
0
 

Author Comment

by:rnicholus
ID: 17075399
Hi Ajay-Singh,

Thanks for your reply.
I don't understand how this is related to the cookies server needs. Could you please explain more?
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17075525
yes. there could be 2 cases:
1. server needs a cookie that client is not sending and server redirects (after adding some cookies) to some page. When client ignores the second page - it leads to infinite redirection.
2. The server is not configured correctly. Like when we try to download page x.html, it redirects to y.html. When y.html is asked it redirects to x.html
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:rnicholus
ID: 17075580
Ajay-Singh,

1. What do you mean by "client ignores the second page."?
2. If it happens very random and only once in a while, isn't it unlikely that the server actually needs the cookie?

Thanks for the on-going help.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17075615
> What do you mean by "client ignores the second page."?
sorry about typo - i mean when client ignore the cookie sent my the server in the redirection response.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17075627
> If it happens very random and only once in a while, isn't it unlikely
> that the server actually needs the cookie?
and are you able to download this page consistently from standard browsers (like IE)
0
 

Author Comment

by:rnicholus
ID: 17075712
One of my coworker have tried to access the page manually when the "Server redirected too many times (20)" message occurs in the program console output.
He said that he tried to login several times using username and pwd that has been provided to us but the page rejected the login.
And then it prints the exception below.

I'm not sure whether this is caused by my friends trying to login too many times or could be something else.

-----------------------------------------------------------------------------------------

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      ..........

root cause

java.lang.NullPointerException
      org.apache.jsp.error_jsp._jspService(error_jsp.java:415)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      ..........
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17075867
by any change you jsp redirects based on some condition? can you post that part of the jsp code?
0
 

Author Comment

by:rnicholus
ID: 17075928
That JSP exception is not coming from my program. What I have is a console-based program that access this page.

The JSP exception is what my friend see in the browser (I think he used Internet Explorer) when trying to access that page.
0
 
LVL 4

Assisted Solution

by:astorer
astorer earned 150 total points
ID: 17077641
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 150 total points
ID: 17078090
I think, you are looking for this,

try {
  URL url = new URL("yourURL");
  HttpURLConnection con = (HttpURLConnection) url.openConnection();
  con.setFollowRedirects(true);
  con.setInstanceFollowRedirects(false);
  con.connect();
 
  while (String.valueOf(con.getResponseCode()).startsWith("3")) {
     String theLocation = con.getHeaderField("Location");
     con.disconnect();
     url = new URL(theLocation);
     con = (HttpURLConnection) url.openConnection();
     con.setFollowRedirects(true);
     con.setInstanceFollowRedirects(false);
     con.connect();
     }
     /** at this point you are located at the last(target)page of
         redirection chain */
 
} catch (Exception ex) { ex.printStackTrace(); }

0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17078101
and this may also help you to increase the max redirects!

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4458085
0
 

Author Comment

by:rnicholus
ID: 17082360
ksivananth,
could you please explain to me what your code will do?

astorer,
i have seen the link before. i'm currently running the code the link provides -> just to know what URL I am being redirected to.
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17083497
It checks if the request is redirected, if so, makes a connection to the redirected URL! If your URL redirects more than 20 times, you may consider using the maxRedirects property.
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17083500
but did u try that?
0
 

Author Comment

by:rnicholus
ID: 17100848
I will try this code. I'll let you know
0
 

Author Comment

by:rnicholus
ID: 17131681
ksivananth,

i tried your code and when the exception occurs, it doesn't go inside the while loop.
any advice?

thanks
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17132252
>>i tried your code and when the exception occurs, it doesn't go inside the while loop.

what exception?

is it the "Server redirected too many times (20)"? if so, try set the "http.maxRedirects" property to large value!
0
 

Expert Comment

by:khimanijay
ID: 24261286
Check this out. Its the similar problem I face and here is the solution to it...
http://jaykhimani.blogspot.com/2009/04/problem-with-jdk-and-network-proxy.html
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
why cannot we forward request once the response is committed 2 46
Apps blocked by Java 9 88
oracle 11g 23 107
printf performancy 11 70
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question