List of usage examples for org.apache.commons.httpclient.util URIUtil encodePath
public static String encodePath(String unescaped) throws URIException
From source file:org.apache.hadoop.fs.azure.MockStorageInterface.java
private static URI convertKeyToEncodedUri(String key) { try {/*from w ww . j av a 2 s. c om*/ String encodedKey = URIUtil.encodePath(key); URI uri = new URI(encodedKey); return uri; } catch (URISyntaxException e) { throw new AssertionError("Failed to encode key: " + key); } catch (URIException e) { throw new AssertionError("Failed to encode key: " + key); } }
From source file:org.apache.hadoop.fs.azure.MockStorageInterface.java
@Override public CloudBlobContainerWrapper getContainerReference(String name) throws URISyntaxException, StorageException { String fullUri;/* ww w . ja v a 2 s. c o m*/ try { fullUri = baseUriString + "/" + URIUtil.encodePath(name); } catch (URIException e) { throw new RuntimeException("problem encoding fullUri", e); } MockCloudBlobContainerWrapper container = new MockCloudBlobContainerWrapper(fullUri, name); // Check if we have a pre-existing container with that name, and prime // the wrapper with that knowledge if it's found. for (PreExistingContainer existing : preExistingContainers) { if (fullUri.equalsIgnoreCase(existing.containerUri)) { // We have a pre-existing container. Mark the wrapper as created and // make sure we use the metadata for it. container.created = true; backingStore.setContainerMetadata(existing.containerMetadata); break; } } return container; }
From source file:org.apache.maven.wagon.providers.webdav.CorrectedWebdavResource.java
public boolean mkcolMethod(String path) throws HttpException, IOException { setClient();// ww w . j a va 2 s . co m MkcolMethod method = new MkcolMethod(URIUtil.encodePath(path)); generateIfHeader(method); generateTransactionHeader(method); int statusCode = 0; try { statusCode = client.executeMethod(method); } catch (IOException e) { throw e; } // Possbile MKCOL Status Codes => SC_CREATED // WebdavStatus.SC_FORBIDDEN, SC_METHOD_NOT_ALLOWED, SC_CONFLICT, // SC_LOCKED, SC_UNSUPPORTED_MEDIA_TYPE, SC_INSUFFICIENT_STORAGE setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
From source file:org.apache.nutch.tools.AbstractCommonCrawlFormat.java
protected String getUrl() { try {//w w w .j a v a2 s.com return URIUtil.encodePath(url); } catch (URIException e) { LOG.error("Can't encode URL " + url); } return url; }
From source file:org.apache.sentry.hdfs.PathsUpdate.java
/** * * @param path : Needs to be a HDFS location with scheme * @return Path in the form a list containing the path tree with scheme/ authority stripped off. * Returns null if a non HDFS path or if path is null/empty *//*from w w w . j a va 2s. co m*/ public static List<String> parsePath(String path) { try { URI uri = null; if (StringUtils.isNotEmpty(path)) { uri = new URI(URIUtil.encodePath(path)); } else { return null; } Preconditions.checkNotNull(uri.getScheme()); if (uri.getScheme().equalsIgnoreCase("hdfs")) { return Lists.newArrayList(uri.getPath().split("^/")[1].split("/")); } else { return null; } } catch (URISyntaxException e) { throw new RuntimeException("Incomprehensible path [" + path + "]"); } catch (URIException e) { throw new RuntimeException("Unable to create URI: ", e); } }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Updates the resource with a new set of aces. * * @param path the server relative path of the resource to which the given * ACEs shall be applied/* w w w . ja v a 2s.c o m*/ * @param aces the ACEs to apply * @return true if the method succeeded */ public boolean aclMethod(String path, Ace[] aces) throws HttpException, IOException { setClient(); AclMethod method = new AclMethod(URIUtil.encodePath(path)); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateIfHeader(method); for (int i = 0; i < aces.length; i++) { Ace ace = aces[i]; method.addAce(ace); } generateTransactionHeader(method); generateAdditionalHeaders(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Return the <code>AclProperty</code> for the resource at the given path * * @param path the server relative path of the resource to request * @return acl property, null if the server doesn't respond with * <code>AclProperty</code>/*w ww.jav a2 s. c om*/ */ public AclProperty aclfindMethod(String path) throws HttpException, IOException { setClient(); AclProperty acl = null; Vector properties = new Vector(); properties.addElement(AclProperty.TAG_NAME); // Default depth=0, type=by_name PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path), DepthSupport.DEPTH_0, properties.elements()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); if (property instanceof AclProperty) { acl = (AclProperty) property; } } } return acl; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Get the <code>PrincipalCollectionSetProperty</code> for the resource. * * @param path the server relative path of the resource to request * @return principal collection set Property, null if the server doesn't * respond with a <code>PrincipalCollectionSetProperty</code> *///from w w w . j a v a 2s .c o m public PrincipalCollectionSetProperty principalCollectionSetFindMethod(String path) throws HttpException, IOException { setClient(); PrincipalCollectionSetProperty set = null; Vector properties = new Vector(); properties.addElement(PrincipalCollectionSetProperty.TAG_NAME); // Default depth=0, type=by_name PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path), DepthSupport.DEPTH_0, properties.elements()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); if (property instanceof PrincipalCollectionSetProperty) { set = (PrincipalCollectionSetProperty) property; } } } return set; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Return the LockDiscoveryProperty for the resource at the given path * * @param path the server relative path of the resource to request * @return null if the server doesn't respond with a LockDiscoveryProperty *//*from ww w . j a v a 2 s. c o m*/ public LockDiscoveryProperty lockDiscoveryPropertyFindMethod(String path) throws HttpException, IOException { setClient(); LockDiscoveryProperty set = null; Vector properties = new Vector(); properties.addElement(LockDiscoveryProperty.TAG_NAME); // Default depth=0, type=by_name PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path), DepthSupport.DEPTH_0, properties.elements()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); if (property instanceof LockDiscoveryProperty) { set = (LockDiscoveryProperty) property; } } } return set; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute OPTIONS method for the given path. * * @param path the server relative path of the resource to request * @return true if the method is succeeded. * @exception HttpException// ww w . ja va 2 s . c o m * @exception IOException * @see #getAllowedMethods() */ public boolean optionsMethod(String path) throws HttpException, IOException { setClient(); OptionsMethod method; if (path.trim().equals("*")) method = new OptionsMethod("*"); else method = new OptionsMethod(URIUtil.encodePath(path)); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); if (statusCode >= 200 && statusCode < 300) { // check if the specific method is possbile allowedMethods = method.getAllowedMethods(); // check WebDAV capabilities. davCapabilities = method.getDavCapabilities(); return true; } return false; }