[appengine-java] Re: Python url fetch against java appengine servlet

2011-03-30 Thread Roman Nurik
Just found this thread from a Google search. I was running into the same 
problem; after switching to Python 2.7 this problem seems to have gone away.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Python url fetch against java appengine servlet

2010-04-12 Thread matt.rosencrantz
OK, not to beat a dead horse here but  I used tcpdump to watch the
traffic going back and forth between my java program and the jetty
server.  So here's what my java sends:

GET /bumbleverse/load/object HTTP/1.1
User-Agent: Java/1.6.0_17
Host: localhost:
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive


The server responds:

HTTP/1.1 404 Not Found
Content-Type: text/html; charset=iso-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1388
Server: Jetty(6.1.x)


[redacted error message in html that says NOT FOUND]
...



OK fine so you're thinking, well he must have the URL wrong.  Well, I
opened up good old telnet and pasted in the headers that the java
program had sent (just cut and paste out of the terminal).

>telnet localhost 
Connected to localhost.
Escape character is '^]'.
GET /bumbleverse/load/object HTTP/1.1
User-Agent: Java/1.6.0_17
Host: localhost:
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive


HTTP/1.1 200 OK
Content-Type: text/plain; charset=iso-8859-1
Content-Length: 101
Server: Jetty(6.1.x)

[followed by the expected text output]


Thanks for any help/ideas...

Matt

On Apr 12, 9:33 pm, "matt.rosencrantz" 
wrote:
> As a fallback I've created a Java version of my uploader.  I'm
> basically doing:
>                         URL url = new 
> URL("http://localhost:/load/object";);
>                         URLConnection con = url.openConnection();
>                         con.setDoOutput(true);
>                         con.setDoInput(true);
>
>                         con.connect();
>
>                         OutputStreamWriter out =
>                                 new OutputStreamWriter(con.getOutputStream());
>                         out.write("key=value");
>                         out.close();
>
>                         InputStream is = con.getInputStream();
>                         result = IOUtils.toString(is);
>                         is.close();
>
> However, the line "InputStream is = con.getInputStream();" produces a
> FileNotFound exception.  Some research turned up that this is probably
> because the server is giving back a 404.  I can load the exact same
> URL in the browser and it works fine.  Is there a way to get low level
> (apache style) request logs for the dev server?  My servlet isn't
> seeing anything.
>
> Thanks for any help,
> Matt
>
> On Apr 12, 12:58 pm, "matt.rosencrantz" 
> wrote:
>
>
>
> > Hello,
>
> > I am trying to build a very simple data loading python script for my
> > Java servlet based appengine app.  Unfortunately python can't seem to
> > open an URL from appengine (or the development server anyway).  If you
> > just start with the eclipse appengine project template (call the
> > project fetchtest) then a single servlet will be generated like:
>
> > import java.io.IOException;
> > import javax.servlet.http.*;
>
> > @SuppressWarnings("serial")
> > public class FetchTestServlet extends HttpServlet {
> >         public void doGet(HttpServletRequest req, HttpServletResponse resp)
> >                         throws IOException {
> >                 resp.setContentType("text/plain");
> >                 resp.getWriter().println("Hello, world");
> >         }
>
> > }
>
> > It will serve by default on:  http://localhost:/fetchtest
>
> > I then write the python script:
>
> > import urllib2
> > import sys
> > import time
>
> > for i in range(10):
> >     try:
> >         print urllib2.urlopen('http://localhost:/
> > fetchtest').read()
> >     except:
> >         print "Unexpected error:", sys.exc_info()
>
> >     time.sleep(1)
>
> > Well, the first time in the python loop the fetch succeeds, but fails
> > after that.  In fact if I run the script again all the calls will
> > fail.  It only ever works the first time I load the URL after
> > restarting the server.  In fact if I load the url in a browser once
> > then the script fails on even the first loop iteration.  The python
> > output looks like:
>
> > >python ../util/test.py
>
> > Hello, world
>
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
> > Unexpected error: (, error(54, 'Connection reset
> > by peer'), )
>
> > I've tried catching all exceptions and inspecting what state I know
> > how to on the server side, but it seems like there is no error at all
> > in the servlet.  I've tried carefully reading and closing all the
> > different input and output streams in the request and res

[appengine-java] Re: Python url fetch against java appengine servlet

2010-04-12 Thread matt.rosencrantz
As a fallback I've created a Java version of my uploader.  I'm
basically doing:
URL url = new URL("http://localhost:/load/object";);
URLConnection con = url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);

con.connect();

OutputStreamWriter out =
new OutputStreamWriter(con.getOutputStream());
out.write("key=value");
out.close();

InputStream is = con.getInputStream();
result = IOUtils.toString(is);
is.close();

However, the line "InputStream is = con.getInputStream();" produces a
FileNotFound exception.  Some research turned up that this is probably
because the server is giving back a 404.  I can load the exact same
URL in the browser and it works fine.  Is there a way to get low level
(apache style) request logs for the dev server?  My servlet isn't
seeing anything.

Thanks for any help,
Matt

On Apr 12, 12:58 pm, "matt.rosencrantz" 
wrote:
> Hello,
>
> I am trying to build a very simple data loading python script for my
> Java servlet based appengine app.  Unfortunately python can't seem to
> open an URL from appengine (or the development server anyway).  If you
> just start with the eclipse appengine project template (call the
> project fetchtest) then a single servlet will be generated like:
>
> import java.io.IOException;
> import javax.servlet.http.*;
>
> @SuppressWarnings("serial")
> public class FetchTestServlet extends HttpServlet {
>         public void doGet(HttpServletRequest req, HttpServletResponse resp)
>                         throws IOException {
>                 resp.setContentType("text/plain");
>                 resp.getWriter().println("Hello, world");
>         }
>
> }
>
> It will serve by default on:  http://localhost:/fetchtest
>
> I then write the python script:
>
> import urllib2
> import sys
> import time
>
> for i in range(10):
>     try:
>         print urllib2.urlopen('http://localhost:/
> fetchtest').read()
>     except:
>         print "Unexpected error:", sys.exc_info()
>
>     time.sleep(1)
>
> Well, the first time in the python loop the fetch succeeds, but fails
> after that.  In fact if I run the script again all the calls will
> fail.  It only ever works the first time I load the URL after
> restarting the server.  In fact if I load the url in a browser once
> then the script fails on even the first loop iteration.  The python
> output looks like:
>
> >python ../util/test.py
>
> Hello, world
>
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
> Unexpected error: (, error(54, 'Connection reset
> by peer'), )
>
> I've tried catching all exceptions and inspecting what state I know
> how to on the server side, but it seems like there is no error at all
> in the servlet.  I've tried carefully reading and closing all the
> different input and output streams in the request and response objects
> to no avail.  Can anyone help me debug why this doesn't work?  I
> really don't know where to look.
>
> Thanks,
> Matt

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.