Jersey, Jax-rs ssl

Hello,
  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();
		//ROOTURL=https://server.net:8443
		webResource = client.resource(JiraConstant.ROOTURL+"/issue/"+issueID);
		response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").get(ClientResponse.class);
		return(response.getEntity(String.class));
	}

Open in new window


Thanks
SiemensSENAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.