58
58
import org .slf4j .Logger ;
59
59
import org .slf4j .LoggerFactory ;
60
60
61
+ import javax .net .ssl .HostnameVerifier ;
61
62
import javax .net .ssl .SSLContext ;
62
63
import java .io .IOException ;
63
64
import java .util .ArrayList ;
@@ -87,6 +88,7 @@ public static class Builder {
87
88
private HostDescription host ;
88
89
private Long ttl ;
89
90
private SSLContext sslContext ;
91
+ private HostnameVerifier hostnameVerifier ;
90
92
private Integer timeout ;
91
93
92
94
public Builder user (final String user ) {
@@ -134,13 +136,18 @@ public Builder sslContext(final SSLContext sslContext) {
134
136
return this ;
135
137
}
136
138
139
+ public Builder hostnameVerifier (final HostnameVerifier hostnameVerifier ) {
140
+ this .hostnameVerifier = hostnameVerifier ;
141
+ return this ;
142
+ }
143
+
137
144
public Builder timeout (final Integer timeout ) {
138
145
this .timeout = timeout ;
139
146
return this ;
140
147
}
141
148
142
149
public HttpConnection build () {
143
- return new HttpConnection (host , timeout , user , password , useSsl , sslContext , util , contentType , ttl , httpCookieSpec );
150
+ return new HttpConnection (host , timeout , user , password , useSsl , sslContext , hostnameVerifier , util , contentType , ttl , httpCookieSpec );
144
151
}
145
152
}
146
153
@@ -154,7 +161,7 @@ public HttpConnection build() {
154
161
private final HostDescription host ;
155
162
156
163
private HttpConnection (final HostDescription host , final Integer timeout , final String user , final String password ,
157
- final Boolean useSsl , final SSLContext sslContext , final ArangoSerialization util , final Protocol contentType ,
164
+ final Boolean useSsl , final SSLContext sslContext , final HostnameVerifier hostnameVerifier , final ArangoSerialization util , final Protocol contentType ,
158
165
final Long ttl , final String httpCookieSpec ) {
159
166
super ();
160
167
this .host = host ;
@@ -166,11 +173,10 @@ private HttpConnection(final HostDescription host, final Integer timeout, final
166
173
final RegistryBuilder <ConnectionSocketFactory > registryBuilder = RegistryBuilder
167
174
.create ();
168
175
if (Boolean .TRUE == useSsl ) {
169
- if (sslContext != null ) {
170
- registryBuilder .register ("https" , new SSLConnectionSocketFactory (sslContext ));
171
- } else {
172
- registryBuilder .register ("https" , new SSLConnectionSocketFactory (SSLContexts .createSystemDefault ()));
173
- }
176
+ registryBuilder .register ("https" , new SSLConnectionSocketFactory (
177
+ sslContext != null ? sslContext : SSLContexts .createSystemDefault (),
178
+ hostnameVerifier != null ? hostnameVerifier : SSLConnectionSocketFactory .getDefaultHostnameVerifier ()
179
+ ));
174
180
} else {
175
181
registryBuilder .register ("http" , new PlainConnectionSocketFactory ());
176
182
}
0 commit comments