cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Response Code when a URL is launched from Web Dynpro

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Your Portal server is most probably behind a firewall and thus you might need a proxy to be able to connect to the URL. You can get and set proxy settings using the System class.

Former Member
0 Kudos

Hello Pascal,

Thanks for your reply..

But can you please explain with an example of what exactly i need to do...

Probably some lines of code will help..

Regards

Sundeep

chintan_virani
Active Contributor
0 Kudos

Sundeep,

Check the example in this [Link|http://developer.apple.com/qa/java/java25.html]

Chintan

Former Member
0 Kudos

Try searching/google first please. You'll find lots of examples.

Former Member
0 Kudos

Hello Pascal,

My portal server is not behind any firewall..

Just thought u would like to know that from a Web Dynpro application u cannot get the correct response code by using the standard HttpUrlConnection approach..

And thanks for your invaluable advice of searching google first...

Sundeep

Answers (0)