List of usage examples for org.apache.commons.httpclient HttpsURL HttpsURL
public HttpsURL(char[] paramArrayOfChar) throws URIException, NullPointerException
From source file:org.apache.webdav.ant.Utils.java
public static HttpURL createHttpURL(String url) throws URIException { if (url.startsWith("https://")) { return new HttpsURL(url); } else {/* w w w . java2s . co m*/ return new HttpURL(url); } }
From source file:org.apache.webdav.cmd.Client.java
private static HttpURL uriToHttpURL(String uri) throws URIException { return uri.startsWith("https") ? new HttpsURL(uri) : new HttpURL(uri); }
From source file:org.apache.webdav.connector.WebDAVConnectionSpec.java
/** * Creates a specification where the {@link WebDAVConnection} shall go to. * //from ww w . j a va 2 s . c o m * @param url url string of the Slide (WebDAV) server * @param userName user name for login to the Slide (WebDAV) server * @param password password for login to the Slide (WebDAV) server * @param timeout timeout of the externally controlled transaction * @throws URIException if the given uri is not a valid one */ public WebDAVConnectionSpec(String url, String userName, String password, int timeout) throws URIException { this.httpURL = url.startsWith("https") ? new HttpsURL(url) : new HttpURL(url); this.httpURL.setUserinfo(userName, password); this.timeout = timeout; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Set WebDAV properties following to the given http URL. * This method is fundamental for getting information of a collection. * * @param responses An enumeration over {@link ResponseEntity} items, one * for each resource for which information was returned via PROPFIND. * * @exception HttpException/*from w w w. j a va2s . c om*/ * @exception IOException The socket error with a server. */ protected void setWebdavProperties(Enumeration responses) throws HttpException, IOException { // Make the resources in the collection empty. childResources.removeAll(); while (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); boolean itself = false; String href = response.getHref(); if (!href.startsWith("/")) href = URIUtil.getPath(href); href = decodeMarks(href); /* * Decode URIs to common (unescaped) format for comparison * as HttpClient.URI.setPath() doesn't escape $ and : chars. */ String httpURLPath = httpURL.getPath(); String escapedHref = URIUtil.decode(href); // Normalize them to both have trailing slashes if they differ by one in length. int lenDiff = escapedHref.length() - httpURLPath.length(); int compareLen = 0; if (lenDiff == -1 && !escapedHref.endsWith("/")) { compareLen = escapedHref.length(); lenDiff = 0; } else if (lenDiff == 1 && !httpURLPath.endsWith("/")) { compareLen = httpURLPath.length(); lenDiff = 0; } // if they are the same length then compare them. if (lenDiff == 0) { if ((compareLen == 0 && httpURLPath.equals(escapedHref)) || httpURLPath.regionMatches(0, escapedHref, 0, compareLen)) { // escaped href and http path are the same // Set the status code for this resource. if (response.getStatusCode() > 0) setStatusCode(response.getStatusCode()); setExistence(true); itself = true; } } // Get to know each resource. WebdavResource workingResource = null; if (itself) { workingResource = this; } else { workingResource = createWebdavResource(client); workingResource.setDebug(debug); } // clear the current lock set workingResource.setLockDiscovery(null); // Process the resource's properties Enumeration properties = response.getProperties(); while (properties.hasMoreElements()) { Property property = (Property) properties.nextElement(); // ------------------------------ Checking WebDAV properties workingResource.processProperty(property); } String displayName = workingResource.getDisplayName(); if (displayName == null || displayName.trim().equals("")) { displayName = getName(href, true); } if (!itself) { String myURI = httpURL.getEscapedURI(); char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/") + getName(href, false)).toCharArray(); HttpURL childURL = httpURL instanceof HttpsURL ? new HttpsURL(childURI) : new HttpURL(childURI); childURL.setRawAuthority(httpURL.getRawAuthority()); workingResource.setHttpURL(childURL, NOACTION, defaultDepth); workingResource.setExistence(true); workingResource.setOverwrite(getOverwrite()); } workingResource.setDisplayName(displayName); if (!itself) childResources.addResource(workingResource); } }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Set the HttpURL of this WebdavResource. * It must be put an escaped http URL as an argument. * * @param escapedHttpURL The escaped http URL string. * @exception HttpException//from w w w.j a v a 2 s. c o m * @exception IOException * @see #setHttpURL(HttpURL) * @see #setUserInfo(java.lang.String, java.lang.String) * @see #setPath(java.lang.String) */ public void setHttpURL(String escapedHttpURL) throws HttpException, IOException { setHttpURL(escapedHttpURL.startsWith("https") ? new HttpsURL(escapedHttpURL) : new HttpURL(escapedHttpURL)); }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Get the HttpURL except for userinfo.//from w w w.ja v a 2 s .co m * * @return httpURL the http URL. */ public HttpURL getHttpURLExceptForUserInfo() throws URIException { return httpURL instanceof HttpsURL ? new HttpsURL(httpURL.getRawURI()) : new HttpURL(httpURL.getRawURI()); }
From source file:org.apache.webdav.ui.WebdavSystemView.java
private static HttpURL uriToHttpURL(String uri) throws URIException { HttpURL url = null;/*from w w w.j a va 2s . c o m*/ if (uri.startsWith("http://")) { url = new HttpURL(uri); } else if (uri.startsWith("https://")) { url = new HttpsURL(uri); } else { throw new URIException("Unknown protocol in URL " + uri); } return url; }
From source file:org.fao.geonet.kernel.harvest.harvester.webdav.WebDavRetriever.java
private WebdavResource createResource(String url) throws Exception { if (log.isDebugEnabled()) log.debug("Creating WebdavResource"); HttpURL http = url.startsWith("https") ? new HttpsURL(url) : new HttpURL(url); if (params.useAccount) { if (log.isDebugEnabled()) log.debug("using account, username: " + params.username + " password: " + params.password); http.setUserinfo(params.username, params.password); } else {//from w ww . j av a 2 s .c om if (log.isDebugEnabled()) log.debug("not using account"); } //--- setup proxy, if the case GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); SettingManager sm = gc.getSettingManager(); boolean enabled = sm.getValueAsBool("system/proxy/use", false); String host = sm.getValue("system/proxy/host"); String port = sm.getValue("system/proxy/port"); if (!enabled) { if (log.isDebugEnabled()) { log.debug("local proxy not enabled"); log.debug("returning a new WebdavResource"); log.debug("using http port: " + http.getPort() + " http uri: " + http.getURI()); } return new WebdavResource(http, 1); } else { if (log.isDebugEnabled()) log.debug("local proxy enabled"); if (!Lib.type.isInteger(port)) { throw new Exception("Proxy port is not an integer : " + port); } if (log.isDebugEnabled()) { log.debug("returning a new WebdavResource"); log.debug( "using http proxy port: " + port + " proxy host: " + host + " http uri: " + http.getURI()); } return new WebdavResource(http, host, Integer.parseInt(port)); } }
From source file:org.fao.geonet.kernel.harvest.harvester.webdav.WebDavRetriever.java
private void retrieveFiles(WebdavResource wr) throws IOException { String path = wr.getPath();/*from ww w .jav a 2 s. c o m*/ if (log.isDebugEnabled()) log.debug("Scanning resource : " + path); WebdavResource[] wa = wr.listWebdavResources(); if (log.isDebugEnabled()) log.debug("# " + wa.length + " webdav resources found in: " + wr.getPath()); if (wa.length > 0) { int startSize = files.size(); for (WebdavResource w : wa) { // heikki: even though response indicates that a sub directory is a collection, according to Slide // that is never the case. To determine if a resource is a sub directory, use the following // trick : // if(w.getIsCollection()) { if (w.getPath().equals(wr.getPath()) && w.getDisplayName().length() > 0) { if (params.recurse) { if (log.isDebugEnabled()) log.debug(w.getPath() + " is a collection, processed recursively"); String url = w.getHttpURL().getURI(); url = url + w.getDisplayName() + "/"; HttpURL http = url.startsWith("https") ? new HttpsURL(url) : new HttpURL(url); WebdavResource huh = new WebdavResource(http, 1); retrieveFiles(huh); } else { if (log.isDebugEnabled()) log.debug(w.getPath() + " is a collection. Ignoring because recursion is disabled."); } } else { if (log.isDebugEnabled()) log.debug(w.getName() + " is not a collection"); if (w.getName().toLowerCase().endsWith(".xml")) { if (log.isDebugEnabled()) log.debug("found xml file ! " + w.getName().toLowerCase()); files.add(new WebDavRemoteFile(w)); } else { if (log.isDebugEnabled()) log.debug(w.getName().toLowerCase() + " is not an xml file"); } } } int endSize = files.size(); int added = endSize - startSize; if (added == 0) { if (log.isDebugEnabled()) log.debug("No xml files found in path : " + path); } else { if (log.isDebugEnabled()) log.debug("Found " + added + " xml file(s) in path : " + path); } } }
From source file:org.gradle.api.internal.artifacts.publish.ivycomponents.WebdavRepository.java
public void put(File source, String destination, boolean overwrite) throws IOException { int fileNameStart = destination.lastIndexOf('/'); String baseUrl = destination.substring(0, fileNameStart + 1); String destinationFileName = destination.substring(fileNameStart + 1); HttpsURL hrl = new HttpsURL(baseUrl); hrl.setUserinfo(user, userPassword); WebdavResource wdr = new WebdavResource(hrl); wdr.putMethod(wdr.getPath() + '/' + destinationFileName, source); wdr.close();//from w w w. ja v a2 s. c o m }