@Test public void testGetConfiguration() throws GuacamoleException { String uri1 = "ssh: GuacamoleConfiguration config1 = QCParser.getConfiguration(uri1); assertEquals("ssh", config1.getProtocol()); assertEquals("hostname1.domain.local", config1.getParameter("hostname")); assertEquals("guacuser", config1.getParameter("username")); assertEquals("guacpassword", config1.getParameter("password")); assertEquals("value1", config1.getParameter("param1")); assertEquals("value2", config1.getParameter("param2")); String uri2 = "rdp: GuacamoleConfiguration config2 = QCParser.getConfiguration(uri2); assertEquals("rdp", config2.getProtocol()); assertEquals("windows1.domain.tld", config2.getParameter("hostname")); assertEquals("domain\\guacuser", config2.getParameter("username")); assertEquals("adPassword123", config2.getParameter("password")); assertEquals("true", config2.getParameter("enable-sftp")); String uri3 = "vnc: GuacamoleConfiguration config3 = QCParser.getConfiguration(uri3); assertEquals("vnc", config3.getProtocol()); assertEquals("mirror1.example.com", config3.getParameter("hostname")); assertEquals("5910", config3.getParameter("port")); }
public static GuacamoleConfiguration getConfiguration(String uri) throws GuacamoleException { URI qcUri; try { qcUri = new URI(uri); if (!qcUri.isAbsolute()) throw new TranslatableGuacamoleClientException("URI must be absolute.", "QUICKCONNECT.ERROR_NOT_ABSOLUTE_URI"); } catch (URISyntaxException e) { throw new TranslatableGuacamoleClientException("Invalid URI Syntax", "QUICKCONNECT.ERROR_INVALID_URI"); } String protocol = qcUri.getScheme(); String host = qcUri.getHost(); int port = qcUri.getPort(); String userInfo = qcUri.getUserInfo(); String query = qcUri.getQuery(); GuacamoleConfiguration qcConfig = new GuacamoleConfiguration(); if (protocol != null && !protocol.isEmpty()) qcConfig.setProtocol(protocol); else throw new TranslatableGuacamoleClientException("No protocol specified.", "QUICKCONNECT.ERROR_NO_PROTOCOL"); if (port > 0) qcConfig.setParameter("port", Integer.toString(port)); if (host != null && !host.isEmpty()) qcConfig.setParameter("hostname", host); else throw new TranslatableGuacamoleClientException("No host specified.", "QUICKCONNECT.ERROR_NO_HOST"); if (query != null && !query.isEmpty()) { try { Map<String, String> queryParams = parseQueryString(query); if (queryParams != null) for (Map.Entry<String, String> entry: queryParams.entrySet()) qcConfig.setParameter(entry.getKey(), entry.getValue()); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } if (userInfo != null && !userInfo.isEmpty()) { try { parseUserInfo(userInfo, qcConfig); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } return qcConfig; }
QCParser { public static GuacamoleConfiguration getConfiguration(String uri) throws GuacamoleException { URI qcUri; try { qcUri = new URI(uri); if (!qcUri.isAbsolute()) throw new TranslatableGuacamoleClientException("URI must be absolute.", "QUICKCONNECT.ERROR_NOT_ABSOLUTE_URI"); } catch (URISyntaxException e) { throw new TranslatableGuacamoleClientException("Invalid URI Syntax", "QUICKCONNECT.ERROR_INVALID_URI"); } String protocol = qcUri.getScheme(); String host = qcUri.getHost(); int port = qcUri.getPort(); String userInfo = qcUri.getUserInfo(); String query = qcUri.getQuery(); GuacamoleConfiguration qcConfig = new GuacamoleConfiguration(); if (protocol != null && !protocol.isEmpty()) qcConfig.setProtocol(protocol); else throw new TranslatableGuacamoleClientException("No protocol specified.", "QUICKCONNECT.ERROR_NO_PROTOCOL"); if (port > 0) qcConfig.setParameter("port", Integer.toString(port)); if (host != null && !host.isEmpty()) qcConfig.setParameter("hostname", host); else throw new TranslatableGuacamoleClientException("No host specified.", "QUICKCONNECT.ERROR_NO_HOST"); if (query != null && !query.isEmpty()) { try { Map<String, String> queryParams = parseQueryString(query); if (queryParams != null) for (Map.Entry<String, String> entry: queryParams.entrySet()) qcConfig.setParameter(entry.getKey(), entry.getValue()); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } if (userInfo != null && !userInfo.isEmpty()) { try { parseUserInfo(userInfo, qcConfig); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } return qcConfig; } }
QCParser { public static GuacamoleConfiguration getConfiguration(String uri) throws GuacamoleException { URI qcUri; try { qcUri = new URI(uri); if (!qcUri.isAbsolute()) throw new TranslatableGuacamoleClientException("URI must be absolute.", "QUICKCONNECT.ERROR_NOT_ABSOLUTE_URI"); } catch (URISyntaxException e) { throw new TranslatableGuacamoleClientException("Invalid URI Syntax", "QUICKCONNECT.ERROR_INVALID_URI"); } String protocol = qcUri.getScheme(); String host = qcUri.getHost(); int port = qcUri.getPort(); String userInfo = qcUri.getUserInfo(); String query = qcUri.getQuery(); GuacamoleConfiguration qcConfig = new GuacamoleConfiguration(); if (protocol != null && !protocol.isEmpty()) qcConfig.setProtocol(protocol); else throw new TranslatableGuacamoleClientException("No protocol specified.", "QUICKCONNECT.ERROR_NO_PROTOCOL"); if (port > 0) qcConfig.setParameter("port", Integer.toString(port)); if (host != null && !host.isEmpty()) qcConfig.setParameter("hostname", host); else throw new TranslatableGuacamoleClientException("No host specified.", "QUICKCONNECT.ERROR_NO_HOST"); if (query != null && !query.isEmpty()) { try { Map<String, String> queryParams = parseQueryString(query); if (queryParams != null) for (Map.Entry<String, String> entry: queryParams.entrySet()) qcConfig.setParameter(entry.getKey(), entry.getValue()); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } if (userInfo != null && !userInfo.isEmpty()) { try { parseUserInfo(userInfo, qcConfig); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } return qcConfig; }  }
QCParser { public static GuacamoleConfiguration getConfiguration(String uri) throws GuacamoleException { URI qcUri; try { qcUri = new URI(uri); if (!qcUri.isAbsolute()) throw new TranslatableGuacamoleClientException("URI must be absolute.", "QUICKCONNECT.ERROR_NOT_ABSOLUTE_URI"); } catch (URISyntaxException e) { throw new TranslatableGuacamoleClientException("Invalid URI Syntax", "QUICKCONNECT.ERROR_INVALID_URI"); } String protocol = qcUri.getScheme(); String host = qcUri.getHost(); int port = qcUri.getPort(); String userInfo = qcUri.getUserInfo(); String query = qcUri.getQuery(); GuacamoleConfiguration qcConfig = new GuacamoleConfiguration(); if (protocol != null && !protocol.isEmpty()) qcConfig.setProtocol(protocol); else throw new TranslatableGuacamoleClientException("No protocol specified.", "QUICKCONNECT.ERROR_NO_PROTOCOL"); if (port > 0) qcConfig.setParameter("port", Integer.toString(port)); if (host != null && !host.isEmpty()) qcConfig.setParameter("hostname", host); else throw new TranslatableGuacamoleClientException("No host specified.", "QUICKCONNECT.ERROR_NO_HOST"); if (query != null && !query.isEmpty()) { try { Map<String, String> queryParams = parseQueryString(query); if (queryParams != null) for (Map.Entry<String, String> entry: queryParams.entrySet()) qcConfig.setParameter(entry.getKey(), entry.getValue()); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } if (userInfo != null && !userInfo.isEmpty()) { try { parseUserInfo(userInfo, qcConfig); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } return qcConfig; }  static GuacamoleConfiguration getConfiguration(String uri); static Map<String, String> parseQueryString(String queryStr); static void parseUserInfo(String userInfo, 
            GuacamoleConfiguration config); static String getName(GuacamoleConfiguration config); }
QCParser { public static GuacamoleConfiguration getConfiguration(String uri) throws GuacamoleException { URI qcUri; try { qcUri = new URI(uri); if (!qcUri.isAbsolute()) throw new TranslatableGuacamoleClientException("URI must be absolute.", "QUICKCONNECT.ERROR_NOT_ABSOLUTE_URI"); } catch (URISyntaxException e) { throw new TranslatableGuacamoleClientException("Invalid URI Syntax", "QUICKCONNECT.ERROR_INVALID_URI"); } String protocol = qcUri.getScheme(); String host = qcUri.getHost(); int port = qcUri.getPort(); String userInfo = qcUri.getUserInfo(); String query = qcUri.getQuery(); GuacamoleConfiguration qcConfig = new GuacamoleConfiguration(); if (protocol != null && !protocol.isEmpty()) qcConfig.setProtocol(protocol); else throw new TranslatableGuacamoleClientException("No protocol specified.", "QUICKCONNECT.ERROR_NO_PROTOCOL"); if (port > 0) qcConfig.setParameter("port", Integer.toString(port)); if (host != null && !host.isEmpty()) qcConfig.setParameter("hostname", host); else throw new TranslatableGuacamoleClientException("No host specified.", "QUICKCONNECT.ERROR_NO_HOST"); if (query != null && !query.isEmpty()) { try { Map<String, String> queryParams = parseQueryString(query); if (queryParams != null) for (Map.Entry<String, String> entry: queryParams.entrySet()) qcConfig.setParameter(entry.getKey(), entry.getValue()); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } if (userInfo != null && !userInfo.isEmpty()) { try { parseUserInfo(userInfo, qcConfig); } catch (UnsupportedEncodingException e) { throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e); } } return qcConfig; }  static GuacamoleConfiguration getConfiguration(String uri); static Map<String, String> parseQueryString(String queryStr); static void parseUserInfo(String userInfo, 
            GuacamoleConfiguration config); static String getName(GuacamoleConfiguration config);  }