Exemple #1
0
    /**
     * Parse the room read response received from reservation backend.
     *
     * <p>This will request the retry if the response status code differs from 200, 201 or 4xx.
     *
     * @param response The Apache HTTP client response
     * @throws IOException
     * @throws ParseException
     * @throws FaultTolerantRESTRequest.RetryRequestedException
     */
    @Override
    protected void parse(HttpResponse response)
        throws IOException, ParseException, FaultTolerantRESTRequest.RetryRequestedException {

      int statusCode = response.getStatusLine().getStatusCode();

      logger.info("STATUS CODE: " + statusCode);

      if (200 == statusCode || 201 == statusCode) {
        // OK
        conference = readConferenceResponse(conference, response);

        result = new ApiResult(statusCode, conference);
      } else if ((statusCode >= 400) && (statusCode < 500)) {
        // Client side error, indicates that the reservation
        // backend do not want the resubmission
        ErrorResponse error = readErrorResponse(response);

        result = new ApiResult(statusCode, error);

      } else {

        // Unusual status code, request the retry
        throw new FaultTolerantRESTRequest.RetryRequestedException();
      }
    }
Exemple #2
0
 private boolean fetchApp(String url, String username, String password) throws JSONException {
   try {
     if (username == "null") {
       username = null;
     }
     if (password == "null") {
       password = null;
     }
     HttpResponse response = makeRequest(url, username, password);
     StatusLine sl = response.getStatusLine();
     int code = sl.getStatusCode();
     HttpEntity entity = response.getEntity();
     InputStream content = entity.getContent();
     if (code != 200) {
       return false;
     } else {
       ZipInputStream data = new ZipInputStream(content);
       return saveAndVerify(data);
     }
   } catch (ClientProtocolException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return false;
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return false;
   }
 }
 public Result<InputStream> getInputStream(String endpoint) throws IOException {
   HttpClient cli = createClient();
   HttpGet get = createGet(endpoint);
   HttpResponse res = cli.execute(get);
   Object result = null;
   if (res.getStatusLine().getStatusCode() == 200) result = res.getEntity().getContent();
   else {
     RestResponse resp = new RestResponse(res);
     result = unmarshalPOJO(resp, InputStream.class);
     cli.getConnectionManager().shutdown();
   }
   return new Result<InputStream>(result);
 }
 /**
  * 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();
   }
 }
 /**
  * @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();
   }
 }