Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Can't Get a Response Using URLConnection After Upgrading from JDK1.3 to JDK1.4

Posted on 2011-03-19
9
Medium Priority
?
532 Views
Last Modified: 2012-05-11
We've been frustrated with this problem for days and I'm running out of ideas. We have a servlet running under JDK1.3 and Tomcat 4.0.6 on a Windows 2003 server. We need to upgrade it so that we can talk to a server with an EV SSL cert. We thought this would be a slam-dunk, but after we recompiled in JDK1.4 and made the necessary tweaks to account for the JDK1.4 changes, we can't use URLConnection to the https or http port of an external site. We tested making a simple http connections to yahoo.com and google.com and nothing comes back. When we use our code to make an http connection to an internal site, everything looks good.

This feels like a firewall issue, but we can't get our heads around why a firewall is preventing responses from an internal request. We're using a CISCO ASA 5505 firewall and see nothing in the logs that jump out at us.

We're stumped. Is this a jdk issue? Why was this working perfectly in jdk1.3 and can't work in jdk1.4?

Any suggestions? We've exhausted all our ideas. Thanks.
0
Comment
Question by:lostinqueens
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 4

Expert Comment

by:sgvill
ID: 35174019
don't know if this will work, but try the URL with and without the ending slash
0
 
LVL 92

Expert Comment

by:objects
ID: 35174094
what response code are you getting?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35174281

Are you specifying the proxy?
http://www.rgagnon.com/javadetails/java-0085.html

I remember in some cases when I was trying to connect to outside
with Java it didn't want to do it without specifying proxy.

I think more recently I haven't encountered that issue,
maybe they changed something in our company,
but there were times when I could not do it directly.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 27

Expert Comment

by:mrcoffee365
ID: 35175975
There were some possibly minor changes in UrlConnection behavior between JDK 1.3 and 1.4.  You need to post the exception you're getting, and the code with the line number noted in the exception for us to help solve the problem.

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35183221
It's conceivable your jre network settings have not been replicated for  your new jre. They are not replicated automatically
0
 

Accepted Solution

by:
lostinqueens earned 0 total points
ID: 35195127
Thanks for everyone's suggestions. We finally figured out our problem. With JDK1.3, only the http/1.0 protocol is used. So, when we made our request with JDK1.3, http/1.0 was used and the *entire* response was sent back at once with a content-length header. We were able to read the content-length header and know how big of a response we received.

With JDK1.4, either http/1.0 or http/1.1 can be used, but you can't decide which protocol is actually used. With http/1.1, the data comes back in chunks and thus, the content-length header does not provide information on the entire response. We modified our code to no longer look at content-length header but instead continue to read the response we receive until there is no more response and we know we've captured everything. We used ByteArrayInputStream similar to what's mentioned in this post: http://stackoverflow.com/questions/719107/java-urlconnection-http-1-0.

I believe our code worked when testing against an internal server because the internal server saw the request as coming from the internal network so decided to use http/1.0, but when the same server saw a request coming from an outside network, it decided to chunk the response using http/1.1 and thus our code failed.

So, in the end, our problem was an http/1.0 vs. http/1.1 issue and a thinly documented change to URLConnection from JDK1.3 to JDK1.4.
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 35195846
Thanks for posting the solution.  Next time -- post the exception and your code, and we'll be able to help.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35196429
>>
With http/1.1, the data comes back in chunks and thus, the content-length header does not provide information on the entire response. We modified our code to no longer look at content-length header but instead continue to read the response we receive until there is no more response and we know we've captured everything.
>>

Two points there:

a. The Content-Length header should  report on the length of what is requested whether it's chunked or not, whichever version of HTTP
b. You can't rely on Content-Length being set, whichever version of HTTP

You thus need to read to EOS every time
0
 

Author Closing Comment

by:lostinqueens
ID: 35225502
Not an easy problem to track down. Hopefully, few have suffered with this issue as long as we did.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For months I had no idea how to 'discover' the IP address of the other end of a link (without asking someone who knows), and it drove me batty. Think about it. You can't use Cisco Discovery Protocol (CDP) because it's not implemented on the ASAs.…
In this article, the configuration steps in Zabbix to monitor devices via SNMP will be discussed with some real examples on Cisco Router/Switch, Catalyst Switch, NAS Synology device.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question