Java Code Examples for org.jclouds.http.HttpResponse#getStatusCode()

The following examples show how to use org.jclouds.http.HttpResponse#getStatusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HookSettingsParser.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
@Override
public HookSettings apply(final HttpResponse input) {
    final int statusCode = input.getStatusCode();
    try {
        final String payload;
        switch (statusCode) {
            case 200: // means we have actual settings
                payload = Strings2.toStringAndClose(input.getPayload().openStream());
                break;
            case 204: // means we have no settings
                payload = null;
                break;
            default:
                throw new RuntimeException(input.getStatusLine());
        }
        final JsonElement settings = BitbucketUtils.nullToJsonElement(payload);
        return HookSettings.of(settings);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
 
Example 2
Source File: GenerateTempURL.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private void generatePutTempURL() throws IOException {
   System.out.format("Generate PUT Temp URL%n");

   // Create the Payload
   String data = "This object will be public for 10 minutes.";
   ByteSource source = ByteSource.wrap(data.getBytes());
   Payload payload = Payloads.newByteSourcePayload(source);

   // Create the Blob
   Blob blob = blobStore.blobBuilder(FILENAME).payload(payload).contentType("text/plain").build();
   HttpRequest request = blobStoreContext.getSigner(REGION).signPutBlob(CONTAINER, blob, TEN_MINUTES);

   System.out.format("  %s %s%n", request.getMethod(), request.getEndpoint());

   // PUT the file using jclouds
   HttpResponse response = blobStoreContext.utils().http().invoke(request);
   int statusCode = response.getStatusCode();

   if (statusCode >= 200 && statusCode < 299) {
      System.out.format("  PUT Success (%s)%n", statusCode);
   }
   else {
      throw new HttpResponseException(null, response);
   }
}
 
Example 3
Source File: GenerateTempURL.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private void generateDeleteTempURL() throws IOException {
   System.out.format("Generate DELETE Temp URL%n");

   HttpRequest request = blobStoreContext.getSigner(REGION).signRemoveBlob(CONTAINER, FILENAME);

   System.out.format("  %s %s%n", request.getMethod(), request.getEndpoint());

   // DELETE the file using jclouds
   HttpResponse response = blobStoreContext.utils().http().invoke(request);
   int statusCode = response.getStatusCode();

   if (statusCode >= 200 && statusCode < 299) {
      System.out.format("  DELETE Success (%s)%n", statusCode);
   }
   else {
      throw new HttpResponseException(null, response);
   }
}
 
Example 4
Source File: RequestStatusParser.java    From jenkins-rest with Apache License 2.0 5 votes vote down vote up
@Override
public RequestStatus apply(final HttpResponse input) {
    final int statusCode = input.getStatusCode();
    if (statusCode >= 200 && statusCode < 400) {
        return RequestStatus.create(true, null);
    } else {
        throw new RuntimeException(input.getStatusLine());
    }
}
 
Example 5
Source File: SystemInfoFromJenkinsHeaders.java    From jenkins-rest with Apache License 2.0 5 votes vote down vote up
@Override
public SystemInfo apply(HttpResponse response) {
    final int statusCode = response.getStatusCode();
    if (statusCode >= 200 && statusCode < 400) {
        return SystemInfo.create(response.getFirstHeaderOrNull("X-Hudson"), response.getFirstHeaderOrNull("X-Jenkins"),
            response.getFirstHeaderOrNull("X-Jenkins-Session"),
            response.getFirstHeaderOrNull("X-Instance-Identity"), response.getFirstHeaderOrNull("X-SSH-Endpoint"),
            response.getFirstHeaderOrNull("Server"), null);
    } else {
        throw new RuntimeException(response.getStatusLine());
    }
}
 
Example 6
Source File: CrumbParser.java    From jenkins-rest with Apache License 2.0 5 votes vote down vote up
@Override
public Crumb apply(final HttpResponse input) {
    final int statusCode = input.getStatusCode();
    if (statusCode >= 200 && statusCode < 400) {
        try {
            return Crumb.create(crumbValue(input), sessionIdCookie(input));
        } catch (final IOException e) {
            throw new RuntimeException(input.getStatusLine(), e);
        }
    } else {
        throw new RuntimeException(input.getStatusLine());
    }
}
 
Example 7
Source File: RequestStatusParser.java    From bitbucket-rest with Apache License 2.0 5 votes vote down vote up
@Override
public RequestStatus apply(final HttpResponse input) {
    final int statusCode = input.getStatusCode();
    if (statusCode >= 200 && statusCode < 400) {
        return RequestStatus.create(true, null);
    } else {
        throw new RuntimeException(input.getStatusLine());
    }
}
 
Example 8
Source File: DeleteRepositoryParser.java    From bitbucket-rest with Apache License 2.0 5 votes vote down vote up
@Override
public RequestStatus apply(final HttpResponse input) {
    final int statusCode = input.getStatusCode();
    if (statusCode >= 200 && statusCode < 400) {
        if (statusCode == 204) {
            throw new ResourceNotFoundException("The repository does not exist in this project.");
        } else {
            return RequestStatus.create(true, null);
        }
    } else {
        throw new RuntimeException(input.getStatusLine());
    }
}