Example usage for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT

List of usage examples for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT.

Prototype

int SC_NO_CONTENT

To view the source code for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT.

Click Source Link

Document

<tt>204 No Content</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:com.cloud.network.brocade.BrocadeVcsApiTest.java

@Test
public void testCreateNetwork() throws BrocadeVcsApiException, IOException {
    // Prepare//from   w ww.j a  v  a  2s  .  c  o  m

    method = mock(HttpPatch.class);

    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(response.getStatusLine()).thenReturn(statusLine);

    // Execute
    api.createNetwork(VLAN_ID, NETWORK_ID);

    // Assert
    verify(method, times(6)).releaseConnection();
    assertEquals("Wrong URI for Network creation REST service", Constants.URI, uri);
    assertEquals("Wrong HTTP method for Network creation REST service", "patch", type);
}

From source file:com.zimbra.cs.store.http.HttpStoreManager.java

@Override
public boolean deleteFromStore(String locator, Mailbox mbox) throws IOException {
    HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
    DeleteMethod delete = new DeleteMethod(getDeleteUrl(mbox, locator));
    try {/*from   w  w  w.ja v a 2  s .co  m*/
        int statusCode = HttpClientUtil.executeMethod(client, delete);
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) {
            return true;
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return false;
        } else {
            throw new IOException("unexpected return code during blob DELETE: " + delete.getStatusText());
        }
    } finally {
        delete.releaseConnection();
    }
}

From source file:com.cloud.network.brocade.BrocadeVcsApiTest.java

@Test
public void testDeleteNetwork() throws BrocadeVcsApiException, IOException {
    // Prepare//from w w w .j av a  2s  .  co m

    method = mock(HttpPatch.class);

    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(response.getStatusLine()).thenReturn(statusLine);

    // Execute
    api.deleteNetwork(VLAN_ID, NETWORK_ID);

    // Assert
    verify(method, times(3)).releaseConnection();
    assertEquals("Wrong URI for Network creation REST service", Constants.URI, uri);
    assertEquals("Wrong HTTP method for Network creation REST service", "patch", type);
}

From source file:com.cerema.cloud2.lib.resources.files.UploadRemoteFileOperation.java

public boolean isSuccess(int status) {
    return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED
            || status == HttpStatus.SC_NO_CONTENT));
}

From source file:com.cloud.network.brocade.BrocadeVcsApiTest.java

@Test
public void testAssociateMacToNetwork() throws BrocadeVcsApiException, IOException {
    // Prepare/*w ww  .j  ava  2s  .  c om*/

    method = mock(HttpPatch.class);

    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(response.getStatusLine()).thenReturn(statusLine);

    // Execute
    api.associateMacToNetwork(NETWORK_ID, MAC_ADDRESS_32);

    // Assert
    verify(method, times(1)).releaseConnection();
    assertEquals("Wrong URI for Network creation REST service", Constants.URI, uri);
    assertEquals("Wrong HTTP method for Network creation REST service", "patch", type);
}

From source file:com.worldline.easycukes.rest.client.JerseyClientHelper.java

/**
 * Convert the reponse got from a REST call to bean wrapper
 *
 * @param response the response got from a REST call
 * @return a {@link ClientResponse} containing the results of the REST call
 *//*ww w .  ja va  2s.co m*/
private static ResponseWrapper toResponseWrapper(@NonNull final ClientResponse response) {
    String responseString = null;
    if (response != null && response.getStatus() != HttpStatus.SC_NO_CONTENT) {
        responseString = response.getEntity(String.class);
    }
    return new ResponseWrapper(responseString, response.getStatus());
}

From source file:com.cloud.network.brocade.BrocadeVcsApiTest.java

@Test
public void testDisassociateMacFromNetwork() throws BrocadeVcsApiException, IOException {
    // Prepare/*from  www  .j  a v  a  2s. c  om*/

    method = mock(HttpPatch.class);

    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(response.getStatusLine()).thenReturn(statusLine);

    // Execute
    api.disassociateMacFromNetwork(NETWORK_ID, MAC_ADDRESS_32);

    // Assert
    verify(method, times(1)).releaseConnection();
    assertEquals("Wrong URI for Network creation REST service", Constants.URI, uri);
    assertEquals("Wrong HTTP method for Network creation REST service", "patch", type);
}

From source file:com.gisgraphy.rest.RestClient.java

private int executeAndCheckStatusCode(HttpMethod httpMethod)
        throws IOException, HttpException, RestClientException {
    int statusCode = httpClient.executeMethod(httpMethod);
    if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED
            && statusCode != HttpStatus.SC_NO_CONTENT) {
        throw new RestClientException(statusCode, "restclient exception for " + httpMethod.getURI() + " : "
                + statusCode + ", " + HttpStatus.getStatusText(statusCode));
    }/* w w  w .ja  v  a2 s. c  om*/
    return statusCode;
}

From source file:com.kodokux.github.api.GithubApiUtil.java

private static void checkStatusCode(@NotNull HttpMethod method) throws IOException {
    int code = method.getStatusCode();
    switch (code) {
    case HttpStatus.SC_OK:
    case HttpStatus.SC_CREATED:
    case HttpStatus.SC_ACCEPTED:
    case HttpStatus.SC_NO_CONTENT:
        return;/* w w w . j a v  a  2s.  co m*/
    case HttpStatus.SC_BAD_REQUEST:
    case HttpStatus.SC_UNAUTHORIZED:
    case HttpStatus.SC_PAYMENT_REQUIRED:
    case HttpStatus.SC_FORBIDDEN:
        String message = getErrorMessage(method);
        if (message.contains("API rate limit exceeded")) {
            throw new GithubRateLimitExceededException(message);
        }
        throw new GithubAuthenticationException("Request response: " + message);
    default:
        throw new GithubStatusCodeException(code + ": " + getErrorMessage(method), code);
    }
}

From source file:com.cerema.cloud2.lib.resources.files.CopyRemoteFileOperation.java

protected boolean isSuccess(int status) {
    return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT;
}