cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the readLine() method when reading data from a URL?

Former Member
0 Kudos

Hello,

I have a URL which contains text input.

The only way to get the data from this URL is by opening a URL connection to it.

I would like to get the data from this URL but at the same time I would like to be able to use readLine() method of BufferedReader in order to read the data line by line.

My question is how do I combine between these two requirements in order to reed the data from the URL?

Roy

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Roy,

this becomes challenging

Ok, You must find the difference between Your standalone application and the portal.

The main difference is allways the classpath. Meaning that maybe the portal is using another implementation of URLConnection than Your standalone version.

I know that SAP use their own SSL libraries for example. Is Your URL an https url ?

If so there could also be differences in the awareness of server certificates.

Can you give me more details here, mabay I get an idea where you could look for.

Best Regards

Frank

Former Member
0 Kudos

Hi Roy,

hm strange ....

Two things:

1. What is Your portal version ? EP6 SP2 is running on JDK 1.3.1 whereas SP9 or higher runs on 1.4.X. Maybe there is a JAVA Version issue.

2. Is your portal server able to connect to the url via the network ? This is not allways the case due to firewalls, or proxy settings.

Good luck

Frank

Former Member
0 Kudos

Hello Frank,

1. I am using EP6 SP11 on the server and JDK 1.4.2 on my PC Client.

2. When I open a browser from the Portal Machine I a able to reach this URL. When I run the stand-alone Java app from the Portal machine I a able to reach the URL. Only when I run it as a DynPro app (meaning deployed as an ear file to the Portal) it fails to connect.

Strange I agree, but there also must be a solution to that...

Former Member
0 Kudos

Hello Roy,

can you try out this code.

URL yahoo = new URL("http://www.yahoo.com/");

URLConnection yc = yahoo.openConnection();

BufferedReader in = new BufferedReader(

new InputStreamReader(

yc.getInputStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)

System.out.println(inputLine);

in.close();

Regards,

Mohan R

Former Member
0 Kudos

Mohan,

This is the same code I am using already...

I am using with HttpURLConnection and not URLConnection but even if I try URLConnection it doesn't work.

Frank,

Here is some more info that might help you:

1. The application is working when I am aiming it to an outside URL, such as yahoo.

2. I am importing the same java.sun jars, so I don't know how SAP can use their own implementation.

3. The target URL I am pointing to is sitting inside of our LAN but on a different domain which is behind FireWall. Could it be that the InputStream is opening the connection on a port which is different than port 80 even though I am opening it through HttpURLConnection? But even if this is true, how is it working as a stand-alone...?

Former Member
0 Kudos

Roy,

It seems that your connection requires proxy host / port settings. These settings is supplied by default stand-alone JRE but not with JRE used by SAP WebAS.

VS

Former Member
0 Kudos

I tried to define our proxy through the System Object but this doesn't seem to help...

Former Member
0 Kudos

How you have done this exactly?

VS

Former Member
0 Kudos

Like this:

System.getProperties().put("proxySet", "true");

System.getProperties().put("proxyHost", "<proxy_ip>");

System.getProperties().put("proxyPort", "<proxy_port>");

Former Member
0 Kudos

Roy,

First try http.proxyHost and http.proxyPort.

Next, probably the following will be interested to you http://bdn.borland.com/article/0,1410,29783,00.html

VS

Former Member
0 Kudos

Hi Roy,

You could try the following.

if urlConnection is the URLConnection you have opened.


InputStream is = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
BufferedReader br = new BufferedReader(isr);

InputStreamReader is a bridge between byte data and char data. But again you could run into encoding issues.

In my example I am using the charset "UTF-8". You must be sure whether this is the correct charset of Your input.

Best Regards

Frank

Former Member
0 Kudos

10q Frank for your kind help

Former Member
0 Kudos

Hello Frank,

I have a strange problem with your code sample:

When I run it from my client computer as a standalone Java application it is working but when I deploy the same code to the Portal it fails at this line:

InputStream is = urlConnection.getInputStream();

The Error message is:

"Server returned http response code: 503 for URL...."

503 means that the URL can't be found on the target server but if this is true than how can it be that it finds the same URL on the same Server when I run the same code as a standalone Java application?

Any ideas...?

Former Member
0 Kudos

Oh and one more thing: When I open a browser from the Portal Server I am able to reach the problematic URL...