예제 #1
0
 def __delete(self, url):
     try:
         client = BasicHttpClient(url)
         delete = DeleteMethod(url)
         statusInt = client.executeMethod(delete)
         return True
     except Exception, e:
         return False
예제 #2
0
 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
예제 #3
0
 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 = ""
예제 #4
0
 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"
예제 #5
0
    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"
예제 #6
0
    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()
예제 #7
0
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