Page 1 of 2 12 LastLast
Results 1 to 20 of 27
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default java.lang.IllegalArgumentException: URI scheme is not "file"

    Uploading my applet and getting this error:

    java.lang.IllegalArgumentException: URI scheme is not "file"
    at java.io.File.<init>(File.java:366)
    at slideshowapplet.SlideshowApplet.checkImageFolders( SlideshowApplet.java:424)
    at slideshowapplet.SlideshowApplet.init(SlideshowAppl et.java:173)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1658)
    at java.lang.Thread.run(Thread.java:680)

    Until now it worked on the browser from a file on my computer....




    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package slideshowapplet;
    
    /**
     *
     * @author willem
     */
    
    
    import java.io.*;
    //import java.io.IOException;
    import javax.activation.MimetypesFileTypeMap;
    import javax.imageio.ImageIO;
    import javax.swing.border.Border;
    
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import java.net.URISyntaxException;
    import java.net.URL;
    import javax.swing.*;
    import javax.swing.Timer;
    
    
    public class SlideshowApplet extends JApplet implements Runnable {
        //String name;
        private Thread runner;
        private MimetypesFileTypeMap ft;
        private JPanel imagePanelx;
        private int screenx = 700, screeny = 600, xwindowsize = 1000,
                ywindowsize = 800, imageWidth, imageHeight, slidetime,
                maximages, imagecount, leftcornerX, leftcornerY;
        private boolean timerflag=true, textflag = false;
        private URL imagePath, iconPath;
        private File folder;
        private String  foldername;
        private ActionListener blistener;
        private ActionListener timelistener;
        private ArrayList imagefiles;
        private JButton ST, BW, FW;
        private ImageIcon BWicon, FWicon, STicon, GOicon;
        private DisplayScreen DS;
        private Color bluecolor, blackcolor, redcolor, colorset;
        private Timer time;
        private JLabel label1, label2, label3, label4, label5, textlabel;
    
    
    
        public void init() {
    
            // the five parameters set the functions of the
            // slideshow: foldername that contains the pictures
            // within workdir images/slideshow/foldername to set
            // next the duration in seconds
            // the screen size of the slides in x/y
            // and finally the flag for the buttons if thrue
            // there are buttons to stop and forward/ backward images
    
            // the applet tag parameters
            int buttons = 0;
            foldername = getParameter("foldername");
            if (foldername == null) foldername = "calella";
            System.out.println("image foldername " + foldername);
    
            try{
                int dt = Integer.parseInt(getParameter("displaytext"));
                if (dt == 1) {
                    textflag = true;
                }
                else {
                    textflag = false;
                }
            }
            catch(NumberFormatException e){
                slidetime = 5;
                timerflag = true;
                System.out.println("image time wrong " + slidetime);
            }
    
            try{
                int intValue = Integer.parseInt(getParameter("setbackgroundcolor"), 16);
                colorset = new Color( intValue );
            }
            catch(NumberFormatException e){
                int intValue = Integer.parseInt(getParameter("FFFFFF"), 16);
                colorset = new Color( intValue );
                System.out.println("no background available" + slidetime);
            }
    
    
            try{
                slidetime = Integer.parseInt(getParameter("imagetime"));
                if (slidetime == 0) {
                    timerflag = false;
                    buttons = 2;
                }
                else {
                    timerflag = true;
                    buttons = 3;
                }
            }
            catch(NumberFormatException e){
                slidetime = 5;
                timerflag = true;
                System.out.println("image time wrong " + slidetime);
            }
    
            try{
                screenx = Integer.parseInt(getParameter("sizeX"));
                if (screenx == 0) screenx = 400;
            }
            catch(NumberFormatException e){
                screenx = 400;
                System.out.println("screenX wrong " + screenx);
            }
    
            try{
                screeny = Integer.parseInt(getParameter("sizeY"));
                if (screeny == 0) screeny = 400;
    
            }
            catch(NumberFormatException e){
                screeny = 430;
                System.out.println("screenY wrong " + screeny);
            }
            try{
                buttons = Integer.parseInt(getParameter("buttons"));
                if (buttons == 0) timerflag = true;
    
                if (buttons == 2) timerflag = false;
                else timerflag = true;
                System.out.println("button " + buttons + " timerflag " + timerflag);
            }
            catch(NumberFormatException e){
                buttons = 3;
                timerflag = true;
                System.out.println("buttonflag wrong " + buttons);
            }
    
            try{
                int crossover = Integer.parseInt(getParameter("crossover"));
                if (crossover == 0) crossover = -1;
            }
            catch(NumberFormatException e){
                System.out.println("cross over wrong " );
            }
    
            leftcornerX = 0;
            leftcornerY = 0;
    
        //    setBounds(leftcornerX, leftcornerY, xwindowsize, ywindowsize);
    
            bluecolor = Color.BLUE;
            blackcolor = Color.BLACK;
            redcolor = Color.RED;
    
            // this method checks the presences of the two image folders
            // 1) "images" and "slideshow" folder
            // 2) the current folder, within the second folder,
            // sets by the applet tag. The doListofImages sets
            // an array with the valit image file names
            // the GUI stuff
    
            // add panel to frame
    
            blistener = new ButtonDialog();
            timelistener = new TimeSetter();
            ft = new MimetypesFileTypeMap(); // image type check
            doListofImagefiles(checkImageFolders(foldername));
            DS = new DisplayScreen();  // the display panel
            this.add(createGUI(buttons)); // two/ three or none buttons 2/3 or 0
            DS.getSlideImage(imagefiles.get(0));
            repaint();
        }
    
    
    
            // the GUI and the button panel
        private JPanel createGUI(int bt) {
    
                JPanel mainPanel = new JPanel(new BorderLayout());
                JPanel buttonPanel = new JPanel();
                JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
                JPanel northPanel = new JPanel(new GridLayout(5,1));
                mainPanel.setBackground(colorset);
                buttonPanel.setBackground(colorset);
                southPanel.setBackground(colorset);
                northPanel.setBackground(colorset);
    
                textlabel = new JLabel();
                label1 = new JLabel();
                label2 = new JLabel();
                label3 = new JLabel();
                label4 = new JLabel();
                label5 = new JLabel();
                northPanel.add(label1);
                northPanel.add(label2);
                northPanel.add(label3);
                northPanel.add(label4);
                northPanel.add(label5);
    
            if (bt != 0)  {
                FW = new JButton();
          //      FW.setPreferredSize(new Dimension(65, 30));
                FW.setBorder(BorderFactory.createEmptyBorder());
                FW.setContentAreaFilled(false);
                FWicon = createButtonIcon("FW.jpg");
                FW.setIcon(FWicon);
                FW.addActionListener(blistener);
                FW.setActionCommand("FW");
    
    
                BW = new JButton();
          //      FW.setPreferredSize(new Dimension(65, 30));
                BW.setBorder(BorderFactory.createEmptyBorder());
                BW.setContentAreaFilled(false);
                BWicon = createButtonIcon("BW.jpg");
                BW.setIcon(BWicon);
                BW.addActionListener(blistener);
                BW.setActionCommand("BW");
    
                ST = new JButton();
          //      FW.setPreferredSize(new Dimension(65, 30));
                ST.setBorder(BorderFactory.createEmptyBorder());
                ST.setContentAreaFilled(false);
                STicon = createButtonIcon("ST.jpg");
                GOicon = createButtonIcon("GO.jpg");
                ST.setIcon(STicon);
                ST.addActionListener(blistener);
                ST.setActionCommand("ST");
    
                if (bt == 2) { // two buttons
                    buttonPanel.add(BW);
                    buttonPanel.add(FW);
                    FW.setEnabled(true);
                    BW.setEnabled(true);
                }
                else { // three buttons
                    buttonPanel.add(BW);
                    buttonPanel.add(ST);
                    buttonPanel.add(FW);
                    ST.setEnabled(true);
                    ST.setIcon(STicon);
                    BW.setEnabled(false);
                    FW.setEnabled(false);
                }
                southPanel.add(textlabel);
                southPanel.add(buttonPanel);
    
                Border etched = BorderFactory.createEtchedBorder(bluecolor,
                                                                bluecolor);
               // buttonPanel.setBorder(etched);
          }
    
            mainPanel.add(DS, BorderLayout.CENTER);
            mainPanel.add(southPanel, BorderLayout.SOUTH);
         //   mainPanel.add(northPanel, BorderLayout.NORTH); // for monitoring
            return mainPanel;
        }
    
    
    
        private ImageIcon createButtonIcon (String Iname)  { // load button icons
            ImageIcon Iicon = null;
            try {
    
                    URL url = new URL(
                    iconPath + File.separator +  Iname);
    
                      Iicon = new ImageIcon(url);
             }
             catch (IOException e) {
                    System.out.println(" path error "  +
                                     "images" + Iname);
             }
    
            return Iicon;
        }
    
    
    
        public void start() {
    
            if (runner == null); {
                runner = new Thread(this);
                runner.start();
    
                System.out.println("Thread started.");
                DS.getSlideImage(imagefiles.get(0));
                repaint();
            }
        }
    
        public void stop() {
    
                if (runner != null) {
                    runner.interrupt();
                    runner = null;
                    stoptimer();
                    System.out.println("Thread successfully stopped.");
                    System.out.println("timer stopped ");
                }
        }
    
        public void destroy() {
    
        }
    
    
        public void run() { // runs the image timer
            timer(slidetime); // image timer set by tag
            if (timerflag)  {
                starttimer();
                System.out.println("Timer Started");
            }
            else System.out.println("Timer NOT Started");
        }
    
    
    
        public void timer(int st)  {
            time = new Timer((1000 * st), timelistener);
            time.setRepeats(true);
        }
        public void starttimer() {
             time.start();
        }
        public void stoptimer() {
             time.stop();
        }
    
        class  TimeSetter implements ActionListener { // timer listener for
            public void actionPerformed(ActionEvent event)  { // automatic image display
                    imagecount++;
                    if (imagecount >= maximages) imagecount = 0;
    
                    DS.getSlideImage( imagefiles.get(imagecount));
                    repaint();
            }
        }
    
    
    
        private class ButtonDialog implements ActionListener { // button listener
    
           public void actionPerformed(ActionEvent e) {
    
               String cmd = e.getActionCommand();
    
                if (e.getSource() == FW) { // forwards
                    imagecount++;
                    if (imagecount >= maximages) imagecount = 0;
    
                    DS.getSlideImage( imagefiles.get(imagecount)) ;
                    repaint();
                }
    
                if (e.getSource() == BW) { // backwards
    
                    if (imagecount <= 1) imagecount = maximages;
                    imagecount--;
    
                    DS.getSlideImage( imagefiles.get(imagecount)) ;
                    repaint();
                }
    
                if ((cmd.equals("ST") || (cmd.equals("GO")))) { // stop start button
                   if (cmd.equals("ST")) {
                       stoptimer();
                       BW.setEnabled(true);
                       FW.setEnabled(true);
                       ST.setIcon(GOicon);
                       ST.setActionCommand("GO");
                   }
                   else {
                       starttimer();
                       BW.setEnabled(false);
                       FW.setEnabled(false);
                       ST.setIcon(STicon);
                       ST.setActionCommand("ST");
                   }
               }
          }
       }
    
    
        private File checkImageFolders(String currentf) {
            // There are two image folders the first is called slideshowImages
            // at the codebase (classes).
            // the second folder (name currentf) is set by the applet tag
            // this folder contains all the images for display
            boolean flag = false;
    
          // System.out.println(" getcodebase " + getCodeBase().toString());
          // label1.setText(" codebase " + getCodeBase());
          // label2.setText(" documentbase " + getDocumentBase());
    
            try {
                 imagePath = new URL(getCodeBase(), "slideshowImages");
                 iconPath  = new URL(getCodeBase(), "slideshowapplet");
                 flag = true;
            } catch (IOException ex) {
                System.out.println("can not read folder slideshowImages : " + imagePath);
                System.out.println(ex.getMessage());
                flag = false;
            } imagePath = null;
    
    
            try {
                 imagePath = new URL(getCodeBase(), "slideshowImages" +
                         File.separator + currentf);
                 flag = true;
            } catch (IOException ex) {
                System.out.println("can not read current image folder : " + currentf);
                System.out.println(ex.getMessage());
                flag = false;
            }
    
            try {
                    folder = new File(imagePath.toURI());
                    System.out.println(" try " + folder);
                    flag = true;
                }
            catch(URISyntaxException e) {
                    folder = new File(imagePath.getPath());
                    System.out.println(" catch " + folder);
                    flag = false;
            }
    
    
            if (folder.exists()) {
                System.out.println(" yes file folder exsists " + folder);
                flag = true;
            }
            else  {
                System.out.println(" no file folder " + folder);
                flag = false;
            }
    
             System.out.println(" the flag set to " + flag +
                     " the folder content " + imagePath.toString());
           //  label3.setText(" appletpath " + appletp);
           //  label4.setText(" folderpath " + folder);
             if (flag)
             return folder;
             else
             return null;
        }
    
        private void doListofImagefiles( File currentfpath)  {
            // storing the present files of the folder
            // into a temporal array for checking
            if ( currentfpath != null)  {
                File[] listOfFiles = currentfpath.listFiles();
                //the array list will contain the correct files
                imagefiles = new ArrayList();
                System.out.println(); System.out.println();
    
                for (int i = 0; i < listOfFiles.length; i++)  {
                    String file = listOfFiles[i].getName();
                    System.out.print(i + "  > " + file );
                    // check for files against folders
                    if (listOfFiles[i].isFile()) {
                        //adding the checked correct image files
                        if (checkImageType(listOfFiles[i]))  {
                               imagefiles.add(file);
                        }
    
                    }
                }
            maximages = imagefiles.size();
            System.out.println(" the array list length is: " + maximages);
            }
            else
            System.out.println(" no array setup: " + currentfpath);
        }
    
    
        private boolean checkImageType (File f)  {
            boolean flag = false;
    
                    String fl = ft.getContentType(f);
    
                    String type = fl.split("/")[0];
                    if(type.equals("image"))  {
                            System.out.println("  Is an image:  <" +
                                    fl.split("/")[1] + ">   ");
                            return true;
                    }
                    else  {
                            System.out.println("  Is NOT an image");
                            return false;
                    }
        }
    
    
        // inner class that draws the photos on a panel
    
        class DisplayScreen extends JPanel {
            private Image img;
    
    
            public DisplayScreen() {
              //  getSlideImage(imagefiles.get(0));
              //  repaint();
            }
    
            public void getSlideImage(Object imf)      {
    
                try {
                       URL url = new URL( imagePath +
                               File.separator + (String) imf);
    
                       img = ImageIO.read(url);
                       scaleImage(img.getWidth(null), img.getHeight(null));
                       if (textflag)
                       textlabel.setText(" Reff. " + (imagecount + 1));
                     //  label5.setText(" image file " + imf);
                }
                catch (IOException e) {
                    System.out.println(" path error "  + iconPath +
                                     File.separator + (String) imf);
                }
           }
    
    
            public void scaleImage(int w, int h)  {
                   imageWidth = screenx;
                   imageHeight = screeny;
                   double rat = 1.0;
              //   if (Math.abs(w-imageWidth) >= Math.abs(h-imageHeight)) {
                   if ((w-imageWidth) >= (h-imageHeight)) {
                       rat = (double) imageWidth / (double)  w;
                   }
                   else  {
                       rat = (double) imageHeight / (double) h;
                   }
                   imageWidth = (int) ( w * rat);
                   imageHeight = (int) ( h * rat);
                    //  label2.setText(" X " + w + " Y " + h);
                    //  label3.setText(" scaleX " + imageWidth + " scaleY " + imageHeight);
                    //  label1.setText(" screenY " + screenx + " screenY " + screeny);
    
            }
    
    
            public void paint(Graphics g) {
                    Graphics2D g2 = (Graphics2D)g;
                    g2.setPaint(Color.red);
                 //   Rectangle rect = new Rectangle(leftcornerX,
                 //           leftcornerY, screenx, screeny);
                 //   g2.draw(rect);
                    g2.setColor(colorset);
                    g2.fillRect(leftcornerX,leftcornerY, screenx,screeny);
                    g2.drawImage(img, leftcornerX,
                            leftcornerY, imageWidth, imageHeight, null);
            }
    
    
        } // end inner class
    
    }

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    The problem obviously occurs at one of these methods:
    -doListofImagefiles( File currentfpath)
    -private File checkImageFolders(String currentf)
    and it has to do with file path versus URL, right?
    So what code should not be present here (since it works just
    fine when starting it on a browser from-out a file)....

    might this be the problem: folder = new File(imagePath.toURI());?

    and what happens when I return (after checking all), imagePath..

    so at the end of the private File checkImageFolders(String currentf)
    return imagePath;
    (changing the return type of course into URL)
    Last edited by willemjav; 06-07-2013 at 11:35 AM.

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    Yet another problem, since currentfpath is now of type URL and not of File
    I can not say anymore:
    File[] listOfFiles = currentfpath.listFiles(); (at the method doListofImagefiles( File currentfpath)
    that is now doListofImagefiles( URL currentfpath))
    so how am I going to get around this now....

    The bottom question is: what is the difference between
    file path path and a URL?

    URL starts with www. or http://www.
    and both (file path and URL) have a series of "/"

    So why can I not take a file path and put before it http://www
    which would turn it into a URL, right?

    like:
    URL = http://www + file path
    Last edited by willemjav; 06-08-2013 at 09:48 AM.

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    The exception is caused by line 424:
    folder = new File(imagePath.toURI());

  5. #5
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    Finally, if the current file path is of type URL:
    -URL currentfpath;
    -and that path leads to a file folder
    -how am I going to get a list of files inside that folder?
    (File[] listOfFiles = currentfpath.listFiles(); only works when currentfpath is of type File)

  6. #6
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    I changed the code which gets the file list of the folder and I am getting
    again a java.io.IOException:



    can't download file >>> sun.net.http://www.protocol.http.HttpURLConn...xxxxxxxxxxxxxx

    07-jun-2013 20:55:45 slideshowapplet.SlideshowApplet doListofImagefiles
    SEVERE: null
    java.io.IOException: Server returned HTTP response code: 403 for URL: http://xxxxxxxxxxxxxxxx
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1436)
    at slideshowapplet.SlideshowApplet.doListofImagefiles (SlideshowApplet.java:461)
    at slideshowapplet.SlideshowApplet.init(SlideshowAppl et.java:180)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1658)
    at java.lang.Thread.run(Thread.java:680)


    here is that new code:

    imagePath = new URL(getCodeBase(), "slideshowImages");

    imagePath = new URL(getCodeBase(), "slideshowImages" +
    File.separator + currentf);

    (currentfpath = imagePath)

    Java Code:
    private void doListofImagefiles( URL currentfpath)  { //URL
            
            java.net.URLConnection con = null;
            if ( currentfpath != null)  {
                try {
    
                    con = currentfpath.openConnection();
                    con.connect();
                   
                    //the array list will contain the correct image files
                    imagefiles = new ArrayList();
                    java.io.BufferedReader in = new java.io.BufferedReader(new
                            java.io.InputStreamReader(con.getInputStream()));
                    String line;
                 
                    int i = 0;
                    for (; (line = in.readLine()) != null;) {
                        System.out.println(i + "  > " + line);
                        //adding the checked correct image files
                        if (checkImageType(line)) { // check fgr image format
                            imagefiles.add(line);
                        }
                        i++;
                    }
                    maximages = imagefiles.size();
                    System.out.println(" the array list length is: " + maximages);
                } catch (IOException ex) {
                    System.out.println("  can't download file >>> " + con);
                    Logger.getLogger(SlideshowApplet.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else
            System.out.println(" no array setup: " + currentfpath);
        }
    Last edited by willemjav; 06-08-2013 at 09:52 AM.

  7. #7
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    Do I need do grant some permission at the host...
    and how I do that if so?

    This applet stuff is dizzy making

    (a patient meets his doctor and says:
    "if I push here, it really hurts"
    the doctor:
    "so don't do it")
    Last edited by willemjav; 06-07-2013 at 10:22 PM.

  8. #8
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    java.io.IOException: Server returned HTTP response code: 403 for URL: http://xxxxxxxxxxxxxxxxxxxxxxxxxx
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1436)

    It is the server that is not willing to serve the request, right?
    Should I contact them?
    Or is there another way to get around this problem?

    found this:

    10.4.4 403 Forbidden

    The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.
    Last edited by willemjav; 06-08-2013 at 09:54 AM.

  9. #9
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    So what can be done, about this server block?

    over and out!
    Last edited by willemjav; 06-08-2013 at 09:54 AM.

  10. #10
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    knock, knock, anybody at home at the Java applet department?


    -The problem of the applet should be found at the next method doListofImagefiles
    (this method reads the directory, a list of image files of of the folder "principal")

    -The URL currentfpath is based on:
    currentfpath = new URL(getCodeBase(), "slideshowImages" +
    File.separator + currentf);
    which is http://gitanatrip.com/dxxxxxxwillem/...ages/principal

    The method breaks of at: "connection is open" at line 10
    The spanish text: "Entrada de caché no encontrada"
    means: can not find entry of caché (what ever that is)
    so from here on the method jumps to the exception:
    "can't download file "

    What might be going on here?



    read the file list path is: http://gitanatrip.com/dwillem/classe...ages/principal
    connection is open
    network: Entrada de caché no encontrada [url: http://gitanatrip.com/dwillem/classe...ages/principal, versión: null]
    network: Conectando http://gitanatrip.com/dwillem/classe...ages/principal con proxy=DIRECT
    network: Conectando http://gitanatrip.com:80/ con proxy=DIRECT
    network: Entrada de caché no encontrada [url: http://gitanatrip.com/dwillem/classe...ges/principal/, versión: null]
    network: Conectando http://gitanatrip.com/dwillem/classe...ges/principal/ con proxy=DIRECT
    network: Conectando http://gitanatrip.com:80/ con proxy=DIRECT
    can't download file >>> sun.net.http://www.protocol.http.HttpURLConn...ges/principal/
    11-jun-2013 13:18:19 slideshowapplet.SlideshowApplet doListofImagefiles
    SEVERE: null
    java.io.IOException: Server returned HTTP response code: 403 for URL: http://gitanatrip.com/dwillem/classe...ges/principal/
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1436)
    at slideshowapplet.SlideshowApplet.doListofImagefiles (SlideshowApplet.java:482)
    at slideshowapplet.SlideshowApplet.init(SlideshowAppl et.java:179)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1658)
    at java.lang.Thread.run(Thread.java:680)


    Java Code:
    private void doListofImagefiles( URL currentfpath)  { //URL
            // storing the present files of the folder
            // into a temporal array for checking
    
            java.net.URLConnection con = null;
            if ( currentfpath != null)  {
                try {
                    System.out.println(" read the file list path is: " + currentfpath);
                    con = currentfpath.openConnection();
                    System.out.println(" connection is open");
                    con.addRequestProperty("User-Agent",
                            "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; "
                            + "Win64; x64; Trident/5.0)");
    
    
    
                    //File[] listOfFiles = currentfpath.listFiles();
                    //the array list will contain the correct files
                    imagefiles = new ArrayList();
                    java.io.BufferedReader in = new java.io.BufferedReader(new
                            java.io.InputStreamReader(con.getInputStream()));
                    String line;
                   
                    int i = 0;
                    for (; (line = in.readLine()) != null;) {
                        System.out.println(i + "  > " + line);
                        //adding the checked correct image files
                        if (checkImageType(line)) {
                            imagefiles.add(line);
                        }
                        i++;
                    }
                    maximages = imagefiles.size();
                    System.out.println(" the array list length is: " + maximages);
                } catch (IOException ex) {
                    System.out.println("  can't download file >>> " + con);
                    Logger.getLogger(SlideshowApplet.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else
            System.out.println(" no array setup: " + currentfpath);
        }

  11. #11
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    The server does not like me doing this:

    Java Code:
    java.io.BufferedReader in = new java.io.BufferedReader(new
                            java.io.InputStreamReader(con.getInputStream()));
                    String line;
                    
                    int i = 0;
                    for (; (line = in.readLine()) != null;) {
                        System.out.println(i + "  > " + line);
                        //adding the checked correct image files
                        if (checkImageType(line)) {
                            imagefiles.add(line);
                        }
                        i++;
                    }
    what alternative I have for reading in the directory of files according
    the applet law?

  12. #12
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    Here the rewritten method and still problems!
    From here the code jumps to the catch:

    java.io.BufferedReader in = new java.io.BufferedReader(new
    java.io.InputStreamReader(con.getInputStream()));

    Line 22 still prints out

    Java Code:
      private void doListofImagefiles(String foldername)  { //URL
            // storing the present files of the folder
            // into a temporal array for checking
    
            URL url = null;
            java.net.URLConnection con = null;
            try {
                  url = new URL(getCodeBase(), "slideshowImages" +
                        File.separator + foldername);
                  System.out.println(" Do the image file list of " + foldername);
                  System.out.println(" the file list path is: " + url);
    
            }
            catch (MalformedURLException ex) {
                  Logger.getLogger(SlideshowApplet.class.getName()).log(Level.SEVERE, null, ex);
                  System.out.println(" can't find the file path: " + url);
            }
            
            if ( url != null)  {
                try {
                    con = url.openConnection();
                    System.out.println(" connection is open for the file list " + con);
                
                    //the array list will contain the correct files
                    imagefiles = new ArrayList();
                    java.io.BufferedReader in = new java.io.BufferedReader(new
                            java.io.InputStreamReader(con.getInputStream()));
                     
               //    InputStream in = con.getInputStream(); 
                    
                    String line;
                    System.out.println(" BufferedReader is initiated");
                    int i = 0;
                    for (; (line = in.readLine()) != null;) {
                        System.out.print(i + "  > " + line);
                        //adding the checked correct image files
                        if (checkImageType(line)) {
                            imagefiles.add(line);
                        }
                        i++;
                    }
                    maximages = imagefiles.size();
                    System.out.println(" the arraylist length is: " + maximages);
                } catch (IOException ex) {
                    System.out.println("  can't download the file list " + con);
                    Logger.getLogger(SlideshowApplet.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else
            System.out.println(" no fillename array is setup: " + url);
        }

  13. #13
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    here is the error message after line 22

    can't download the file list sun.net.http://www.protocol.http.HttpURLConn...ges/principal/
    11-jun-2013 23:14:27 slideshowapplet.SlideshowApplet doListofImagefiles
    SEVERE: null
    java.io.IOException: Server returned HTTP response code: 403 for URL: http://gitanatrip.com/dxxxxxwillem/c...ges/principal/
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1436)
    at slideshowapplet.SlideshowApplet.doListofImagefiles (SlideshowApplet.java:484)
    at slideshowapplet.SlideshowApplet.init(SlideshowAppl et.java:182)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1658)
    at java.lang.Thread.run(Thread.java:680)

  14. #14
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    So I finally contacted (after trying to understand what is the problem) the server (spanish comp)
    and here is their answer:

    Good morning Willem,




    You can clearly see that this applet need JAVA to work correctly. Our servers don’t work with JAVA.



    In this case, the only service that we can offer you is a non managed service as a VPS or a dedicated server.



    Thank you and have a nice day.





    :-)



    IS THERE ANY HOPE FOR THIS APPLET LEFT, PLS JAVA FORUM TELL ME....

  15. #15
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,095
    Rep Power
    4

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    An applet is restricted to communicate only with the host it originated from. It's a security thing. Check the address the applet is connecting to and see if it matches the host/ip address in the URL. (You might want to resolve the host's ip address to see what it actually is).

  16. #16
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,095
    Rep Power
    4

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    You could make a textfile with the names of the images and upload that to the server. Download that file from your applet and you have the names of the images to download. http is not suitable for querying directories.

  17. #17
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    ok surfman I'd like to very much get to the bottom of this reading this eg

    HTTP Error 403 Forbidden Explained

    Is there any other way to read a file dir at the host server?

    Could you pls also tell me where this problem really lays:

    a) my programming skills;
    b) java site (sand box stuFF)
    c) host for not having Java installed or not wanting to grant permissions
    Last edited by willemjav; 06-12-2013 at 01:28 PM.

  18. #18
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    surfman this won't work either, or could you suggest any alternative:

    Java Code:
          con = url.openConnection();
                 
    
                    String contentType = con.getContentType();
    
                    System.out.println("contentType:" + contentType);
    
                    con.connect();
    
                    System.out.println(" connection is open for the file list " + con);
                
                    //the array list will contain the correct files
                    imagefiles = new ArrayList();
                    java.io.BufferedReader in = new java.io.BufferedReader(new
                            java.io.InputStreamReader(con.getInputStream()));
    
         
                    String line;
                    System.out.println(" BufferedReader is initiated");
                    int i = 0;
                    for (; (line = in.readLine()) != null;) {
                        System.out.print(i + "  > " + line);
                        //adding the checked correct image files
                        if (checkImageType(line)) {
                            imagefiles.add(line);
                        }
                        i++;
                    }
                    maximages = imagefiles.size();
                    System.out.println(" the arraylist length is: " + maximages);
                } catch (IOException ex) {
                    System.out.println("  can't download the file list ");
                    Logger.getLogger(SlideshowApplet.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println("  end of error message ");
                }

  19. #19
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    I know I am asking to much but what does this part of the error code mean:
    sun.net.http://www.protocol.http.HttpURLConn...ion.java:1436)

  20. #20
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: java.lang.IllegalArgumentException: URI scheme is not "file"

    BTW I could make a text file etc. but I have 9 small slideshows running on that site!
    (each picking up its own image folder, you see)
    So that would be quite messy, surfman

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 12-21-2011, 07:44 PM
  2. Replies: 4
    Last Post: 09-16-2011, 11:08 PM
  3. Replies: 6
    Last Post: 03-19-2011, 08:10 PM
  4. Replies: 12
    Last Post: 05-26-2009, 02:48 PM
  5. Replies: 1
    Last Post: 08-06-2007, 07:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •