1616
1717package com .arangodb .example .ssl ;
1818
19+ import java .io .File ;
1920import java .io .IOException ;
2021import java .net .URISyntaxException ;
2122import java .net .URL ;
22- import java .nio .file .Paths ;
2323import java .security .KeyManagementException ;
2424import java .security .KeyStoreException ;
2525import java .security .NoSuchAlgorithmException ;
3737import com .arangodb .ArangoHost ;
3838import com .arangodb .entity .ArangoVersion ;
3939import com .arangodb .http .HttpResponseEntity ;
40+ import com .arangodb .util .TestUtils ;
4041
4142/*-
4243 * Example for using a HTTPS connection
@@ -75,67 +76,74 @@ public class SslExample {
7576 @ Test
7677 public void httpTest () throws ArangoException {
7778
78- ArangoConfigure configuration = new ArangoConfigure ();
79+ final ArangoConfigure configuration = new ArangoConfigure ();
7980 // get host and port from arangodb.properties
8081 // configuration.setArangoHost(new ArangoHost("localhost", 8529));
8182 configuration .init ();
8283
83- ArangoDriver arangoDriver = new ArangoDriver (configuration );
84+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
8485
85- ArangoVersion version = arangoDriver .getVersion ();
86+ final ArangoVersion version = arangoDriver .getVersion ();
8687 Assert .assertNotNull (version );
8788
8889 }
8990
9091 @ Test
9192 public void sslConnectionTest () throws ArangoException {
92- // use HTTPS with java default trust store
93-
94- ArangoConfigure configuration = new ArangoConfigure ();
95- configuration .setArangoHost (new ArangoHost ("www.arangodb.com" , 443 ));
96- configuration .setUseSsl (true );
97- configuration .init ();
98-
99- ArangoDriver arangoDriver = new ArangoDriver (configuration );
100-
101- HttpResponseEntity response = arangoDriver .getHttpManager ().doGet ("/" );
102- Assert .assertEquals (200 , response .getStatusCode ());
93+ final String javaVersion = System .getProperty ("java.version" );
94+ if (TestUtils .compareVersion (javaVersion , "1.7" ) > -1 ) {
95+ // use HTTPS with java default trust store
96+ ArangoConfigure configuration = null ;
97+ try {
98+ configuration = new ArangoConfigure ();
99+ configuration .setArangoHost (new ArangoHost ("www.arangodb.com" , 443 ));
100+ configuration .setUseSsl (true );
101+ configuration .init ();
102+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
103+ final HttpResponseEntity response = arangoDriver .getHttpManager ().doGet ("/" );
104+ Assert .assertEquals (200 , response .getStatusCode ());
105+ } finally {
106+ if (configuration != null ) {
107+ configuration .shutdown ();
108+ }
109+ }
110+ }
103111 }
104112
105113 @ Test
106114 public void sslWithSelfSignedCertificateTest () throws ArangoException , KeyManagementException ,
107115 NoSuchAlgorithmException , KeyStoreException , CertificateException , IOException , URISyntaxException {
108116
109117 // create a sslContext for the self signed certificate
110- URL resource = this .getClass ().getResource (SSL_TRUSTSTORE );
111- SSLContext sslContext = SSLContexts .custom ()
112- .loadTrustMaterial (Paths . get (resource .toURI ()). toFile ( ), SSL_TRUSTSTORE_PASSWORD .toCharArray ()).build ();
118+ final URL resource = this .getClass ().getResource (SSL_TRUSTSTORE );
119+ final SSLContext sslContext = SSLContexts .custom ()
120+ .loadTrustMaterial (new File (resource .toURI ()), SSL_TRUSTSTORE_PASSWORD .toCharArray ()).build ();
113121
114- ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
122+ final ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
115123 configuration .setSslContext (sslContext );
116124 configuration .init ();
117125
118- ArangoDriver arangoDriver = new ArangoDriver (configuration );
126+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
119127
120- ArangoVersion version = arangoDriver .getVersion ();
128+ final ArangoVersion version = arangoDriver .getVersion ();
121129 Assert .assertNotNull (version );
122130 }
123131
124132 @ Test
125133 public void sslHandshakeExceptionTest () {
126- ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
134+ final ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
127135 configuration .init ();
128136
129- ArangoDriver arangoDriver = new ArangoDriver (configuration );
137+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
130138
131139 try {
132140 // java do not trust self signed certificates
133141
134142 arangoDriver .getVersion ();
135143 Assert .fail ("this should fail" );
136144
137- } catch (ArangoException e ) {
138- Throwable cause = e .getCause ();
145+ } catch (final ArangoException e ) {
146+ final Throwable cause = e .getCause ();
139147 Assert .assertTrue (cause instanceof javax .net .ssl .SSLHandshakeException );
140148 }
141149 }
@@ -145,23 +153,23 @@ public void sslPeerUnverifiedExceptionTest() throws ArangoException, KeyManageme
145153 NoSuchAlgorithmException , KeyStoreException , CertificateException , IOException , URISyntaxException {
146154
147155 // create a sslContext for the self signed certificate
148- URL resource = this .getClass ().getResource (SSL_TRUSTSTORE );
149- SSLContext sslContext = SSLContexts .custom ()
150- .loadTrustMaterial (Paths . get (resource .toURI ()). toFile ( ), SSL_TRUSTSTORE_PASSWORD .toCharArray ()).build ();
156+ final URL resource = this .getClass ().getResource (SSL_TRUSTSTORE );
157+ final SSLContext sslContext = SSLContexts .custom ()
158+ .loadTrustMaterial (new File (resource .toURI ()), SSL_TRUSTSTORE_PASSWORD .toCharArray ()).build ();
151159
152- ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
160+ final ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
153161 // 127.0.0.1 is the wrong name
154162 configuration .getArangoHost ().setHost ("127.0.0.1" );
155163 configuration .setSslContext (sslContext );
156164 configuration .init ();
157165
158- ArangoDriver arangoDriver = new ArangoDriver (configuration );
166+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
159167
160168 try {
161169 arangoDriver .getVersion ();
162170 Assert .fail ("this should fail" );
163- } catch (ArangoException e ) {
164- Throwable cause = e .getCause ();
171+ } catch (final ArangoException e ) {
172+ final Throwable cause = e .getCause ();
165173 Assert .assertTrue (cause instanceof javax .net .ssl .SSLPeerUnverifiedException );
166174 }
167175
0 commit comments