From 3899a908a37899879e151ba09feb17f6e52edff5 Mon Sep 17 00:00:00 2001 From: Simon Bernard Date: Thu, 20 Jun 2019 18:16:57 +0200 Subject: [PATCH] Rename ConfigurationException in InvalidConfigurationException --- .../bootstrap/demo/BootstrapStoreImpl.java | 4 +-- .../demo/servlet/BootstrapServlet.java | 4 +-- .../bootstrap/ConfigurationChecker.java | 34 +++++++++---------- ...ava => InvalidConfigurationException.java} | 14 ++++---- 4 files changed, 28 insertions(+), 28 deletions(-) rename leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/{ConfigurationException.java => InvalidConfigurationException.java} (71%) diff --git a/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/BootstrapStoreImpl.java b/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/BootstrapStoreImpl.java index c81401a7dd..289fe4d9be 100644 --- a/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/BootstrapStoreImpl.java +++ b/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/BootstrapStoreImpl.java @@ -30,7 +30,7 @@ import org.eclipse.leshan.server.bootstrap.BootstrapConfig; import org.eclipse.leshan.server.bootstrap.BootstrapStore; import org.eclipse.leshan.server.bootstrap.ConfigurationChecker; -import org.eclipse.leshan.server.bootstrap.ConfigurationChecker.ConfigurationException; +import org.eclipse.leshan.server.bootstrap.InvalidConfigurationException; import org.eclipse.leshan.util.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -79,7 +79,7 @@ public BootstrapConfig getBootstrap(String endpoint, Identity deviceIdentity) { return bootstrapByEndpoint.get(endpoint); } - public void addConfig(String endpoint, BootstrapConfig config) throws ConfigurationException { + public void addConfig(String endpoint, BootstrapConfig config) throws InvalidConfigurationException { configChecker.verify(config); bootstrapByEndpoint.put(endpoint, config); saveToFile(); diff --git a/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/servlet/BootstrapServlet.java b/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/servlet/BootstrapServlet.java index 2e954aca83..2d693b8b67 100644 --- a/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/servlet/BootstrapServlet.java +++ b/leshan-bsserver-demo/src/main/java/org/eclipse/leshan/server/bootstrap/demo/servlet/BootstrapServlet.java @@ -28,7 +28,7 @@ import org.apache.commons.lang.StringUtils; import org.eclipse.leshan.server.bootstrap.BootstrapConfig; -import org.eclipse.leshan.server.bootstrap.ConfigurationChecker.ConfigurationException; +import org.eclipse.leshan.server.bootstrap.InvalidConfigurationException; import org.eclipse.leshan.server.bootstrap.demo.BootstrapStoreImpl; import com.google.gson.Gson; @@ -114,7 +114,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S bsStore.addConfig(endpoint, cfg); resp.setStatus(HttpServletResponse.SC_OK); } - } catch (JsonSyntaxException | ConfigurationException e) { + } catch (JsonSyntaxException | InvalidConfigurationException e) { sendError(resp, HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } } diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/ConfigurationChecker.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/ConfigurationChecker.java index 744b7d475c..fc3c449c70 100644 --- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/ConfigurationChecker.java +++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/ConfigurationChecker.java @@ -64,12 +64,12 @@ public ConfigurationChecker(String[] algorithms) { /** * Verify if the {@link BootstrapConfig} is valid and consistent. *

- * Raise a {@link ConfigurationException} if config is not OK. + * Raise a {@link InvalidConfigurationException} if config is not OK. * * @param config the bootstrap configuration to check. - * @throws ConfigurationException if bootstrap configuration is not invalid. + * @throws InvalidConfigurationException if bootstrap configuration is not invalid. */ - public void verify(BootstrapConfig config) throws ConfigurationException { + public void verify(BootstrapConfig config) throws InvalidConfigurationException { // check security configurations for (Map.Entry e : config.security.entrySet()) { BootstrapConfig.ServerSecurity sec = e.getValue(); @@ -97,18 +97,18 @@ public void verify(BootstrapConfig config) throws ConfigurationException { validateOneSecurityByServer(config); } - protected void checkNoSec(ServerSecurity sec) throws ConfigurationException { + protected void checkNoSec(ServerSecurity sec) throws InvalidConfigurationException { assertIf(!isEmpty(sec.secretKey), "NO-SEC mode, secret key must be empty"); assertIf(!isEmpty(sec.publicKeyOrId), "NO-SEC mode, public key or ID must be empty"); assertIf(!isEmpty(sec.serverPublicKey), "NO-SEC mode, server public key must be empty"); } - protected void checkPSK(ServerSecurity sec) throws ConfigurationException { + protected void checkPSK(ServerSecurity sec) throws InvalidConfigurationException { assertIf(isEmpty(sec.secretKey), "pre-shared-key mode, secret key must not be empty"); assertIf(isEmpty(sec.publicKeyOrId), "pre-shared-key mode, public key or id must not be empty"); } - protected void checkRPK(ServerSecurity sec) throws ConfigurationException { + protected void checkRPK(ServerSecurity sec) throws InvalidConfigurationException { assertIf(isEmpty(sec.secretKey), "raw-public-key mode, secret key must not be empty"); assertIf(decodeRfc5958PrivateKey(sec.secretKey) == null, "raw-public-key mode, secret key must be RFC5958 encoded private key"); @@ -120,7 +120,7 @@ protected void checkRPK(ServerSecurity sec) throws ConfigurationException { "raw-public-key mode, server public key must be RFC7250 encoded public key"); } - protected void checkX509(ServerSecurity sec) throws ConfigurationException { + protected void checkX509(ServerSecurity sec) throws InvalidConfigurationException { assertIf(isEmpty(sec.secretKey), "x509 mode, secret key must not be empty"); assertIf(decodeRfc5958PrivateKey(sec.secretKey) == null, "x509 mode, secret key must be RFC5958 encoded private key"); @@ -132,12 +132,12 @@ protected void checkX509(ServerSecurity sec) throws ConfigurationException { "x509 mode, server public key must be DER encoded X.509 certificate"); } - protected void validateMandatoryField(ServerSecurity sec) throws ConfigurationException { + protected void validateMandatoryField(ServerSecurity sec) throws InvalidConfigurationException { // checks mandatory fields if (StringUtils.isEmpty(sec.uri)) - throw new ConfigurationException("LwM2M Server URI is mandatory"); + throw new InvalidConfigurationException("LwM2M Server URI is mandatory"); if (sec.securityMode == null) - throw new ConfigurationException("Security Mode is mandatory"); + throw new InvalidConfigurationException("Security Mode is mandatory"); } @@ -145,26 +145,26 @@ protected void validateMandatoryField(ServerSecurity sec) throws ConfigurationEx * Each server entry must have 1 security entry. * * @param config the bootstrap configuration to check. - * @throws ConfigurationException if bootstrap configuration is not invalid. + * @throws InvalidConfigurationException if bootstrap configuration is not invalid. */ - protected void validateOneSecurityByServer(BootstrapConfig config) throws ConfigurationException { + protected void validateOneSecurityByServer(BootstrapConfig config) throws InvalidConfigurationException { for (Map.Entry e : config.servers.entrySet()) { BootstrapConfig.ServerConfig srvCfg = e.getValue(); // shortId checks if (srvCfg.shortId == 0) { - throw new ConfigurationException("short ID must not be 0"); + throw new InvalidConfigurationException("short ID must not be 0"); } // look for security entry BootstrapConfig.ServerSecurity security = getSecurityEntry(config, srvCfg.shortId); if (security == null) { - throw new ConfigurationException("no security entry for server instance: " + e.getKey()); + throw new InvalidConfigurationException("no security entry for server instance: " + e.getKey()); } if (security.bootstrapServer) { - throw new ConfigurationException( + throw new InvalidConfigurationException( "the security entry for server " + e.getKey() + " should not be a bootstrap server"); } } @@ -219,9 +219,9 @@ protected Certificate decodeCertificate(byte[] encodedCert) { } } - protected static void assertIf(boolean condition, String message) throws ConfigurationException { + protected static void assertIf(boolean condition, String message) throws InvalidConfigurationException { if (condition) { - throw new ConfigurationException(message); + throw new InvalidConfigurationException(message); } } diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/ConfigurationException.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/InvalidConfigurationException.java similarity index 71% rename from leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/ConfigurationException.java rename to leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/InvalidConfigurationException.java index 36f7aea428..db2845022b 100644 --- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/ConfigurationException.java +++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/InvalidConfigurationException.java @@ -18,30 +18,30 @@ /** * Exception raised when {@link BootstrapConfig} is invalid. */ -public class ConfigurationException extends Exception { +public class InvalidConfigurationException extends Exception { private static final long serialVersionUID = 1L; - public ConfigurationException() { + public InvalidConfigurationException() { } - public ConfigurationException(String m) { + public InvalidConfigurationException(String m) { super(m); } - public ConfigurationException(String m, Object... args) { + public InvalidConfigurationException(String m, Object... args) { super(String.format(m, args)); } - public ConfigurationException(Throwable e) { + public InvalidConfigurationException(Throwable e) { super(e); } - public ConfigurationException(String m, Throwable e) { + public InvalidConfigurationException(String m, Throwable e) { super(m, e); } - public ConfigurationException(Throwable e, String m, Object... args) { + public InvalidConfigurationException(Throwable e, String m, Object... args) { super(String.format(m, args), e); } } \ No newline at end of file