Sounds like java sandboxing to me. i.e, you are running with a security manager that prevents connecting to that site. Applets, for example, are only allowed to make connections to the site they are served from.
B. On 28 October 2011 13:17, Gregory Hamel <[email protected]> wrote: > I'm testing couchDb for use in my java app and I can't seem to read document > attachments using plain old Java http. > > I have a good understanding of couch and for this test I've setup a new > dbase with a single doc having a single image attached. I can get the image > from couch using a browser and using curl, both without authentication, so I > know that my uri is correct and I know there is no security on the dbase. > > However.. When I try to read the image using java i get a permission denied > exception at the socket level and the Erlang console (ya its windoze) > doesn't log anything at all. Yet this code *will* pull an image from another > website. > > Is there some additional header that I need to setup on my connection before > connecting? > > Here's the relevant portion of my code and the resulting stacktrace.. > > // this fails > try { > URL u = new URL("http://192.168.1.7:5984/test/img/jv0h.jpg"); > HttpURLConnection conn = (HttpURLConnection)u.openConnection(); > conn.setRequestMethod("GET"); > conn.connect(); > image1 = ImageIO.read(conn.getInputStream()); > } catch (IOException e) { > e.printStackTrace(); > } > > // and this fails > try { > URL url2 = new URL("http://192.168.1.7:5984/test/img/jv0h.jpg"); > image2 = ImageIO.read(url2); > } catch (IOException e) { > e.printStackTrace(); > } > > // but this works > try { > URL url2 = new URL("http://java.com/images/jv0h.jpg"); > image3 = ImageIO.read(url2); > } catch (IOException e) { > e.printStackTrace(); > } > > > javax.imageio.IIOException: Can't get input stream from URL! > at javax.imageio.ImageIO.read(ImageIO.java:1395) > at test1.ShowImage.<init>(ShowImage.java:25) > at test1.ShowImage.main(ShowImage.java:40) > Caused by: java.net.SocketException: Permission denied: connect > at java.net.DualStackPlainSocketImpl.connect0(Native Method) > at > java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180) > at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) > at java.net.Socket.connect(Socket.java:579) > at java.net.Socket.connect(Socket.java:528) > at sun.net.NetworkClient.doConnect(NetworkClient.java:180) > at sun.net.www.http.HttpClient.openServer(HttpClient.java:388) > at sun.net.www.http.HttpClient.openServer(HttpClient.java:483) > at sun.net.www.http.HttpClient.<init>(HttpClient.java:213) > at sun.net.www.http.HttpClient.New(HttpClient.java:300) > at sun.net.www.http.HttpClient.New(HttpClient.java:316) > at > sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:992) > at > sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:928) > at > sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:846) > at > sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1296) > at java.net.URL.openStream(URL.java:1035) > at javax.imageio.ImageIO.read(ImageIO.java:1393) > ... 2 more > >
