I have recently built a feature to submit issues directly from our product using the JIRA REST Java Client (v1.0). The client is working as expected and sumbits issues to our JIRA server but I now need to add proxy settings to the client so it can work in corporate networks etc.
According to the following ticket we are unable to configure a proxy with v1.0, is this correct? If so, is version 2 stable enough for production and how would I go about migrating?
https://ecosystem.atlassian.net/browse/JRJC-107
Many thanks,
James
Community moderators have prevented the ability to post new answers.
Thanks for your answer but I fear this won't help, since NTLM is challenge response and based on connection. So I have the feeling that there is no public interface in your code that allows me do solve this problem...
The ProxySelector is not the problem. It seems that the authentication makes the difference. The first part of the code uses the plain vanilla JiraRest client. The security proxy answers that the proxy authentication failed. I have set hostname and port using the -Dproxy... settings in both cases
1) Rest Client
URL jiraServerUri = new URL("myJiraUrl"); AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory(); JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "username", "password"); Issue issue = restClient.getIssueClient().getIssue("myIssue").get(); System.out.println(issue.getDescription()); restClient.close();
2) Here I'm connecting to the same url with low level API and it works!
Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { returnnew PasswordAuthentication("username", "password".toCharArray()); } }); URL url = new URL("myJiraUrl"); URLConnection connection = url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while((line = reader.readLine())!=null) { System.out.println(line); }
UPDATE: the small tool TCPMon helped me to see the request parameters of request 1 (low level api) and it seems, that the authentication expected is NTLM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then you just need custom authentication handler ;).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aleksander: would you mind showing in an example how the proxy could be configured? I'm trying to talk to a JIRA instance through a proxy that does not require authentication, but the httpclient seems to use authentication, which results in an error. I don't see how I can change proxy configuration in the HttpClient, since the ProxySelectorAsyncRoutePlanner is not accessible nor is the nonCachingHttpClient
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I don't have example for proxy. But looking at the code I can suggest setting proxy selector in ProxySelector#setDefault, as DefaultHttpClient uses ProxySelector.getDefault().
Can you share the code that you tried and doesn't work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The 1.x version is already abandoned - we're not going to improve it further. Although you can build a 1.x version by yourself - there is a not-well-tested change that allows to get apache http client instance used by JRJC (JiraRestClient#getTransportClient()).
The 2.x version is quite stable now - it will take some time to hit the release (due to limited resources for that project), but API is rather stable, so grab the last milestone release and try it! In 2.x it's possible to configure the proxy, as you can pass HTTP client to the JRJC factory (AsynchronousJiraRestClientFactory#create(URI serverUri, HttpClient httpClient)), but it's not yet as easy as just passing proxy configuration (you have to create HttpClient by yourself - see AsynchronousHttpClientFactory).
The migration from 1.x to 2.x should be not-so-hard ;). The biggest change is that every method now returns Promise, so you have to call .claim() to get the actual result (or make a use of asynchronous API - see Promise class for details).
Another important change is that you have to cleanup JRJC instance by yourself - just call close() on it after you're done (or just cleanup httpClient if you have created your own instance).
If you want to migrate, change the dependency to:
<dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client-core</artifactId> <version>2.0.0-m15</version> </dependency>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it possible for you to provide a code snippet for doing the same? I have been trying to do it and it does not look so straight forward !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Regarding the claim() method, I can help you with that. Instead of using:
jc.getSearchClient().searchJql("type = Bug ORDER BY RANK ASC", null);
try using something like this:
jc.getSearchClient().searchJql("type = Bug ORDER BY RANK ASC").claim();
shortly, remove ",null" in the method's parameter and add ".claim()" in order to get the desired object instead of Promise<object>.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aleksander Mierzwicki
Where can I find 2.0.0-m15 jar file (or 2.0.0-m25 which is the latest as of now)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JRJC is in Atlassian public maven repository: https://maven.atlassian.com/public/com/atlassian/jira/jira-rest-java-client-core/
The last released version to maven is: https://maven.atlassian.com/content/repositories/atlassian-public/com/atlassian/jira/jira-rest-java-client-core/2.0.0-m23/
But the best way is to build your project using maven (you'll need to add Atlassian public to settings.xml), as this allows you to easily collect all the dependencies.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks. I just realized that jira-rest-java-client has been split into jira-rest-java-client-core and jira-rest-java-client-api and have tried to put into my pom.xml only this:
<dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client-core</artifactId> <version>2.0.0-m23</version> </dependency> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client-api</artifactId> <version>2.0.0-m23</version> </dependency>
and atlas-debug started JIRA normally, without issues, but I again experienced the same ClassNotFound runtime exception, as decsribed here https://answers.atlassian.com/questions/192961/jira-rest-client-proper-usage and here https://answers.atlassian.com/questions/194331/can-anyone-provide-a-simple-example-of-jira-rest-java-client-jrjc-plugin-code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.