Skip to content

Commit 482c914

Browse files
aploesejpwsutton
authored andcommitted
changed visibility of MqttConnectOptions.validateURI to public, to be able to use this method for external validation too. (#329)
changed logging to avoid NullPointerExceptions with invalid URLs. Signed-off-by: Arne Plöse <aploese@gmx.de>
1 parent ca65d8d commit 482c914

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/MqttConnectOptions.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,26 +500,29 @@ public void setServerURIs(String[] array) {
500500
* @param srvURI The Server URI
501501
* @return the URI type
502502
*/
503-
protected static int validateURI(String srvURI) {
503+
public static int validateURI(String srvURI) {
504504
try {
505505
URI vURI = new URI(srvURI);
506-
if (vURI.getScheme().equals("ws")){
506+
if ("ws".equals(vURI.getScheme())){
507507
return URI_TYPE_WS;
508508
}
509-
else if (vURI.getScheme().equals("wss")) {
509+
else if ("wss".equals(vURI.getScheme())) {
510510
return URI_TYPE_WSS;
511511
}
512512

513-
if (!vURI.getPath().equals("")) {
514-
throw new IllegalArgumentException(srvURI);
513+
if ((vURI.getPath() == null) || vURI.getPath().isEmpty()) {
514+
// No op path must be empty
515515
}
516-
if (vURI.getScheme().equals("tcp")) {
516+
else {
517+
throw new IllegalArgumentException(srvURI);
518+
}
519+
if ("tcp".equals(vURI.getScheme())) {
517520
return URI_TYPE_TCP;
518521
}
519-
else if (vURI.getScheme().equals("ssl")) {
522+
else if ("ssl".equals(vURI.getScheme())) {
520523
return URI_TYPE_SSL;
521524
}
522-
else if (vURI.getScheme().equals("local")) {
525+
else if ("local".equals(vURI.getScheme())) {
523526
return URI_TYPE_LOCAL;
524527
}
525528
else {

0 commit comments

Comments
 (0)