Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 23 of 23

Thread: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

  1. #1
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Hello all

    I am not new to Java but I am new to this forum.
    I am struggling over an applet that should read a file dir of
    the host (not the client).
    Being a good boy I constantly use, of course, a code based path....

    I am getting a "java.io.IOException: Server returned HTTP response code: 403 "
    and I do know what it means.

    here is the method in question (I get until the print "connection is open" than the method

    jumps to the catch statement):

    private void doListofImagefiles(String foldername)  { //URL
            //checking and storing the present files of the folder
     
            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();
                 //   HttpURLConnection conh = (HttpURLConnection) url.openConnection();
     
     
     
                  //  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()));
     
               //    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 ");
                    Logger.getLogger(SlideshowApplet.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println("  end of error message ");
                }
            }
            else
            System.out.println(" no fillename array is setup: " + url);
        }

    How can I improve to code so it'll work
    and where lays the problem:

    a) my programming skills;
    b) java site (sand box stuff)
    c) host for not having Java installed or not wanting to grant permissions

    thanks pls any help is welcome....


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,616
    Thanks
    25
    Thanked 321 Times in 299 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    You are trying to list the files in a server directory? Best guess is that the server does not want to provide you with that access. HTTP 403 is an access denied error. The server received and understood your request, but refused to fulfill it. This is not uncommon.

    Are you attempting to access a server which you have ftp access to? If so, my suggestion would be to try a server-side approach. For example, to solve this problem myself, I have:
    1. Created a simple php file that can read the files (I can help you with this step, it is very simple)
    2. Made the php file output the data somehow (I use xml, but you can probably just use plain text)
    3. Made my java program query the php file to get the result
    4. Parsed the php response in my java program

    This is all very simple to do, and may solve your server issues (unless your host refuses php access like this, which it probably does not).
    There are other ways to go about doing this, but I have found the above to be by far the easiest, most reliable, and fastest.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    auss that is very interesting what you are saying! A friend yesterday talked about php (which I do not know) and said that it is not difficult to learn.
    For the moment I am learning Java collections (reading the javacore II book). I will turn very soon (next chapter) to interneting.
    I suspected that the problems lays with the server (Spanish based) and when I asked they answered this:

    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.

    So it is not true that "Java has to be installed" in order to make my applet run, right? (since it runs on the client's comp)
    He just does not want to grant that permission, right?
    I will eventually (when reading the next javacore chapter) get into php as well (have downloaded a manual yesterday).
    But for the moment it is all pretty overwelming....

    Auss is there another way to make that code run? Or might that mean to much trouble?
    The method jumps to the catch after I opened the con connection.
    The host does not like me doing:

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

    what alternative is there for this.....
    I eventually will get to your four points, because I do not know if applets have a clear future
    (they do not run on my family's Ipad after Steve Jobs "prophetic" words about Java)

    thanks Auss

    ps "Are you attempting to access a server which you have ftp access to? " yes!

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,616
    Thanks
    25
    Thanked 321 Times in 299 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    It might be a restricted file type, so .jar files or whatever will not be allowed to upload. Many free hosts disallow executable languages on their servers for several reasons. If you would like, I can provide you with a free host which allows java. For "small" websites, they don't force ads on your pages, but for "big" websites they put a few. Unfortunately, those ads are those crappy javascript ads which look like viruses, so it might scare some people off.

    The php file I use to get a list of files is this (I am probably using some outdated libraries, but I am a php noob):
    <?php 
    	header('Content-type: text/xml');
     
        /* create a dom document with encoding utf8 */
        $domtree = new DOMDocument('1.0', 'UTF-8');
     
    	/* Root */
    	$xmlRoot = $domtree->createElement("list");
    	$xmlRoot = $domtree->appendChild($xmlRoot);
     
    	$conn = ftp_connect("yourhost") or die("Could not connect");
    	ftp_login($conn,"yourLogIn","yourPassword");
    	$array = ftp_nlist($conn,"theFolderToLookIn");
    	foreach($array as $value) {
    		if(strpos($value,".anExtension")) { //I am filtering by extension, you don't have to
    			$xmlRoot->appendChild($domtree->createElement('file',$value));
    		}
    	}
    	ftp_close($conn);
     
    	/* get the xml printed */
        echo $domtree->saveXML();
    ?>

    That just builds a basic XML output of the files in the directory, which I can then call directly from java and parse with the following code (it uses a class called XMLUtilities which I made to help myself parse XML documents more easily, you can ignore references to that class and just use the standard java API):
    public static List<String> getFileList() throws Exception {
    		String query = HOST_URL+"listFiles.php";
    		List<String> ret = new ArrayList<String>();
    		try {
    			URL url = new URL(query);
    			logger.info("Querying: "+url.getPath());
    			Document document = XMLUtilities.loadXMLFromURL(url); //Loads the XML file into a Document from the URL
    			Element element = XMLUtilities.getChildElement(document, "list"); //Gets the root node
    			NodeList list = element.getElementsByTagName("file"); //Gets a list of all the file nodes
    			for(int i=0;i<list.getLength();i++) {
    				String file = list.item(i).getTextContent(); //Gets the file name
    				if(file.contains(".")) {
    					file = file.substring(0,file.indexOf(".")); //Gets rid of the extensions for my own reasons
    				}
    				ret.add(file); //Adds the file name to my list
    			}
    		} catch(SAXParseException ex) {
    			throw new Exception("Prolog Exception"); //This is thrown when the server has too many connections
    		} catch(Exception ex) {
    			ex.printStackTrace();
    		}
    		return ret;
    	}

    If you wanted to try to do it in only java, you would have to make an FTP connection and read the directory itself. That will return some crazy weird file that contains a list of the file names, as well as a bunch of other html stuff and other crap. This can be a real pain to do. It will also require you to add a digital signature to your jar. But if your server chooses to, they can probably not let you connect this way.

    --- Update ---

    Also, applets, for the most part, are already being fazed out. But Jobs was still wrong that Java has no place. Most companies are moving to html5 and other web-specific languages to build the user interfaces, and only using java as the back-end system. This works quite well because java interacts with javascript, jsp, json, xml, php, ect. relatively easily.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. The Following User Says Thank You to aussiemcgr For This Useful Post:

    willemjar (June 13th, 2013)

  6. #5
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Auss many thanks I'll look into it all!
    "If you would like, I can provide you with a free host which allows java."
    I might be very interested since I am still trying out the site and need some space to do so.
    I worked so hard on that applet (still no easy job for me) and like to it see at work.
    (there are actually several in different sizes with and without text buttons etc.)
    That space might be even a solution for the future since the web only contains only 25 mb.
    so let me know where to upload, please

    salud willem

    ps the ftp version of java I will get into when studying my next chapter: internet!

  7. #6
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,616
    Thanks
    25
    Thanked 321 Times in 299 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    I use Free Web Hosting Area - PHP 5.4, MySQL 5.5, FTP, Autoinstaller
    They have a handful of domains you can use. I use orgfree. There does seem to be the occasional connectivity issue lately (says there are too many people connecting to the server), but it is usually pretty good. They have free database support, but the database can only be connected to via localhost (meaning, from the server-side), so it can be a bit of pain to use.
    I would HIGHLY suggest using an FTP program (such as FileZilla) instead of their provided FTP client. Their FTP client seems to like to slam the door in your face.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  8. #7
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    I used fetch for a while
    Thanks for those links!
    The applet will run without problem, I hope?

  9. #8
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,616
    Thanks
    25
    Thanked 321 Times in 299 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    The servers should fully support java. The only problem I've had with my applet is when the server is down, but that is to be expected I suppose.
    With that being said, it does NOT seem to be an application server. For now, you probably don't care, but when you start reading about servlets, jsp, and other server-side java-related programming, just know that you will not be able to run that on the server. Server-side requires an application server, which is a server that has Tomcat, GlassFish, ect. installed.
    You'd be hard pressed to find an application host for free. I haven't been able to find one, so I do all my server-side programming with php scripts.
    Java Applets do NOT require an application server, since it is running on the client (instead of the server), so you should be fine for now.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  10. The Following User Says Thank You to aussiemcgr For This Useful Post:

    willemjar (June 13th, 2013)

  11. #9
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Great I haven't a domain name yet. I suppose one gets a (small) space to upload under some:
    www.sdfdfs/sfdsf/sdfds/sfds/myspace
    I'll put the index etc. first in a folder to try out things in a private manner,
    before publishing the site

    Thanks again for all your good and relevant info, Auss

    --- Update ---

    You need to have a domain name to start the site
    (I'd like to get that later after the site is running correctly)?

  12. #10
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    auss got the site (thanks again) you can reach it here:

    mywebpage

    but run into the same trouble (I believe)? Here is the error code:

    java.security.AccessControlException: access denied (java.net.SocketPermission e.freewebhostingarea.com:80 connect,resolve)
    at java.security.AccessControlContext.checkPermission (AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(Acc essController.java:549)
    at java.lang.SecurityManager.checkPermission(Security Manager.java:532)
    at sun.plugin2.applet.Applet2SecurityManager.checkPer mission(Applet2SecurityManager.java:221)
    at java.lang.SecurityManager.checkConnect(SecurityMan ager.java:1034)
    at sun.plugin2.applet.Applet2SecurityManager.checkCon nect(Applet2SecurityManager.java:522)
    at sun.net.http://www.http.HttpClient.openServe...ient.java:521)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java :227)
    at sun.net.www.http.HttpClient.New(HttpClient.java:300)
    at sun.net.www.http.HttpClient.New(HttpClient.java:317)
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:970)
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:911)
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:836)
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:2116)
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1367)
    at slideshowapplet.SlideshowApplet.doListofImagefiles (SlideshowApplet.java:486)
    at slideshowapplet.SlideshowApplet.init(SlideshowAppl et.java:183)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1658)
    at java.lang.Thread.run(Thread.java:680)[COLOR="Silver"]

    3d.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org .mozilla.jss
    basic: Oyente de progreso añadido: sun.plugin.util.GrayBoxPainter$GrayBoxProgressList ener@1408a92
    network: Conectando http://willemii.orgfree.com/tryoutwe...owApplet.class con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com:80/ con proxy=DIRECT
    network: Entrada de caché encontrada [url: http://willemii.orgfree.com/tryoutwe...owApplet.class, versión: null] prevalidated=false/0
    network: Conectando http://willemii.orgfree.com/tryoutwebsite/classes/slideshowapplet/SlideshowApplet$DisplayScreen.class con proxy=DIRECT
    network: Entrada de caché encontrada [url: http://willemii.orgfree.com/tryoutwebsite/classes/slideshowapplet/SlideshowApplet$DisplayScreen.class, versión: null] prevalidated=false/0
    network: Conectando http://willemii.orgfree.com/tryoutwe...owApplet.class con proxy=DIRECT
    basic: Subprograma cargado.
    basic: Applet resized and added to parent container
    basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 338098 us, pluginInit dt 1398461 us, TotalTime: 1736559 us
    Java Plug-in 1.6.0_45
    Usando versión JRE 1.6.0_45-b06-451-10M4406 Java HotSpot(TM) 64-Bit Server VM
    Directorio de inicio del usuario = /Users/willem>>> image foldername principal
    >>> background availablejava.awt.Color[r=255,g=255,b=255]
    >>> image time 5
    >>> screenX 700
    >>> screenY 400
    >>> button 3 timerflag true
    network: Conectando http://willemii.orgfree.com/tryoutwebsite/classes/slideshowapplet/SlideshowApplet$ButtonDialog.class con proxy=DIRECT
    network: Entrada de caché encontrada [url: http://willemii.orgfree.com/tryoutwebsite/classes/slideshowapplet/SlideshowApplet$ButtonDialog.class, versión: null] prevalidated=false/0
    network: Conectando http://willemii.orgfree.com/tryoutwebsite/classes/slideshowapplet/SlideshowApplet$TimeSetter.class con proxy=DIRECT
    network: Entrada de caché encontrada [url: http://willemii.orgfree.com/tryoutwebsite/classes/slideshowapplet/SlideshowApplet$TimeSetter.class, versión: null] prevalidated=false/0
    1> the folder slideshowImages : http://willemii.orgfree.com/tryoutwe...lideshowImages
    2> the folder slideshowapplet icon for button: http://willemii.orgfree.com/tryoutwe...lideshowapplet
    3> the current image folder : http://willemii.orgfree.com/tryoutwe...ages/principal
    4> the flag set to true the path is: http://willemii.orgfree.com/tryoutwe...ages/principal
    Do the image file list of principal
    the file list path is: http://willemii.orgfree.com/tryoutwe...ages/principal
    connection is open for the file list sun.net.http://www.protocol.http.HttpURLConn...ages/principal
    network: Conectando http://willemii.orgfree.com/tryoutwe...ages/principal con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com/tryoutwe...ges/principal/ con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com:80/ con proxy=DIRECT
    network: Conectando http://e.freewebhostingarea.com/403.html con proxy=DIRECT
    network: Conectando http://e.freewebhostingarea.com:80/crossdomain.xml con proxy=DIRECT
    network: Conectando http://e.freewebhostingarea.com:80/ con proxy=DIRECT
    basic: Oyente de progreso eliminado: sun.plugin.util.GrayBoxPainter$GrayBoxProgressList ener@1408a92
    java.security.AccessControlException: access denied (java.net.SocketPermission e.freewebhostingarea.com:80 connect,resolve)
    at java.security.AccessControlContext.checkPermission (AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(Acc essController.java:549)
    at java.lang.SecurityManager.checkPermission(Security Manager.java:532)
    at sun.plugin2.applet.Applet2SecurityManager.checkPer mission(Applet2SecurityManager.java:221)
    at java.lang.SecurityManager.checkConnect(SecurityMan ager.java:1034)
    at sun.plugin2.applet.Applet2SecurityManager.checkCon nect(Applet2SecurityManager.java:522)
    at sun.net.http://www.http.HttpClient.openServe...ient.java:521)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java :227)
    at sun.net.www.http.HttpClient.New(HttpClient.java:300)
    at sun.net.www.http.HttpClient.New(HttpClient.java:317)
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:970)
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:911)
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:836)
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:2116)
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1367)
    at slideshowapplet.SlideshowApplet.doListofImagefiles (SlideshowApplet.java:488)
    at slideshowapplet.SlideshowApplet.init(SlideshowAppl et.java:183)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1658)
    at java.lang.Thread.run(Thread.java:680)
    Excepción: java.security.AccessControlException: access denied (java.net.SocketPermission e.freewebhostingarea.com:80 connect,resolve)
    Ignored exception: java.security.AccessControlException: access denied (java.net.SocketPermission e.freewebhostingarea.com:80 connect,resolve)
    basic: setting up a new GraBoxPainter for Error
    basic: Applet initialized
    basic: Starting applet
    basic: completed perf rollup
    Thread started.
    basic: Applet started
    basic: Told clients applet is started
    Timer Started

  13. #11
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Auss I have it working (reading the folder directory)
    but indeed it is dishing up a lot of crap I do not understand!
    Look here the first part comes from the file version of the website which is correct.
    The second listing comes from the website....
    So I have to look into this what else it is printing....

    BufferedReader is initiated
    0 > .DS_Store Is NOT an image
    1 > 11149051_large2.jpg Is an image: <jpeg>
    2 > 369_3168.jpg Is an image: <jpeg>
    3 > b120329030340.0.jpeg Is an image: <jpeg>
    4 > barcelonaspainmillion.jpg Is an image: <jpeg>
    5 > COSTA BRAVA 1.jpg Is an image: <jpeg>
    6 > espectacular-casa-diseno1.jpg Is an image: <jpeg>
    7 > Foto10247Piso2377.jpg Is an image: <jpeg>
    8 > images.jpeg Is an image: <jpeg>
    9 > images-1.jpeg Is an image: <jpeg>
    10 > images-2.jpeg Is an image: <jpeg>
    11 > images-3.jpeg Is an image: <jpeg>
    12 > images-4.jpeg Is an image: <jpeg>
    13 > images-5.jpeg Is an image: <jpeg>
    14 > images-6.jpeg Is an image: <jpeg>
    15 > images-7.jpeg Is an image: <jpeg>
    16 > img11.JPG Is an image: <jpeg>
    17 > maresme-estate-2.jpg Is an image: <jpeg>
    18 > P1040397-2-450x200.jpg Is an image: <jpeg>
    19 > russia.jpg Is an image: <jpeg>
    20 > T1772_Manual_p1.jpg Is an image: <jpeg>
    21 > Unknown-1.jpeg Is an image: <jpeg>
    22 > Unknown-2.jpeg Is an image: <jpeg>
    23 > Unknown-3.jpeg Is an image: <jpeg>
    the arraylist length is: 23

    ==================================================
    BufferedReader is initiated
    0 > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> Is NOT an image
    1 > <html> Is NOT an image
    2 > <head> Is NOT an image
    3 > <title>Index of /tryoutwebsite/classes/slideshowImages/principal</title> Is NOT an image
    4 > </head> Is NOT an image
    5 > <body> Is NOT an image
    6 > <h1>Index of /tryoutwebsite/classes/slideshowImages/principal</h1> Is NOT an image
    7 > <pre><img src="/icons/blank.gif" alt="Icon "> <a href="?C=N;O=D">Name</a> <a href="?C=M;O=A">Last modified</a> <a href="?C=S;O=A">Size</a> <a href="?C=D;O=A">Description</a><hr><img src="/icons/back.gif" alt="[DIR]"> <a href="/tryoutwebsite/classes/slideshowImages/">Parent Directory</a> - Is NOT an image
    8 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="11149051_large2.jpg">11149051_large2.jpg</a> 15-Jun-2013 05:19 84K Is NOT an image
    9 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="369_3168.jpg">369_3168.jpg</a> 15-Jun-2013 05:19 31K Is NOT an image
    10 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="COSTA%20BRAVA%201.jpg">COSTA BRAVA 1.jpg</a> 15-Jun-2013 05:19 43K Is NOT an image
    11 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="Foto10247Piso2377.jpg">Foto10247Piso2377.jpg </a> 15-Jun-2013 05:19 54K Is NOT an image
    12 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="P1040397-2-450x200.jpg">P1040397-2-450x200.jpg</a> 15-Jun-2013 05:20 51K Is NOT an image
    13 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="T1772_Manual_p1.jpg">T1772_Manual_p1.jpg</a> 15-Jun-2013 05:20 29K Is NOT an image
    14 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="Unknown-1.jpeg">Unknown-1.jpeg</a> 15-Jun-2013 05:20 10K Is NOT an image
    15 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="Unknown-2.jpeg">Unknown-2.jpeg</a> 15-Jun-2013 05:20 8.1K Is NOT an image
    16 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="Unknown-3.jpeg">Unknown-3.jpeg</a> 15-Jun-2013 05:20 8.1K Is NOT an image
    17 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="b120329030340.0.jpeg">b120329030340.0.jpeg</a> 15-Jun-2013 05:19 55K Is NOT an image
    18 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="barcelonaspainmillion.jpg">barcelonaspainmil lion.jpg</a> 15-Jun-2013 05:19 44K Is NOT an image
    19 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="espectacular-casa-diseno1.jpg">espectacular-casa-diseno1.jpg</a> 15-Jun-2013 05:19 22K Is NOT an image
    20 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="images-1.jpeg">images-1.jpeg</a> 15-Jun-2013 05:19 5.7K Is NOT an image
    21 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="images-2.jpeg">images-2.jpeg</a> 15-Jun-2013 05:19 6.3K Is NOT an image
    22 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="images-3.jpeg">images-3.jpeg</a> 15-Jun-2013 05:19 8.7K Is NOT an image
    23 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="images-4.jpeg">images-4.jpeg</a> 15-Jun-2013 05:19 9.6K Is NOT an image
    24 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="images-5.jpeg">images-5.jpeg</a> 15-Jun-2013 05:19 13K Is NOT an image
    25 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="images-6.jpeg">images-6.jpeg</a> 15-Jun-2013 05:19 11K Is NOT an image
    26 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="images-7.jpeg">images-7.jpeg</a> 15-Jun-2013 05:19 16K Is NOT an image
    27 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="images.jpeg">images.jpeg</a> 15-Jun-2013 05:19 9.5K Is NOT an image
    28 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="img11.JPG">img11.JPG</a> 15-Jun-2013 05:20 47K Is NOT an image
    29 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="maresme-estate-2.jpg">maresme-estate-2.jpg</a> 15-Jun-2013 05:20 83K Is NOT an image
    30 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="russia.jpg">russia.jpg</a> 15-Jun-2013 05:20 23K Is NOT an image
    31 > <hr></pre> Is NOT an image
    32 > </body></html> Is NOT an image
    the arraylist length is: 0

    --- Update ---

    It is obvious that the second listing is not finding images
    and is not filling the arraylist: so I end up empty handed again
    But I am making progress, right?

  14. #12
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,616
    Thanks
    25
    Thanked 321 Times in 299 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    The server will refuse directly reading a folder from an exterior program (such as an applet) unless you code in the connection specifications and sign the jar (you have to do both).

    To code in connection specifications do the following:
    private static final String FTP_PASSWORD = ""; //Put your FTP password here
    private static final String WEBSITE_FTP = "ftp://willemii.orgfree.com:FTP_PASSWORD@willemii.orgfree.com";
    private List<String> fileList = new ArrayList<String>();
     
    private boolean readFileList() {
    	BufferedReader in = null;
    	try{
    		URL url = new URL(WEBSITE_FTP+"/FOLDER_TO_READ");
    		URLConnection aurlconn = url.openConnection();
    		in = new BufferedReader(new InputStreamReader(aurlconn.getInputStream()));
    		String line = in.readLine();
    		while(line!=null) {
    			String res = parseLine(line);
    			if(res!=null)
    			{	
    				fileList.add(res.trim());
    			}
    			line = in.readLine();
    		}
    		in.close();
    		return true;
    	}catch(Exception ex){ex.printStackTrace();}
    	return false;
    }
     
    private String parseLine(String line) {
    	//Whatever code you figured out to parse the line of the file to find the individual files
    }

    You then need to sign your applet. Without signing your applet, the connection will be refused.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  15. #13
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,616
    Thanks
    25
    Thanked 321 Times in 299 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    You are making progress. The problem now is that you have to use a rather creative algorithm for determining the file names.
    Based on the above input, here is the algorithm I would suggest to you:
    1. You should search each line for the sequence: a href=. If you don't find the sequence, read the next line; otherwise get the index of the sequence and go to step 2.
    2. Search for the first instance of > after the index from step 1. If you don't find the symbol, read the next line; otherwise get the index and go to step 3.
    3. Get the index of the first sequence of </a> after the index from step 2. If you don't find the sequence, read the next line; otherwise get the String between the index from step 2 and the one found in this step.
    4. Validate the file found is indeed an image by checking the extension on the file name String from step 3. If it is an image, add to the array; otherwise read the next line.
    5. Return to step 1 on the rest of the line (to ensure there isn't more than one image file on the line)

    I "think" that algorithm should parse the directory the way you want. That is of course assuming that the sequence I used is always there and never changes.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  16. #14
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    yea auss, great, that is the way to go.
    I'l work on it and you hear from me soon!

    here is the file type searching method (should be rewritten):

       String line; // the line read from the file
                    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 ");
                }
            }
            else
            System.out.println(" no fillename array is setup: " + url);
        }
     
     
        private boolean checkImageType (String f)  {
     
                    String fl = ft.getContentType(f);  // MimetypesFileTypeMap ft;
     
                    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;
                    }
        }

  17. #15
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Auss I haven't tried it yet (too late go to sleep first)
    but this might do the job?

    sample strings
    8 > <img src="/icons/image2.gif" alt="[IMG]"> <a href="11149051_large2.jpg">11149051_large2.jpg</a> 15-Jun-2013 05:19 84K Is NOT an image
    1 > 11149051_large2.jpg Is an image: <jpeg>



     private void doListofImagefiles()  { //URL
             //checking and storing the present files of the folder
     
            URL url = null;
            java.net.URLConnection con = null;
            try {
                  url = new URL(getCodeBase(), "slideshowImages" +
                        File.separator + currentfolder);
                  System.out.println(" Do the image file list of " + currentfolder);
                  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();
               //   HttpURLConnection conh = (HttpURLConnection) url.openConnection();
     
                //  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;
                    String imgstring = null;
                    for (; (line = in.readLine()) != null;) {
                         StringTokenizer tok = new StringTokenizer(line);
                         while (tok.hasMoreElements()) {
                             String s = tok.nextToken();
                             String sub = s.substring(0, 5);
                             if (sub.equals("href=")) {
                                 System.out.println(" print id " + s);
     
                                 for (int ii = 0; ii < s.length(); ii++) {
                                     if (s.charAt(ii) == '"') {
                                         int cnt = ii;
                                         do  {
                                             imgstring = imgstring + s.charAt(cnt);
                                         } while (s.charAt(ii) == '"');
                                     }
     
                                 }
     
                             }
     
                         }
     
     
                        System.out.print(i + " > " + imgstring);
                        //adding the checked correct image files
                        if (checkImageType(imgstring)) {
                            imagefiles.add(imgstring);
                        }
                        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 ");
                }
            }
            else
            System.out.println(" no fillename array is setup: " + url);
        }

  18. #16
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    This method works on the file version of the webpage
    But it wont work when uploading!
    Anyway the alg. is to complicated (on of my mayor problems)
    For now I have to correct some student exams (I am a musician).
    but I'll turn back to this soon.
    Any comments welcome

     private void doListofImagefiles()  { //URL
             //checking and storing the present files of the folder
     
            URL url = null;
            java.net.URLConnection con = null;
            try {
                  url = new URL(getCodeBase(), "slideshowImages" +
                        File.separator + currentfolder);
                  System.out.println(" Do the image file list of " + currentfolder);
                  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();
               //   HttpURLConnection conh = (HttpURLConnection) url.openConnection();
     
                //  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()));
     
               //    InputStream in = con.getInputStream();
     
                    String line;
                    System.out.println(" BufferedReader is initiated");
                    int i = 0;
     
                    for (; (line = in.readLine()) != null;) {
                         String imgstring = "";
                         // deviding the readin line by space between strings
                         StringTokenizer tok = new StringTokenizer(line);
                         if (tok.hasMoreElements()) {            
                        // if (false) {
                            while (tok.hasMoreElements()) {
     
                                String s = tok.nextToken();
                                System.out.print(i + " token " + s);
                                if (s.length() > 5) {
                                    String sub = s.substring(0, 5);
                                    if (sub.equals("href=")) {
                                    System.out.println(" print id " + s);
     
                                        for (int ii = 0; ii < s.length(); ii++) {
                                            if (s.charAt(ii) == '"') {
                                                int cnt = ii;
                                                do  {
                                                    imgstring = imgstring + s.charAt(cnt);
                                                } while (s.charAt(ii) == '"');
                                            }
     
                                        }
     
                                    }
                                }
                                // building string including spaces
                                imgstring = imgstring + s;
     
                            }
                        }
                        // incase there no space
                        else imgstring = line;
     
     
                        System.out.print(i + " > " + imgstring);
                        //adding the checked correct image files
                        if (checkImageType(imgstring)) {
                            imagefiles.add(imgstring);
                        }
                        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 ");
                }
            }
            else
            System.out.println(" no fillename array is setup: " + url);
        }
     
     
        private boolean checkImageType (String f)  {
     
                    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;
                    }
        }


    --- Update ---

    This would be more elegant, right?
    But what exceptions you get here?

     String imgstring = "";
                         // deviding the readin line by space between strings
                         StringTokenizer tok = new StringTokenizer(line);
                         if (tok.hasMoreElements()) {            
                        // if (false) {
                            while (tok.hasMoreElements()) {
     
                                String s = tok.nextToken();
                                System.out.print(i + " token " + s);
                                try {
                                    String sub = s.substring(0, 5);
                                    if (sub.equals("href=")) {
                                    System.out.println(" print id " + s);
     
                                        for (int ii = 0; ii < s.length(); ii++) {
                                            if (s.charAt(ii) == '"') {
                                                int cnt = ii;
                                                do  {
                                                    imgstring = imgstring + s.charAt(cnt);
                                                } while (s.charAt(ii) == '"');
                                            }
     
                                        }
     
                                    }
                                }
                                catch (ArgumentOutOfRangeException e) { // <- I have to write that exception says the compiler?
                                    System.out.print(i + " out of bound " + s);
                                } 
                                // building string including spaces
                                imgstring = imgstring + s;
     
                            }
                        }
                        // incase there no space
                        else imgstring = line;


    --- Update ---

    Lets take some distance to all this.
    Why is this HTML stuff appearing?
    Because that server is turning the output into a HTML page, right?
    (It might be that php is generating that code, right Auss?)
    The file version of the site does not do that and works just fine!

    My first attempt of filtering out that HTML stuff failed, so
    I have to rethink my method again.

    Auss is right to say that the <a href=" string is an important identifier.
    After getting this string I only need to read the content between the two quotes, right?
    Or better: <a href=" is opening the string reader and " is closing it.

    But there is a problem, what does one do with " inside a " --- " ?
    So this one helps s.charAt(int i) == '"'
    But there is still <a href=" ending into a "

    so what to do here?

    ps the <a href= identifier is

    if (s.length() > 5) {
    String sub = s.substring(0, 5);
    if (sub.equals("href=")) {

  19. #17
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    I believe I am almost there, but still having some trouble (man it is not easy for me).
    So I do the following
    1) I save the complete directory line as a string called imgstring
    2) Than I check if there are more tokens (divided by empty space)
    3) Next I look for the href= string
    until here all goes ok
    4) when found 3) I empty imgstring and try to fill it again until "
    but this part goes wrong! See the Do/ While loop

    A string to be checked looks like this:
    <img src="/icons/image2.gif" alt="[IMG]"> <a href="11149051_large2.jpg">11149051_large2.jpg</a> 15-Jun-2013 05:19 84K

    while (tok.hasMoreElements()) {
                         //the token has several space units
                            String s = tok.nextToken();                         
                            if (s.length() > 5) {
                                String sub = s.substring(0, 5);
                                if (sub.equals("href=")) {
                                System.out.println(" is img token: " + s);
                                    imgstring = "";
     
                                    int count2 = 6;
                                    do  {
                                         imgstring = imgstring + s.charAt(count2);
                                         count2++;
                                    } while (s.charAt(count2) == '"');
                                    System.out.println(" is img token filtered: "
                                                                        + imgstring);
                                    System.out.println(); System.out.println();
                                }  
                            }
                         }

    I believe the while (s.charAt(count2) == '"'); that is pr0bably alright?
    But what about this:
    String imgstring = imgstring + Character.toString(s.charAt(count2));
    And this (al not working):
    String imgstring = imgstring + s.substring(count2, count2);

  20. #18
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    I looked at it a long time and I do not understand what is going on here.

    This is an example of a directory line:
    <img src="/icons/image2.gif" alt="[IMG]"> <a href="COSTA%20BRAVA%201.jpg">COSTA BRAVA 1.jpg</a>

    The above string gets tokenized (using empty-space)

    The next is the output of the cited code at the bottom part.

    is img token: href="COSTA%20BRAVA%201.jpg">COSTA
    <C>
    is img token filtered: C


     StringTokenizer tok = new StringTokenizer(line);
     
                         while (tok.hasMoreElements()) {
                         //the token has several space units
                            String s = tok.nextToken();                         
                            if (s.length() > 5) {
                                String sub = s.substring(0, 5);
                                if (sub.equals("href=")) { // finds the image string
                                System.out.println(" is img token: " + s);
                                    imgstring = "";
     
                                    int count2 = 6;
                                    do  {
                                         imgstring = imgstring +
                                             Character.toString(s.charAt(count2));
                                             //    s.substring(count2, count2);
                                         System.out.print("<" + imgstring + ">");
                                         count2++;
                                    } while (s.charAt(count2) == '"');
                                    System.out.println();
                                    System.out.println(" is img token filtered: "
                                                                        + imgstring);
                                    System.out.println(); System.out.println();
                                }  
                            }
                         }


    --- Update ---

    Dear willem

    why you don't try while (s.charAt(count2) != '"');

    of course willem how utterly stupid of me

    salud willem

  21. #19
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Pls give me some feed back concerning the applets

    mywebpage

    still testing things

    some of my friends got this:

    access denied (java.net.SocketPermission...

    what is that about......

  22. #20
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Dear Aus and All

    This is really annoying I had it all working Yesterday (the several slideshow applets at my site) and now I get again a 403 error.
    When reading this thread you'll find out that it all started with this 403-java/ server error. And after some help of Auss and me getting some what of a listen of a folder directory, I started to work to get the applets going.
    The server generated a web page format of the directory and I wrote (having to take several obstacles) a filter algorithm that would deliver me a clean list of image files to download for the slideshows (there are like 8 different slides that all pickup a different folder).

    I GOT IT GOING YESTERDAY BUT TODAY AGAIN THE TROUBLES (403 CODE) ARE HERE TO STAY!

    Probably the server observed what I was doing (and succeeding) and "slammed the door in my face". Sure the server is gratis and I will write an email but there is not much to complain about, right?

    I sincerely believe now that there is no future for Applets anymore (even when it worked for one night on my Mac, several friends of mine got different error codes on their computers like ClassNotFoundException and access denied (java.net.SocketPermission). It is really very sad because now I have to look up one of this pre-cooked slideshows and adjust my page to it (when I opened the side one firefox --wink, wink-- appeared a flash plugin installing window…… is the server giving me a hint…..).

    It is already a global issue, guys: in order to stay safe and to "have security" we need to give up our freedom of expression and our room to move, right!

    --- Update ---

    Dear Sir Madam

    I opened a free website space at you server and thank you for that.

    I am using that space mywebpage for testing a slideshow applet. The trouble the applet goes through is that it needs to list several directories of some image file names (exclusively through code-base command). The path is http://willemii.orgfree.com/tryoutwe...ages/principal (or some more folders at slideshowImages level).

    Your server let me do that yesterday, but today I got a "HTTP 403 access denied error" from the server. Sir, Madam, I am not peaking into your server directories. I am only interested in that specific file path and I am asking you to grant me a permission to do so.

    Thank you ones again for the free webspace

    willem

  23. #21
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Got an answer from the server guys:
    "Hi, if you upgrade that error will disappear. It is a hotlink protection for free accounts."
    Oh.......

  24. #22
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    Ok next struggle signing the applet, this might do it:
    (working with Netbeans)
    Here's how you do it:

    1. Open your project.
    2. Go to File --> Project Properties.
    3. Click "Web Start"
    4. Click "Enable Web Start"
    5. Under Signing click customize and select the correct option (self sign should be enough)

    Build the project. It'll create some jnlp's and other stuff but the jar is signed as well.

    Javier A. Ortiz Bultr

    Since I have the applet files in a jar file (should be concerning the signature)
    I've got a new problem: java.lang.ClassNotFoundException: slideshowapplet.SlideshowApplet.class

    The applet tag is now:

    <APPLET codebase="classes"
    code="slideshowapplet/SlideshowApplet.class"
    archive="slideshowapplet/SlideshowApplet.jar"
    width=750 height=450>

    the path is (from code base) classes/slideshowapplet/slideshowapplet.jar
    and the jar contains the SlideshowApplet.class

    So please help me what is going wrong now

    --- Update ---

    at the META-INF there is under INDEX.LIST (whatever that is)

    JarIndex-Version: 1.0

    slideshowapplet.jar
    slideshowapplet

    --- Update ---

    changed the applet tag into

    <APPLET
    archive="slideshowapplet/SlideshowApplet.jar"
    code="slideshowapplet/SlideshowApplet.class"
    width=750 height=450>

    and the relative path is now slideshowapplet/slideshowapplet.jar
    Still get the error but there is a strange thing happening!
    I find this path listed, which is correct: network: Conectando http://willemii.orgfree.com/tryoutwe...owApplet.class
    BUT NEXT I FIND A RELATIVE LINK OF MY HARD DISK.... WOW WHERE IS THIS COMING FROM

    --- Update ---

    Usando versión JRE 1.6.0_45-b06-451-10M4406 Java HotSpot(TM) 64-Bit Server VM
    Directorio de inicio del usuario = /Users/willemcargar: clase slideshowapplet/SlideshowApplet.class no encontrada.
    the red is that link
    man this stuff is really confusing....

    --- Update ---

    It gets weirder the class name is: SlideshowApplet.class
    The jar name is: slideshowapplet.jar
    But the path shows:
    network: Conectando willemii.orgfree.com/tryoutwebsite/slideshowapplet/SlideshowApplet.jar con proxy=DIRECT
    SlideshowApplet.jar
    So I changed the capitals manually, wow where is this coming from?
    AND NOW THINGS ARE ADVANCING SOME MORE

    --- Update ---

    The classes are loaded
    but there is a problem with certificate (do not know why that is in spanish
    but you guys know spanish it is the US second language, right:
    security: jpicertstore.cert.getkeystore
    security: Iniciar la comprobación del reemplazo de la autoridad de certificación raíz
    security: La autoridad de certificación raíz no se ha reemplazado
    Ignored exception: java.security.cert.CertificateException: La configuración de seguridad no permitirá dar permisos a los certificados autofirmados

    --- Update ---

    The error says (in spanish) as if the certificate is NOT signed"

    --- Update ---

    so here is the whole thing and there is (on top) still the link to my hard disk


    basic: Oyente de progreso añadido: sun.plugin.util.GrayBoxPainter$GrayBoxProgressList ener@4a57ea52
    basic: Plugin2ClassLoader.addURL parent called for http://willemii.orgfree.com/tryoutwe...showApplet.jar
    network: Conectando http://willemii.orgfree.com/tryoutwe...showApplet.jar con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com:80/ con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com/tryoutwe...showApplet.jar con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com:80/ con proxy=DIRECT
    network: Descargando recurso: http://willemii.orgfree.com/tryoutwe...showApplet.jar
    Content-Length: 25.711
    Content-Encoding: null
    security: La comprobación de revocación de lista negra está activada
    security: Cargando certificados CA raíz desde /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security/cacerts
    security: Certificados CA raíz cargados desde /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security/cacerts
    security: Cargando certificados desde el almacén de certificados de la sesión de despliegue
    security: Certificados cargados desde el almacén de certificados de la sesión de despliegue
    security: Cargando certificados CA raíz desde from keychain
    security: Certificados CA raíz cargados desde from keychain
    security: Validar la cadena de certificados mediante la interfaz de programación CertPath
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: jpicertstore.cert.getkeystore
    security: Iniciar la comprobación del reemplazo de la autoridad de certificación raíz
    security: La autoridad de certificación raíz no se ha reemplazado
    Ignored exception: java.security.cert.CertificateException: La configuración de seguridad no permitirá dar permisos a los certificados autofirmados
    security: Validar la cadena de certificados mediante la interfaz de programación CertPath
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: jpicertstore.cert.getkeystore
    security: Iniciar la comprobación del reemplazo de la autoridad de certificación raíz
    security: La autoridad de certificación raíz no se ha reemplazado
    Ignored exception: java.security.cert.CertificateException: La configuración de seguridad no permitirá dar permisos a los certificados autofirmados
    security: Validar la cadena de certificados mediante la interfaz de programación CertPath
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: Obtener colección de certificados del almacén de certificados CA raíz
    security: jpicertstore.cert.getkeystore
    security: Iniciar la comprobación del reemplazo de la autoridad de certificación raíz
    security: La autoridad de certificación raíz no se ha reemplazado
    basic: Subprograma cargado.
    basic: Applet resized and added to parent container
    basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 565249 us, pluginInit dt 61004615 us, TotalTime: 61569864 us
    Java Plug-in 1.6.0_45
    Usando versión JRE 1.6.0_45-b06-451-10M4406 Java HotSpot(TM) 64-Bit Server VM
    Directorio de inicio del usuario = /Users/willem>>> image foldername principal
    >>> background availablejava.awt.Color[r=255,g=255,b=255]
    >>> image time 5
    >>> screenX 700
    >>> screenY 400
    >>> button 3 timerflag true
    1> the folder slideshowImages : http://willemii.orgfree.com/tryoutwe...lideshowImages
    2> the folder slideshowapplet icon for button: http://willemii.orgfree.com/tryoutwe...lideshowapplet
    3> the current image folder : http://willemii.orgfree.com/tryoutwe...ages/principal
    4> the flag set to true THE FOLDER PATH IS: http://willemii.orgfree.com/tryoutwe...ages/principal
    ------------------------------------


    Do the image file list of http://willemii.orgfree.com/tryoutwe...ages/principal
    network: Conectando http://willemii.orgfree.com/tryoutwe...ages/principal con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com:80/ con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com/tryoutwe...ges/principal/ con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com:80/ con proxy=DIRECT
    can't download the file list
    20-jun-2013 23:43:30 slideshowapplet.SlideshowApplet doListofImagefiles
    SEVERE: null
    java.io.IOException: Server returned HTTP response code: 403 for URL: http://willemii.orgfree.com/tryoutwe...ges/principal/
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1436)
    at slideshowapplet.SlideshowApplet.doListofImagefiles (SlideshowApplet.java:496)
    at slideshowapplet.SlideshowApplet.init(SlideshowAppl et.java:183)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1658)
    at java.lang.Thread.run(Thread.java:680)
    end of error message
    network: Conectando http://willemii.orgfree.com/tryoutwe...wapplet/FW.jpg con proxy=DIRECT
    network: Conectando http://willemii.orgfree.com:80/ con proxy=DIRECT
    The icon images are downloaded: http://willemii.orgfree.com/tryoutwe...wapplet/FW.jpg
    network: Conectando http://willemii.orgfree.com/tryoutwe...wapplet/BW.jpg con proxy=DIRECT
    The icon images are downloaded: http://willemii.orgfree.com/tryoutwe...wapplet/BW.jpg
    network: Conectando http://willemii.orgfree.com/tryoutwe...wapplet/ST.jpg con proxy=DIRECT
    The icon images are downloaded: http://willemii.orgfree.com/tryoutwe...wapplet/ST.jpg
    network: Conectando http://willemii.orgfree.com/tryoutwe...wapplet/GO.jpg con proxy=DIRECT
    The icon images are downloaded: http://willemii.orgfree.com/tryoutwe...wapplet/GO.jpg
    basic: Oyente de progreso eliminado: sun.plugin.util.GrayBoxPainter$GrayBoxProgressList ener@4a57ea52
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at slideshowapplet.SlideshowApplet.init(SlideshowAppl et.java:186)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1658)
    at java.lang.Thread.run(Thread.java:680)
    Excepción: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    Ignored exception: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    basic: setting up a new GraBoxPainter for Error
    basic: Applet initialized
    basic: Starting applet
    basic: completed perf rollup
    Thread started.


    Timer Started


    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at slideshowapplet.SlideshowApplet.start(SlideshowApp let.java:311)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1719)
    at java.lang.Thread.run(Thread.java:680)
    Excepción: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    Ignored exception: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    basic: Applet started
    basic: Told clients applet is started
    Exception in thread "AWT-EventQueue-2" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at slideshowapplet.SlideshowApplet$TimeSetter.actionP erformed(SlideshowApplet.java:363)
    at javax.swing.Timer.fireActionPerformed(Timer.java:2 91)
    at javax.swing.Timer$DoPostEvent.run(Timer.java:221)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:708)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:669)
    at java.awt.EventQueue$2.run(EventQueue.java:667)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 678)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

    --- Update ---

    The famous error code is still there probably because the certificate is there
    but it is like it is not signed.... (so how to sign that d--- thing?)

    java.io.IOException: Server returned HTTP response code: 403 for URL: http://willemii.orgfree.com/tryoutwe...ges/principal/[COLOR="Silver"]

  25. #23
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am getting a "java.io.IOException: Server returned HTTP response code: 403 "

    I modified the FTP suggestion of Auss in a way that it is NOT an applet
    (applets are to restricked to begin with).
    But I got the next error listening, which shows
    that the thing breaks down from the
    buffered reader, right?
    any suggestions what is going on


    FTP is open ftp://willemii.orgfree.com:FTP_PASSW...ages/principal
    sun.net.ftp.FtpLoginException: Not logged in
    FTP did not work out
    at sun.net.ftp.FtpClient.readReply(FtpClient.java:231 )
    at sun.net.ftp.FtpClient.issueCommand(FtpClient.java: 193)
    at sun.net.ftp.FtpClient.login(FtpClient.java:516)
    at sun.net.http://www.protocol.ftp.FtpURLConnec...tion.java:276)
    at sun.net.http://www.protocol.ftp.FtpURLConnec...tion.java:352)
    at slideshowapplet.Main.readFileList(Main.java:47)
    at slideshowapplet.Main.<init>(Main.java:28)
    at slideshowapplet.Main.main(Main.java:32)

    so here is the main part:
    private boolean readFileList() {
    	BufferedReader in = null;
            java.net.URLConnection con = null;
    	try{
    		URL url = new URL(WEBSITE_FTP + File.separator + "tryoutwebsite" +
                         File.separator + "slideshowImages" +
                        File.separator + "principal");
    		con = url.openConnection();
                    System.out.println(" FTP is open " + url);
    		in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    		String line = in.readLine();
                    System.out.println(" buffered reader initialized ");
    		while(line!=null) {
    			String res = parseLine(line);
    			if(res!=null)
    			{
    				fileList.add(res.trim());
    			}
    			line = in.readLine();
    		}
    		in.close();
    		return true;
    	}catch(Exception ex){
                ex.printStackTrace();
                System.out.println(" FTP did not work out ");
            }
    	return false;
    }
     
        private String parseLine(String line) {
    	System.out.println(" --> " + line);
            return line;

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  2. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  3. Calling .Net HttpHandler from Java - "Bad Request" Returned
    By fordej2511 in forum Member Introductions
    Replies: 0
    Last Post: May 5th, 2011, 02:11 PM
  4. Help needed for "java.io.IOException: Not in GZIP format"
    By goldest in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: August 10th, 2010, 03:05 AM
  5. Replies: 1
    Last Post: March 31st, 2010, 09:42 PM