You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bauer Steven-P27098 <St...@motorola.com> on 2000/08/18 01:28:06 UTC

Problem with urlConnection

I am having a problem with opening a urlConnection within a servlet. (I am
using tomcat 3.1 on NT, Sun JDK1.2.2)  

Running the follw code segment in a java application work fine but when I
try it from a servlet I get an exception.
Does anyone know what I am doing wrong?

Thanks,
Steven Bauer


Code Segment:
public static String urlconnect(String url) {
       String results = null;
       try{
            URL stockURL = new URL(url);
            URLConnection c = stockURL.openConnection();
            
            c.setUseCaches(true);
            c.setDoOutput(true);
            c.setDoInput(true);

            
            InputStream is = c.getInputStream();
		      
            BufferedReader d = new BufferedReader(new
InputStreamReader(is));
            results = "XML "+c.toString();
            String rLine;
            while( (rLine = d.readLine()) != null ) results += rLine +"\n";
       } catch (Exception e) { e.printStackTrace(); } 
       return results;
 } 

Exception:
java.io.FileNotFoundException:
http://shock.tcg.phx.mcd.mot.com/stock/servlet/StockService/?symbols=mot
        at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:530)
        at aTest.urlconnect(aTest.java:34)
        at aTest.doGet(aTest.java:51)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.ja
va:503)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.ja
va:597)
        at
org.apache.tomcat.servlets.InvokerServlet.service(InvokerServlet.java
:257)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.ja
va:503)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:559
)
        at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processCon
nection(Ajp12ConnectionHandler.java:156)
        at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.j
ava:338)
        at java.lang.Thread.run(Thread.java:479)