Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

URLConnection: getInputStream() Throws FileNotFoundException Randomly

1,825 views
Skip to first unread message

David F. White

unread,
Mar 22, 2001, 2:25:12 PM3/22/01
to

Hi, we've got a problem that we cannot solve and I hope someone can point
me toward a solution. We have a java class that reads URL contents and returns
the contents as a string. This java class is utilized in several of our
applications and works without error. However, in one of our products this
class is not working.

Specifically, the method getInputStream() on the object URLConnection is
randomly throwing a FileNotFoundException for valid URLs.

This class is instantiated from a JSP page being served by Allaire's JRUN
and is used to return content for rendering in Plumtree's portal product.

Here is the call stack for the exception:

java.io.FileNotFoundException:
http://white/test/test.dll?Widget=PortalBridge&Display=Bookma
rk&Size=Wide&SetTemp=N&Portal=PT&UserName=PT-Administrator&Section=100338
&AdminUN=Admin at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection
.java, Compiled Code) at
com.opentext.myLivelink.LivelinkCommon.getURLContents(LivelinkCommon.java,
Compiled Code) at
jrun__LLRemoteGadgets__LivelinkBookmark__LLBookmark_view2ejsp35._jspService(
jrun__LLRemoteGadgets__LivelinkBookmark__LLBookmark_view2ejsp35.java,
Compiled Code) at
allaire.jrun.jsp.HttpJSPServlet.service(HttpJSPServlet.java, Compiled Code)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java, Compiled Code) at
allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java, Compiled Code) at
allaire.jrun.servlet.JRunNamedDispatcher.forward(JRunNamedDispatcher.java,
Compiled Code) at allaire.jrun.jsp.JSPServlet.service(JSPServlet.java,
Compiled Code) at allaire.jrun.servlet.JRunSE.service(JRunSE.java, Compiled
Code) at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java, Compiled Code)
at
allaire.jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.jav
a, Compiled Code) at allaire.jrun.servlet.JRunSE.service(JRunSE.java,
Compiled Code) at allaire.jrun.servlet.JvmContext.dispatch(JvmContext.java,
Compiled Code) at allaire.jrun.jrpp.ProxyEndpoint.run(ProxyEndpoint.java,
Compiled Code) at allaire.jrun.ThreadPool.run(ThreadPool.java, Compiled
Code) at allaire.jrun.WorkerThread.run(WorkerThread.java, Compiled Code)


Here is the code for the method getURLContents():


public String getURLContents( String addrURL )
{
String pageURLContents = "";
String pageLine = "";

URL objURL = null;
URLConnection objURLConnection = null;

// add handler for SSL

System.setProperty( "java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol" );

try
{
StringBuffer pageContents = new StringBuffer( "" );

if ( addrURL == null )
pageURLContents = "ERROR: No URL was specified.";
else if ( addrURL.length() == 0 )
pageURLContents = "ERROR: No URL was specified.";
else
{
objURL = new URL( addrURL );

if ( objURL.getProtocol().equals( "http" ) ||
objURL.getProtocol().equals( "https" ) )
{
objURLConnection = objURL.openConnection();

// get a reader to store the URL contents

BufferedReader r = new BufferedReader(
new InputStreamReader(
objURLConnection.getInputStream()));

while( ( pageLine = r.readLine() ) != null )
{
pageContents.append( pageLine );
pageContents.append( "\r\n" );
}

// close the reader

r.close();

pageURLContents = pageContents.toString();

// check for content

if ( pageURLContents.length() < 1 )

pageURLContents = "The server did not return any
content for the specified URL.";

}
else
{
pageURLContents = "ERROR: Bad protocol. Only the HTTP and
HTTPS protocols are supported.";
}
}
}
catch ( Exception e )
{
// output the exception contents

pageURLContents = getCallStack( e );
}

return ( pageURLContents );
}


Any help is greatly appreciated.

Thanks...

Dave White

Murvin Ming-Wai Lai

unread,
Mar 23, 2001, 2:22:44 AM3/23/01
to

Hi, I'm also working on similar stuffs. Make a url connection btw an
application and servlet. I got this FileNotFoundException couple times.
Then I found out my problem is that JDK is not the most recent one. So, I
install the JDK1.3 Or If I run it in window, I didn't specify the
classpath. I hope this will help you solving your problem.

Murvin

David F. White <wh...@infinet.com> wrote:

: Hi, we've got a problem that we cannot solve and I hope someone can point

: // close the reader

: r.close();

: pageURLContents = pageContents.toString();

: return ( pageURLContents );
: }

: Thanks...

: Dave White


--
.........................................................................
*>>>>Murvin Lai<<<< >>>>--Muffin--<<<< email: murvi...@sfu.ca *
*homepage: http://www.sfu.ca/~mmlai mm...@sfu.ca *
`````````````````````````````````````````````````````````````````````````

David F. White

unread,
Mar 23, 2001, 11:41:26 AM3/23/01
to

I'll answer my own question! We were able to solve the problem this
morning and I'm passing on this information.

It turns out the URLs being accessed by URLConnection objects were
being created on multiple threads. Furthermore, the machine specified on
the URLs was an NT workstation, NOT an NT server. IIS on NT workstations
limits the number of simultaneous connections to four.

Therefore, depending on which threads completed first, different
requests to the method getInputStream() on URLConnection would throw the
FileNotFoundException because no more connections were being allowed by IIS
on the NT workstation.

Switching to an NT or Windows 2000 server solved our problem.

Dave White

0 new messages