List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:sf.net.experimaestro.connectors.SSHConnector.java
public SSHConnector(URI uri, ConnectorOptions options) { this(uri.getUserInfo(), uri.getHost(), uri.getPort(), options); }
From source file:net.bluemix.todo.connector.CloudantServiceInfoCreator.java
@Override public CloudantServiceInfo createServiceInfo(Map<String, Object> serviceData) { Map<String, Object> credentials = (Map<String, Object>) serviceData.get("credentials"); String id = (String) serviceData.get("name"); try {/*w w w .ja v a2 s .co m*/ URI uri = new URI((String) credentials.get("url")); String scheme = uri.getScheme(); int port = uri.getPort(); String host = uri.getHost(); String path = uri.getPath(); String query = uri.getQuery(); String fragment = uri.getFragment(); String url = new URI(scheme, "", host, port, path, query, fragment).toString(); String[] userInfo = uri.getUserInfo().split(":"); return new CloudantServiceInfo(id, userInfo[0], userInfo[1], url); } catch (URISyntaxException e) { return null; } }
From source file:org.apache.hadoop.fs.TestFileSystem.java
static void runTestCache(int port) throws Exception { Configuration conf = new Configuration(); MiniDFSCluster cluster = null;/*from w w w . j a va 2 s . c om*/ try { cluster = new MiniDFSCluster(port, conf, 2, true, true, null, null); URI uri = cluster.getFileSystem().getUri(); LOG.info("uri=" + uri); { FileSystem fs = FileSystem.get(uri, new Configuration()); checkPath(cluster, fs); for (int i = 0; i < 100; i++) { assertTrue(fs == FileSystem.get(uri, new Configuration())); } } if (port == NameNode.DEFAULT_PORT) { //test explicit default port URI uri2 = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), NameNode.DEFAULT_PORT, uri.getPath(), uri.getQuery(), uri.getFragment()); LOG.info("uri2=" + uri2); FileSystem fs = FileSystem.get(uri2, conf); checkPath(cluster, fs); for (int i = 0; i < 100; i++) { assertTrue(fs == FileSystem.get(uri2, new Configuration())); } } } finally { if (cluster != null) cluster.shutdown(); } }
From source file:com.flipkart.aesop.runtime.producer.MysqlEventProducer.java
/** * Extracts individual attributes such as username, password, hostname, port ,server id etc from the uri of the * format mysql://or_test%2For_test@localhost:3306/3306/mysql-bin * @param uri uri of the format mysql://or_test%2For_test@localhost:3306/3306/mysql-bin * @return returns bin log prefix/* ww w . ja v a 2s .c om*/ */ protected String processUri(URI uri) throws InvalidConfigException { String userInfo = uri.getUserInfo(); if (null == userInfo) { String errorMessage = "missing user info in: " + uri; LOGGER.error(errorMessage); throw new InvalidConfigException(errorMessage); } int slashPos = userInfo.indexOf('/'); if (slashPos < 0) { slashPos = userInfo.length(); } else if (0 == slashPos) { String errorMessage = "missing user name in user info: " + userInfo; LOGGER.error(errorMessage); throw new InvalidConfigException(errorMessage); } String userName = userInfo.substring(0, slashPos); String userPass = slashPos < userInfo.length() - 1 ? userInfo.substring(slashPos + 1) : null; String hostName = uri.getHost(); int port = uri.getPort(); if (port < 0) port = DEFAULT_MYSQL_PORT; String path = uri.getPath(); if (null == path) { String errorMessage = "missing path: " + uri; LOGGER.error(errorMessage); throw new InvalidConfigException(errorMessage); } Matcher matcher = PATH_PATTERN.matcher(path); if (!matcher.matches()) { String errorMessage = "invalid path:" + path; LOGGER.error(errorMessage); throw new InvalidConfigException(errorMessage); } String[] group = matcher.group().split("/"); if (group.length != 3) { String errorMessage = "Invalid format " + Arrays.toString(group); LOGGER.error(errorMessage); throw new InvalidConfigException(errorMessage); } String serverIdStr = group[SERVER_ID]; int serverId = -1; try { serverId = Integer.parseInt(serverIdStr); } catch (NumberFormatException e) { String errorMessage = "incorrect mysql serverid:" + serverId; LOGGER.error(errorMessage); throw new InvalidConfigException(errorMessage); } /** Assign them to incoming variables */ if (null != openReplicator) { openReplicator.setUser(userName); if (null != userPass) { openReplicator.setPassword(userPass); } openReplicator.setHost(hostName); openReplicator.setPort(port); openReplicator.setServerId(serverId); } LOGGER.debug("Extracted bin log prefix is " + group[BIN_LOG_PREFIX]); return group[BIN_LOG_PREFIX]; }
From source file:com.mellanox.jxio.ServerPortal.java
private URI replacePortInURI(URI uri, int newPort) { URI newUri = null;//w w w . ja v a2 s.co m try { newUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), newPort, uri.getPath(), uri.getQuery(), uri.getFragment()); if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "uri with port " + newPort + " is " + newUri.toString()); } } catch (URISyntaxException e) { e.printStackTrace(); LOG.error(this.toLogString() + "URISyntaxException occured while trying to create a new URI"); } return newUri; }
From source file:com.sap.core.odata.fit.basic.issues.TestIssue105.java
@Test public void checkContextForDifferentHostNamesRequests() throws ClientProtocolException, IOException, ODataException, URISyntaxException { URI uri1 = URI.create(getEndpoint().toString() + "$metadata"); HttpGet get1 = new HttpGet(uri1); HttpResponse response1 = getHttpClient().execute(get1); assertNotNull(response1);//from w ww . j a v a 2 s.c o m URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot(); assertEquals(uri1.getHost(), serviceRoot1.getHost()); get1.reset(); URI uri2 = new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(), uri1.getQuery(), uri1.getFragment()); HttpGet get2 = new HttpGet(uri2); HttpResponse response2 = getHttpClient().execute(get2); assertNotNull(response2); URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot(); assertEquals(uri2.getHost(), serviceRoot2.getHost()); }
From source file:com.microsoftopentechnologies.azchat.web.mediaservice.AzureChatMediaService.java
/** * This method retrieve the MP4 streaming URL from assetInfoFile. * /* w w w. j a v a 2s . co m*/ * @param streaming * @param streamingAssetFile * @param streamingAsset * @return * @throws Exception */ private String getMP4StreamngURL(AccessPolicyInfo streaming, AssetFileInfo streamingAssetFile, AssetInfo streamingAsset) throws Exception { String streamingURL = null; LocatorInfo locator = mediaService .create(Locator.create(streaming.getId(), streamingAsset.getId(), LocatorType.SAS)); URI mp4Uri = new URI(locator.getPath()); mp4Uri = new URI(mp4Uri.getScheme(), mp4Uri.getUserInfo(), mp4Uri.getHost(), mp4Uri.getPort(), mp4Uri.getPath() + AzureChatConstants.CONSTANT_BACK_SLASH + streamingAssetFile.getName(), mp4Uri.getQuery(), mp4Uri.getFragment()); streamingURL = mp4Uri.toString(); return streamingURL; }
From source file:com.mellanox.jxio.ServerPortal.java
private URI replaceIPinURI(URI uriForForward, String uriIPAddress) { URI newUri = null;/*w w w .j av a 2s . co m*/ try { newUri = new URI(uriForForward.getScheme(), uriForForward.getUserInfo(), new URI(uriIPAddress).getHost(), uriForForward.getPort(), uriForForward.getPath(), uriForForward.getQuery(), uriForForward.getFragment()); } catch (URISyntaxException e) { e.printStackTrace(); LOG.error(this.toLogString() + "URISyntaxException occured while trying to create a new URI"); } return newUri; }
From source file:net.bluemix.connectors.core.info.IBMObjectStorageServiceInfo.java
public IBMObjectStorageServiceInfo(final String id, final String url) throws URISyntaxException { super(id);//from w w w. j a v a 2s . c o m final String modUrl = url.replaceFirst(IBMObjectStorageServiceInfo.SCHEME, "https"); final URI uri = new URI(modUrl); this.authUrl = uri.getScheme() + "://" + uri.getHost(); if (uri.getPort() > 0) { this.authUrl = authUrl + ":" + uri.getPort(); } if (uri.getUserInfo() != null) { final String[] credentials = uri.getUserInfo().split(":"); this.userId = credentials[0]; this.password = credentials[1]; } if (uri.getPath() != null) { //the path includes the '/' after the host final String[] path = uri.getPath().split("/"); if (path.length == 3) { this.project = path[1]; this.domainName = path[2]; } } }
From source file:org.jvoicexml.interpreter.grammar.GrammarLoader.java
/** * Take the route of processing an external grammar. * * @param context/*from ww w . java 2s . c o m*/ * The current context * @param attributes * attributes governing the fetch. * @param grammar * The grammar to be processed. * * @return Is just the string representation of the grammar as well as the * type. * * @throws UnsupportedFormatError * If an unsupported grammar has to be processed. * @throws BadFetchError * If the document could not be fetched successfully. * @throws SemanticError * if the srcexpr attribute could not be evaluated * @exception URISyntaxException * if the URI of the external grammar could not be resolved */ private GrammarDocument loadExternalGrammar(final VoiceXmlInterpreterContext context, final FetchAttributes attributes, final Grammar grammar) throws BadFetchError, UnsupportedFormatError, SemanticError, URISyntaxException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("loading external grammar"); } // First of all, we need to check, if user has provided any // grammar type. URI src = getExternalUriSrc(grammar, context); if (src.getFragment() != null) { // TODO add support for URI fragments LOGGER.warn("URI fragments are currently not supported: " + "ignoring fragment"); src = new URI(src.getScheme(), src.getUserInfo(), src.getHost(), src.getPort(), src.getPath(), src.getQuery(), null); } // Now load the grammar LOGGER.info("loading grammar from source: '" + src + "'"); final FetchAttributes adaptedAttributes = adaptFetchAttributes(attributes, grammar); final GrammarDocument document = context.acquireExternalGrammar(src, adaptedAttributes); if (document == null) { throw new BadFetchError("Unable to load grammar '" + src + "'!"); } return document; }