|
18 | 18 | import java.io.File;
|
19 | 19 | import java.net.InetAddress;
|
20 | 20 | import java.net.UnknownHostException;
|
| 21 | +import java.util.Arrays; |
21 | 22 | import java.util.List;
|
22 | 23 | import java.util.Map;
|
| 24 | +import java.util.stream.Collectors; |
| 25 | +import java.util.stream.Stream; |
23 | 26 |
|
24 | 27 | import org.eclipse.californium.core.coap.CoAP;
|
25 | 28 | import org.eclipse.californium.scandium.dtls.cipher.CipherSuite;
|
|
31 | 34 | import org.eclipse.leshan.core.demo.cli.converters.InetAddressConverter;
|
32 | 35 | import org.eclipse.leshan.core.demo.cli.converters.ResourcePathConverter;
|
33 | 36 | import org.eclipse.leshan.core.demo.cli.converters.StrictlyPositiveIntegerConverter;
|
| 37 | +import org.eclipse.leshan.core.endpoint.Protocol; |
34 | 38 | import org.eclipse.leshan.core.node.LwM2mPath;
|
35 | 39 | import org.eclipse.leshan.core.util.StringUtils;
|
36 | 40 |
|
@@ -316,24 +320,33 @@ public void run() {
|
316 | 320 | // extract scheme
|
317 | 321 | int indexOf = main.url.indexOf("://");
|
318 | 322 | String scheme = main.url.substring(0, indexOf);
|
319 |
| - // we support only coap and coaps |
320 |
| - if (!"coap".equals(scheme) && !"coaps".equals(scheme) && !"coap+tcp".equals(scheme)) { |
321 |
| - throw new MultiParameterException(spec.commandLine(), String.format( |
322 |
| - "Invalid URL %s : unknown scheme '%s', we support only 'coap' or 'coaps' or 'coap+tcp' for now", |
323 |
| - main.url, scheme), "-u"); |
| 323 | + // check URI scheme is supported |
| 324 | + List<String> supportedUnsecuredProtocol = Arrays.asList(Protocol.COAP, Protocol.COAP_TCP) // |
| 325 | + .stream().map(Protocol::getUriScheme).collect(Collectors.toList()); |
| 326 | + List<String> supportedTlsBasedProtocol = Arrays.asList(Protocol.COAPS) // |
| 327 | + .stream().map(Protocol::getUriScheme).collect(Collectors.toList()); |
| 328 | + List<String> allSupportedProtocol = Stream |
| 329 | + .concat(supportedUnsecuredProtocol.stream(), supportedTlsBasedProtocol.stream()) |
| 330 | + .collect(Collectors.toList()); |
| 331 | + |
| 332 | + if (!allSupportedProtocol.contains(scheme)) { |
| 333 | + throw new MultiParameterException(spec.commandLine(), |
| 334 | + String.format("Invalid URL %s : unknown scheme '%s', we support only %s for now", main.url, scheme, |
| 335 | + String.join(" or ", allSupportedProtocol)), |
| 336 | + "-u"); |
324 | 337 | }
|
325 | 338 | // check scheme matches configuration
|
326 | 339 | if (identity.hasIdentity()) {
|
327 |
| - if (!scheme.equals("coaps")) { |
| 340 | + if (!supportedTlsBasedProtocol.contains(scheme)) { |
328 | 341 | throw new MultiParameterException(spec.commandLine(), String.format(
|
329 |
| - "Invalid URL %s : '%s' scheme must be used without PSK, RPK or x509 option. Do you mean 'coaps' ? ", |
330 |
| - main.url, scheme), "-u"); |
| 342 | + "Invalid URL %s : '%s' scheme must be used without PSK, RPK or x509 option. Do you mean %s ? ", |
| 343 | + main.url, scheme, String.join(" or ", supportedTlsBasedProtocol)), "-u"); |
331 | 344 | }
|
332 | 345 | } else {
|
333 |
| - if (!scheme.equals("coap") && !scheme.equals("coap+tcp")) { |
| 346 | + if (!supportedUnsecuredProtocol.contains(scheme)) { |
334 | 347 | throw new MultiParameterException(spec.commandLine(), String.format(
|
335 |
| - "Invalid URL %s : '%s' scheme must be used with PSK, RPK or x509 option. Do you mean 'coap' ? ", |
336 |
| - main.url, scheme), "-u"); |
| 348 | + "Invalid URL %s : '%s' scheme must be used with PSK, RPK or x509 option. Do you mean %s ? ", |
| 349 | + main.url, scheme, String.join(" or ", supportedUnsecuredProtocol)), "-u"); |
337 | 350 | }
|
338 | 351 | }
|
339 | 352 | }
|
|
0 commit comments