Go Premium for a chance to win a PS4. Enter to Win

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
?
529 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

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.

Question has a verified solution.

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

During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
As managed cloud service providers, we often get asked to intervene when cloud deployments go awry. Attracted by apparent ease-of-use, flexibility and low computing costs, companies quickly adopt leading public cloud platforms such as Amazon Web Ser…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

916 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