on 06-25-2009 11:03 PM
Hello
I´m building a simple servlet that retrieves Cookies information of a website and displays in the screen. I´m using the following code to retrieve headers:
HttpURLConnection urlConn;
URL url= new URL ("http://mywebsite");
urlConn = (HttpURLConnection) url.openConnection();
String testHeader = urlConn.getHeaderField(2);
out.println("Key: " + testHeader);
When I run this code locally, it runs perfectly and fast. When I run on J2EE Server SAP, the getHeaderField line takes about 3 minutes to end. I changed the code to show the current time before and after the "print" of Header. The result is:
Thu, 25-Jun-2009 18:53:21
Key: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8k mod_jk/1.2.28
Thu, 25-Jun-2009 18:56:31
If I take the line of "getHeaderField" off, the program runs fast.
Does anyone have an idea of what´s going on ? I´m using J2EE SAP Server of Netweaver 7.0 (sp13)
Thanks
Edited by: vitorz on Jun 26, 2009 12:05 AM
Edited by: vitorz on Jun 26, 2009 12:05 AM
Hi,
Please try the below code to display the headerfield info.
>for (int j = 1; ; j++) {
>header = uc.getHeaderField(j);
>if (header == null)
>break;
>System.out.println(uc.getHeaderFieldKey(j) + " " + header);
>}
Regards,
Muthukumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
I got the same result. Running it locally, its runs instantly, but running from j2ee server it took 3 minutes to get the first header. From second to last, it was instantly.
08:59:10
Header 1: Date Fri, 26 Jun 2009 11:57:54 GMT
09:02:20
Header 2: Server Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8k mod_jk/1.2.28
09:02:20
Header 3: Cache-Control no-store
09:02:20
Header 4: Pragma no-cache
09:02:20
Header 5: Expires Thu, 01 Jan 1970 00:00:00 GMT
09:02:20
Header 6: Set-Cookie JSESSIONID=cx5fp98pu7;Path=/
09:02:20
Header 7: Servlet-Engine Tomcat Web Server/3.3.1 Final ( JSP 1.1; Servlet 2.2 )
09:02:20
Header 8: Content-Length 4540
09:02:20
Header 9: Keep-Alive timeout=5, max=100
09:02:20
Header 10: Connection Keep-Alive
09:02:20
Header 11: Content-Type image/jpeg
09:02:20
Hi vitorz,
it depends on the underlying implementation of the java.net API, but it looks like the openConnection method doesn't do a lot. Then the 1st time the getHeaderField method is called, an actual network connection is made and the entire response is read. After that, the headers are cached. Apparently the server has an issue while connecting to the URL you specified. There could be many reasons for that, e.g. firewalls, proxies etc. This looks like a network issue to me. Is it correct you're requesting an image over https? Not that there's anything wrong with that...
Kind regards,
Sigiswald
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.