Is there a way to attach a file to Jira issue using JRJC 2.0 ? If yes, can you give me some examples of it? Also, is there a way to ignore ssl errors in JRJC? The following code (using earlier version of JRJC) gives SSL certificate validation error. If there is no way to ignore, from where can I get the certificate to add to my java keystore?
:
final java.net.URI jiraServerUri = new java.net.URI(<jira company url>);
FileInputStream fileStreamPath = new FileInputStream(filepath);
JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
// final JiraRestClientFactory factory = new JiraRestClientFactory();
NullProgressMonitor pm = new NullProgressMonitor();
System.out.println("Server Url :"+jiraServerUri);
// JiraRestClient restClient = new JiraRestClient();
String newKey = <issue-key>;
final java.net.URI AttachmentUri = new java.net.URI(jiraServerUri+"/rest/api/2/issue/"+newKey+"/attachments");
JiraRestClient restClient = factory.createWithBasicHttpAuthentication(AttachmentUri,<username>,<password>);
Issue issue1 = restClient.getIssueClient().getIssue(newKey,pm);
System.out.println("URI :"+issue1.getAttachmentsUri());
//restClient.getIssueClient().addAttachment(pm,issue1.getAttachmentsUri(), fileStreamPath , imageName);
restClient.getIssueClient().addAttachment(pm,AttachmentUri, fileStreamPath, "Test Image");
// return attachmentfilepath;
You can find example code for adding atachments in testAddAttachment:
https://bitbucket.org/atlassian/jira-rest-java-client/src/483536cf7956295b4e1f6d9a46aa9bcb7c21379b/test/src/test/java/it/AsynchronousIssueRestClientTest.java?at=master
For SSL problem you can just add certificate to keystore and use that keystore.
To get certificate you can use openssl command line tool:
openssl s_client -connect ${your-jira-url}:${ssl-port} -showcerts
How to add key to keystore:
http://stackoverflow.com/questions/2893819/telling-java-to-accept-self-signed-ssl-certificate
How to tell java to use your keystore:
http://stackoverflow.com/questions/5871279/java-ssl-and-cert-keystore
Puting this together:
# Get cert (you need copy the cert and save to file my.jks) openssl s_client -connect localhost:8090 -showcerts # Add cert to keystore keytool -import -v -trustcacerts -alias localhost-8090 -file some.cert -keystore my.jks -keypass changeit -storepass changeit # Run app java -Djavax.net.ssl.trustStore=my.jks ...
Thank you for the response. I've added the certificate to my keystore and that error seems to have gone away. However, I'm getting the following error on getIssue:
"The method getIssue from type IssueRestClient refers to missing type Promise".
From where can I import com.atlassian.util.concurrent.Promise?
Here is my code:
final JiraRestClient client ;
final IssueRestClient issueClient = client.getIssueClient();
final Issue issue = issueClient.getIssue("TST-3").claim();
String str = "Wojtek";
final String filename1 = "my-test-file";
issueClient.addAttachment(issue.getAttachmentsUri(), new ByteArrayInputStream(str.getBytes("UTF-8")), filename1).claim();
final String filename2 = "my-picture.png";
final Issue issueWithAttachments = issueClient.getIssue("TST-3").claim();
Thank you. Your help is appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the response. I've added the certificate to my keystore and that error seems to have gone away. Why does the following not work:
final JiraRestClientFactory clientFactory = new AsynchronousJiraRestClientFactory();
It erros and tells me to change type of JiraRestClientFactory.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What exact version of JRJC do you use? How does look your dependency in pom.xml? Do you have also dependency to older version of JRJC?
It looks like you have incorrect dependency in pom.xml, as the code above looks fine to me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Aleksander, your hint, how to get certificate from (cloud/hosted) JIRA server using openssl (instead of IE/Internet Options/Content/Certificates… export) save me. Thank you! Best regards, Roberto.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I.e. How to get certificates from a JIRA server instance in the Atlassian cloud: openssl s_client -connect myJiraInstanceInTheCloud.atlassian.net:443 -showcerts
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what if I don't want / can't add a certificate to some specific server?
how can I force JIRA Rest client Java library to accept expired certificates?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JRJC is great, I belive it uses customized Apache HTTP Client internally, why not externalize this dependency and give an option for the user to specify a HttpClient instance. That will add the capability of setting custom HttpClient with SSL Context in it, thereby allowing both static certificate configuration (via Keystore) as well as dynamic setting of required certificates.
Most of the companies hosts JIRA under HTTPS protocol and assigns private certificates for each users.
thanks,
Ratheesh R Nair
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.