def __delete(self, url): try: client = BasicHttpClient(url) delete = DeleteMethod(url) statusInt = client.executeMethod(delete) return True except Exception, e: return False
def __put(self, url, data): try: client = BasicHttpClient(url) put = PostMethod(url) put.addParameter("", data) statusInt = client.executeMethod(put) r = str(statusInt), post.getResponseBodyAsString().strip() except Exception, e: r = str(e), None
def __get(self, url): try: client = BasicHttpClient(url) get = GetMethod(url) statusInt = client.executeMethod(get) s = get.getResponseBodyAsString().strip() except Exception, e: print "__get() Error - '%s'" % str(e) s = ""
def __init__(self): responseType = "text/html; charset=UTF-8" responseMsg = "" func = formData.get("func") if func == "placeName": try: placeName = formData.get("q") url = "http://ws.geonames.org/searchJSON?fuzzy=0.7&q=" + placeName client = BasicHttpClient(url) get = GetMethod(url) statusInt = client.executeMethod(get) r = str(statusInt) jsonConfigHelper = JsonConfigHelper(get.getResponseBodyAsString().strip()) for geoName in jsonConfigHelper.getJsonList("geonames"): responseMsg += "%s, %s|%s \n" % (geoName.get("name"), geoName.get("countryName"), geoName.get("geonameId")) except Exception, e: print "exception: ", str(e) r = str(e), None responseType = "text/plain; charset=UTF-8"
def __activate__(self, context): self.vc = context responseType = "text/html; charset=UTF-8" responseMsg = "" func = self.vc("formData").get("func") if func == "placeName": try: placeName = self.vc("formData").get("q") url = "http://ws.geonames.org/searchJSON?fuzzy=0.7&q=" + placeName client = BasicHttpClient(url) get = GetMethod(url) statusInt = client.executeMethod(get) r = str(statusInt) json = JsonSimple(get.getResponseBodyAsString().strip()) for geoName in json.getJsonSimpleList("geonames"): responseMsg += "%s, %s|%s \n" % (geoName.getString(None, "name"), geoName.getString(None, "countryName"), geoName.getString(None, "geonameId")) except Exception, e: print "exception: ", str(e) r = str(e), None responseType = "text/plain; charset=UTF-8"
def __activate__(self, context): self.vc = context self.url = self.vc["formData"].get("url") self.method = self.vc["formData"].get("method") self.payload = self.vc["formData"].get("json") self.writer = self.vc["response"].getPrintWriter("text/html; charset=UTF-8") self.client = BasicHttpClient(self.url) #response = self.process() responseMsg = "Hi" self.writer.println(responseMsg) self.writer.close()
class AnotarProxyData: def __init__(self): pass def __activate__(self, context): self.vc = context self.url = self.vc["formData"].get("url") self.method = self.vc["formData"].get("method") self.payload = self.vc["formData"].get("json") self.writer = self.vc["response"].getPrintWriter("text/html; charset=UTF-8") self.client = BasicHttpClient(self.url) #response = self.process() responseMsg = "Hi" self.writer.println(responseMsg) self.writer.close() def process(self): print "***** " + self.method switch = { "DELETE" : self.__delete, "GET" : self.__get, "POST" : self.__post, "PUT" : self.__put } status, reply = switch.get(self.method)() if status.startswith("2"): json = reply[:-1] + ', "status":"%s"}' % status return json else: return "{\"status\": \""+status+"\"}" def __get(self): try: get = GetMethod(self.url) statusInt = self.client.executeMethod(get) r = str(statusInt), get.getResponseBodyAsString().strip() except Exception, e: r = str(e), None return r