Jersey, Jax-rs ssl

Posted on 2014-08-21
Last Modified: 2014-09-08
  I need to consume  a restAPI via SSL using jersey. The certificate for the application is self sign.  I have a class that work via http but not https. How can I re-write it to support https

public String getIssue(String issueID) 
		WebResource webResource;
		ClientResponse response;
		auth = new String(Base64.encode(JConstant.ID_PASS));
		Client client = Client.create();
		webResource = client.resource(JiraConstant.ROOTURL+"/issue/"+issueID);
		response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").get(ClientResponse.class);

Open in new window

Question by:SiemensSEN
    1 Comment
    LVL 35

    Accepted Solution

    The certificate for the application is self sign
    This would be the root cause of your issues, I'm guessing. (although if you included the error message that you got when it "not worked" it would help). The client needs to be able to verify the certificate that the server is presenting which it can't do if the certificate is self-signed. There are a number of ways to fix this but the easiest/most correct way (other than using a proper CA signed & issued certificate) would be to import the certificate into the clients truststore so that it knows that you trust that server.

    I haven't used Jersey specifically before but looking at the docs it appears that by default it uses the standard code for handling HTTP/HTTPS communication. The packages by default use the <JRE_HOME>/lib/security/cacerts file as it's truststore so it should just be a matter of importing the certificate into that (using keytool, etc)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    seriesUp challenge 7 79
    instanceof  operator in java 26 54
    SSL Cert Popup during Exchange Migration 7 36
    allStar challenge 1 26
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    The viewer will learn how to implement Singleton Design Pattern in Java.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now