Url.openStream() 5x

Hello
Please, I know this is impossible, and how quickly one can get into a recursive rut, however I have an application that when I connect to a url that is a struts app, it makes 5 calls per single url.openStream(). I know it is impossible for little stupid me to have "discovered" this however I tried to make sure that it was not multiple threads, put in probes, tested the struts app, even worked up using Apache's HttpClient, of course to no difference.
I am calling, a subclass of httpservlet within which I am making the url call. I know the atomicity of the call going in, can see the call in doPost, but see five calls against the struts app. The stuts app works just fine when executed from a webpage; one call, one pass. Is it just that somehow 5 threads are being created. Can I somehow monitor the main thread in my subclassed servlet and see it spawn the threads after the url.openStream()? I have tried 1.4.2_14 and 1.5._09 to the same effect. Ideas? tia.

Nevermind. The sound of chagrin.

Similar Messages

  • URL.openStream() works in Windows but not in Linux

    I am having a problem with this line:
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    in the code sample further below.
    A simple program using this line works when compiled in my Windows XP:
    java version "1.6.0_03"
    Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
    Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
    but not when compiled on my RedHat FC 4 server:
    java version "1.4.2"
    gij (GNU libgcj) version 4.0.2 20051125 (Red Hat 4.0.2-8)
    The program (making using of a previous froum example and pared down to minimize tangent topics):
    The code works for all 3 URLs in Windows. In Linux it only works for the 1st one (bbc.co site)
    Error is listed below the code:
    import java.net.*;
    import java.io.*;
    public class BBC {
    public static void main(String[] args) throws Exception
    //    URL url = new URL("http://news.bbc.co.uk/sport1/hi/football/eng_prem/6205747.stm");
    //    URL url = new URL("http://www.weatherunderground.com/global/stations/71265.html");
        URL url = new URL("http://www.weatherunderground.com");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        int nLineCnt = 0;
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            nLineCnt++;
        System.out.println("nLineCnt=" + nLineCnt);
    //--------------------------------------------------------------------------------------------------------------------------------------------Exception in thread "main" java.lang.StringIndexOutOfBoundsException
    at java.lang.String.substring(int, int) (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.net.protocol.http.Request.readResponse(gnu.java.net.LineInputStream) (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.net.protocol.http.Request.dispatch() (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.net.protocol.http.HTTPURLConnection.connect() (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.net.protocol.http.HTTPURLConnection.getInputStream() (/usr/lib/libgcj.so.6.0.0)
    at java.net.URL.openStream() (/usr/lib/libgcj.so.6.0.0)
    at BBC.main(java.lang.String[]) (Unknown Source)
    at gnu.java.lang.MainThread.call_main() (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)
    Can anyone please suggest what I can do to be able to process the weatherunderground URL?
    Claude

    To me it would suggest a bug in the VM that you are using.
    Solutions
    1. Use a different VM
    2. Write your own code to process the http code. Depending on licensing for the VM in use and the VM itself. you might be
    able to find the bug in that code, fix it yourself, and then use your fix (start up command line options for VM.) Otherwise
    you have to duplicate the functionality. You might look to jakarta commons, there might be code there that does that.

  • URL.openstream doesn't work

    Hi,
    I run the demo program form java tutorial. Code as below:
    import java.net.*;
    import java.io.*;
    public class urltest {
    public static void main(String[] args) throws Exception {
         URL yahoo = new URL("http://www.yahoo.com/");
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        yahoo.openStream()));
         String inputLine;
         while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         in.close();
    but it gives the follow output
    Exception in thread "main" java.net.NoRouteToHostException: Operation timed out:
    no further information
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
    urce)
    at java.net.URL.openStream(Unknown Source)
    at urltest.main(urltest.java:30)
    Plz advise.

    Thx Jean, I modify the OS to Windows 95, but the program still don't work
    code:
    import java.net.*;
    import java.io.*;
    public class urltest {
    public static void main(String[] args) throws Exception {
         URL yahoo = new URL("http://www.yahoo.com/");
         HttpURLConnection uc = (HttpURLConnection)yahoo.openConnection();
    uc.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.5; Windows 95)");
    uc.setRequestProperty("Connection","Keep-Alive");
    uc.setDoOutput(true);
    uc.setDoInput(true);
    uc.setUseCaches(false);
    uc.setRequestMethod("GET");
    uc.setFollowRedirects(false);
    uc.setInstanceFollowRedirects(false);
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        uc.getInputStream()));
         String inputLine=in.readLine();
         //while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         in.close();
    The output is
    Exception in thread "main" java.net.NoRouteToHostException: Operation timed out:
    no further information
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
    urce)
    at urltest.main(urltest.java:39)
    Plz advise

  • How to use "url.openStream()" . What this function does?

    how to use "url.openStream()" . What this function does?
    Edited by: sahil1287 on Apr 16, 2009 10:02 PM

    http://java.sun.com/javase/6/docs/api/java/net/URL.html#openStream()
    http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html

  • Help with URL.openStream

    Hi,
    This small Java program hangs if run on 1.3.1 but not 1.2.2 or some version of 1.4:
    import java.net.*;
    import java.io.*;
    import java.security.*;
    public class V {
        public static void main(String args[]) throws MalformedURLException, IOExcep
    tion, AccessControlException {
            String u = "http://www.rsmas.miami.edu/~angel/a.sh";
            InputStream     inp;
            BufferedReader  dis;
            try {
                int                 i;
                String              s;
                URL                 url;
                URLConnection       urlConn;
                url = new URL(u);
                System.out.println("URL constructor");
                inp = url.openStream();
                System.out.println("stream opened");
                dis = new BufferedReader(new InputStreamReader(inp));
                System.out.println("BufferedReader created");
                //  skip leading html headers
                while ((s = dis.readLine()) != null) {
                    if (s.startsWith("<body"))
                        break;
                System.out.println("found <body>");
            catch (MalformedURLException mue) {
                System.out.println("Bad URL: " + mue);
                throw(mue);
            catch (IOException ioe) {
                System.out.println("Error reading from remote: " + ioe);
                throw(ioe);
            catch (AccessControlException e) {
                System.out.println("Access Control Exception");
                throw(e);
    }The CGI script is
        #!/bin/sh
        echo "Content-type: text/html\r"
        echo "\r"
        echo "<html>"
        echo "<body>"
        echo "<pre>"
        while true; do
            echo "Hi there"
            sleep 3
        doneAny thoughts?
    Thanks,
    Angel

    what's it hanging after? does it print any of your lines out? You don't need to call connect() on the URLConnection, do you? Maybe not if using openStream().
    BTW, is that script going to loop forever? The URL isn't working.

  • Passing user/pass by URL (url.openstream())

    Hi guys,
    I have a tough one for you...hehe
    In a JSP, I create a URL... and open it URL.openstream...read each line and write them into another file.
    1)Since the calling JSP is in a directory that ask username and password, when I call the URL, it cannot open it because no username and password give access to the page.
    How can I pass username and password?
    2)I could let the called jsp in a public zone, but the problem is that even if I use jsessionid the session change... do you know why?
    Thanks guys!

    You should have session variables attached to your page. Check Connection and Session, you should be able to use something like getProperties ("userid")

  • Url.openstream():strange result of available().

    I test my first network programming,and the result is very strange,It seems that the result of available() is random!
    URL url= new URL("ftp://ftp.pku.edu.cn/pub/proxy.txt");
    InputStream is=url.openStream();
    /***** the output is 0 ********/
    System.out.println(is.available());
    URL url1= new URL("ftp://ftp.pku.edu.cn/pub/proxy.txt");          is=url1.openStream();
    /******* the result is 4092 ************/
         System.out.println(is.available());
    Why this happen? the result should be equal!

    is that the exact code that shows those results? anyway, it doesn't matter, available() is not random, it just may return different values as it reads in more bytes, so if the other send keeps sending data, available() will keep returning larger and larger values!
    perhaps the first time the connection with a little slow, the server may not have responded very quickyl, or the underlying buffer might not have been full enough so it didn't flush it out to you, in any case, available() is not random.

  • URL openStream problem. URL String length

    Hi,
    My problem is about length of the url string. I'm simply creating a URL and trying to call openStream() to get content. But if the length of url string exceeds 118 characters, I'm getting an exception. It says Server returned Http response code 505.
    If I try the same url string in a browser it's working.
    Thanks for all replies in advance...

    the problem solved, it was about white space not length... I didn't notice the white space there sorry!

  • JSP bug? url.openStream() = server redirected too many times

    I tried something the other day that works in Java, so it should work as a JSP scriptlet, but I received an error message that others have posted elsewhere without a compete resolution. Specifically, given a URL, say u, one ought to be able to do u.openStream() and eventually read the remote page. Typically, one might want to try
    URL u = new URL("http://someserver.com/path/file.xxx")
    BufferedReader bfr = new BufferedReader(new InputStreamReader(u.openStream()))and then read bfr line-by-line. The problem that seems to be fairly common is that the openStream() call throws a ProtocolException claiming "server redirected too many times (20), ."
    What I've seen is that this exception occurs whenever the URL is outside the Tomcat server whence the call is being made; in our case, we're running "out-of-the-box" Jakarta Tomcat 4.1.29 on port 8080 of a w2k server. The code works perfectly in native Java and in JSP for a URL of the form "/anotherpage.jsp"
    Is this a bug in JSP, or in our version of Tomcat, or is there just some configuration parameter that needs to be changed from its default? As I said, I've seen similar posts (with less detailed analysis) in the Usenet newsgroups, but not one has generated a response that explains and resolves the matter.
    Perhaps a JSP guru out there could set the record straight? Thanks.
    P.S. I know that the use of scriptlets in JSP is being discouraged, but they are still supported AFAIK.

    Sure scriptlets are still supported. Most times though you can do things better with a custom tag. Why reinvent the wheel?
    Just as a suggestion, you might try the JSTL <c:import> tag.
    It basically does just this behind the scenes.
    However I don't think that will help you in the end - it will probably hit the same error message.
    My guess would be that the problem is not caused by java/JSP as such, but by a firewall, or configuration somewhere.
    The following works fine for me (ignoring broken images of course)
    <%@ page import="java.net.*, java.io.*" %>
    <%
    URL u = new URL("http://www.google.com");
    BufferedReader bfr = new BufferedReader(new InputStreamReader(u.openStream()));
    String line = null;
    while ((line = bfr.readLine()) != null){
      out.println(line);
    %>Hope this helps,
    evnafets

  • Url serialization and openStream

    Once I serialize a java.net.URL and serialize it again URL.openStream throws a NullPointerException. What can I do about this? Is this a jdk bug?
    Exception occurred during event dispatching:
    java.lang.NullPointerException
    at sun.net.www.ParseUtil.decode(ParseUtil.java:27)
    at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:62)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:133)
    at java.net.URL.openStream(URL.java:798)
    at sun.applet.AppletAudioClip.<init>(AppletAudioClip.java:62)
    at java.applet.Applet.newAudioClip(Applet.java:233)
    at net.turingcomplete.phosphor.client.ClientOptions.playMessNotifySound(ClientOptions.java:318)
    at net.turingcomplete.phosphor.client.test.button1ActionPerformed(test.java:52)
    at net.turingcomplete.phosphor.client.test.access$1(test.java:51)
    at net.turingcomplete.phosphor.client.test$2.actionPerformed(test.java:42)
    at java.awt.Button.processActionEvent(Button.java:329)
    at java.awt.Button.processEvent(Button.java:302)
    at java.awt.Component.dispatchEventImpl(Component.java:2595)
    at java.awt.Component.dispatchEvent(Component.java:2499)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
    at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)

    I have figured out what the problem is. This is the output of the pre-serialized version:
    DEBUG| 'getAuthority null'
    DEBUG| 'getFile /C:/MyDocuments_NOSPACE/Phosphor/sounds/yahoo_msg.wav'
    DEBUG| 'getHost '
    DEBUG| 'getPath /C:/MyDocuments_NOSPACE/Phosphor/sounds/yahoo_msg.wav'
    DEBUG| 'getPort -1'
    DEBUG| 'getProtocol file'
    DEBUG| 'getQuery null'
    DEBUG| 'getRef null'
    DEBUG| 'getUserInfo null'
    DEBUG| 'getContent sun.applet.AppletAudioClip@595f51'
    and this is the output of the post-serialized version:
    DEBUG| 'getAuthority null'
    DEBUG| 'getFile /C:/MyDocuments_NOSPACE/Phosphor/sounds/yahoo_msg.wav'
    DEBUG| 'getHost '
    DEBUG| 'getPath null'
    DEBUG| 'getPort -1'
    DEBUG| 'getProtocol file'
    DEBUG| 'getQuery null'
    DEBUG| 'getRef null'
    DEBUG| 'getUserInfo null'
    where getcontent returns throws NullPointerException.
    So it looks like serializing a URL has real limitations. I guess you should only serialize the info needed to create the URL again, unless anyone has a way of successfully reserializing a URL.

  • Application URL not working properly

    We have a custom application hosted on weblogic8.1 cluster. And this is in production environment.
    What we observed was, I am using FireFox browser and works fine for me. And I noticed it did not work a few days ago only once. However, most of the other users use IE6.0 and seems not able to access this URL. So some tried using IE 7.0 and worked fine for some time. But, the problem persisted very often as few can and others cannot.
    Can anybody tell me what could be the problem or should I be modifying any files in weblogic server.
    This is working pretty fine in testing environement.

    Thank you very much for the hint, though I have not tried your suggestion. I tried a little more and found the following way might be simpler - using "java.url.*" and "java.io.*". Just a simple test:
    ============================
    URL url=new URL("ftp://usrname:password@hostname/localDirectory/filename.txt");
    InputStream is=url.openStream();
    BufferedReader in=new BufferedReader(new InputStreamReader(is));
    String line;
    while((line=in.readLine()) !=null) { System.out.println(line);
    ==========================================
    Of course, other data format would work in a similar way.
    Cheers,
    ljiang001

  • Reading a pdf file from URL into Byte array/ByteBuffer in an applet.

    I'm trying to figure out why this particular snippet of code isn't working for me. I've got an applet which is supposed to read a .pdf and display it with a pdf-renderer library, but for some reason when I read in the .pdf files which sit on my server, they end up as being corrupt. I've tested it by writing the files back out again.
    I've tried viewing the applet in both IE and Firefox and the corrupt files occur. Funny thing is, when I trying viewing the applet in Safari (for Windows), the file is actually fine! I understand the JVM might be different, but I am still lost. I've compiled in Java 1.5. JVMs are 1.6. The snippet which reads the file is below.
    public static ByteBuffer getAsByteArray(URL url) throws IOException {
            ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
            URLConnection connection = url.openConnection();
            int contentLength = connection.getContentLength();
            InputStream in = url.openStream();
            byte[] buf = new byte[512];
            int len;
            while (true) {
                len = in.read(buf);
                if (len == -1) {
                    break;
                tmpOut.write(buf, 0, len);
            tmpOut.close();
            ByteBuffer bb = ByteBuffer.wrap(tmpOut.toByteArray(), 0,
                                            tmpOut.size());
            //Lines below used to test if file is corrupt
            //FileOutputStream fos = new FileOutputStream("C:\\abc.pdf");
            //fos.write(tmpOut.toByteArray());
            return bb;
    }I must be missing something, and I've been banging my head trying to figure it out. Any help is greatly appreciated. Thanks.

    Keshav.. wrote:
    I too was going through the same problem but I found for some pdfs it worked fine.I didnt get ur solution.Please explain bcoz it may work for every pdfThis thread is over 3 years old and dead. Please open a new thread which provides details of the problem you are having. Link to this thread if you think it is necessary.
    I shall lock this thread.

  • Can not read file from URL

    I have this code for loadbitmap() function:
    String s = getCodeBase()+sdir+sfile;
    System.out.println("codeBase is=" + s);
    URL url = new URL(s);
    InputStream fs = url.openStream();
    BufferedInputStream bs = new BufferedInputStream(fs);
    And the file is a .bmp file, so I go on decoding this etc. It works fine within VisualCafe.
    When I created a virtual directory in IIS and run this applet from
    http://localhost/ImageApplet/ImageApplet.html address:
    I get in 1.3.1 Plug-in this error:
    codeBase is=http://localhost/ImageApplet/duke/some1.BMP
    Caught exception in loadbitmap!java.io.FileNotFoundException: http://localhost/ImageApplet/duke/some1.BMP
    If a type this as address in browser, it shows the image.
    Could any one tell me what I am doing wrong here?

    You can try this, even though it is not supposed to be different from your original code:
    URL url = new URL(getCodeBase(), sdir+sfile);
    System.out.println("getting image from " + url);
    InputStream fs = url.openStream();
    BufferedInputStream bs = new BufferedInputStream(fs);
    I could understand a SecurityException but a FileNotFoundException... A FileNotFoundException... You are reading from a stream originating from a URL, not a file!!!
    Which line causes the exception?

  • Writing data into file from URL address

    Hi!
    I need to download file from certain url address and write it to file on my local disk. The file being downloaded is a image file and therefore
    I cannot make sure what encoding should I use. When I save file manually on disk and compare it with the file written programmatically, then
    the bytes in both files are not equal. Any smart advises are welcome.
    The code being used is:
    import java.net.*;
    import java.io.*;
    public class UrlParser {
         public static void main(String[] args) {
              String data;
              try{
                   // Construct a URL object
                   URL url = new URL("http://stockcharts.com/c-sc/sc?s=qqqq&p=D&b=3&g=0&i=t74934638175&r=4028");
                   // Open a connection to the URL object
                   String encoding = "UTF8";
                   BufferedReader html = new BufferedReader(new InputStreamReader(url.openStream(),encoding));      
                   Writer img_out = new OutputStreamWriter(new FileOutputStream("sc.gif"), encoding);
                   while((data = html.readLine()) != null) {
                        img_out.write( data );
                   img_out.close();
              } catch(MalformedURLException e) {
                   System.out.println(e);
              } catch(IOException e) {
                   System.out.println(e);
    }

    Use InputStream and OutputStream classes, not Readers/Writers. The latter are for "text" I/O, not "binary".

  • Read file from URL and save to FTP

    Hi,
    I have worked in java few years back, now I am out of touch. My friend asked me to create an applet program for him which he can use to download a file from remote location to his ftp server.
    For e.g.
    File
    http://www.demo.com/filename.avi
    Saved to
    ftp://username:password@ftpsite_address/foldername
    I was searching for the classes which I can use to achieve this functionality.
    To save to FTP
    URL url = new URL("ftp://username:[email protected]/folder/filename");
    URLConnection urlconnection = url.openConnection();
    long l = urlconnection.getContentLength();
    OutputStream outputstream = null;
    outputstream = urlconnection.getOutputStream();Using the above code I can get the outputstream to which I can write.
    I am now stuck here, have some doubts.
    What all classes should I use to read a file like
    http://www.demo.com/filename.avi
    I know I can use URL to open connection to URLS and then streams to read the url.
    I am interested in knowing the class which I should use to read any type of file. File can be zip/avi/rar or anything else.
    What all method of the class should I use to read the file which will support all type of files.
    Which classes should I use to write the files. The files are going to be huge in terms of size.
    I have searched everywhere but every place different classes are used.
    Any help is appreciated.

    Ok now I have started coding but facing a problem.
    [PHP]try {
         URL url = new URL("http://url_to_file/test.txt");
         URLConnection urlconnection = url.openConnection();
         long l = urlconnection.getContentLength();
         fTextArea.append("Content Length = " + l);
         BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
         String line;
         while ((line = in.readLine()) != null)
              fTextArea.append("\n"+line);
         in.close();
    } catch (Exception e) {
    fTextArea.append(e);
    return;
    [PHP]
    When I run this code locally it works fine but when run in browser it shows security exception
    java.security.AccessControlException: access denied (java.net.SocketPermission site:80 connect,resolve)
    What should I do to resolve this error. Sorry for being such a noob but do not have much info about this.

Maybe you are looking for

  • TS3899 All of a sudden, I can't open links in my emails.  Not just yahoo, but others as well.

    For the last 2 or 3 weeks, I haven't been able to open links in my emails.  This includes personal & business accounts.  One is Yahoo & the other is Outlook Exchange.  I've never had any problem before.  It's only on the IPad.  I have 2 other tablets

  • XML not showing load progress...

    I have a fla file that loads a slide show from an XML file. The xml file contains info about each slide. There's over a 100 slides so the loading takes some time. However I'm not getting actual load progress. It traces nothing until after the load is

  • CS3 crashes upon opening Mac OSX

    I am unable to open CS3.  I receive the following box and then if I click ok contribute closes.  I am running OSX on my mac.  Any suggestions would be greatly appreciated!

  • How i know the password of user created by su10

    Hi all, i have created three users by SU10 and gave the role y_functional_all , but the problem is that how i will get the password for that user to connect. rgds imran

  • Motion Path missing!

    For some reason, I cannot find a way to make simple moving text animation by moving the text in canvas. Few days ago, when I created a first project in Live Type, I just placed the keyframes to timeline and setted the text´s starting and ending point