List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:org.esigate.util.UriUtils.java
/** * Concatenates 2 {@link URI} by taking the beginning of the first (up to the path) and the end of the other * (starting from the path). While concatenating, checks that there is no doubled "/" character between the path * fragments./* ww w. ja v a2 s .c o m*/ * * @param base * the base uri * @param relPath * the path to concatenate with the base uri * @return the concatenated uri */ public static URI concatPath(URI base, String relPath) { String resultPath = base.getPath() + StringUtils.stripStart(relPath, "/"); try { URI result = new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), resultPath, null, null); return result; } catch (URISyntaxException e) { throw new InvalidUriException(e); } }
From source file:org.hippoecm.frontend.service.restproxy.RestProxyServicePlugin.java
static String createRestURI(String value, final HttpServletRequest request) { if (StringUtils.isEmpty(value)) { throw new IllegalStateException( "No REST service URI configured. Please set the plugin configuration property '" + CONFIG_REST_URI + "'"); }// w ww . j av a 2 s. c o m try { URI u = new URI(value); final int portNumber; if (u.getPort() == -1) { portNumber = request.getLocalPort(); } else { portNumber = u.getPort(); } return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), portNumber, u.getRawPath(), u.getRawQuery(), u.getRawFragment()).toString(); } catch (URISyntaxException e) { throw new IllegalStateException( "Invalid REST service URI configured. Please correct the plugin configuration property '" + CONFIG_REST_URI + "'", e); } }
From source file:org.talend.core.runtime.maven.MavenUrlHelper.java
public static MavenArtifact parseMvnUrl(String mvnUrl, boolean setDefaultValue) { if (mvnUrl == null || !mvnUrl.startsWith(MVN_PROTOCOL)) { return null; }//from w w w.ja va 2 s.c o m MavenArtifact artifact = new MavenArtifact(); try { String substring = mvnUrl.substring(MVN_PROTOCOL.length()); // repo int repoUrlIndex = substring.lastIndexOf(REPO_SEPERATOR); if (repoUrlIndex > 0) { // has repo url String repoWithUserPwd = substring.substring(0, repoUrlIndex); String repoUrl = repoWithUserPwd; try { URI repoWithUserPwdURI = new URI(repoWithUserPwd); String userPassword = repoWithUserPwdURI.getUserInfo(); URI repoWithoutUserPwdURI = new URI(repoWithUserPwdURI.getScheme(), null, repoWithUserPwdURI.getHost(), repoWithUserPwdURI.getPort(), repoWithUserPwdURI.getPath(), repoWithUserPwdURI.getQuery(), repoWithUserPwdURI.getFragment()); repoUrl = repoWithoutUserPwdURI.toString(); try { repoUrl = URLDecoder.decode(repoUrl, "UTF-8"); } catch (Exception e) { // nothing to do } // username and password if (StringUtils.isNotEmpty(userPassword)) { int splitIndex = userPassword.indexOf(USER_PASSWORD_SPLITER); if (0 < splitIndex) { artifact.setUsername(userPassword.substring(0, splitIndex)); if (splitIndex < userPassword.length() - 1) { String password = userPassword.substring(splitIndex + 1); if (password != null) { String decryptedPassword = decryptPassword(password); if (decryptedPassword != null) { password = decryptedPassword; } } artifact.setPassword(password); } } } } catch (Exception e) { ExceptionHandler.process(e); } artifact.setRepositoryUrl(repoUrl); substring = substring.substring(repoUrlIndex + 1); } String[] segments = substring.split(SEPERATOR); // only group-id and artifact-id is required if (segments.length < 2 || segments[0].trim().length() == 0 || segments[1].trim().length() == 0) { return null; } artifact.setGroupId(segments[0].trim()); artifact.setArtifactId(segments[1].trim()); // version if (segments.length >= 3 && segments[2].trim().length() > 0) { // validate the version String verStr = segments[2].trim(); if (VERSION_LATEST.equals(verStr)) { artifact.setVersion(VERSION_LATEST); } else if (VERSION_SNAPSHOT.equals(verStr)) { artifact.setVersion(VERSION_SNAPSHOT); } else if (verStr.length() > 0) { // range := ( '[' | '(' ) version ',' version ( ')' | ']' ) // TODO, maybe need parse the range for version. if ((verStr.startsWith("[") || verStr.startsWith("(")) && (verStr.endsWith(")") || verStr.endsWith("]"))) { artifact.setVersion(verStr); } else { artifact.setVersion(verStr); } } } if (segments.length >= 4 && segments[3].trim().length() > 0) { // has packaging artifact.setType(segments[3].trim()); } if (segments.length >= 5 && segments[4].trim().length() > 0) {// has classifier // classifier is can be null. artifact.setClassifier(segments[4].trim()); } /* * set default values. */ if (artifact.getVersion() == null && setDefaultValue) { // if not set, will be LATEST by default artifact.setVersion(VERSION_LATEST); } if (artifact.getType() == null && setDefaultValue) { // if not set, will be jar by default artifact.setType(MavenConstants.TYPE_JAR); } } catch (Exception e) { ExceptionHandler.process(new Exception("Problem happened when install this maven URL: " + mvnUrl, e)); return null; } return artifact; }
From source file:org.apache.syncope.core.util.ConnIdBundleManager.java
private static void initRemote(final URI location) { // 1. Extract conf params for remote connection from given URI final String host = location.getHost(); final int port = location.getPort(); final GuardedString key = new GuardedString(location.getUserInfo().toCharArray()); final boolean useSSL = location.getScheme().equals("connids"); final List<TrustManager> trustManagers = new ArrayList<TrustManager>(); final String[] params = StringUtils.isBlank(location.getQuery()) ? null : location.getQuery().split("&"); if (params != null && params.length > 0) { final String[] trustAllCerts = params[0].split("="); if (trustAllCerts != null && trustAllCerts.length > 1 && "trustAllCerts".equalsIgnoreCase(trustAllCerts[0]) && "true".equalsIgnoreCase(trustAllCerts[1])) { trustManagers.add(new X509TrustManager() { @Override//from ww w.j ava 2s . c om public void checkClientTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { // no checks, trust all } @Override public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { // no checks, trust all } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }); } } LOG.debug( "Configuring remote connector server:" + "\n\tHost: {}" + "\n\tPort: {}" + "\n\tKey: {}" + "\n\tUseSSL: {}" + "\n\tTrustAllCerts: {}", host, port, key, useSSL, !trustManagers.isEmpty()); RemoteFrameworkConnectionInfo info = new RemoteFrameworkConnectionInfo(host, port, key, useSSL, trustManagers, 60 * 1000); LOG.debug("Remote connection info: {}", info); // 2. Get connector info manager ConnectorInfoManager manager = ConnectorInfoManagerFactory.getInstance().getRemoteManager(info); if (manager == null) { throw new NotFoundException("Remote ConnectorInfoManager"); } CONN_MANAGERS.put(location, manager); }
From source file:org.apache.jena.jdbc.remote.RemoteEndpointDriver.java
/** * Get the URI with irrelevant components (Fragment and Querystring) * stripped off/*from w w w .j a va 2 s . c o m*/ * * @param input * URI * @return URI with irrelevant components stripped off or null if stripping * is impossible */ private static String stripIrrelevantComponents(String input) { try { URI orig = new URI(input); return new URI(orig.getScheme(), orig.getUserInfo(), orig.getHost(), orig.getPort(), orig.getPath(), null, null).toString(); } catch (URISyntaxException e) { return null; } }
From source file:password.pwm.http.client.PwmHttpClient.java
public static HttpClient getHttpClient(final Configuration configuration, final PwmHttpClientConfiguration pwmHttpClientConfiguration) throws PwmUnrecoverableException { final DefaultHttpClient httpClient; try {//from w ww . j a va 2 s. c o m if (Boolean.parseBoolean(configuration.readAppProperty(AppProperty.SECURITY_HTTP_PROMISCUOUS_ENABLE))) { httpClient = new DefaultHttpClient(makeConnectionManager(new X509Utils.PromiscuousTrustManager())); } else if (pwmHttpClientConfiguration != null && pwmHttpClientConfiguration.getCertificates() != null) { final TrustManager trustManager = new X509Utils.CertMatchingTrustManager(configuration, pwmHttpClientConfiguration.getCertificates()); httpClient = new DefaultHttpClient(makeConnectionManager(trustManager)); } else { httpClient = new DefaultHttpClient(); } } catch (Exception e) { throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, "unexpected error creating promiscuous https client: " + e.getMessage())); } final String strValue = configuration.readSettingAsString(PwmSetting.HTTP_PROXY_URL); if (strValue != null && strValue.length() > 0) { final URI proxyURI = URI.create(strValue); final String host = proxyURI.getHost(); final int port = proxyURI.getPort(); final HttpHost proxy = new HttpHost(host, port); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); final String username = proxyURI.getUserInfo(); if (username != null && username.length() > 0) { final String password = (username.contains(":")) ? username.split(":")[1] : ""; final UsernamePasswordCredentials passwordCredentials = new UsernamePasswordCredentials(username, password); httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), passwordCredentials); } } final String userAgent = PwmConstants.PWM_APP_NAME + " " + PwmConstants.SERVLET_VERSION; httpClient.getParams().setParameter(HttpProtocolParams.USER_AGENT, userAgent); return httpClient; }
From source file:org.apache.activemq.artemis.utils.uri.BeanSupport.java
public static void setData(URI uri, HashMap<String, Object> properties, Set<String> allowableProperties, Map<String, String> query, Map<String, Object> extraProps) { if (allowableProperties.contains("host")) { properties.put("host", "" + uri.getHost()); }/*from w w w . j av a2 s . c om*/ if (allowableProperties.contains("port")) { properties.put("port", "" + uri.getPort()); } if (allowableProperties.contains("userInfo")) { properties.put("userInfo", "" + uri.getUserInfo()); } for (Map.Entry<String, String> entry : query.entrySet()) { if (allowableProperties.contains(entry.getKey())) { properties.put(entry.getKey(), entry.getValue()); } else { extraProps.put(entry.getKey(), entry.getValue()); } } }
From source file:org.apache.jena.jdbc.remote.RemoteEndpointDriver.java
/** * Strips the last component of the given URI if possible * //ww w.j ava 2 s. c o m * @param input * URI * @return Reduced URI or null if no further reduction is possible */ private static String stripLastComponent(String input) { try { URI uri = new URI(input); if (uri.getFragment() != null) { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), null).toString(); } else if (uri.getQuery() != null) { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null).toString(); } else if (uri.getPath() != null) { // Try and strip off last segment of the path String currPath = uri.getPath(); if (currPath.endsWith("/")) { currPath = currPath.substring(0, currPath.length() - 1); if (currPath.length() == 0) currPath = null; return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), currPath, null, null).toString(); } else if (currPath.contains("/")) { currPath = currPath.substring(0, currPath.lastIndexOf('/') + 1); if (currPath.length() == 0) currPath = null; return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), currPath, null, null).toString(); } else { // If path is non-null it must always contain a / // otherwise it would be an invalid path // In this case there are no further components to strip return null; } } else { // No further components to strip return null; } } catch (URISyntaxException e) { // Error stripping component return null; } }
From source file:com.netflix.spinnaker.orca.config.RedisConfiguration.java
@Deprecated // rz - Kept for backwards compat with old connection configs public static JedisPool createPool(GenericObjectPoolConfig redisPoolConfig, String connection, int timeout, Registry registry, String poolName) { URI redisConnection = URI.create(connection); String host = redisConnection.getHost(); int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort(); String redisConnectionPath = isNotEmpty(redisConnection.getPath()) ? redisConnection.getPath() : "/" + DEFAULT_DATABASE; int database = Integer.parseInt(redisConnectionPath.split("/", 2)[1]); String password = redisConnection.getUserInfo() != null ? redisConnection.getUserInfo().split(":", 2)[1] : null;//from w w w . ja v a 2 s. c o m JedisPool jedisPool = new JedisPool( redisPoolConfig != null ? redisPoolConfig : new GenericObjectPoolConfig(), host, port, timeout, password, database, null); final Field poolAccess; try { poolAccess = Pool.class.getDeclaredField("internalPool"); poolAccess.setAccessible(true); GenericObjectPool<Jedis> pool = (GenericObjectPool<Jedis>) poolAccess.get(jedisPool); registry.gauge(registry.createId("redis.connectionPool.maxIdle", "poolName", poolName), pool, (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue()); registry.gauge(registry.createId("redis.connectionPool.minIdle", "poolName", poolName), pool, (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMinIdle()).doubleValue()); registry.gauge(registry.createId("redis.connectionPool.numActive", "poolName", poolName), pool, (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getNumActive()).doubleValue()); registry.gauge(registry.createId("redis.connectionPool.numIdle", "poolName", poolName), pool, (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue()); registry.gauge(registry.createId("redis.connectionPool.numWaiters", "poolName", poolName), pool, (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue()); return jedisPool; } catch (NoSuchFieldException | IllegalAccessException e) { throw new BeanCreationException("Error creating Redis pool", e); } }
From source file:org.apache.activemq.artemis.utils.uri.URISchema.java
public static void setData(URI uri, HashMap<String, Object> properties, Set<String> allowableProperties, Map<String, String> query) { if (allowableProperties.contains("host")) { properties.put("host", "" + uri.getHost()); }//from w w w. ja v a 2 s . c o m if (allowableProperties.contains("port")) { properties.put("port", "" + uri.getPort()); } if (allowableProperties.contains("userInfo")) { properties.put("userInfo", "" + uri.getUserInfo()); } for (Map.Entry<String, String> entry : query.entrySet()) { if (allowableProperties.contains(entry.getKey())) { properties.put(entry.getKey(), entry.getValue()); } } }