on 08-20-2004 12:42 PM
Hi,
When i am trying to read a URL i am getting follwoing exception.
"ERRORjava.net.ProtocolException: Server redirected too many times (20)"
Code :
URL resutlsURL = new URL(file);
BufferedReader in = new BufferedReader( new InputStreamReader(resutlsURL.openStream()));
BufferedWriter out=new BufferedWriter(new FileWriter("c:/folder.xml"));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
out.write(inputLine );
}
in.close();
out.close();
Where file http://dptest:3080/WebAS/AUTOTEST/630_SP_TEST_2K/index.xml
Please let me know the solution.
Thanks & Regards
Anilkumar
Hi,
Please let me know how to do these setting in SAP J2EE engine.
Regards
Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Detlev ,
Thanx for your reply.
I have tried the code sent by you.
Its printing Responsecode as 401 and returning Null value for header.
I can able to open that XML though Internet Explorer.
I am using JDK1.4.2. Is there any dependency ??
Thanks & Regards
Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anilkumar,
401 is "Unauthorized". I don't know how the request is handled at your server, but there must be some authorization action. The "normal" behaviour for a 401 response is that the client may repeat the request with a suitable Authorization header field. Maybe (I'm not sure) Java in this case in fact tries to start the request again (but in fact without authorization). Maybe (again) this is counted internally as a redirect. If all this is the case, it would be obvious that this happens "infinitely" - here up to 20 times, than Java says "enough is enough".
So the next try should be:
a) Disable the Authorization action at server side.
OR
b) Add an Authorization header field (this would mean to open a regular HttpURLConnection as shown in the testing example).
Hope it helps
Detlev
Hi Anilkumar,
the code should work; the problem seems to be on the server, <i>it</i> seems to redirect.
Can you call the xml with your browser?
Maybe you can test this:
URL url = new URL(file);
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.println("Response code = " + connection.getResponseCode());
String header = connection.getHeaderField("location");
if (header != null) System.out.println("Redirected to " + header);
Hope this helps
Detlev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.