?
Solved

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

Posted on 2011-03-19
9
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

When speed and performance are vital to revenue, companies must have complete confidence in their cloud environment.
You deserve ‘straight talk’ from your cloud provider about your risk, your costs, security, uptime and the processes that are in place to protect your mission-critical applications.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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