on 02-15-2008 5:26 PM
Hello Experts,
I have a Web Dynpro Application in which in one of its views i have an IFrame UI element in which i will show a resource stored somewhere ..
But before showing it i want to check if the resource actually exists. For this i have to check the HTTP Response code from Web Dynpro Application without setting it in the Iframe..
I am using the following code to get the Response Code:
try{
URL url = new URL("Some Url");
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
wdComponentAPI.getMessageManager().reportSuccess("Response code ="+connection.getResponseCode());
}catch(Exception e){
wdComponentAPI.getMessageManager().reportSuccess("Exception");
}
Now the Problem is whatever response Code occurs 403 (for No Proper Authorization), 404 (for Resource not found) etc..
i always get Response Code= 500 (which is for Internal Server Error) shown in the messgae i have printed.
Please let me know the correct way of getting the Response Code from Web Dynpro.
Also my resource is lying on a SAP Portal 6.4
Best Regards
Sundeep
Edited by: Sundeep Sethi on Feb 18, 2008 9:07 AM
Edited by: Sundeep Sethi on Feb 18, 2008 10:23 AM
Hi,
Check this code from /thread/5242768 [original link is broken] if it works.
try{
URL myurl = new URL("http://calendar.google.com");
URLConnection connection = myurl.openConnection();
if(connection instanceof HttpURLConnection) {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
HttpURLConnection.setFollowRedirects(true);
httpConnection.setRequestMethod("HEAD");
httpConnection.connect();
System.out.println("Response = "+httpConnection.getResponseCode());
}
}
catch(Exception e) {
// print exception
}
Regards,
Harini S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Harini ,
First of all Thanks for your reply..
But the thing still does not wor...
The response code that is returned is 500 which is for Internal Server error..
What is happening is if there is any kind of problem in retreiving the document the server send 500 as response code and not 403 or 404 which is the actual problem...
Does this have to do something with the Portal server where my document is located ...
Will highly appreciate any help on this...
Regards
Sundeep
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
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.