The Artima Developer Community
Sponsored Link

Java Answers Forum
java.io.FileNotFoundException: http://localhost:8080

16 replies on 2 pages. Most recent reply: Nov 27, 2005 9:16 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 16 replies on 2 pages [ « | 1 2 ]
Ahsan Safdar

Posts: 2
Nickname: cdbever
Registered: Nov, 2005

Re: java.io.FileNotFoundException: <a href="http://localhost:8080"><a href= Posted: Nov 24, 2005 8:19 PM
Reply to this message Reply
Advertisement
Ok here is the detail.
1. Yes the name of the servlet is ImageRetriever. The servlet fetches an Image from the database where it is stored as a blob.
2. I have tested the servlet by calling it directly from the browser using the URL http://localhost:8084/GEFT/ImageRetriever?imageId=1. This produces the required image in the browser.
2. Yes i am using the port 8084 for my TomCat server, which is integrated with the netBeans development environment i am using.
4. I have also tested calling this servlet from a .jsp page placed in the root (same directory as the applet) and it successfully connects with the servlet and receives the image data.
5. I port the same code (the one i tested in jsp page) to the applet making only minimal changes like using getCodeBase() to fetch the host name and port and suddenly it connects no more.

Here is a little more detail of the code i am using.
 protected Image getImage(String imageId) throws Exception {
        URL imageURL = new URL(getCodeBase(), "/GEFT/ImageRetriever");
        URLConnection connection = imageURL.openConnection();
 
        // Make sure browser doesn't cache this URL.
        connection.setUseCaches(false);
        // Tell browser to allow me to send data to server.
        connection.setDoOutput(true);
        
        // Grows if necessary
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512);
        // Stream that writes into buffer
        PrintWriter outstr = new PrintWriter(byteStream, true);
        String postData = URLEncoder.encode("imageId=") + URLEncoder.encode(imageId);
        
        // Write POST data into local buffer
        outstr.print(postData);
        // Flush since above used print, not println
        outstr.flush();
        // POST requests are required to have Content-Length
        String lengthString = String.valueOf(byteStream.size());
        connection.setRequestProperty("Content-Length", lengthString);
        
        // Netscape sets the Content-Type to multipart/form-data by default.
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        
        // Write POST data to real output stream
        byteStream.writeTo(connection.getOutputStream());
        
        connection.connect();
        
        [b]InputStream input = connection.getInputStream();[/b]
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        // set read buffer size
        byte[] rb = new byte[1024];
        int ch = 0;
        // process the data
        while ((ch=input.read(rb)) != -1) {
            output.write(rb, 0, ch);
        }
        // transfer to byte buffer
        byte[] b = output.toByteArray();
        input.close();
        output.close();
        // load final buffer to image Icon
        ImageIcon imgIcon = new ImageIcon(b);
        return imgIcon.getImage();
    }


The Exception comes in the line
InputStream input = connection.getInputStream();
.

Here is the Exception as it shows in the java console
java.io.FileNotFoundException: http://localhost:8084/GEFT/ImageRetriever
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at GEFTMain.getImage(GEFTMain.java:103)
at GEFTMain.init(GEFTMain.java:46)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Initially i thought it had something to do with the placement of the applet. However i have tried placing it in several locations but the error remains the same. I also tried deploying my application to a different server (Resin) instead of the Tomcat that i am using currently.
I am using jdk1.4.2

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: java.io.FileNotFoundException: <a href="http://localhost:8080"><a href= Posted: Nov 27, 2005 9:16 PM
Reply to this message Reply
This Book is where I got most of the ideas to get my
Applet to communicate with a Servlet:

http://www.unix.org.ua/orelly/java-ent/servlet/ch10_02.htm

Flat View: This topic has 16 replies on 2 pages [ « | 1  2 ]
Topic: spam Previous Topic   Next Topic Topic: Caller Id using JTAPI

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use