Skip to content

Instantly share code, notes, and snippets.

@ltddev
Created March 27, 2014 20:22
Show Gist options
  • Save ltddev/9817684 to your computer and use it in GitHub Desktop.
Save ltddev/9817684 to your computer and use it in GitHub Desktop.
HttpServletInvocationTests
'''
HttpServletInvocationTests.py
A simple test harness to invoke servlet on web server to provide a simple
REST architectured service, in this simple test case a servlet that simply
returns the string format of a Java Date object instance. this is chosen
because of its simplicity but also because re-running it clearly shows
that the output is dynamic and not static and so fits nicely with the
REST architecture I am attempting to build serverside and the REST client
running on the mobile device. for this test case/Usecase I am using
the urllib2.module, part of standard python library 2.x-3x.
it is also a protototype of using Pythonista to generate a stanalone
client to be built in Xcode and deployed to the ios device as a standalone
.ipa or ios application. The actual serverside sevice is irrelevant so
long as it acuurately represents the REST architecure and represents
any arbitrarily complex service.
So too the client-side code is not intended to represent ptoduction
code but only to test viability of using Pythonista to build clients
in Python exported to Xcode for the final packaging and means of
distibution.
'''
import urllib2, webbrowser, console
port = ':9080'
currIP = '192.168.0.11'
#currIP = 'swosnick-pc'
url = 'http://'+ currIP + port + '/HelloWorldWeb/HelloWorldServlet'
console.clear()
print 'Trying to open url ' + url
request = urllib2.Request(url,None)
response = urllib2.urlopen(request).read()
print (response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment