I’m trying to use the jira-rest-java-client-core library to connect to our Jira instance in the public cloud. The problem is, my company requires an HTTP proxy for external connections. Here’s what I’ve tried so far:
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI jiraServerUri = URI.create("https://our-jira-instance.com");
JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "myUsername", "myPassword");
I also attempted to set proxy settings using system properties:
System.setProperty("http.proxyHost", "proxy.mycompany.com");
System.setProperty("http.proxyPort", "8080");
System.setProperty("https.proxyHost", "proxy.mycompany.com");
System.setProperty("https.proxyPort", "8080");
This works fine with HttpURLConnection, but when using JiraRestClient, I get a 407 error. Any ideas on how to properly configure the proxy for this library? I’m stumped and could really use some help!
I encountered a similar issue when using the jira-rest-java-client-core library behind a corporate proxy. In my case, setting system properties didn’t work because the library uses Apache HttpClient, which doesn’t always respect them. I managed to solve the problem by explicitly configuring the proxy settings. I created a custom HttpClientOptions object and passed a proxy-configured route planner to the JiraRestClientFactory. For example:
HttpHost proxy = new HttpHost("proxy.mycompany.com", 8080, "http");
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
HttpClientOptions options = new HttpClientOptions();
options.setProxyRoutePlanner(routePlanner);
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI jiraServerUri = URI.create("https://our-jira-instance.com");
JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "myUsername", "myPassword", options);
This approach explicitly configures the proxy for the HttpClient underlying the library, which helped me overcome the 407 error.
I’ve dealt with this exact problem before. The key is to configure the proxy at the HttpClient level, as the jira-rest-java-client-core library doesn’t always pick up system properties.
Here’s what worked for me:
- Create a custom HttpClientBuilder with proxy settings.
- Use this builder to create a custom AsyncHttpClient.
- Pass this custom client to the JiraRestClientFactory.
Here’s a code snippet that illustrates this approach:
HttpHost proxy = new HttpHost("proxy.mycompany.com", 8080);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials("proxyUser", "proxyPass"));
HttpClientBuilder clientBuilder = HttpClientBuilder.create()
.setProxy(proxy)
.setDefaultCredentialsProvider(credentialsProvider);
AsyncHttpClient httpClient = new AsynchronousHttpClientFactory()
.createClient(clientBuilder.build());
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory(httpClient);
JiraRestClient client = factory.createWithBasicHttpAuthentication(jiraServerUri, "jiraUser", "jiraPass");
This method ensures that all requests made through the JiraRestClient use the specified proxy settings.
hey mate, i had this same headache w/ jira client. wat worked 4 me was using a custom ProxySelector. heres the gist:
ProxySelector.setDefault(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
return Collections.singletonList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.mycompany.com", 8080)));
}
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {}
});
then just create ur client as usual. hope this helps!