List of usage examples for java.net URI getFragment
public String getFragment()
From source file:com.github.parisoft.resty.request.Request.java
/** * Creates a request from a {@link URI}.<br> * The URI must conform the <a href=https://www.ietf.org/rfc/rfc2396.txt>RFC 2396</a> with the <i>path</i> and <i>query</i> properly encoded.<br> * <br>/*w ww.java2 s .c om*/ * For your convenience, call this constructor with the base address of your request - like {@literal <scheme>://<authority>} - * and use {@link #path(String...)} and {@link #query(String, String)} to configure the URI path and query respectively without worring about escape.<br> * <br> * As example, you can do<br> * <pre> * URI partialUri = new URI("http://some.domain.org:1234"); * Request request = new Request(partialUri) * .path("any unescaped path") * .query("don't", "scape too"); * </pre> * or * <pre> * URI fullUri = new URI("http://some.domain.org:1234/any%20unescaped%20path?don%27t=scape+too"); * Request request = new Request(fullUri); * </pre> * <i>Note:</i> this is equivalent to {@link RESTy#request(URI)} * * @param uri A {@link URI} as defined by <a href=https://www.ietf.org/rfc/rfc2396.txt>RFC 2396</a> * @throws IllegalArgumentException If the URI is null */ public Request(URI uri) { if (uri == null) { throw new IllegalArgumentException("Cannot create a request: URI cannot be null"); } path(emptyIfNull(uri.getPath())); try { query(URLEncodedUtils.parse(uri, UTF_8.name())); rootUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, uri.getFragment()); } catch (Exception e) { throw new IllegalArgumentException("Cannot create a request: " + e.getMessage()); } }
From source file:org.apache.hadoop.mapreduce.JobResourceUploader.java
/** * Upload and configure files, libjars, jobjars, and archives pertaining to * the passed job./*from www .ja v a 2 s . c o m*/ * * @param job the job containing the files to be uploaded * @param submitJobDir the submission directory of the job * @throws IOException */ public void uploadFiles(Job job, Path submitJobDir) throws IOException { Configuration conf = job.getConfiguration(); short replication = (short) conf.getInt(Job.SUBMIT_REPLICATION, Job.DEFAULT_SUBMIT_REPLICATION); if (!(conf.getBoolean(Job.USED_GENERIC_PARSER, false))) { LOG.warn("Hadoop command-line option parsing not performed. " + "Implement the Tool interface and execute your application " + "with ToolRunner to remedy this."); } // get all the command line arguments passed in by the user conf String files = conf.get("tmpfiles"); String libjars = conf.get("tmpjars"); String archives = conf.get("tmparchives"); String jobJar = job.getJar(); // // Figure out what fs the JobTracker is using. Copy the // job to it, under a temporary name. This allows DFS to work, // and under the local fs also provides UNIX-like object loading // semantics. (that is, if the job file is deleted right after // submission, we can still run the submission to completion) // // Create a number of filenames in the JobTracker's fs namespace LOG.debug("default FileSystem: " + jtFs.getUri()); if (jtFs.exists(submitJobDir)) { throw new IOException("Not submitting job. Job directory " + submitJobDir + " already exists!! This is unexpected.Please check what's there in" + " that directory"); } submitJobDir = jtFs.makeQualified(submitJobDir); submitJobDir = new Path(submitJobDir.toUri().getPath()); FsPermission mapredSysPerms = new FsPermission(JobSubmissionFiles.JOB_DIR_PERMISSION); FileSystem.mkdirs(jtFs, submitJobDir, mapredSysPerms); Path filesDir = JobSubmissionFiles.getJobDistCacheFiles(submitJobDir); Path archivesDir = JobSubmissionFiles.getJobDistCacheArchives(submitJobDir); Path libjarsDir = JobSubmissionFiles.getJobDistCacheLibjars(submitJobDir); // add all the command line files/ jars and archive // first copy them to jobtrackers filesystem if (files != null) { FileSystem.mkdirs(jtFs, filesDir, mapredSysPerms); String[] fileArr = files.split(","); for (String tmpFile : fileArr) { URI tmpURI = null; try { tmpURI = new URI(tmpFile); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } Path tmp = new Path(tmpURI); Path newPath = copyRemoteFiles(filesDir, tmp, conf, replication); try { URI pathURI = getPathURI(newPath, tmpURI.getFragment()); DistributedCache.addCacheFile(pathURI, conf); } catch (URISyntaxException ue) { // should not throw a uri exception throw new IOException("Failed to create uri for " + tmpFile, ue); } } } if (libjars != null) { FileSystem.mkdirs(jtFs, libjarsDir, mapredSysPerms); String[] libjarsArr = libjars.split(","); for (String tmpjars : libjarsArr) { Path tmp = new Path(tmpjars); Path newPath = copyRemoteFiles(libjarsDir, tmp, conf, replication); DistributedCache.addFileToClassPath(new Path(newPath.toUri().getPath()), conf); } } if (archives != null) { FileSystem.mkdirs(jtFs, archivesDir, mapredSysPerms); String[] archivesArr = archives.split(","); for (String tmpArchives : archivesArr) { URI tmpURI; try { tmpURI = new URI(tmpArchives); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } Path tmp = new Path(tmpURI); Path newPath = copyRemoteFiles(archivesDir, tmp, conf, replication); try { URI pathURI = getPathURI(newPath, tmpURI.getFragment()); DistributedCache.addCacheArchive(pathURI, conf); } catch (URISyntaxException ue) { // should not throw an uri excpetion throw new IOException("Failed to create uri for " + tmpArchives, ue); } } } if (jobJar != null) { // copy jar to JobTracker's fs // use jar name if job is not named. if ("".equals(job.getJobName())) { job.setJobName(new Path(jobJar).getName()); } Path jobJarPath = new Path(jobJar); URI jobJarURI = jobJarPath.toUri(); // If the job jar is already in a global fs, // we don't need to copy it from local fs if (jobJarURI.getScheme() == null || jobJarURI.getScheme().equals("file")) { copyJar(jobJarPath, JobSubmissionFiles.getJobJar(submitJobDir), replication); job.setJar(JobSubmissionFiles.getJobJar(submitJobDir).toString()); } } else { LOG.warn("No job jar file set. User classes may not be found. " + "See Job or Job#setJar(String)."); } addLog4jToDistributedCache(job, submitJobDir); // set the timestamps of the archives and files // set the public/private visibility of the archives and files ClientDistributedCacheManager.determineTimestampsAndCacheVisibilities(conf); // get DelegationToken for cached file ClientDistributedCacheManager.getDelegationTokens(conf, job.getCredentials()); }
From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProviderTest.java
private void assertReadRequest(URI uri, String mimeType) throws StorageException, IOException { ReadStorageRequest readRequest = new ReadStorageRequestImpl(uri, null); ReadStorageResponse readResponse = provider.read(readRequest); ContentItem item = readResponse.getContentItem(); LOGGER.debug("Item retrieved: {}", item); assertThat(item.getId(), is(uri.getSchemeSpecificPart())); if (uri.getFragment() != null) { assertThat(item.getQualifier(), is(uri.getFragment())); }/* w w w . java 2 s . co m*/ assertThat(item.getMimeTypeRawData(), is(mimeType)); List<String> parts = provider.getContentFilePathParts(uri.getSchemeSpecificPart(), uri.getFragment()); String expectedFilePath = baseDir + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_REPOSITORY + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_STORE + File.separator + parts.get(0) + File.separator + parts.get(1) + File.separator + parts.get(2) + (StringUtils.isNotBlank(item.getQualifier()) ? File.separator + item.getQualifier() : "") + File.separator + item.getFilename(); assertThat(Files.exists(Paths.get(expectedFilePath)), is(true)); assertTrue(item.getSize() > 0); }
From source file:com.hortonworks.registries.schemaregistry.webservice.SchemaRegistryResource.java
/** * Checks whether the current instance is a leader. If so, it invokes the given {@code supplier}, else current * request is redirected to the leader node in registry cluster. * * @param uriInfo/* w ww .ja v a2s .c o m*/ * @param supplier * @return */ private Response handleLeaderAction(UriInfo uriInfo, Supplier<Response> supplier) { LOG.info("URI info [{}]", uriInfo.getRequestUri()); if (!leadershipParticipant.get().isLeader()) { URI location = null; try { String currentLeaderLoc = leadershipParticipant.get().getCurrentLeader(); URI leaderServerUrl = new URI(currentLeaderLoc); URI requestUri = uriInfo.getRequestUri(); location = new URI(leaderServerUrl.getScheme(), leaderServerUrl.getAuthority(), requestUri.getPath(), requestUri.getQuery(), requestUri.getFragment()); LOG.info("Redirecting to URI [{}] as this instance is not the leader", location); } catch (Exception e) { throw new RuntimeException(e); } return Response.temporaryRedirect(location).build(); } else { LOG.info("Invoking here as this instance is the leader"); return supplier.get(); } }
From source file:com.tripit.auth.OAuthCredential.java
public boolean validateSignature(URI requestUri) throws URISyntaxException, UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException { List<NameValuePair> argList = URLEncodedUtils.parse(requestUri, "UTF-8"); SortedMap<String, String> args = new TreeMap<String, String>(); for (NameValuePair arg : argList) { args.put(arg.getName(), arg.getValue()); }/*from w w w . j a v a2s . c o m*/ String signature = args.remove("oauth_signature"); String baseUrl = new URI(requestUri.getScheme(), requestUri.getUserInfo(), requestUri.getAuthority(), requestUri.getPort(), requestUri.getPath(), null, requestUri.getFragment()).toString(); return (signature != null && signature.equals(generateSignature(baseUrl, args))); }
From source file:org.talend.core.nexus.HttpClientTransport.java
private IProxySelectorProvider createProxySelectorProvider() { IProxySelectorProvider proxySelectorProvider = new TalendProxySelector.AbstractProxySelectorProvider() { private Thread currentThread = Thread.currentThread(); @Override/*w w w . j av a 2s. c o m*/ public List<Proxy> select(URI uri) { // return Collections.EMPTY_LIST; List<Proxy> newProxys = new ArrayList<>(); if (uri == null) { return newProxys; } String schema = uri.getScheme(); if (schema != null && schema.toLowerCase().startsWith("socket")) { //$NON-NLS-1$ try { URI newUri = new URI("https", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); List<Proxy> proxys = TalendProxySelector.getInstance().getDefaultProxySelector() .select(newUri); if (proxys != null && !proxys.isEmpty()) { newProxys.addAll(proxys); } else { newUri = new URI("http", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); proxys = TalendProxySelector.getInstance().getDefaultProxySelector().select(newUri); if (proxys != null && !proxys.isEmpty()) { newProxys.addAll(proxys); } } } catch (URISyntaxException e) { ExceptionHandler.process(e); } } return newProxys; } @Override public boolean canHandle(URI uri) { if (Thread.currentThread() == currentThread) { return true; } return false; } }; return proxySelectorProvider; }
From source file:com.mirth.connect.connectors.ws.WebServiceConnectorServlet.java
public URI getURIWithCredentials(URI wsdlUrl, String username, String password) throws URISyntaxException { /* add the username:password to the URL if using authentication */ if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) { String hostWithCredentials = username + ":" + password + "@" + wsdlUrl.getHost(); if (wsdlUrl.getPort() > -1) { hostWithCredentials += ":" + wsdlUrl.getPort(); }//w w w.java2s. com wsdlUrl = new URI(wsdlUrl.getScheme(), hostWithCredentials, wsdlUrl.getPath(), wsdlUrl.getQuery(), wsdlUrl.getFragment()); } return wsdlUrl; }
From source file:org.cryptomator.frontend.webdav.mount.WindowsWebDavMounter.java
@Override public WebDavMount mount(URI uri, Map<MountParam, Optional<String>> mountParams) throws CommandFailedException { final String driveLetter = mountParams.getOrDefault(MountParam.WIN_DRIVE_LETTER, Optional.empty()) .orElse(AUTO_ASSIGN_DRIVE_LETTER); if (driveLetters.getOccupiedDriveLetters().contains(CharUtils.toChar(driveLetter))) { throw new CommandFailedException("Drive letter occupied."); }/* w w w. j a va 2 s. c om*/ final String hostname = mountParams.getOrDefault(MountParam.HOSTNAME, Optional.empty()).orElse(LOCALHOST); try { final URI adjustedUri = new URI(uri.getScheme(), uri.getUserInfo(), hostname, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); CommandResult mountResult = mount(adjustedUri, driveLetter); return new WindowsWebDavMount( AUTO_ASSIGN_DRIVE_LETTER.equals(driveLetter) ? getDriveLetter(mountResult.getStdOut()) : driveLetter); } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid host: " + hostname); } }
From source file:cn.isif.util_plus.http.client.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery()); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:org.dita.dost.module.reader.AbstractReaderModule.java
/** * Add the given file the wait list if it has not been parsed. * * @param ref reference to absolute system path */// w w w. j a va 2 s . c o m void addToWaitList(final Reference ref) { final URI file = ref.filename; assert file.isAbsolute() && file.getFragment() == null; if (doneList.contains(file) || waitList.contains(ref) || file.equals(currentFile)) { return; } waitList.add(ref); }