I have just been handed a groovy project that is using the Jodd library (I have little experience with this). I am looking to find out how you setup configuration so that http and https calls can be made behind a company proxy.
At the moment a helper class has been setup
#! /usr/bin/groovy
package org.myOrg
import groovy.json.JsonBuilder
@Grab("org.jodd:jodd-http:3.8.5")
import jodd.http.HttpRequest
/**
* Helper class for making REST calls from a Jenkins Pipeline job.
*/
class JenkinsHttpClient {
// Constants
private static final String USER_AGENT = "User-Agent";
private final HttpRequest httpRequest
private final String userAgent = 'Jenkins'
JenkinsHttpClient() {
httpRequest = new HttpRequest()
}
/**
* GET method
* @param url - This is the endpoint
* @return response body as String
*/
private def get(String url) {
def resp = httpRequest.get(url)
.header(USER_AGENT, userAgent)
.send()
return resp.bodyText()
}
How or where do I add config so that this will work behind a proxy?
HttpConnectionProvideralso allows you to specify the proxy. Just provide theProxyInfoinstance with the information about the used proxy (type, address, port, username, password):Jodd supports HTTP, SOCKS4 and SOCKE5 proxy types.
See the documentation.