Esempio n. 1
0
    def executeRequest(self, request):
        client = None
        response = None
        try:
            if not self.verify:
                client = self.create_http_client()
            elif self.params.proxyUsername and self.params.proxyPassword:
                credentials = UsernamePasswordCredentials(self.params.proxyUsername, self.params.proxyPassword)
                auth_scope = AuthScope(self.params.proxyHost, Integer.valueOf(self.params.proxyPort))
                creds_provider = BasicCredentialsProvider()
                creds_provider.setCredentials(auth_scope, credentials)
                client = HttpClientBuilder.create().setDefaultCredentialsProvider(creds_provider).build()
            else:
                client = HttpClients.createDefault()

            response = client.execute(request)
            status = response.getStatusLine().getStatusCode()
            entity = response.getEntity()
            result = EntityUtils.toString(entity, "UTF-8") if entity else None
            headers = response.getAllHeaders()
            EntityUtils.consume(entity)

            return HttpResponse(status, result, headers)
        finally:
            if response:
                response.close()
            if client:
                client.close()
Esempio n. 2
0
    def executeRequest(self, request):
        client = None
        response = None
        try:
            local_context = BasicHttpContext()
            if self.authentication == "Ntlm":
                credentials = self.get_credentials()
                client = self.get_ntlm_client()
                credentials_provider = BasicCredentialsProvider()
                credentials_provider.setCredentials(
                    AuthScope.ANY,
                    NTCredentials(credentials["username"],
                                  credentials["password"], None,
                                  credentials["domain"]))
                local_context.setAttribute(HttpClientContext.CREDS_PROVIDER,
                                           credentials_provider)
            else:
                client = HttpClients.createDefault()
                self.set_basic_credentials(request)

            response = client.execute(request, local_context)
            status = response.getStatusLine().getStatusCode()
            entity = response.getEntity()
            result = EntityUtils.toString(entity, "UTF-8") if entity else None
            headers = response.getAllHeaders()
            EntityUtils.consume(entity)

            return HttpResponse(status, result, headers)
        finally:
            if response:
                response.close()
            if client:
                client.close()
Esempio n. 3
0
    def executeRequest(self, request):
        self.logger.debug('executeRequest:  request: %s' % repr(request))
        client = None
        response = None
        try:
            client = HttpClients.createDefault()
            response = client.execute(request)
            self.logger.debug('executeRequest: response: %s' % repr(response))

            status = response.getStatusLine().getStatusCode()
            self.logger.debug('executeRequest:   status: %s' % status)

            entity = response.getEntity()
            data = EntityUtils.toString(entity, "UTF-8") if entity else None
            headers = response.getAllHeaders()
            EntityUtils.consume(entity)

            return HttpResponse(status, data, headers)

        except Exception as e:
            self.logger.error('executeRequest: failed: %s' % repr(e))
            raise e

        finally:
            if response:
                response.close()
            if client:
                client.close()
    def executeRequest(self, request):
        client = None
        response = None
        try:
            client = HttpClients.createDefault()
            response = client.execute(request)
            status = response.getStatusLine().getStatusCode()
            entity = response.getEntity()
            result = EntityUtils.toString(entity, "UTF-8") if entity else None
            headers = response.getAllHeaders()
            EntityUtils.consume(entity)

            return HttpResponse(status, result, headers)
        finally:
            if response:
                response.close()
            if client:
                client.close()
    def execute_request(self, request):
        client = None
        response = None
        try:
            client = HttpClients.createDefault()
            response = client.execute(request)
            status = response.getStatusLine().getStatusCode()
            entity = response.getEntity()
            result = EntityUtils.toString(entity, "UTF-8") if entity else None
            headers = response.getAllHeaders()
            EntityUtils.consume(entity)

            return HttpResponse(status, result, headers)
        finally:
            if response:
                response.close()
            if client:
                client.close()