In a Java app, should it be possible open a stream on a URL which has the same domain as the server running the app?
For example, I am running a Play! Framework app on:
http://www.my-domain.com/
And the URL I am trying to open an InputStream on is:
http://www.my-domain.com/public/zipfile.zip
When I try to access the inputstream via the URL openStream() method, the the app hangs (but still runs) and does not proceed any further (as if it has become locked).
The line of code causing the problem is as follows:
InputStream is = new BufferedInputStream(url.openStream(), 1024);
Extra Information
The code works as expected when accessing a URL from a different domain, eg:
http://www.different-domain.com/public/zipfile.zip
I have tried using 127.0.0.1, I have tried my network IP address and I have faked a real domain using hosts. None of these have worked, which leads me to believe this is a problem with a url being referenced from the same domain as the same as the app which is running it.
I’m not sure what you call ‘self referencing’ but if you mean that ‘server’ and ‘client’ are within the same application perhaps it’s threading issue (like the same thread is trying to read and write to the stream at the same time)? I would take a thread dump ‘jps’ then ‘jstack’ from command line while your application is running and see what thread is blocking on.