GUACAMOLE-38: Implement QuickConnectException for providing exceptions to the user.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/73020135 Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/73020135 Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/73020135 Branch: refs/heads/staging/1.0.0 Commit: 730201358edb26ee27ab90f808fa72f146e0454b Parents: 8c13021 Author: Nick Couchman <vn...@apache.org> Authored: Mon May 21 10:54:14 2018 -0400 Committer: Nick Couchman <vn...@apache.org> Committed: Fri Jun 1 13:40:53 2018 -0400 ---------------------------------------------------------------------- .../quickconnect/QuickConnectException.java | 86 ++++++++++++++++++++ .../auth/quickconnect/utility/QCParser.java | 13 ++- .../src/main/resources/translations/en.json | 6 ++ 3 files changed, 101 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/73020135/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectException.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectException.java b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectException.java new file mode 100644 index 0000000..6e4d5b9 --- /dev/null +++ b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectException.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.guacamole.auth.quickconnect; + +import org.apache.guacamole.GuacamoleClientException; +import org.apache.guacamole.language.Translatable; +import org.apache.guacamole.language.TranslatableMessage; + +/** + * An exception that is thrown by this extension when an error occurs + * attempting to create and establish a connection with a user-provided + * URI. + */ +public class QuickConnectException extends GuacamoleClientException + implements Translatable { + + /** + * A message that can be passed through the translation service + * to provide information about the error that occurred. + */ + private final TranslatableMessage translatableMessage; + + /** + * Create a QuickConnectException with the given message and translationKey. + * The message will not be passed through the translation system; the + * translationKey will be passed through the translation system. Both should + * describe the error. + * + * @param message + * A string describing the error that occurred when trying to create + * or establish the connection. This will not be passed through the + * translation system. + * + * @param translationKey + * A key known to the translation system describing the error that + * occurred when trying to create or establish the connection. + * This will be passed through the translation system to provide + * a localized version of the message. + */ + public QuickConnectException(String message, String translationKey) { + super(message); + this.translatableMessage = new TranslatableMessage(translationKey); + } + + /** + * Create a new QuickConnectException given the human-readable message, + * which will not be passed through the translation system, and the + * translatableMessage, which will be passed through the translation system. + * Both parameters should describe the error preventing the connection + * from being created or established. + * + * @param message + * The human-readable message describing the error, which will not + * be passed through the translation system. + * + * @param translatableMessage + * The human-readable message describing the error, which will be + * passed through the translation system. + */ + public QuickConnectException(String message, TranslatableMessage translatableMessage) { + super(message); + this.translatableMessage = translatableMessage; + } + + @Override + public TranslatableMessage getTranslatableMessage() { + return translatableMessage; + } + +} http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/73020135/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java index 2810f1d..f61f510 100644 --- a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java +++ b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java @@ -33,6 +33,7 @@ import java.util.regex.Pattern; import org.apache.guacamole.GuacamoleClientException; import org.apache.guacamole.GuacamoleServerException; import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.auth.quickconnect.QuickConnectException; import org.apache.guacamole.protocol.GuacamoleConfiguration; /** @@ -79,10 +80,12 @@ public class QCParser { try { qcUri = new URI(uri); if (!qcUri.isAbsolute()) - throw new GuacamoleClientException("URI must be absolute."); + throw new QuickConnectException("URI must be absolute.", + "QUICKCONNECT.ERROR_NOT_ABSOLUTE_URI"); } catch (URISyntaxException e) { - throw new GuacamoleClientException("Invalid URI Syntax", e); + throw new QuickConnectException("Invalid URI Syntax", + "QUICKCONNECT.ERROR_INVALID_URI"); } // Break out individual components of the URI. @@ -99,7 +102,8 @@ public class QCParser { if (protocol != null && !protocol.isEmpty()) qcConfig.setProtocol(protocol); else - throw new GuacamoleClientException("No protocol specified."); + throw new QuickConnectException("No protocol specified.", + "QUICKCONNECT.ERROR_NO_PROTOCOL"); // Check for provided port number if (port > 0) @@ -109,7 +113,8 @@ public class QCParser { if (host != null && !host.isEmpty()) qcConfig.setParameter("hostname", host); else - throw new GuacamoleClientException("No host specified."); + throw new QuickConnectException("No host specified.", + "QUICKCONNECT.ERROR_NO_HOST"); // Look for extra query parameters and parse them out. if (query != null && !query.isEmpty()) { http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/73020135/extensions/guacamole-auth-quickconnect/src/main/resources/translations/en.json ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-quickconnect/src/main/resources/translations/en.json b/extensions/guacamole-auth-quickconnect/src/main/resources/translations/en.json index 2c2dc8e..50ffb2d 100644 --- a/extensions/guacamole-auth-quickconnect/src/main/resources/translations/en.json +++ b/extensions/guacamole-auth-quickconnect/src/main/resources/translations/en.json @@ -6,6 +6,12 @@ "QUICKCONNECT" : { "ACTION_CONNECT" : "Connect", + + "ERROR_INVALID_URI" : "Invalid URI Specified", + "ERROR_NO_HOST" : "No host specified", + "ERROR_NO_PROTOCOL" : "No protocol specified", + "ERROR_NOT_ABSOLUTE_URI" : "URI is not absolute", + "FIELD_PLACEHOLDER_URI" : "Enter Connection URI" }