Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Based on the <a href="http://docs.oracle.com/javase/7/docs/api/" rel="nofollow">Java 7's Javadoc</a> of <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html" rel="nofollow">URLConnection</a> there are two possible reasons this is happening. </p> <p>The first possible cause is that the content length is greater than Integer.MAX_VALUE. To determine if this is the issue I would use <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html#getContentLengthLong%28%29" rel="nofollow">getContentLengthLong()</a> because this returns a long instead of an int and if the content length is greater than Integer.MAX_VALUE <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html#getContentLength%28%29" rel="nofollow">getContentLength()</a> will return -1. Also, since Java 7 it is preffered to use <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html#getContentLengthLong%28%29" rel="nofollow">getContentLengthLong()</a> over <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html#getContentLength%28%29" rel="nofollow">getContentLength()</a> as stated in the <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html" rel="nofollow">Java 7's URLConnection Javadoc</a>, "it returns a long instead and is therefore more portable." If you desire to use both JRE 6 and 7 I would create a Java 6 and 7 wrapper classes to create a set of methods that your application uses to interact with URLs. Than in your application's start script check if the host has JRE 6 or 7 and load the proper wrapper class according to the JRE version. This is generally a good design because it prevents your application from being dependent on one specific JRE, third party library or application, etc.</p> <p>The second possibility is that the content-length header field is not known by the server so the <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html#getContentLength%28%29" rel="nofollow">getContentLength()</a> or <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html#getContentLengthLong%28%29" rel="nofollow">getContentLengthLong()</a> method returns a value of -1. This is why I suggest trying <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html#getContentLengthLong%28%29" rel="nofollow">getContentLengthLong()</a> before anything else because it will probably be the quickest fix. If both methods return -1 I would suggest using an application like [Apache JMeter][11] to determine the header information. A quick way of doing this is to have JMeter "<a href="http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Proxy_Server" rel="nofollow">HTTP Proxy Server</a>" running with your browser's proxy settings set to go to use localhost as the address and the port you set the HTTP Proxy Server for the port. The information recorded will appear as individual elements themselves and if you expand them there should be a HTTP Header Manager that contains the name of each Header with its value next to it.</p> <p>Lastly, you may want to do analysis on the server itself to see if there are any issues. Verify logs look ok, that all the correct processes are up, configuration's are set correctly, the file still exists and is in the correct location, etc. Maybe the server is not set to respond to content length requests anymore. Also, verify if your code functions with JRE 7 on another host</p> <p>I hope these suggestions will be of value to you and that your are able to solve this issue you seem to be having. I would also note that you really should consider using a wrapper class and following the notes for each version of third party class that you use in the future so that you follow better practices that are easier to maintain like reducing the amount of external dependencies you have by using wrapper classes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload