List of usage examples for java.net URI getScheme
public String getScheme()
From source file:org.apache.droids.protocol.http.HttpProtocol.java
@Override public boolean isAllowed(URI uri) throws IOException { if (forceAllow) { return forceAllow; }// w w w. j a va 2 s . co m 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:com.subgraph.vega.internal.http.requests.HttpRequestBuilder.java
@Override public synchronized void setFromUri(URI uri) { if (uri.getScheme() != null) { scheme = uri.getScheme();//from www. j ava 2 s . com if (uri.getHost() != null) { host = uri.getHost(); hostPort = uri.getPort(); if (hostPort == -1) { hostPort = getSchemeDefaultPort(scheme); } } } setPathFromUri(uri); }
From source file:com.ibm.bi.dml.api.DMLScript.java
/** * /*ww w . ja v a2s . c o m*/ * @param config * @throws IOException * @throws DMLRuntimeException */ private static void checkSecuritySetup(DMLConfig config) throws IOException, DMLRuntimeException { //analyze local configuration String userName = System.getProperty("user.name"); HashSet<String> groupNames = new HashSet<String>(); try { //check existence, for backwards compatibility to < hadoop 0.21 if (UserGroupInformation.class.getMethod("getCurrentUser") != null) { String[] groups = UserGroupInformation.getCurrentUser().getGroupNames(); for (String g : groups) groupNames.add(g); } } catch (Exception ex) { } //analyze hadoop configuration JobConf job = ConfigurationManager.getCachedJobConf(); boolean localMode = InfrastructureAnalyzer.isLocalMode(job); String taskController = job.get("mapred.task.tracker.task-controller", "org.apache.hadoop.mapred.DefaultTaskController"); String ttGroupName = job.get("mapreduce.tasktracker.group", "null"); String perm = job.get(MRConfigurationNames.DFS_PERMISSIONS, "null"); //note: job.get("dfs.permissions.supergroup",null); URI fsURI = FileSystem.getDefaultUri(job); //determine security states boolean flagDiffUser = !(taskController.equals("org.apache.hadoop.mapred.LinuxTaskController") //runs map/reduce tasks as the current user || localMode // run in the same JVM anyway || groupNames.contains(ttGroupName)); //user in task tracker group boolean flagLocalFS = fsURI == null || fsURI.getScheme().equals("file"); boolean flagSecurity = perm.equals("yes"); LOG.debug("SystemML security check: " + "local.user.name = " + userName + ", " + "local.user.groups = " + ProgramConverter.serializeStringCollection(groupNames) + ", " + "mapred.job.tracker = " + job.get("mapred.job.tracker") + ", " + "mapred.task.tracker.task-controller = " + taskController + "," + "mapreduce.tasktracker.group = " + ttGroupName + ", " + "fs.default.name = " + ((fsURI != null) ? fsURI.getScheme() : "null") + ", " + MRConfigurationNames.DFS_PERMISSIONS + " = " + perm); //print warning if permission issues possible if (flagDiffUser && (flagLocalFS || flagSecurity)) { LOG.warn("Cannot run map/reduce tasks as user '" + userName + "'. Using tasktracker group '" + ttGroupName + "'."); } //validate external filenames working directories String localtmpdir = config.getTextValue(DMLConfig.LOCAL_TMP_DIR); String hdfstmpdir = config.getTextValue(DMLConfig.SCRATCH_SPACE); if (!LocalFileUtils.validateExternalFilename(localtmpdir, false)) throw new DMLRuntimeException("Invalid (non-trustworthy) local working directory."); if (!LocalFileUtils.validateExternalFilename(hdfstmpdir, true)) throw new DMLRuntimeException("Invalid (non-trustworthy) hdfs working directory."); }
From source file:com.tascape.reactor.report.SuiteResultExportTestRailView.java
private void getParameters() throws URISyntaxException { Map<String, String> map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); String v = map.get("srid"); if (v != null) { this.srid = v; LOG.debug("srid={}", this.srid); }//from w ww . jav a2 s.c om String ref = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("referer"); URI u = new URI(ref); this.logBaseUrl = u.getScheme() + "://" + u.getHost() + ":" + u.getPort() + "/logs/" + srid + "/"; LOG.debug("logBaseUrl={}", logBaseUrl); }
From source file:com.seajas.search.contender.service.modifier.AbstractModifierService.java
/** * Retrieve the FTP client belonging to the given URI. * /*from w w w .j av a 2s.co m*/ * @param uri * @return FTPClient */ protected FTPClient retrieveFtpClient(final URI uri) { // Create the FTP client FTPClient ftpClient = uri.getScheme().equalsIgnoreCase("ftps") ? new FTPSClient() : new FTPClient(); try { ftpClient.connect(uri.getHost(), uri.getPort() != -1 ? uri.getPort() : 21); if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { ftpClient.disconnect(); logger.error("Could not connect to the given FTP server " + uri.getHost() + (uri.getPort() != -1 ? ":" + uri.getPort() : "") + " - " + ftpClient.getReplyString()); return null; } if (StringUtils.hasText(uri.getUserInfo())) { if (uri.getUserInfo().contains(":")) ftpClient.login(uri.getUserInfo().substring(0, uri.getUserInfo().indexOf(":")), uri.getUserInfo().substring(uri.getUserInfo().indexOf(":") + 1)); else ftpClient.login(uri.getUserInfo(), ""); } if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { ftpClient.disconnect(); logger.error("Could not login to the given FTP server " + uri.getHost() + (uri.getPort() != -1 ? ":" + uri.getPort() : "") + " - " + ftpClient.getReplyString()); return null; } // Switch to PASV and BINARY mode ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); return ftpClient; } catch (IOException e) { logger.error("Could not close input stream during archive processing", e); } return null; }
From source file:com.github.brandtg.pantopod.crawler.CrawlingEventHandler.java
private URI getNextUri(URI url, String href, String chroot) throws Exception { // if (href.contains("..")) { ///*from w w w . ja va 2 s .co m*/ // throw new IllegalArgumentException("Relative URI not allowed: " + href); // } URI hrefUri = URI.create(href.trim().replaceAll(" ", "+")); URIBuilder builder = new URIBuilder(); builder.setScheme(hrefUri.getScheme() == null ? url.getScheme() : hrefUri.getScheme()); builder.setHost(hrefUri.getHost() == null ? url.getHost() : hrefUri.getHost()); builder.setPort(hrefUri.getPort() == -1 ? url.getPort() : hrefUri.getPort()); if (hrefUri.getPath() != null) { StringBuilder path = new StringBuilder(); if (hrefUri.getHost() == null && chroot != null) { path.append(chroot); } // Ensure no two slashes if (hrefUri.getPath() != null && hrefUri.getPath().length() > 0 && hrefUri.getPath().charAt(0) == '/' && path.length() > 0 && path.charAt(path.length() - 1) == '/') { path.setLength(path.length() - 1); } path.append(hrefUri.getPath()); builder.setPath(chroot == null ? "" : chroot + hrefUri.getPath()); } if (hrefUri.getQuery() != null) { builder.setCustomQuery(hrefUri.getQuery()); } if (hrefUri.getFragment() != null) { builder.setFragment(hrefUri.getFragment()); } return builder.build(); }
From source file:com.netscape.certsrv.client.PKIClient.java
public <T> T createProxy(String subsystem, Class<T> clazz) throws URISyntaxException { if (subsystem == null) { // by default use the subsystem specified in server URI subsystem = getSubsystem();//www. j ava 2 s . c o m } if (subsystem == null) { throw new PKIException("Missing subsystem name."); } URI serverURI = config.getServerURI(); URI resourceURI = new URI(serverURI.getScheme(), serverURI.getUserInfo(), serverURI.getHost(), serverURI.getPort(), "/" + subsystem + "/rest", serverURI.getQuery(), serverURI.getFragment()); return connection.createProxy(resourceURI, clazz); }
From source file:org.eel.kitchen.jsonschema.ref.JsonRef.java
/** * Main constructor, {@code protected} by design * * @param uri the URI to build that reference *///from w ww .ja v a2 s. c o m protected JsonRef(final URI uri) { final String scheme = uri.getScheme(); final String ssp = uri.getSchemeSpecificPart(); final String uriFragment = uri.getFragment(); final String realFragment = uriFragment == null ? "" : uriFragment; try { this.uri = new URI(scheme, ssp, realFragment); locator = new URI(scheme, ssp, ""); fragment = JsonFragment.fromFragment(realFragment); asString = this.uri.toString(); hashCode = asString.hashCode(); } catch (URISyntaxException e) { throw new RuntimeException("WTF??", e); } }
From source file:org.n52.sos.web.JdbcUrl.java
protected final void parse(String string) throws URISyntaxException { URI uri = new URI(string); scheme = uri.getScheme(); uri = new URI(uri.getSchemeSpecificPart()); type = uri.getScheme();/*w ww .java 2s .c o m*/ host = uri.getHost(); port = uri.getPort(); String[] path = uri.getPath().split(SLASH_STRING); if (path.length == 1 && !path[0].isEmpty()) { database = path[0]; } else if (path.length == 2 && path[0].isEmpty() && !path[1].isEmpty()) { database = path[1]; } for (NameValuePair nvp : URLEncodedUtils.parse(uri, "UTF-8")) { if (nvp.getName().equals(QUERY_PARAMETER_USER)) { user = nvp.getValue(); } else if (nvp.getName().equals(QUERY_PARAMETER_PASSWORD)) { password = nvp.getValue(); } } }
From source file:com.cloudera.impala.planner.S3PlannerTest.java
/** * Remove any non-constant components of the given file path. For S3, the * actual bucket name, which will be unique to the tester's setup, needs to * be replaced with a fixed bucket name. *//*from w w w. ja v a2s. c o m*/ @Override protected Path cleanseFilePath(Path path) { path = super.cleanseFilePath(path); URI fsURI = fsName.toUri(); URI pathURI = path.toUri(); Assert.assertTrue("error: " + path + " is not on filesystem " + fsName, fsURI.getScheme().equals(pathURI.getScheme()) && fsURI.getAuthority().equals(pathURI.getAuthority())); return Path.mergePaths(S3A_CANONICAL_BUCKET, path); }