List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:org.integratedmodelling.sql.SQLServer.java
public static String getUser(URI url) { String ret = ""; String uinfo = url.getUserInfo(); if (uinfo != null) { String user[] = url.getUserInfo().split(":"); ret = user[0];/*from w w w .j av a 2 s . c o m*/ } return ret; }
From source file:org.integratedmodelling.sql.SQLServer.java
public static String getPassword(URI url) { String ret = ""; String uinfo = url.getUserInfo(); if (uinfo != null) { String user[] = url.getUserInfo().split(":"); if (user.length > 1) { ret = user[1];//from ww w . j a v a2s .c o m } } return ret; }
From source file:org.opennms.netmgt.ackd.readers.HypericAckProcessor.java
/** * <p>fetchHypericAlerts</p> * * @param hypericUrl a {@link java.lang.String} object. * @param alertIds a {@link java.util.List} object. * @return a {@link java.util.List} object. * @throws org.apache.commons.httpclient.HttpException if any. * @throws java.io.IOException if any.//from www . j ava 2 s . c om * @throws javax.xml.bind.JAXBException if any. * @throws javax.xml.stream.XMLStreamException if any. */ public static List<HypericAlertStatus> fetchHypericAlerts(String hypericUrl, List<String> alertIds) throws IOException, JAXBException, XMLStreamException { List<HypericAlertStatus> retval = new ArrayList<HypericAlertStatus>(); if (alertIds.size() < 1) { return retval; } for (int i = 0; i < alertIds.size(); i++) { // Construct the query string for the HTTP operation StringBuffer alertIdString = new StringBuffer(); alertIdString.append("?"); for (int j = 0; (j < ALERTS_PER_HTTP_TRANSACTION) && (i < alertIds.size()); j++, i++) { if (j > 0) alertIdString.append("&"); // Numeric values, no need to worry about URL encoding alertIdString.append("id=").append(alertIds.get(i)); } final HttpClientWrapper clientWrapper = HttpClientWrapper.create().setConnectionTimeout(3000) .setSocketTimeout(3000) // Set a custom user-agent so that it's easy to tcpdump these requests .setUserAgent("OpenNMS-Ackd.HypericAckProcessor"); HttpUriRequest httpMethod = new HttpGet(hypericUrl + alertIdString.toString()); // Parse the URI from the config so that we can deduce the username/password information String userinfo = null; try { URI hypericUri = new URI(hypericUrl); userinfo = hypericUri.getUserInfo(); } catch (final URISyntaxException e) { LOG.warn("Could not parse URI to get username/password stanza: {}", hypericUrl, e); } if (userinfo != null && !"".equals(userinfo)) { final String[] credentials = userinfo.split(":"); if (credentials.length == 2) { clientWrapper.addBasicCredentials(credentials[0], credentials[1]).usePreemptiveAuth(); } else { LOG.warn("Unable to deduce username/password from '{}'", userinfo); } } try { CloseableHttpResponse response = clientWrapper.execute(httpMethod); retval = parseHypericAlerts(new StringReader(EntityUtils.toString(response.getEntity()))); } finally { IOUtils.closeQuietly(clientWrapper); } } return retval; }
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * Returns a new {@link URI} containing only the scheme, user info, host, * and port of the given {@link URI}.// w w w . j a va 2s .c o m * * @param uri * the {@link URI} to remove the path and query parts from (must not * be <code>null</code>) * @return a new {@link URI} containing only the scheme, user info, host, * and port of the given {@link URI} */ public static URI removePathAndQueryParts(final URI uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ try { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); } catch (final URISyntaxException e) { final IllegalArgumentException e2 = new IllegalArgumentException( MessageFormat.format(Messages.getString("URIUtils.IllegalURIFormat"), uri)); //$NON-NLS-1$ e2.initCause(e); throw e2; } }
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * Returns a new {@link URI} containing only the scheme, user info, host, * port, and path of the given {@link URI}. * * @param uri/*w w w.j a v a2 s. co m*/ * the {@link URI} to remove the query parts from (must not be * <code>null</code>) * @return a new {@link URI} containing only the scheme, user info, host, * port, and path of the given {@link URI} */ public static URI removeQueryParts(final URI uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ try { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null); } catch (final URISyntaxException e) { final IllegalArgumentException e2 = new IllegalArgumentException( MessageFormat.format(Messages.getString("URIUtils.IllegalURIFormat"), uri)); //$NON-NLS-1$ e2.initCause(e); throw e2; } }
From source file:com.sworddance.util.UriFactoryImpl.java
/** * suitable for namespacing//from w w w .j av a 2s. com * @return the uri with relative schema ( ex. //facebook.com/path/to/stuff?query ) */ public static URI createNamespaceUri(Object uriStr) { URI temp = createUriWithOptions(uriStr, true, true); try { URI namesUri = new URI(null, temp.getUserInfo(), temp.getHost(), -1, temp.getPath(), temp.getQuery(), temp.getFragment()); return namesUri; } catch (URISyntaxException e) { return null; } }
From source file:org.hl7.fhir.client.ResourceAddress.java
public static URI appendHttpParameters(URI basePath, Map<String, String> parameters) { try {/* w ww. j ava2 s. c o m*/ Set<String> httpParameterNames = parameters.keySet(); String query = basePath.getQuery(); for (String httpParameterName : httpParameterNames) { if (query != null) { query += "&"; } else { query = ""; } query += httpParameterName + "=" + parameters.get(httpParameterName); } return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(), basePath.getPort(), basePath.getPath(), query, basePath.getFragment()); } catch (Exception e) { throw new EFhirClientException("Error appending http parameter", e); } }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Checks whether the given URL string begins with a protocol (http://, * ftp://, etc.) If it does, the string is returned unchanged. If it does * not, full URL is returned and is constructed as parentUrl "/" url. * * @param url input URL string in absolute or relative form * @param parentUrl base URL to use if the given URL is in relative form * @return an absolute URL/*ww w .j a v a 2 s .c o m*/ */ public static URI relToAbs(String url, URI parentUrl) throws URISyntaxException { if (!StringUtils.hasLength(url)) { throw new URISyntaxException(url, "The input url was empty!"); } URI parent2 = new URI(parentUrl.getScheme(), parentUrl.getUserInfo(), parentUrl.getAuthority(), parentUrl.getPort(), parentUrl.getPath() + "/", // Parent URL path must end with "/" for // this to work. resolve() removes any // duplicates. parentUrl.getQuery(), parentUrl.getFragment()); return parent2.resolve(url.trim()); }
From source file:org.apache.oozie.action.hadoop.SparkMain.java
/** * Spark compares URIs based on scheme, host and port. Here we convert URIs * into the default format so that Spark won't think those belong to * different file system. This will avoid an extra copy of files which * already exists on same hdfs./* ww w .j a v a 2 s. co m*/ * * @param fs * @param fileUri * @return fixed uri * @throws URISyntaxException */ private static URI getFixedUri(FileSystem fs, URI fileUri) throws URISyntaxException { if (fs.getUri().getScheme().equals(fileUri.getScheme()) && (fs.getUri().getHost().equals(fileUri.getHost()) || fileUri.getHost() == null) && (fs.getUri().getPort() == -1 || fileUri.getPort() == -1 || fs.getUri().getPort() == fileUri.getPort())) { return new URI(fs.getUri().getScheme(), fileUri.getUserInfo(), fs.getUri().getHost(), fs.getUri().getPort(), fileUri.getPath(), fileUri.getQuery(), fileUri.getFragment()); } return fileUri; }
From source file:org.rssowl.core.util.URIUtils.java
/** * A helper to convert custom schemes (like feed://) to the HTTP counterpart. * * @param uri the uri to get as HTTP/HTTPS {@link URI}. * @return the converted {@link URI} if necessary. *///from w w w . j a va 2 s . co m public static URI toHTTP(URI uri) { if (uri == null) return uri; String scheme = uri.getScheme(); if (HTTP_SCHEME.equals(scheme) || HTTPS_SCHEME.equals(scheme)) return uri; String newScheme = HTTP_SCHEME; if (SyncUtils.READER_HTTPS_SCHEME.equals(scheme)) newScheme = HTTPS_SCHEME; try { return new URI(newScheme, uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { return uri; } }