SSL error JRJC

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;

3 answers

1 accepted

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.

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!

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.

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.

I.e. How to get certificates from a JIRA server instance in the Atlassian cloud: openssl s_client -connect myJiraInstanceInTheCloud.atlassian.net:443 -showcerts

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? 

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

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Friday in Off-topic

Friday Fun: Riddle me this

Happy Friday, Funmakers! We had a Community Team offsite in Austin this week, and my mind feels primed for thinkin' from all the brainstorming we did!  So, this week's Friday Fun thread w...

126 views 14 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you