List of usage examples for java.net URI getRawPath
public String getRawPath()
From source file:org.soyatec.windowsazure.internal.MessageCanonicalizer2.java
/** * Create the canonicalized resource with the url address and resourceUriComponents. * @param address/*from w w w . j av a 2 s . co m*/ * The uri address of the HTTP request. * @param uriComponents * Components of the Uri extracted out of the request. * @return canonicalized resource */ private static String getCanonicalizedResource(URI address, ResourceUriComponents uriComponents) { // Beginning with an empty string (""), append a forward slash (/), followed by the name of the account that owns the resource being accessed. // Append the resource's encoded URI path, without any query parameters. // Retrieve all query parameters on the resource URI, including the comp parameter if it exists. // Convert all parameter names to lowercase. // Sort the query parameters lexicographically by parameter name, in ascending order. // URL-decode each query parameter name and value. // Append each query parameter name and value to the string in the following format, making sure to include the colon (:) between the name and the value: // parameter-name:parameter-value // If a query parameter has more than one value, sort all values lexicographically, then include them in a comma-separated list: // parameter-name:parameter-value-1,parameter-value-2,parameter-value-n // Append a new line character (\n) after each name-value pair. // Get Container Metadata // GET http://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=metadata // CanonicalizedResource: // /myaccount/mycontainer\ncomp:metadata\nrestype:container // // List Blobs operation: // GET http://myaccount.blob.core.windows.net/container?restype=container&comp=list&include=snapshots&include=metadata&include=uncommittedblobs // CanonicalizedResource: // /myaccount/mycontainer\ncomp:list\ninclude:metadata,snapshots,uncommittedblobs\nrestype:container StringBuilder canonicalizedResource = new StringBuilder(ConstChars.Slash); canonicalizedResource.append(uriComponents.getAccountName()); // Note that AbsolutePath starts with a '/'. String path = address.getRawPath(); // path = path.replaceAll(" ", "%20"); // path = java.net.URLEncoder.encode(path); canonicalizedResource.append(path); NameValueCollection query = HttpUtilities.parseQueryString(address.getQuery()); ArrayList<String> paramNames = new ArrayList<String>(); paramNames.addAll(query.keySet()); Collections.sort(paramNames, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); for (String key : paramNames) { StringBuilder canonicalizedElement = new StringBuilder(URLDecoder.decode(key)); canonicalizedElement.append(ConstChars.Colon); String value = query.getMultipleValuesAsString(key); canonicalizedElement.append(URLDecoder.decode(value)); canonicalizedResource.append(ConstChars.Linefeed); canonicalizedResource.append(canonicalizedElement.toString()); } return canonicalizedResource.toString(); }
From source file:org.apache.manifoldcf.agents.output.hdfs.HDFSOutputConnector.java
/** * @param documentURI/*from w ww. java 2 s . co m*/ * @return * @throws URISyntaxException */ final private String documentURItoFilePath(String documentURI) throws URISyntaxException { StringBuffer path = new StringBuffer(); URI uri = null; uri = new URI(documentURI); if (uri.getScheme() != null) { path.append(uri.getScheme()); path.append("/"); } if (uri.getHost() != null) { path.append(uri.getHost()); if (uri.getPort() != -1) { path.append(":"); path.append(Integer.toString(uri.getPort())); } if (uri.getRawPath() != null) { if (uri.getRawPath().length() == 0) { path.append("/"); } else if (uri.getRawPath().equals("/")) { path.append(uri.getRawPath()); } else { for (String name : uri.getRawPath().split("/")) { if (name != null && name.length() > 0) { path.append("/"); path.append(name); } } } } if (uri.getRawQuery() != null) { path.append("?"); path.append(uri.getRawQuery()); } } else { if (uri.getRawSchemeSpecificPart() != null) { for (String name : uri.getRawSchemeSpecificPart().split("/")) { if (name != null && name.length() > 0) { path.append("/"); path.append(name); } } } } if (path.toString().endsWith("/")) { path.append(".content"); } return path.toString(); }
From source file:org.kitodo.production.services.file.FileService.java
/** * Creates a MetaDirectory.//w w w. j a v a 2 s.c om * * @param parentFolderUri * The URI, where the * @param directoryName * the name of the directory * @return true or false * @throws IOException * an IOException */ URI createMetaDirectory(URI parentFolderUri, String directoryName) throws IOException { if (!fileExist(parentFolderUri.resolve(directoryName))) { CommandService commandService = ServiceManager.getCommandService(); String path = FileSystems.getDefault() .getPath(ConfigCore.getKitodoDataDirectory(), parentFolderUri.getRawPath(), directoryName) .normalize().toAbsolutePath().toString(); List<String> commandParameter = Collections.singletonList(path); File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META)); CommandResult commandResult = commandService.runCommand(script, commandParameter); if (!commandResult.isSuccessful()) { String message = MessageFormat.format( "Could not create directory {0} in {1}! No new directory was created", directoryName, parentFolderUri.getPath()); logger.warn(message); throw new IOException(message); } } else { logger.info("Metadata directory: {} already existed! No new directory was created", directoryName); } return URI.create(parentFolderUri.getPath() + '/' + directoryName); }
From source file:com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.java
/** * {@inheritDoc}//from w w w.j ava 2 s . co m */ @NonNull @Override public String getRepositoryUri(@NonNull BitbucketRepositoryType type, @NonNull BitbucketRepositoryProtocol protocol, @CheckForNull String cloneLink, @NonNull String owner, @NonNull String repository) { switch (type) { case GIT: URI baseUri; try { baseUri = new URI(baseURL); } catch (URISyntaxException e) { throw new IllegalStateException("Server URL is not a valid URI", e); } UriTemplate template = UriTemplate .fromTemplate("{scheme}://{+authority}{+path}{/owner,repository}.git"); template.set("owner", owner); template.set("repository", repository); switch (protocol) { case HTTP: template.set("scheme", baseUri.getScheme()); template.set("authority", baseUri.getRawAuthority()); template.set("path", Objects.toString(baseUri.getRawPath(), "") + "/scm"); break; case SSH: template.set("scheme", BitbucketRepositoryProtocol.SSH.getType()); template.set("authority", "git@" + baseUri.getHost()); if (cloneLink != null) { try { URI cloneLinkUri = new URI(cloneLink); if (cloneLinkUri.getScheme() != null) { template.set("scheme", cloneLinkUri.getScheme()); } if (cloneLinkUri.getRawAuthority() != null) { template.set("authority", cloneLinkUri.getRawAuthority()); } } catch (@SuppressWarnings("unused") URISyntaxException ignored) { // fall through } } break; default: throw new IllegalArgumentException("Unsupported repository protocol: " + protocol); } return template.expand(); default: throw new IllegalArgumentException("Unsupported repository type: " + type); } }
From source file:org.kitodo.production.services.file.FileService.java
/** * Writes a metadata file.//from www. ja v a 2s . c om * * @param gdzfile * the file format * @param process * the process * @throws IOException * if error occurs */ public void writeMetadataFile(LegacyMetsModsDigitalDocumentHelper gdzfile, Process process) throws IOException { RulesetService rulesetService = ServiceManager.getRulesetService(); LegacyMetsModsDigitalDocumentHelper ff; Ruleset ruleset = process.getRuleset(); switch (MetadataFormat.findFileFormatsHelperByName(process.getProject().getFileFormatInternal())) { case METS: ff = new LegacyMetsModsDigitalDocumentHelper(rulesetService.getPreferences(ruleset).getRuleset()); break; default: throw new UnsupportedOperationException("Dead code pending removal"); } // createBackupFile(); URI metadataFileUri = getMetadataFilePath(process, false); String temporaryMetadataFileName = getTemporaryMetadataFileName(metadataFileUri); ff.setDigitalDocument(gdzfile.getDigitalDocument()); // ff.write(getMetadataFilePath()); ff.write(temporaryMetadataFileName); File temporaryMetadataFile = new File(temporaryMetadataFileName); boolean backupCondition = temporaryMetadataFile.exists() && temporaryMetadataFile.length() > 0; if (backupCondition) { createBackupFile(process); renameFile(Paths.get(temporaryMetadataFileName).toUri(), metadataFileUri.getRawPath()); removePrefixFromRelatedMetsAnchorFilesFor(Paths.get(temporaryMetadataFileName).toUri()); } }
From source file:org.georchestra.security.Proxy.java
private URI buildUri(URL url) throws URISyntaxException { // Let URI constructor encode Path part URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), null, // Don't use query part because URI constructor will try to double encode it // (query part is already encoded in sURL) url.getRef());//from ww w. ja v a 2 s. c o m // Reconstruct URL with encoded path from URI class and others parameters from URL class StringBuilder rawUrl = new StringBuilder(url.getProtocol() + "://" + url.getHost()); if (url.getPort() != -1) rawUrl.append(":" + String.valueOf(url.getPort())); rawUrl.append(uri.getRawPath()); // Use encoded version from URI class if (url.getQuery() != null) rawUrl.append("?" + url.getQuery()); // Use already encoded query part return new URI(rawUrl.toString()); }
From source file:org.kitodo.services.file.FileService.java
/** * Writes a metadata file./*from w w w . j a v a 2 s . c o m*/ * * @param gdzfile * the file format * @param process * the process * @throws IOException * if error occurs * @throws PreferencesException * if error occurs * @throws WriteException * if error occurs */ public void writeMetadataFile(Fileformat gdzfile, Process process) throws IOException, PreferencesException, WriteException { createDirectory(URI.create(""), serviceManager.getProcessService().getProcessDataDirectory(process).toString()); RulesetService rulesetService = new RulesetService(); Fileformat ff; URI metadataFileUri; Hibernate.initialize(process.getRuleset()); switch (MetadataFormat.findFileFormatsHelperByName(process.getProject().getFileFormatInternal())) { case METS: ff = new MetsMods(rulesetService.getPreferences(process.getRuleset())); break; case RDF: ff = new RDFFile(rulesetService.getPreferences(process.getRuleset())); break; default: ff = new XStream(rulesetService.getPreferences(process.getRuleset())); break; } // createBackupFile(); metadataFileUri = getMetadataFilePath(process); String temporaryMetadataFileName = getTemporaryMetadataFileName(metadataFileUri); ff.setDigitalDocument(gdzfile.getDigitalDocument()); // ff.write(getMetadataFilePath()); boolean writeResult = ff.write(temporaryMetadataFileName); File temporaryMetadataFile = new File(temporaryMetadataFileName); boolean backupCondition = writeResult && temporaryMetadataFile.exists() && (temporaryMetadataFile.length() > 0); if (backupCondition) { createBackupFile(process); renameFile(Paths.get(temporaryMetadataFileName).toUri(), metadataFileUri.getRawPath()); removePrefixFromRelatedMetsAnchorFilesFor(Paths.get(temporaryMetadataFileName).toUri()); } }
From source file:com.cisco.oss.foundation.http.apache.ApacheHttpClient.java
private URI buildUri(HttpRequest request, Joiner joiner) { URI requestUri = request.getUri(); Map<String, Collection<String>> queryParams = request.getQueryParams(); if (queryParams != null && !queryParams.isEmpty()) { URIBuilder uriBuilder = new URIBuilder(); StringBuilder queryStringBuilder = new StringBuilder(); boolean hasQuery = !queryParams.isEmpty(); for (Map.Entry<String, Collection<String>> stringCollectionEntry : queryParams.entrySet()) { String key = stringCollectionEntry.getKey(); Collection<String> queryParamsValueList = stringCollectionEntry.getValue(); if (request.isQueryParamsParseAsMultiValue()) { for (String queryParamsValue : queryParamsValueList) { uriBuilder.addParameter(key, queryParamsValue); queryStringBuilder.append(key).append("=").append(queryParamsValue).append("&"); }//w ww. ja v a2 s . com } else { String value = joiner.join(queryParamsValueList); uriBuilder.addParameter(key, value); queryStringBuilder.append(key).append("=").append(value).append("&"); } } uriBuilder.setFragment(requestUri.getFragment()); uriBuilder.setHost(requestUri.getHost()); uriBuilder.setPath(requestUri.getPath()); uriBuilder.setPort(requestUri.getPort()); uriBuilder.setScheme(requestUri.getScheme()); uriBuilder.setUserInfo(requestUri.getUserInfo()); try { if (!autoEncodeUri) { String urlPath = ""; if (requestUri.getRawPath() != null && requestUri.getRawPath().startsWith("/")) { urlPath = requestUri.getRawPath(); } else { urlPath = "/" + requestUri.getRawPath(); } if (hasQuery) { String query = queryStringBuilder.substring(0, queryStringBuilder.length() - 1); requestUri = new URI(requestUri.getScheme() + "://" + requestUri.getHost() + ":" + requestUri.getPort() + urlPath + "?" + query); } else { requestUri = new URI(requestUri.getScheme() + "://" + requestUri.getHost() + ":" + requestUri.getPort() + urlPath); } } else { requestUri = uriBuilder.build(); } } catch (URISyntaxException e) { LOGGER.warn("could not update uri: {}", requestUri); } } return requestUri; }
From source file:com.chigix.bio.proxy.buffer.FixedBufferTest.java
License:asdf
@Test public void testURI() { try {/*from w w w . j a v a 2s.co m*/ URI uri = new URI( "http://www.baidu.com/awefawgwage/awefwfa/wefafwef/awdfa?safwefawf=awefaf&afwef=fafwef"); System.out.println(uri.getScheme()); System.out.println(uri.getHost()); System.out.println(uri.getPort()); System.out.println(uri.getQuery()); System.out.println(uri.getPath()); } catch (URISyntaxException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } String illegalQuery = "http://sclick.baidu.com/w.gif?q=a&fm=se&T=1423492890&y=55DFFF7F&rsv_cache=0&rsv_pre=0&rsv_reh=109_130_149_109_85_195_85_85_85_85|540&rsv_scr=1899_1720_0_0_1080_1920&rsv_sid=10383_1469_12498_10902_11101_11399_11277_11241_11401_12550_11243_11403_12470&cid=0&qid=fd67eec000006821&t=1423492880700&rsv_iorr=1&rsv_tn=baidu&path=http%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26f%3D8%26rsv_bp%3D1%26rsv_idx%3D1%26ch%3D%26tn%3Dbaidu%26bar%3D%26wd%3Da%26rn%3D%26rsv_pq%3Dda7dc5fb00004904%26rsv_t%3D55188AMIFp8JX4Jb3hJkfCZHYxQdZOBK%252FhV0kLFfAPijGGrceXBoFpnHzmI%26rsv_enter%3D1%26inputT%3D111"; URI uri; while (true) { try { uri = new URI(illegalQuery); } catch (URISyntaxException ex) { System.out.println(illegalQuery); System.out.println(illegalQuery.charAt(ex.getIndex())); System.out.println(illegalQuery.substring(0, ex.getIndex())); System.out.println(illegalQuery.substring(ex.getIndex() + 1)); try { illegalQuery = illegalQuery.substring(0, ex.getIndex()) + URLEncoder.encode(String.valueOf(illegalQuery.charAt(ex.getIndex())), "utf-8") + illegalQuery.substring(ex.getIndex() + 1); } catch (UnsupportedEncodingException ex1) { } System.out.println(illegalQuery); continue; } break; } System.out.println("SCHEME: " + uri.getScheme()); System.out.println("HOST: " + uri.getHost()); System.out.println("path: " + uri.getRawPath()); System.out.println("query: " + uri.getRawQuery()); System.out.println("PORT: " + uri.getPort()); }