Authenticator Problem: ProtocolException: Server redirected too many times

My program needs to login to a certain website, and I'm using Authenticator to do this. If I supply valid credentials this works fine. However, my program needs to handle the case of the user entering invalid credentials. The site responds to invalid logins by redirecting to itself. If I type the URL into a browser, I get a login prompt, and if I enter an invalid login, it just reloads the page and gives me a new login prompt.
Since java automatically tries to login to every page with the given authenticator, it gets stuck in a loop. Login, redirected to same site, login again, etc. until this exception is thrown:
java.net.ProtocolException: Server redirected too many times (20)
What's the best way to handle this? I've tried adding HttpURLConnection.setFollowRedirects(false); but it doesn't seem to work (it still redirects).

The URL I'm connecting to is http://webservices.schedulesdirect.tmsdatadirect.com/schedulesdirect/tvlistings/xtvdService
Here is my code. Right now it's set to assume an incorrect login if there was a redirect. It works, but it's not ideal imo.
public int grabListings(InputSource listingsSource, Calendar start, Calendar end, URL serverURL,
               String username, String password, Progress progress){
          Authenticator.setDefault(new TVAuthenticator(username, password, this));
          int response=-1;
          try {
               //HttpURLConnection.setFollowRedirects(false);
               progress.progressMessage = "Connecting to Schedules Direct";
               conn = (HttpURLConnection) serverURL.openConnection();
               conn.setRequestProperty("Accept-Encoding", "gzip");
               conn.setRequestProperty("SOAPAction", "urn:TMSWebServices:xtvdWebService#download");
               conn.setRequestMethod("POST");
               conn.setDoInput(true);
               conn.setDoOutput(true);
               //conn.setRequestProperty("Authorization", "digest "  + (new sun.misc.BASE64Encoder().encode(
               //          (username + ":" + password).getBytes())));
               //conn.setInstanceFollowRedirects(false);
               PrintWriter pw = new PrintWriter(conn.getOutputStream());
               pw.println(buildDownloadSOAPEnvelope(start, end));
               pw.flush();
               pw.close();
               BufferedReader br = null;
               String enc = conn.getHeaderField("Content-encoding");
              if (enc != null && enc.equals("gzip")) {
                  br = new BufferedReader(new InputStreamReader(new GZIPInputStream(conn.getInputStream()), "UTF-8"));
              else {
                   br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
              progress.currentProgress = 5;
              progress.progressMessage = "Downloading listings";
              response = conn.getResponseCode();
              System.out.println(response);
               if (response == HttpURLConnection.HTTP_UNAUTHORIZED) {
                    return GRABBER_UNAUTHORIZED;
               if (response == HttpURLConnection.HTTP_OK) {
                    listingsSource.setCharacterStream(br);
                    return GRABBER_OK;
          catch (UnknownHostException e) {
               return GRABBER_CONNECTION_ERROR;
          catch (IOException e) {
               if (redirected) return GRABBER_UNAUTHORIZED;
               else e.printStackTrace();
          return GRABBER_UNKNOWN_ERROR;
     private class TVAuthenticator extends Authenticator {
          private String username, password;
          int count=0;
          HttpGrabber grabber;
          public TVAuthenticator(String user, String pass, HttpGrabber _grabber) {
               username = user;
               password = pass;
               grabber = _grabber;
          protected PasswordAuthentication getPasswordAuthentication() {
               if (count > 0) {
                    grabber.setRedirected(true); //If we were redirected, that means the login failed
                    return null;
               count ++;
               return new PasswordAuthentication(username, password.toCharArray());
     }Edited by: sureshot324 on Oct 15, 2009 10:42 PM

Similar Messages

  • JSP bug? url.openStream() = server redirected too many times

    I tried something the other day that works in Java, so it should work as a JSP scriptlet, but I received an error message that others have posted elsewhere without a compete resolution. Specifically, given a URL, say u, one ought to be able to do u.openStream() and eventually read the remote page. Typically, one might want to try
    URL u = new URL("http://someserver.com/path/file.xxx")
    BufferedReader bfr = new BufferedReader(new InputStreamReader(u.openStream()))and then read bfr line-by-line. The problem that seems to be fairly common is that the openStream() call throws a ProtocolException claiming "server redirected too many times (20), ."
    What I've seen is that this exception occurs whenever the URL is outside the Tomcat server whence the call is being made; in our case, we're running "out-of-the-box" Jakarta Tomcat 4.1.29 on port 8080 of a w2k server. The code works perfectly in native Java and in JSP for a URL of the form "/anotherpage.jsp"
    Is this a bug in JSP, or in our version of Tomcat, or is there just some configuration parameter that needs to be changed from its default? As I said, I've seen similar posts (with less detailed analysis) in the Usenet newsgroups, but not one has generated a response that explains and resolves the matter.
    Perhaps a JSP guru out there could set the record straight? Thanks.
    P.S. I know that the use of scriptlets in JSP is being discouraged, but they are still supported AFAIK.

    Sure scriptlets are still supported. Most times though you can do things better with a custom tag. Why reinvent the wheel?
    Just as a suggestion, you might try the JSTL <c:import> tag.
    It basically does just this behind the scenes.
    However I don't think that will help you in the end - it will probably hit the same error message.
    My guess would be that the problem is not caused by java/JSP as such, but by a firewall, or configuration somewhere.
    The following works fine for me (ignoring broken images of course)
    <%@ page import="java.net.*, java.io.*" %>
    <%
    URL u = new URL("http://www.google.com");
    BufferedReader bfr = new BufferedReader(new InputStreamReader(u.openStream()));
    String line = null;
    while ((line = bfr.readLine()) != null){
      out.println(line);
    %>Hope this helps,
    evnafets

  • IChat Error: "attempted to login too many times" problem/solution

    *I don't know if its okay to post a new topic/question then answer it, but i was having this issue and finally found a resolution so i wanted to share it with everyone.*
    _*Your problem:*_ You Log into ichat then it suddenly begins to act crazy- logging in and out multiple times for no apparent reason... then its gives you the message, yes THE message "You have attempted to login too often in a short period of time. Wait a few minutes before trying to login again".
    You silently think to yourself, "w.t.f". lol.
    Okay, well different things worked for different people, it just depends on the time, the moment, and whether or not ichat wants to act right...
    SOLUTIONS:
    1. Change to SSL
    Go to iChat Menu --> Preferences --> Accounts --> Server Settings --> then check "Use SSL"
    2. Use Port 443
    iChat--> Preferences--> Server Settings --> Use port "443"
    3. Delete the user from my ichat accounts, by pressing the minus sign. Then waiting a couple minutes just to make sure that I would not get the logged in too many times error and re added the account.
    *4. THIS SHOULD MOST Definitely WORK:
    1.) Quit iChat if it is already open, and then open Finder.
    2.) Browse to your user folder (can be found by clicking on your main hard drive, then going to Users > Your Username.
    3.) Open the Library folder and go to the Preferences directory.
    4.) You’ll see a long list of files with a .plist extension. The one we’re looking for is com.apple.iChat.AIM.plist. When you find it, delete it by dragging the file to the trash.
    5.) Launch iChat and this time you should be able to sign in to your AIM account successfully. iChat will automatically rebuild the preference file you deleted.
    _*More INFO:*_
    Now some people may wonder "Why is this happening to me" I'll tell you why:
    The cause of the issue most likely roots from using your Mac at multiple locations (such as home, school, or work), which could lead to the preference files somehow getting corrupted. It sounds serious, but really shouldn't take more than a minute or so to resolve. Just follow the above steps...
    I wish I could take credit for all these, btu I just pulled them from different sites and forums, including forums.macrumers.com and macyourself.com
    I hope this helps someone out there Good Luck.
    Oh and feel free to add other ways to fix this weird issue.

    Also look at http://discussions.apple.com/thread.jspa?threadID=1462798
    The Apple Article on the related Issue
    http://support.apple.com/kb/TS1643
    10:24 PM Saturday; June 6, 2009
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
    Message was edited by: Ralph Johns (UK)
    Corrected link

  • I tried changing my password, and it changed to one that wasnt it, and i dont know it. So i tried it too many times and now its saying it is disabled, connect to itunes. but a problem is that my power button on top is broken. how to i fix it?

    I tried changing my password, and it changed to one that wasnt it, and i dont know it. So i tried it too many times and now its saying it is disabled, connect to itunes. but a problem is that my power button on top is broken. how to i fix it?

    Disabled
    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen                         
    If recovery mode does not work try DFU mode.                        
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: How to back up     
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        

  • My iPad says that I have authorize too many times what can I do to fix this problem?

    MY iPad says that I have authorized it too many times, how do I fix this problem?

    OverDrive has its own application for its media. See <http://omc.overdrive.com/v3-available-now/ios.php>. This has nothing to do with the Adobe Reader for iOS. Sorry!
              - Dov

  • SQL query runs too many times in SQL server Profiler

    Hi Experts
    I have designed a report using SQL database.Report is based on Add Command Object, View and Table.Which are link and gives desired output.
    However it takes long time. In the SQL Sever profiler it shows that query is executing too many times.
    When in the Add Command object I edit the query Say I write TOP 5000 then it executes once however if I write Add 5001 then I face the same behavior.
    I have checked "Grouping on server" option in options.
    Please Advice.
    Regards
    Asha.

    Thanks Raghavendra for reply
    How adding group will help? I have to link this command objects with view and table.Also  When I add "TOP 5000" in add command query it executes only 1 time in SQL query Profiler hower if edit that query to "TOP 5001" then it again it executes several time which is impacting the performance.
    Please advice?
    Regards
    Asha.

  • I have been getting this message " no sim installed " too many times then my phone goes off , its iphone 4S , its really a problem i cant get calls or anything and im not sure how to take the SIM out then insert it again , what to do ??

    i have been getting this message " no sim installed " too many times then my phone goes off , its iphone 4S , its really a problem i cant get calls or anything and im not sure how to take the SIM out then insert it again , what to do ??

    Use the sim tool that came with your phone or a safety pin and just insert it into the hole at the side of the sim tray and push it in and then pull it out.  It is no more difficult than that and then just close it again.

  • Says I tried to log onto AIM too many times.

    I just upgraded my wife's G4 iBook to Leopard and am trying to get the iChat AV to work. I am using a USB cam with iChatUSB and Macam and the camera is working fine. I can get the camera to work over Bonjour to my G5 iMac (also just upgraded to leopard and also using a USB camera with the same set-up). When she tries to do a video or text chat over her AIM account we get an error message saying that she has tried to log on too many times in a short period and to try back later.
    Just to see if her account was locked I wen to the AIM web site and can log in with her ID and password with no problems.
    I have waited over an hour and we are still getting the message. Any suggestions on how to unlock this?
    Thanks,
    David

    I may have found a fix:
    When I went to my ichat pref. I found one difference between the account i was using and the other account I tried. In the sever settings section it lists this for the server slogin.oscar.aol.com the account i was trying to log onto didnt have the first "s" and the SSl box wasn't checked. I tried adding the "s" and checking the box and it fixed things.

  • Upgraded too many times???

    i have recently upgraded my itunes to version 6 or whatever is the latest. after i had done this i decided to upgrade the software on the computer using the 'software update' option. little did i know, the updater updated my itunes. this is a second update, but two different ways. my question is, is it possible to update a program too many times and it getting corrupted or doing too many things? and when a program is updated where does the old version go? does it get stored or thrown out (i am concerned that if the old versions are stored that it would just take up space)?

    When Software Update runs, it will only offer newer versions of installed software.
    This normally does not corrupt the system or applications.
    Sometimes applications are updated and sometimes completely replaced.
    Old files are always deleted, so they don't take precious HD space.
    Did you encounter problems with the iTunes update?
    It's a good habit to always run Disk Utility and perform a 'Repair Disk Permissions' before and after installing/updating software.
    This routine maintenance prevents most troubles.
    M

  • Error saying "this ID has been authorised too many times" , how to resolve ASAP?

    Error saying "this ID has been authorised too many times" , how to resolve ASAP?

    Adobe Live Chat: http://www.adobe.com/support/chat/ivrchat.html
    They can reset your authorizations, and then you must reauthorize any devices you still need.
    (Unfortunately, Adobe haven’t got round to an admin website for viewing and editing authorizations.)
    Some of the representatives haven't been properly trained and don't know what to do (and claim there is nothing they can do);
    in that case the only way seems to be to give up that chat and try another session hoping for a properly trained representative.
    If your problem is with another device using Overdrive, Bluefire, Aldiko or similar third party app, it is recommended not to mention that app when on the chat, just mention that you have run out of authorizations  (E_ACT_TOO_MANY_ACTIVATIONS) .  Thanks to AJP_Bear for that tip.

  • Your password has been incorrectly entered too many times. Go to the...

    "Your password has been incorrectly entered too many times. Go to the iTunes Store on your computer and retrieve your password."
    I keep getting this message, but when I go to iTunes, it lets me in with no problem and I don't know where I should be going to retrieve my password. Additionally, my Mac-based iTunes Library keeps disappearing from the Apple TV menu and today it started streaming (videos from my iTunes library) extremely slowly for some reason which I cannot discern. I don't know what the problem is, but my daughter is getting very frustrated that Word World keeps pausing every minute or so to buffer.
    Any help would be fantastic!

    I, too, am getting this error. Mine is on my Apple TV (black) and seems to happen any time I switch between items on the main menu screen. Apple recently prompted me to change my password for my Apple ID account. However, when I get this error message, I just select 'OK' and go on. It does not seem impact watching any content streamed from my Mac nor does it impact accessing Netflix...
    Other than being a nuisance, I haven't been able to find what is causing it and what limitations are resulting from it. I'm also not sure where I can go to update the password this Apple TV is using.
    Thanks for any help you may provide.

  • Entered wrong network unlocking code too many time...

    Hopeing that you can help. My phone is a lumia 610 locked to the optus network. I accidentally entered the wrong network unlocking code too many times. The phone now blocks any sim card that I put in it. Asks for a PUK code. I got the PUK code from optus, entered it into the phone and it didn't work. I then took my phone into an Optusstore for assistance. They entered the PUK for me and it also didn't work. They then put other sim cards in the phone and it still asks for a PUK code. They tried entering the PUK code for these other SIM cards but it didn't work either. They then put these SIM cards in another phone to test and it worked no problem.
    What's happened to my phone and how do I get it fixed?

    The PUK code relates to the phone only. If you feel that the phone has somehow got "stuck" as you put it and want to try something yourself, then you could try the soft  reset or even the hard reset. Note that you will loss all your data and settings unless you have a previous backup.

  • Attempted to Install 2.3 upgrade,installer folder installed into harddrive but application will not open or replace 2.0 as it says it "should" . I have tried too many times now. Always same response.

    I installed 2.3 upgrade,
    installer folder is in  harddrive but application will not open or replace 2.0 as it says it "should". When I attempt to it just reinstalls the installer, never the functioning application.  I have tried too many times now. Always same response. WOuld love to upgrade ( and purge all the alias 2.3 off hardrive!

    when I went to the library folder there was no receipts only 
    com.adobe.Reader whihc included install.log
    so I guess that means something is missing?
    If above still doesn't resolve problem - go to the folder named 
    "Receipts" in the Mac OS X Library folder (i.e. the main Library 
    not you Users Library) and delete the file named Adobe Photoshop 
    Lightroom 2.pkg
    >

  • Have I removed and re-installed iMovie too many times?

    iMovie09 won't show anything in my Preview Browser when I upload a video clip or a still image. Could it be that I've installed it too many times on my computer? It worked orginally when I installed it and used it with an Aperture demo, but when I tried to use it with iPhoto, it wouldn't work. So I removed Aperture and iMovie and re-installed iMovie but it didn't work then and hasn't after two more removals and re-installations. Could I have used up the number of times I can install iMovie using a 5-time "Family Pack"? When I install the iLife09 disk, iMovie and iPhoto are greyed out and cannot be selected.
    Thanks for the help.

    I took my computer into the Genius Bar today and three guys couldn't figure out why iMovie wouldn't show me any previews. So I brought it home, backed it up again and got ready to erase the hard drive and start over. But first I decided to just reinstall SnowLeopard and upgrade it to v. 10.6.3 v1.1 and then did a full Software Update after that, and guess what. iMovie now works the way it's supposed to. It didn't matter how many times I'd reinstalled iMovie and upgraded iMovie. It was a OSX system problem. Take heart, all you SnowLeopard users.

  • IChat won't connect to AIM. It says I tried to login too many times.

    I was randomly using my comp when i tried to login to iChat and it tried to login several times. After it got done freaking out it suddenly said that i couldn't connect to AIM because i tried to login too many times and that i need to wait a few minutes and try again. I've tried deleting the .plist files and have also tried setting the port to a different one. It keeps coming up with the same error. Is there anyone who is also having this problem and might be able to suggest some solutions? Thanks

    I take it you are trying port 443.
    Try it without the SSL Login
    Also try deleting the com.apple.iChat.AIM.plist and com.apple.iChatAgent.plist together.
    Don't forget to restart iChat.
    9:03 PM Saturday; February 16, 2008

Maybe you are looking for

  • Attempt to set a parameter name that does not occur in the SQL: vc_temp_1

    I have query view object build on the following sql select nvl(u.full_name,e.arabic_first_name||' '||e.arabic_family_name) as empName, (select sc.general_specialty from ta_scientific_certificate sc where sc.user_id=u.user_id group by sc.general_speci

  • Can you change the line spacing in the legend?

    Is there a way to change the line spacing in the legend? I have a pie chart with text and I can't change the line spacing for its legend like you would in a regular text. Is there a way to change it?

  • How do I get ipad to recognise my wifi?

    how do I get my new Ipad to recognise my wifi?

  • Boot from FW 800?

    I've a strange issue with a Western Digital Passport III external drive. It has both FW800 and USB2 connections. I've installed SL 10.6.4 on it and would like to boot my MacPro Quad with it. It will boot fine via USB, but will not boot when connected

  • Reg - SAP Application not UP...

    Hi Gurus,    I'm n the DRP Testing.  I restore the PRD data in one testing server. successfully restore and  I compare the Testing system to PRD System.  All things ok, but never connect the application. Pls advise how to up the Application.. In insi