List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:org.eclipse.orion.internal.server.servlets.workspace.ProjectParentDecorator.java
/** * Adds a parent resource representation to the parent array *//* ww w.jav a 2 s. co m*/ private void addParent(JSONArray parents, String name, URI location) throws JSONException { JSONObject parent = new JSONObject(); parent.put(ProtocolConstants.KEY_NAME, name); parent.put(ProtocolConstants.KEY_LOCATION, location); URI childLocation; try { childLocation = new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), location.getPath(), "depth=1", location.getFragment()); //$NON-NLS-1$ } catch (URISyntaxException e) { throw new RuntimeException(e); } parent.put(ProtocolConstants.KEY_CHILDREN_LOCATION, childLocation); parents.put(parent); }
From source file:fi.mystes.synapse.mediator.ReadFileMediator.java
private InputStream processFtpSftpInput(URI aURI) throws JSchException, SftpException { JSch jsch = new JSch(); Session session = jsch.getSession(aURI.getUserInfo().substring(0, aURI.getUserInfo().indexOf(":")), aURI.getHost(), aURI.getPort()); session.setConfig("StrictHostKeyChecking", "no"); session.setPassword(aURI.getUserInfo().substring(aURI.getUserInfo().indexOf(":") + 1)); session.connect();//from ww w. j ava2s . co m Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftpChannel = (ChannelSftp) channel; return sftpChannel.get(aURI.getPath()); }
From source file:com.trickl.crawler.protocol.http.HttpProtocol.java
@Override public boolean isAllowed(URI uri) throws IOException { if (forceAllow) { return forceAllow; }/* w ww .j av a 2 s .com*/ URI baseURI; try { baseURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), "/", null, null); } catch (URISyntaxException ex) { log.error("Unable to determine base URI for " + uri); return false; } NoRobotClient nrc = new NoRobotClient(contentLoader, userAgent); try { nrc.parse(baseURI); } catch (NoRobotException ex) { log.error("Failure parsing robots.txt: " + ex.getMessage()); return false; } boolean test = nrc.isUrlAllowed(uri); if (log.isInfoEnabled()) { log.info(uri + " is " + (test ? "allowed" : "denied")); } return test; }
From source file:edu.wisc.ws.client.support.DestinationOverridingWebServiceTemplate.java
@Override public String getDefaultUri() { final DestinationProvider destinationProvider = this.getDestinationProvider(); if (destinationProvider != null) { final URI uri = destinationProvider.getDestination(); if (uri == null) { return null; }// w ww . j av a 2s .c o m if (portOverride == null) { return uri.toString(); } final URI overridenUri; try { overridenUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), portOverride, uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { this.logger.error("Could not override port on URI " + uri + " to " + portOverride, e); return uri.toString(); } return overridenUri.toString(); } return null; }
From source file:org.zlogic.vogon.web.PersistenceConfiguration.java
/** * Returns the JPA configuration overrides for database configuration * * @return the map of JPA configuration variables to override for the * database connection/*from w w w . jav a 2s . c o m*/ */ protected Map<String, Object> getDatabaseConfiguration() { Map<String, Object> jpaProperties = new HashMap<>(); boolean fallback = true; if (serverTypeDetector.getServerType() != ServerTypeDetector.ServerType.WILDFLY) jpaProperties.put("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider"); //NOI18N if (serverTypeDetector.getDatabaseType() == ServerTypeDetector.DatabaseType.POSTGRESQL) { String dbURL = null; if (serverTypeDetector.getCloudType() == ServerTypeDetector.CloudType.HEROKU) dbURL = System.getenv("DATABASE_URL"); //NOI18N else if (serverTypeDetector.getCloudType() == ServerTypeDetector.CloudType.OPENSHIFT) dbURL = System.getenv("OPENSHIFT_POSTGRESQL_DB_URL") + "/" + System.getenv("OPENSHIFT_APP_NAME"); //NOI18N try { URI dbUri = new URI(dbURL); String dbConnectionURL = "jdbc:postgresql://" + dbUri.getHost() + ":" + dbUri.getPort() + dbUri.getPath(); //NOI18N //NOI18N String[] usernamePassword = dbUri.getUserInfo().split(":", 2); //NOI18N jpaProperties.put("javax.persistence.jdbc.url", dbConnectionURL); //NOI18N jpaProperties.put("javax.persistence.jdbc.user", usernamePassword[0]); //NOI18N jpaProperties.put("javax.persistence.jdbc.password", usernamePassword[1]); //NOI18N jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); //NOI18N jpaProperties.put("hibernate.connection.driver_class", "org.postgresql.Driver"); //NOI18N fallback = false; } catch (Exception ex) { log.error(messages.getString("ERROR_EXTRACTING_DATABASE_CONFIGURATION"), ex); } } if (serverTypeDetector.getDatabaseType() == ServerTypeDetector.DatabaseType.H2 || fallback) { String dbConnectionURL = MessageFormat.format("jdbc:h2:{0}/Vogon", new Object[] { getH2DatabasePath() }); //NOI18N jpaProperties.put("javax.persistence.jdbc.url", dbConnectionURL); //NOI18N jpaProperties.put("javax.persistence.jdbc.user", ""); //NOI18N jpaProperties.put("javax.persistence.jdbc.password", ""); //NOI18N jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); //NOI18N jpaProperties.put("hibernate.connection.driver_class", "org.h2.Driver"); //NOI18N } return jpaProperties; }
From source file:me.carbou.mathieu.tictactoe.di.ServiceBindings.java
@Provides @Singleton/*from w ww . j av a 2s . c o m*/ JedisPool jedisPool() { URI connectionURI = URI.create(Env.REDISCLOUD_URL); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMinIdle(0); config.setMaxIdle(5); config.setMaxTotal(30); String password = connectionURI.getUserInfo().split(":", 2)[1]; return new JedisPool(config, connectionURI.getHost(), connectionURI.getPort(), Protocol.DEFAULT_TIMEOUT, password); }
From source file:org.eclipse.orion.internal.server.servlets.workspace.WorkspaceResourceHandler.java
/** * Returns a JSON representation of the workspace, conforming to Orion * workspace API protocol.//from w ww . j ava 2s.com * @param workspace The workspace to store * @param requestLocation The location of the current request * @param baseLocation The base location for the workspace servlet */ public static JSONObject toJSON(WorkspaceInfo workspace, URI requestLocation, URI baseLocation) { JSONObject result = MetadataInfoResourceHandler.toJSON(workspace); JSONArray projects = new JSONArray(); URI workspaceLocation = URIUtil.append(baseLocation, workspace.getUniqueId()); URI projectBaseLocation = URIUtil.append(workspaceLocation, "project"); //$NON-NLS-1$ //is caller requesting local children boolean requestLocal = !ProtocolConstants.PATH_DRIVE.equals(URIUtil.lastSegment(requestLocation)); //add children element to conform to file API structure JSONArray children = new JSONArray(); IMetaStore metaStore = OrionConfiguration.getMetaStore(); for (String projectName : workspace.getProjectNames()) { try { ProjectInfo project = metaStore.readProject(workspace.getUniqueId(), projectName); //augment project objects with their location JSONObject projectObject = new JSONObject(); projectObject.put(ProtocolConstants.KEY_ID, project.getUniqueId()); //this is the location of the project metadata projectObject.put(ProtocolConstants.KEY_LOCATION, URIUtil.append(projectBaseLocation, projectName)); projects.put(projectObject); //remote folders are listed separately boolean isLocal = true; IFileStore projectStore = null; try { projectStore = project.getProjectStore(); isLocal = EFS.SCHEME_FILE.equals(projectStore.getFileSystem().getScheme()); } catch (CoreException e) { //ignore and treat as local } if (requestLocal) { //only include local children if (!isLocal) continue; } else { //only include remote children if (isLocal) continue; } JSONObject child = new JSONObject(); child.put(ProtocolConstants.KEY_NAME, project.getFullName()); child.put(ProtocolConstants.KEY_DIRECTORY, true); //this is the location of the project file contents URI contentLocation = computeProjectURI(baseLocation, workspace, project); child.put(ProtocolConstants.KEY_LOCATION, contentLocation); try { if (projectStore != null) child.put(ProtocolConstants.KEY_LOCAL_TIMESTAMP, projectStore.fetchInfo(EFS.NONE, null).getLastModified()); } catch (CoreException coreException) { //just omit the timestamp in this case because the project location is unreachable } try { child.put(ProtocolConstants.KEY_CHILDREN_LOCATION, new URI(contentLocation.getScheme(), contentLocation.getUserInfo(), contentLocation.getHost(), contentLocation.getPort(), contentLocation.getPath(), ProtocolConstants.PARM_DEPTH + "=1", contentLocation.getFragment())); //$NON-NLS-1$ } catch (URISyntaxException e) { throw new RuntimeException(e); } child.put(ProtocolConstants.KEY_ID, project.getUniqueId()); children.put(child); } catch (Exception e) { //ignore malformed children } } try { //add basic fields to workspace result result.put(ProtocolConstants.KEY_LOCATION, workspaceLocation); result.put(ProtocolConstants.KEY_CHILDREN_LOCATION, workspaceLocation); result.put(ProtocolConstants.KEY_DRIVE_LOCATION, URIUtil.append(workspaceLocation, ProtocolConstants.PATH_DRIVE)); result.put(ProtocolConstants.KEY_PROJECTS, projects); result.put(ProtocolConstants.KEY_DIRECTORY, "true"); //$NON-NLS-1$ //add children to match file API result.put(ProtocolConstants.KEY_CHILDREN, children); } catch (JSONException e) { //cannot happen } return result; }
From source file:nl.esciencecenter.xnattool.XnatToolConfig.java
@JsonIgnore public void updateURI(URI uri) { xnatUri = uri;/*ww w . j av a 2s.co m*/ if (uri == null) { xnatUser = null; } else { String userInf = uri.getUserInfo(); // copy username from uri to xnatUser field. if (StringUtil.isWhiteSpace(userInf) == false) { xnatUser = userInf; } } }
From source file:com.github.fedorchuck.webstore.config.DataConfig.java
@SuppressWarnings("ConstantConditions") private void getConfigEnv(Map<String, String> env) { URI dbUri = null; try {//from w w w . ja va2 s. c o m dbUri = new URI(System.getenv("DATABASE_URL")); } catch (URISyntaxException e) { logger.error("problem read config. reason: ", e); } driverClassName = "org.postgresql.Driver"; username = dbUri.getUserInfo().split(":")[0]; password = dbUri.getUserInfo().split(":")[1]; url = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath(); }
From source file:com.sample.amqp.RabbitConfiguration.java
@Bean public ConnectionFactory connectionFactory() { final URI ampqUrl; try {//w w w. j av a2 s .com ampqUrl = new URI(getEnvOrThrow("CLOUDAMQP_URL")); } catch (URISyntaxException e) { throw new RuntimeException(e); } final CachingConnectionFactory factory = new CachingConnectionFactory(); factory.setUsername(ampqUrl.getUserInfo().split(":")[0]); factory.setPassword(ampqUrl.getUserInfo().split(":")[1]); factory.setHost(ampqUrl.getHost()); factory.setPort(ampqUrl.getPort()); factory.setVirtualHost(ampqUrl.getPath().substring(1)); factory.setPublisherReturns(true); return factory; }