[rest-gradle-plugin] 26/83: Adds support for proxies
Alastair McKinstry
mckinstry at moszumanska.debian.org
Wed Oct 25 15:59:04 UTC 2017
This is an automated email from the git hooks/post-receive script.
mckinstry pushed a commit to branch debian/master
in repository rest-gradle-plugin.
commit 51cc535a99daffcd63e8359c11be63bb7e57309e
Author: Andrea Rossi <andrea.rossi at here.com>
Date: Wed Aug 6 11:38:16 2014 +0200
Adds support for proxies
Now the rest task supports proxies, using the standard java system properties
Adds unit test to verify that the proxy gets set
---
.../groovy/org/_10ne/gradle/rest/RestTask.groovy | 12 ++++++++++
.../org/_10ne/gradle/rest/RestTaskSpec.groovy | 27 ++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy b/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
index ddae22c..adb98bd 100644
--- a/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
+++ b/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
@@ -55,6 +55,15 @@ class RestTask extends DefaultTask {
client = new RESTClient()
}
+ void configureProxy(String protocol) {
+ String proxyHost = System.getProperty(protocol.toLowerCase() + ".proxyHost", "")
+ int proxyPort = System.getProperty(protocol.toLowerCase() + ".proxyPort", "0") as int
+ if (proxyHost.length() > 0 && proxyPort > 0) {
+ println "Using " + protocol.toUpperCase() + " proxy: " + proxyHost + ":" + proxyPort
+ client.setProxy(proxyHost, proxyPort, protocol)
+ }
+ }
+
@TaskAction
void executeRequest() {
if (!uri || StringUtils.isBlank(uri)) {
@@ -69,6 +78,9 @@ class RestTask extends DefaultTask {
client.auth.basic(username, password)
}
+ configureProxy('http')
+ configureProxy('https')
+
if (requestHeaders instanceof Map) {
client.headers.putAll(requestHeaders);
}
diff --git a/src/test/groovy/org/_10ne/gradle/rest/RestTaskSpec.groovy b/src/test/groovy/org/_10ne/gradle/rest/RestTaskSpec.groovy
index 5647487..9f750eb 100644
--- a/src/test/groovy/org/_10ne/gradle/rest/RestTaskSpec.groovy
+++ b/src/test/groovy/org/_10ne/gradle/rest/RestTaskSpec.groovy
@@ -142,4 +142,31 @@ class RestTaskSpec extends Specification {
}
1 * mockResponse.getData() >> { 'somedata' }
}
+
+ def 'Configure and execute a request using a proxy'() {
+ setup:
+ System.setProperty('http.proxyHost', "www.abc.com")
+ System.setProperty('http.proxyPort', "8080")
+ Task task = project.tasks.create(name: 'request', type: RestTask) {
+ httpMethod = 'post'
+ uri = 'bob.com'
+ requestContentType = 'requestContentType'
+ requestBody = 'requestBody'
+ contentType = 'contentType'
+ }
+ def mockClient = Mock(RESTClient)
+ task.client = mockClient
+
+ def mockResponse = Mock(HttpResponseDecorator)
+
+ when:
+ task.executeRequest()
+
+ then:
+ 1 * mockClient.setUri('bob.com')
+ 1 * mockClient.setProxy("www.abc.com", 8080, "http")
+ 1 * mockClient.post(_ as Map) >> { Map params ->
+ mockResponse
+ }
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/rest-gradle-plugin.git
More information about the pkg-java-commits
mailing list