public static GuacamoleConfiguration getConfiguration ( String uri ) throws GuacamoleException { // Parse the provided String into a URI object. URI qcUri ; try { qcUri = new URI ( uri ) ; if ( ! qcUri . isAbsolute ( ) ) throw new QuickConnectException ( "URI must be absolute." , "QUICKCONNECT.ERROR_NOT_ABSOLUTE_URI" ) ; } catch ( URISyntaxException e ) { throw new QuickConnectException ( "Invalid URI Syntax" , "QUICKCONNECT.ERROR_INVALID_URI" ) ; } // Break out individual components of the URI. String protocol = qcUri . getScheme ( ) ; String host = qcUri . getHost ( ) ; int port = qcUri . getPort ( ) ; String userInfo = qcUri . getUserInfo ( ) ; String query = qcUri . getQuery ( ) ; // Generate a new GuacamoleConfiguration GuacamoleConfiguration qcConfig = new GuacamoleConfiguration ( ) ; // Check for protocol and set it, or throw an error if not present if ( protocol != null && ! protocol . isEmpty ( ) ) qcConfig . setProtocol ( protocol ) ; else throw new QuickConnectException ( "No protocol specified." , "QUICKCONNECT.ERROR_NO_PROTOCOL" ) ; // Check for provided port number if ( port > 0 ) qcConfig . setParameter ( "port" , Integer . toString ( port ) ) ; // Check for provided host, or throw an error if not present if ( host != null && ! host . isEmpty ( ) ) qcConfig . setParameter ( "hostname" , host ) ; else throw new QuickConnectException ( "No host specified." , "QUICKCONNECT.ERROR_NO_HOST" ) ; // Look for extra query parameters and parse them out. 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 ) ; } } // Look for the username and password and parse them out. 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 ; }
Parse out a URI string and get a GuacamoleConfiguration from that string or an exception if the parsing fails .