Esempio n. 1
0
 private synchronized void doOptions(String url)
     throws NotFoundException, java.net.ConnectException, NotAuthorizedException,
         java.net.UnknownHostException, SocketTimeoutException, IOException,
         com.ettrema.httpclient.HttpException {
   notifyStartRequest();
   String uri = url;
   log.trace("doOptions: {}", url);
   HttpOptions m = new HttpOptions(uri);
   InputStream in = null;
   try {
     int res = Utils.executeHttpWithStatus(client, m, null);
     log.trace("result code: " + res);
     if (res == 301 || res == 302) {
       return;
     }
     Utils.processResultCode(res, url);
   } catch (ConflictException ex) {
     throw new RuntimeException(ex);
   } catch (BadRequestException ex) {
     throw new RuntimeException(ex);
   } finally {
     Utils.close(in);
     notifyFinishRequest();
   }
 }
Esempio n. 2
0
 /**
  * POSTs the variables and returns the body
  *
  * @param url - fully qualified and encoded URL to post to
  * @param params
  * @return
  */
 public String doPost(String url, Map<String, String> params)
     throws com.ettrema.httpclient.HttpException, NotAuthorizedException, ConflictException,
         BadRequestException, NotFoundException {
   notifyStartRequest();
   HttpPost m = new HttpPost(url);
   List<NameValuePair> formparams = new ArrayList<NameValuePair>();
   for (Entry<String, String> entry : params.entrySet()) {
     formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
   }
   UrlEncodedFormEntity entity;
   try {
     entity = new UrlEncodedFormEntity(formparams);
   } catch (UnsupportedEncodingException ex) {
     throw new RuntimeException(ex);
   }
   m.setEntity(entity);
   try {
     ByteArrayOutputStream bout = new ByteArrayOutputStream();
     int res = Utils.executeHttpWithStatus(client, m, bout);
     Utils.processResultCode(res, url);
     return bout.toString();
   } catch (HttpException ex) {
     throw new RuntimeException(ex);
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   } finally {
     notifyFinishRequest();
   }
 }
Esempio n. 3
0
 /**
  * @param sourceUrl - encoded source url
  * @param newUri - encoded destination url
  * @return
  * @throws IOException
  * @throws com.ettrema.httpclient.HttpException
  */
 public synchronized int doMove(String sourceUrl, String newUri)
     throws IOException, com.ettrema.httpclient.HttpException, NotAuthorizedException,
         ConflictException, BadRequestException, NotFoundException, URISyntaxException {
   notifyStartRequest();
   MoveMethod m = new MoveMethod(sourceUrl, newUri);
   try {
     int res = Utils.executeHttpWithStatus(client, m, null);
     Utils.processResultCode(res, sourceUrl);
     return res;
   } finally {
     notifyFinishRequest();
   }
 }
Esempio n. 4
0
 /**
  * @param url - encoded url
  * @return
  * @throws IOException
  * @throws com.ettrema.httpclient.HttpException
  */
 public synchronized int doDelete(String url)
     throws IOException, com.ettrema.httpclient.HttpException, NotAuthorizedException,
         ConflictException, BadRequestException, NotFoundException {
   notifyStartRequest();
   HttpDelete m = new HttpDelete(url);
   try {
     int res = Utils.executeHttpWithStatus(client, m, null);
     Utils.processResultCode(res, url);
     return res;
   } catch (HttpException ex) {
     throw new RuntimeException(ex);
   } finally {
     notifyFinishRequest();
   }
 }
Esempio n. 5
0
 /**
  * @param uri - must be encoded
  * @param lockToken
  * @return
  * @throws com.ettrema.httpclient.HttpException
  */
 public synchronized int doUnLock(String uri, String lockToken)
     throws com.ettrema.httpclient.HttpException, NotAuthorizedException, ConflictException,
         BadRequestException, NotFoundException, URISyntaxException {
   notifyStartRequest();
   UnLockMethod p = new UnLockMethod(uri, lockToken);
   try {
     int result = Utils.executeHttpWithStatus(client, p, null);
     Utils.processResultCode(result, uri);
     return result;
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   } finally {
     notifyFinishRequest();
   }
 }
Esempio n. 6
0
 /**
  * @param from - encoded source url
  * @param newUri - encoded destination
  * @return
  * @throws com.ettrema.httpclient.HttpException
  */
 public synchronized int doCopy(String from, String newUri)
     throws com.ettrema.httpclient.HttpException, NotAuthorizedException, ConflictException,
         BadRequestException, NotFoundException, URISyntaxException {
   notifyStartRequest();
   CopyMethod m = new CopyMethod(from, newUri);
   try {
     int res = Utils.executeHttpWithStatus(client, m, null);
     Utils.processResultCode(res, from);
     return res;
   } catch (HttpException ex) {
     throw new RuntimeException(ex);
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   } finally {
     notifyFinishRequest();
   }
 }
Esempio n. 7
0
 /**
  * Returns the lock token, which must be retained to unlock the resource
  *
  * @param uri - must be encoded
  * @param owner
  * @return
  * @throws com.ettrema.httpclient.HttpException
  */
 public synchronized String doLock(String uri)
     throws com.ettrema.httpclient.HttpException, NotAuthorizedException, ConflictException,
         BadRequestException, NotFoundException, URISyntaxException {
   notifyStartRequest();
   LockMethod p = new LockMethod(uri);
   try {
     String lockXml = LOCK_XML.replace("${owner}", user);
     HttpEntity requestEntity = new StringEntity(lockXml, "UTF-8");
     p.setEntity(requestEntity);
     HttpResponse resp = host().client.execute(p);
     int result = resp.getStatusLine().getStatusCode();
     Utils.processResultCode(result, uri);
     return p.getLockToken(resp);
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   } finally {
     notifyFinishRequest();
   }
 }
Esempio n. 8
0
  /**
   * @param url - the encuded URL to query
   * @param depth - depth to generate responses for. Zero means only the specified url, 1 means it
   *     and its direct children, etc
   * @return
   * @throws IOException
   * @throws com.ettrema.httpclient.HttpException
   */
  public synchronized List<PropFindMethod.Response> doPropFind(String url, int depth)
      throws IOException, com.ettrema.httpclient.HttpException, NotAuthorizedException,
          BadRequestException {
    log.trace("doPropFind: " + url);
    notifyStartRequest();
    final PropFindMethod m = new PropFindMethod(url);
    m.addHeader("Depth", depth + "");

    try {
      if (propFindXml != null) {
        HttpEntity requestEntity = new StringEntity(propFindXml, "UTF-8");
        m.setEntity(requestEntity);
      }

      final List<PropFindMethod.Response> responses = new ArrayList<PropFindMethod.Response>();
      ResponseHandler<Integer> respHandler =
          new ResponseHandler<Integer>() {

            @Override
            public Integer handleResponse(HttpResponse response)
                throws ClientProtocolException, IOException {
              if (response.getStatusLine().getStatusCode() == 207) {
                m.buildResponses(response, responses);
              }
              return response.getStatusLine().getStatusCode();
            }
          };
      Integer res = client.execute(m, respHandler);

      Utils.processResultCode(res, url);
      return responses;
    } catch (ConflictException ex) {
      throw new RuntimeException(ex);
    } catch (NotFoundException e) {
      log.trace("not found: " + url);
      return Collections.EMPTY_LIST;
    } catch (HttpException ex) {
      throw new RuntimeException(ex);
    } finally {
      notifyFinishRequest();
    }
  }
Esempio n. 9
0
 /**
  * @param newUri - must be fully qualified and correctly encoded
  * @return
  * @throws com.ettrema.httpclient.HttpException
  */
 public synchronized int doMkCol(String newUri)
     throws com.ettrema.httpclient.HttpException, NotAuthorizedException, ConflictException,
         BadRequestException, NotFoundException, URISyntaxException {
   notifyStartRequest();
   MkColMethod p = new MkColMethod(newUri);
   try {
     HttpResponse resp = host().client.execute(p);
     int result = resp.getStatusLine().getStatusCode();
     if (result == 409) {
       // probably means the folder already exists
       return result;
     }
     Utils.processResultCode(result, newUri);
     return result;
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   } finally {
     notifyFinishRequest();
   }
 }