Skip to content

Commit 75d6dc2

Browse files
committed
The TCP server/client updateSslOptions method does not update the options when the comparison using equals against the previous options returns true. Sometimes this behavior is not desirable, e.g. when the path to the certificate does not change and such certificates has been overwritten.
1 parent 29ebcb1 commit 75d6dc2

File tree

15 files changed

+312
-92
lines changed

15 files changed

+312
-92
lines changed

src/main/asciidoc/net.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,11 @@ implement certificate rotation).
640640
{@link examples.NetExamples#updateSSLOptions}
641641
----
642642

643-
When the update succeeds the new SSL configuration is used, otherwise the previous configuration is kept.
643+
When the update succeeds the new SSL configuration is used, otherwise the previous configuration is preserved.
644+
645+
NOTE: The options object is compared (using `equals`) against the existing options to prevent an update when the objects
646+
are equals since loading options can be costly. When object are equals, you can use the `force` parameter to force
647+
the update.
644648

645649
==== Self-signed certificates for testing and development purposes
646650

src/main/java/examples/NetExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public void example41(Vertx vertx) {
512512
}
513513

514514
public void updateSSLOptions(HttpServer server) {
515-
Future<Void> fut = server.updateSSLOptions(new SSLOptions()
515+
Future<Boolean> fut = server.updateSSLOptions(new SSLOptions()
516516
.setKeyCertOptions(
517517
new JksOptions()
518518
.setPath("/path/to/your/server-keystore.jks").

src/main/java/io/vertx/core/http/HttpClient.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,58 @@ default Future<HttpClientRequest> request(HttpMethod method, String requestURI)
196196
Future<WebSocket> webSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols);
197197

198198
/**
199-
* Update the client SSL options.
199+
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
200+
* from the existing options object.
200201
*
201-
* Update only happens if the SSL options is valid.
202+
* <p>The boolean succeeded future result indicates whether the update occurred.
202203
*
203204
* @param options the new SSL options
204205
* @return a future signaling the update success
205206
*/
206-
Future<Void> updateSSLOptions(SSLOptions options);
207+
default Future<Boolean> updateSSLOptions(SSLOptions options) {
208+
return updateSSLOptions(options, false);
209+
}
210+
211+
/**
212+
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
213+
* happened (or has failed).
214+
*
215+
* @param options the new SSL options
216+
* @param handler the update handler
217+
*/
218+
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
219+
Future<Boolean> fut = updateSSLOptions(options);
220+
if (handler != null) {
221+
fut.onComplete(handler);
222+
}
223+
}
224+
225+
/**
226+
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
227+
* from the existing options object.
228+
*
229+
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
230+
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
231+
* When object are equals, setting {@code force} to {@code true} forces the update.
232+
*
233+
* <p>The boolean succeeded future result indicates whether the update occurred.
234+
*
235+
* @param options the new SSL options
236+
* @param force force the update when options are equals
237+
* @return a future signaling the update success
238+
*/
239+
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);
207240

208241
/**
209242
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
210243
* happened (or has failed).
211244
*
212245
* @param options the new SSL options
246+
* @param force force the update when options are equals
213247
* @param handler the update handler
214248
*/
215-
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
216-
Future<Void> fut = updateSSLOptions(options);
249+
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
250+
Future<Boolean> fut = updateSSLOptions(options, force);
217251
if (handler != null) {
218252
fut.onComplete(handler);
219253
}

src/main/java/io/vertx/core/http/HttpServer.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,58 @@ public interface HttpServer extends Measured {
125125
Handler<ServerWebSocket> webSocketHandler();
126126

127127
/**
128-
* Update the server SSL options.
128+
* Update the server with new SSL {@code options}, the update happens if the options object is valid and different
129+
* from the existing options object.
129130
*
130-
* Update only happens if the SSL options is valid.
131+
* <p>The boolean succeeded future result indicates whether the update occurred.
131132
*
132133
* @param options the new SSL options
133134
* @return a future signaling the update success
134135
*/
135-
Future<Void> updateSSLOptions(SSLOptions options);
136+
default Future<Boolean> updateSSLOptions(SSLOptions options) {
137+
return updateSSLOptions(options, false);
138+
}
139+
140+
/**
141+
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
142+
* happened (or has failed).
143+
*
144+
* @param options the new SSL options
145+
* @param handler the update handler
146+
*/
147+
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
148+
Future<Boolean> fut = updateSSLOptions(options);
149+
if (handler != null) {
150+
fut.onComplete(handler);
151+
}
152+
}
153+
154+
/**
155+
* <p>Update the server with new SSL {@code options}, the update happens if the options object is valid and different
156+
* from the existing options object.
157+
*
158+
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
159+
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
160+
* When object are equals, setting {@code force} to {@code true} forces the update.
161+
*
162+
* <p>The boolean succeeded future result indicates whether the update occurred.
163+
*
164+
* @param options the new SSL options
165+
* @param force force the update when options are equals
166+
* @return a future signaling the update success
167+
*/
168+
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);
136169

137170
/**
138171
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
139172
* happened (or has failed).
140173
*
141174
* @param options the new SSL options
175+
* @param force force the update when options are equals
142176
* @param handler the update handler
143177
*/
144-
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
145-
Future<Void> fut = updateSSLOptions(options);
178+
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
179+
Future<Boolean> fut = updateSSLOptions(options, force);
146180
if (handler != null) {
147181
fut.onComplete(handler);
148182
}

src/main/java/io/vertx/core/http/WebSocketClient.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,54 @@ default Future<WebSocket> connect(String requestURI) {
102102
Future<WebSocket> connect(WebSocketConnectOptions options);
103103

104104
/**
105-
* Update the client SSL options.
105+
* Update the client with new SSL {@code options}, the update happens if the options object is valid and different
106+
* from the existing options object.
106107
*
107-
* Update only happens if the SSL options is valid.
108+
* @param options the new SSL options
109+
* @return a future signaling the update success
110+
*/
111+
default Future<Boolean> updateSSLOptions(SSLOptions options) {
112+
return updateSSLOptions(options, false);
113+
}
114+
115+
/**
116+
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
117+
* happened (or has failed).
118+
*
119+
* @param options the new SSL options
120+
* @param handler the update handler
121+
*/
122+
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
123+
Future<Boolean> fut = updateSSLOptions(options);
124+
if (handler != null) {
125+
fut.onComplete(handler);
126+
}
127+
}
128+
129+
/**
130+
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
131+
* from the existing options object.
132+
*
133+
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
134+
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
135+
* When object are equals, setting {@code force} to {@code true} forces the update.
108136
*
109137
* @param options the new SSL options
138+
* @param force force the update when options are equals
110139
* @return a future signaling the update success
111140
*/
112-
Future<Void> updateSSLOptions(SSLOptions options);
141+
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);
113142

114143
/**
115144
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
116145
* happened (or has failed).
117146
*
118147
* @param options the new SSL options
148+
* @param force force the update when options are equals
119149
* @param handler the update handler
120150
*/
121-
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
122-
Future<Void> fut = updateSSLOptions(options);
151+
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
152+
Future<Boolean> fut = updateSSLOptions(options, force);
123153
if (handler != null) {
124154
fut.onComplete(handler);
125155
}

src/main/java/io/vertx/core/http/impl/HttpClientBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ public Metrics getMetrics() {
316316
}
317317

318318
// @Override
319-
public Future<Void> updateSSLOptions(SSLOptions options) {
320-
return netClient.updateSSLOptions(options);
319+
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force) {
320+
return netClient.updateSSLOptions(options, force);
321321
}
322322

323323
public HttpClientBase proxyFilter(Predicate<SocketAddress> filter) {

src/main/java/io/vertx/core/http/impl/SharedHttpClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ public Future<WebSocket> webSocketAbs(String url, MultiMap headers, WebsocketVer
145145
}
146146

147147
@Override
148-
public Future<Void> updateSSLOptions(SSLOptions options) {
149-
return delegate.updateSSLOptions(options);
148+
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force) {
149+
return delegate.updateSSLOptions(options, force);
150150
}
151151

152152
@Override

src/main/java/io/vertx/core/http/impl/SharedWebSocketClient.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,8 @@ public Future<WebSocket> connect(WebSocketConnectOptions options) {
6969
}
7070

7171
@Override
72-
public Future<Void> updateSSLOptions(SSLOptions options) {
73-
return delegate.updateSSLOptions(options);
74-
}
75-
76-
@Override
77-
public void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
78-
delegate.updateSSLOptions(options, handler);
72+
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force) {
73+
return delegate.updateSSLOptions(options, force);
7974
}
8075

8176
@Override

src/main/java/io/vertx/core/net/NetClient.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,58 @@ public interface NetClient extends Measured {
115115
Future<Void> close();
116116

117117
/**
118-
* Update the client SSL options.
118+
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
119+
* from the existing options object.
119120
*
120-
* Update only happens if the SSL options is valid.
121+
* <p>The boolean succeeded future result indicates whether the update occurred.
121122
*
122123
* @param options the new SSL options
123124
* @return a future signaling the update success
124125
*/
125-
Future<Void> updateSSLOptions(SSLOptions options);
126+
default Future<Boolean> updateSSLOptions(SSLOptions options) {
127+
return updateSSLOptions(options, false);
128+
}
129+
130+
/**
131+
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
132+
* happened (or has failed).
133+
*
134+
* @param options the new SSL options
135+
* @param handler the update handler
136+
*/
137+
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
138+
Future<Boolean> fut = updateSSLOptions(options);
139+
if (handler != null) {
140+
fut.onComplete(handler);
141+
}
142+
}
143+
144+
/**
145+
* <p>Update the client with new SSL {@code options}, the update happens if the options object is valid and different
146+
* from the existing options object.
147+
*
148+
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
149+
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
150+
* When object are equals, setting {@code force} to {@code true} forces the update.
151+
*
152+
* <p>The boolean succeeded future result indicates whether the update occurred.
153+
*
154+
* @param options the new SSL options
155+
* @param force force the update when options are equals
156+
* @return a future signaling the update success
157+
*/
158+
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);
126159

127160
/**
128161
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
129162
* happened (or has failed).
130163
*
131164
* @param options the new SSL options
165+
* @param force force the update when options are equals
132166
* @param handler the update handler
133167
*/
134-
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
135-
Future<Void> fut = updateSSLOptions(options);
168+
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
169+
Future<Boolean> fut = updateSSLOptions(options, force);
136170
if (handler != null) {
137171
fut.onComplete(handler);
138172
}

src/main/java/io/vertx/core/net/NetServer.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,60 @@ default NetServer listen(SocketAddress localAddress, Handler<AsyncResult<NetServ
200200
int actualPort();
201201

202202
/**
203-
* Update the server SSL options.
203+
* <p>Update the server with new SSL {@code options}, the update happens if the options object is valid and different
204+
* from the existing options object.
204205
*
205-
* Update only happens if the SSL options is valid.
206+
* <p>The boolean succeeded future result indicates whether the update occurred.
206207
*
207208
* @param options the new SSL options
208209
* @return a future signaling the update success
209210
*/
210-
Future<Void> updateSSLOptions(SSLOptions options);
211+
default Future<Boolean> updateSSLOptions(SSLOptions options) {
212+
return updateSSLOptions(options, false);
213+
}
214+
215+
/**
216+
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
217+
* happened (or has failed).
218+
*
219+
* @param options the new SSL options
220+
* @param handler the update handler
221+
*/
222+
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler) {
223+
Future<Boolean> fut = updateSSLOptions(options);
224+
if (handler != null) {
225+
fut.onComplete(handler);
226+
}
227+
}
228+
229+
/**
230+
* <p>Update the server with new SSL {@code options}, the update happens if the options object is valid and different
231+
* from the existing options object.
232+
*
233+
* <p>The {@code options} object is compared using its {@code equals} method against the existing options to prevent
234+
* an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
235+
* When object are equals, setting {@code force} to {@code true} forces the update.
236+
*
237+
* <p>The boolean succeeded future result indicates whether the update occurred.
238+
*
239+
* @param options the new SSL options
240+
* @param force force the update when options are equals
241+
* @return a future signaling the update success
242+
*/
243+
Future<Boolean> updateSSLOptions(SSLOptions options, boolean force);
211244

212245
/**
213246
* Like {@link #updateSSLOptions(SSLOptions)} but supplying a handler that will be called when the update
214247
* happened (or has failed).
215248
*
216249
* @param options the new SSL options
250+
* @param force force the update when options are equals
217251
* @param handler the update handler
218252
*/
219-
default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Void>> handler) {
220-
Future<Void> fut = updateSSLOptions(options);
253+
default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler) {
254+
Future<Boolean> fut = updateSSLOptions(options, force);
221255
if (handler != null) {
222256
fut.onComplete(handler);
223257
}
224-
}}
258+
}
259+
}

0 commit comments

Comments
 (0)