Exemple #1
0
 def urlGet(self, url):
     try:
         client = BasicHttpClient(url)
         get = GetMethod(url)
         code = client.executeMethod(get)
         body = get.getResponseBodyAsString().strip()
         return (str(code), body)
     except Exception, e:
         self.log.error("Error during HTTP request: ", e)
         return (None, None)
    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()
Exemple #3
0
 def urlPost(self, url, postBody):
     try:
         client = BasicHttpClient(url)
         post = PostMethod(url)
         #######
         # Which will work?
         #post.setRequestBody(postBody)
         post.addParameter("xml", postBody)
         #######
         code = client.executeMethod(post)
         if str(code) == "302":
             locationHeader = post.getResponseHeader("location")
             if locationHeader is not None:
                 redirectLocation = locationHeader.getValue()
                 self.log.info("302 Redirection was requested: '{}'",
                               redirectLocation)
                 ##return self.urlPost(redirectLocation, postBody)
         body = post.getResponseBodyAsString().strip()
         return (str(code), body)
     except Exception, e:
         self.log.error("Error during HTTP request: ", e)
         return (None, None)
Exemple #4
0
    def queryJobStatus(self, curationJob):
        relations = ArrayList()
        get = None
        try:
            url = self.systemConfig.getString(None, "curation",
                                              "curation-manager-url")

            client = BasicHttpClient(url + "/job/" +
                                     curationJob.getCurationJobId())
            get = GetMethod(url + "/job/" + curationJob.getCurationJobId())
            client.executeMethod(get)
            status = get.getStatusCode()
            if status != 200:
                text = get.getStatusText()
                self.log.error(
                    String.format(
                        "Error accessing Curation Manager, status code '%d' returned with message: %s",
                        status, text))
                return None

        except Exception, ex:

            return None
    def notifyExternalRelationship(self, relationship, pid, system,
                                   identifier):
        try:
            url = self.systemConfig.getString(None, "curation",
                                              "external-system-urls",
                                              "notify-curation", system)
            url = "http://localhost:9001/default/api/notifyCuration.script?apiKey=1412412412241"
            completeUrl = url + "&relationship=isCollectorOf&curatedPid=" + pid + "&identifier=" + relationship.get(
                "identifier") + "&system=" + self.systemConfig.getString(
                    "redbox", "system") + "&sourceIdentifier=" + identifier
            self.writer.println("the completeUrl: " + completeUrl)
            client = BasicHttpClient(completeUrl)
            get = GetMethod(completeUrl)
            client.executeMethod(get)
            status = get.getStatusCode()
            if status != 200:
                text = get.getStatusText()
                self.log.error(
                    String.format("Error accessing Mint", status, text))
                return None

        except Exception, ex:
            return None
Exemple #6
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"
Exemple #7
0
 def __wget(self, url):
     client = BasicHttpClient(url)
     m = GetMethod(url)
     client.executeMethod(m)
     return IOUtils.toString(m.getResponseBodyAsStream(), "UTF-8")