Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpURL


   * @param pass password
   */
  public WebdavFile(URL url, String user, String pass) throws URIException {
    this(url.getProtocol().equals("https")
        ? new HttpsURL(user, pass, url.getHost(), url.getPort(), url.getPath())
        : new HttpURL(user, pass, url.getHost(), url.getPort(), url.getPath()));
  }
View Full Code Here


        return sResult;
    }

    private static HttpURL uriToHttpURL(String uri) throws URIException {
        return uri.startsWith("https") ? new HttpsURL(uri.toCharArray())
                                       : new HttpURL(uri.toCharArray());
    }
View Full Code Here

        final SimpleHttpServerConnection conn,
        final SimpleRequest request) throws IOException
    {
        Log wireLog = LogFactory.getLog("httpclient.wire");
       
        URI url = new HttpURL(request.getRequestLine().getUri());

        HttpClient client = new HttpClient();
        HostConfiguration hc = new HostConfiguration();
        hc.setHost(url);
        client.setHostConfiguration(hc);
       
        //TODO support other methods
        HttpMethod method = new GetMethod(url.getPathQuery());
        Header[] headers = request.getHeaders();
        for (int i=0; i<headers.length; i++) {
            method.addRequestHeader(headers[i]);
        }
        if (method instanceof EntityEnclosingMethod) {
View Full Code Here

        }

    }

    private static HttpURL uriToHttpURL(String uri) throws URIException {
        HttpURL url = null;
        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);
        }
View Full Code Here

        try {
            if (containingDir == null) {
                throw new IOException("Containing directory is null:");
            }
            WebdavFile newFolder = null;
            HttpURL url = null;

            url = this.uriToHttpURL(containingDir.getPath() +
                                    WebdavFile.davSeparator + newFolderString);
            // Need to add user info so has access for queries
            url.setUserinfo(username, password);
            newFolder = new WebdavFile(url, this.rootURL);
            //System.out.println("new folder : " + newFolder.toString());

            this.connect();
            if (this.webdavResource.mkcolMethod(
View Full Code Here

    public File[] getFiles(File dir, boolean useFileHiding) {
        try {

            String filenames[] = null;
            WebdavFile files[] = null;
            HttpURL url = null;
            String path = null;
            String localDir = null;

            this.connect();
            // Now we try to list files

            path = dir.getPath();
            //System.out.println("getFiles : RAW PATH : '" + path + "'");

            // If path contains the server preamble, we need to extract that
            // and have the path only
            if (path.startsWith("http")) {
                //System.out.println("getFiles : preample : " + this.uri);
                path = path.replaceAll(this.uri, "");
            }
            if (!path.endsWith("/")) {
                path = path + "/";
            }

            //System.out.println("getFiles : path : " + path);

            this.webdavResource.setPath(path);
            filenames = this.webdavResource.list();
            files = new WebdavFile[filenames.length];
            for (int i = 0; i < filenames.length; i++) {
                //System.out.println("file : " + filenames[i]);
                // Lets try to construct a uri from the dir
                // given and the current file

                localDir = dir.getPath();
                if (!localDir.endsWith("/")) localDir = localDir + "/";

                String filepath =  localDir + filenames[i];
                //System.out.println("getFiles : file fullpath : " + filepath);
                url = this.uriToHttpURL(filepath);
                // Need to add user info so has access for queries
                url.setUserinfo(username, password);
                files[i] = new WebdavFile(url, this.rootURL);
            }
            return files;
        } catch (Exception e) {
            System.err.println(e.toString());
View Full Code Here

                return null;
            }
        }
        public File getParentFile() {
            try {
                HttpURL httpURL = null;
                String parent = null;
                parent = this.getParent();
                if (parent == null) {
                    //System.out.println("getParentFile : at root so return null");
                    return null;
                } else {
                    httpURL = this.rootUrl;
                    httpURL.setPath(parent);
                    //System.out.println("getParentFile : set path to " + parent);
                    return new WebdavFile(httpURL, this.rootUrl);
                }
            } catch (Exception e) {
                System.err.println(e.toString());
View Full Code Here

         path = path + "/";
      }
      Stack toBeCreated = new Stack();
     
      while (!path.equals("/")) {
         HttpURL parent = Utils.createHttpURL(httpURL, path);
         if (!collectionExists(client, parent)) {
            toBeCreated.push(path);
            path = path.substring(0, path.lastIndexOf("/", path.length()-2)+1);
         } else {
            break;
         }
      }

      boolean created = !toBeCreated.empty();
      while(!toBeCreated.empty()) {
         HttpURL newColl = Utils.createHttpURL(httpURL, (String)toBeCreated.pop());
         MkcolMethod mkcol = new MkcolMethod(newColl.getURI());
         mkcol.setFollowRedirects(true);
         generateIfHeader(mkcol, lockToken);
         int status = client.executeMethod(mkcol);
         if (status != WebdavStatus.SC_CREATED) {
            HttpException ex = new HttpException("Can't create collection " +
View Full Code Here

       throws URIException
   {
     if (base instanceof HttpsURL) {
        return new HttpsURL((HttpsURL)base, relative);
     } else {
        return new HttpURL(base, relative);
     }
   }
View Full Code Here

   public static HttpURL createHttpURL(String url) throws URIException
   {
      if (url.startsWith("https://")) {
         return new HttpsURL(url);
      } else {
         return new HttpURL(url);
      }
   }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.HttpURL

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.