Working example code: SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault() These properties need to be set (either on the commandline, or in code): =pkcs12 Keytool -import -alias gridserver -file gridserver.crt -storepass $PASS -keystore gridserver.keystore This library provides a simple and flexible API together with a pluggable approach to use low-level HTTP libraries like or Apache HTTP Client. The self-signed server certificate must be imported into a truststore: The missing links was (mostly) the first of the parameters below, and to some extent that I overlooked the difference between keystores and truststores. Got a strong hint here (Gandalfs answer touched a bit on it as well). I am not even sure that the client certificate is the problem here.įinally solved it ). do anything with the inputstream results in: InputStream inputstream = sslsocket.getInputStream() SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("somehost.dk", 3049) I've tried skipping the HttpsURLConnection class (not ideal since I want to talk HTTP with the server), and do this instead: SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault() : Received fatal alert: handshake_failure InputStream inputstream = conn.getInputStream() HttpsURLConnection conn = (HttpsURLConnection)url.openConnection() Ĭonn.setSSLSocketFactory(sslsocketfactory) I've tried two approaches and neither gets me anywhere.įirst, and preferred, try: SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault() Java http client java 8 how to#However, I'm now stuck on how to use the client certificate. The name of the keystore file seems to suggest that the client certificate is not supposed to go in there?Īnyway, adding the root certificate to this store solved the infamous : : PKIX path building failed' problem. I've added the server root certificate and the client certificate to a default java keystore which I found in /System/Library/Frameworks/amework/Versions/1.6.0/Home/lib/security/cacerts (OSX 10.5). setHeader(Content-Type, text/plain charsetutf-8) get. Java http client java 8 code#The server is using an selfsigned root certificate, and requires that a password-protected client certificate is presented. Best Java code snippets using .HttpClient.execute (Showing top 20. I am using Java 6 and am trying to create an HttpsURLConnection against a remote server, using a client certificate.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |