Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Jersey, Jax-rs ssl

  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

1 Solution
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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 javax.net code for handling HTTP/HTTPS communication. The javax.net.ssl 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)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now