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:org.xwiki.test.rest.PageTranslationResourceTest.java

@Test
public void testPUTGETDELETETranslation() throws Exception {
    Page newPage = this.objectFactory.createPage();
    newPage.setTitle("fr titre");
    newPage.setContent("fr contenue");
    newPage.setLanguage(Locale.FRENCH.toString());

    assertFalse(this.testUtils.rest().exists(this.referenceDefault));

    String uri = buildURI(PageTranslationResource.class, getWiki(), this.spaces, this.pageName, Locale.FRENCH)
            .toString();//from   ww  w  .  j a  v a 2  s  .c om

    // PUT
    PutMethod putMethod = executePutXml(uri, newPage, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(),
            TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
    assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
    Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());

    assertEquals("fr titre", modifiedPage.getTitle());
    assertEquals("fr contenue", modifiedPage.getContent());
    assertEquals(Locale.FRENCH.toString(), modifiedPage.getLanguage());

    assertTrue(this.testUtils.rest().exists(this.referenceFR));
    assertFalse(this.testUtils.rest().exists(this.referenceDefault));

    // GET
    GetMethod getMethod = executeGet(uri);
    assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());

    assertEquals("fr titre", modifiedPage.getTitle());
    assertEquals("fr contenue", modifiedPage.getContent());
    assertEquals(Locale.FRENCH.toString(), modifiedPage.getLanguage());

    // DELETE
    DeleteMethod deleteMethod = executeDelete(uri, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(),
            TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
    assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode());

    assertFalse(this.testUtils.rest().exists(this.referenceDefault));
    assertFalse(this.testUtils.rest().exists(this.referenceFR));
}

From source file:org.zenoss.zep.rest.EventsResourceIT.java

@Test
public void testUpdateEventSummary() throws ZepException, IOException {
    List<String> uuids = new ArrayList<String>(100);
    for (int i = 0; i < 100; i++) {
        uuids.add(createSummaryNew(EventSummaryDaoImplIT.createUniqueEvent()).getUuid());
    }//from w w w.j a v  a  2  s.c  o  m

    // Update first 50
    EventStatus status = EventStatus.STATUS_ACKNOWLEDGED;
    String ackUuid = UUID.randomUUID().toString();
    String ackName = "testuser123";

    EventQuery.Builder queryBuilder = EventQuery.newBuilder();
    queryBuilder.setEventFilter(EventFilter.newBuilder().addAllUuid(uuids).build());
    EventQuery query = queryBuilder.build();
    RestResponse restResponse = client.postProtobuf(EVENTS_URI + "/search", query);
    assertEquals(HttpStatus.SC_CREATED, restResponse.getResponseCode());
    String location = restResponse.getHeaders().get("location").get(0);
    String query_uuid = location.substring(location.lastIndexOf('/') + 1);

    final EventSummaryUpdate updateFields = EventSummaryUpdate.newBuilder().setCurrentUserUuid(ackUuid)
            .setCurrentUserName(ackName).setStatus(status).build();
    EventSummaryUpdateRequest.Builder reqBuilder = EventSummaryUpdateRequest.newBuilder();
    reqBuilder.setLimit(50);
    reqBuilder.setUpdateFields(updateFields);
    EventSummaryUpdateRequest req = reqBuilder.build();
    restResponse.getResponse().getEntity().consumeContent();

    restResponse = client.putProtobuf(location, req);
    EventSummaryUpdateResponse response = (EventSummaryUpdateResponse) restResponse.getMessage();
    assertEquals(EventSummaryUpdateRequest.newBuilder(req).setOffset(50).setEventQueryUuid(query_uuid).build(),
            response.getNextRequest());
    assertEquals(uuids.size(), response.getTotal());
    assertEquals(50, response.getUpdated());

    // Repeat request for last 50
    restResponse = client.putProtobuf(location, response.getNextRequest());
    EventSummaryUpdateResponse newResponse = (EventSummaryUpdateResponse) restResponse.getMessage();
    assertFalse(newResponse.hasNextRequest());
    assertEquals(50, response.getUpdated());
    assertEquals(uuids.size(), response.getTotal());

    assertEquals(HttpStatus.SC_NO_CONTENT, client.delete(location).getResponseCode());
    assertEquals(HttpStatus.SC_NOT_FOUND, client.getProtobuf(location).getResponseCode());

    // Verify updates hit the database
    List<EventSummary> summaries = summaryDao.findByUuids(uuids);
    assertEquals(uuids.size(), summaries.size());
    for (EventSummary summary : summaries) {
        assertEquals(status, summary.getStatus());
        assertEquals(ackUuid, summary.getCurrentUserUuid());
        assertEquals(ackName, summary.getCurrentUserName());
    }
}

From source file:org.zenoss.zep.rest.EventsResourceIT.java

@Test
public void testUpdateEventSummaryExclusions() throws ZepException, IOException {
    long firstSeen = System.currentTimeMillis();
    TimestampRange firstSeenRange = TimestampRange.newBuilder().setStartTime(firstSeen).setEndTime(firstSeen)
            .build();//from ww w .  j av a2 s .c o  m
    Set<String> uuids = new HashSet<String>();
    Map<String, EventSummary> excludedUuids = new HashMap<String, EventSummary>();
    for (int i = 0; i < 5; i++) {
        Event event = Event.newBuilder(EventSummaryDaoImplIT.createUniqueEvent()).setCreatedTime(firstSeen)
                .build();
        EventSummary summary = createSummaryNew(event);
        if ((i % 2) == 0) {
            uuids.add(summary.getUuid());
        } else {
            excludedUuids.put(summary.getUuid(), summary);
        }
    }

    EventQuery.Builder queryBuilder = EventQuery.newBuilder();
    queryBuilder.setEventFilter(EventFilter.newBuilder().addFirstSeen(firstSeenRange).build());
    queryBuilder.setExclusionFilter(EventFilter.newBuilder().addAllUuid(excludedUuids.keySet()).build());
    EventQuery query = queryBuilder.build();
    RestResponse restResponse = client.postProtobuf(EVENTS_URI + "/search", query);
    assertEquals(HttpStatus.SC_CREATED, restResponse.getResponseCode());
    String location = restResponse.getHeaders().get("location").get(0);
    restResponse.getResponse().getEntity().consumeContent();

    // Update first 10
    EventStatus status = EventStatus.STATUS_ACKNOWLEDGED;
    String ackUuid = UUID.randomUUID().toString();
    String ackName = "testuser123";

    final EventSummaryUpdate updateFields = EventSummaryUpdate.newBuilder().setCurrentUserUuid(ackUuid)
            .setCurrentUserName(ackName).setStatus(status).build();
    EventSummaryUpdateRequest.Builder reqBuilder = EventSummaryUpdateRequest.newBuilder();
    reqBuilder.setLimit(10);
    reqBuilder.setUpdateFields(updateFields);
    EventSummaryUpdateRequest req = reqBuilder.build();

    EventSummaryUpdateResponse response = (EventSummaryUpdateResponse) client.putProtobuf(location, req)
            .getMessage();
    assertFalse(response.hasNextRequest());
    assertEquals(uuids.size(), response.getUpdated());
    assertEquals(uuids.size(), response.getTotal());

    assertEquals(HttpStatus.SC_NO_CONTENT, client.delete(location).getResponseCode());
    assertEquals(HttpStatus.SC_NOT_FOUND, client.getProtobuf(location).getResponseCode());

    // Verify updates hit the database
    List<String> allUuids = new ArrayList<String>();
    allUuids.addAll(uuids);
    allUuids.addAll(excludedUuids.keySet());
    List<EventSummary> summaries = summaryDao.findByUuids(allUuids);
    assertEquals(allUuids.size(), summaries.size());
    for (EventSummary summary : summaries) {
        if (uuids.contains(summary.getUuid())) {
            assertEquals(status, summary.getStatus());
            assertEquals(ackUuid, summary.getCurrentUserUuid());
            assertEquals(ackName, summary.getCurrentUserName());
        } else {
            // Excluded UUIDs shouldn't have changed
            assertEquals(excludedUuids.get(summary.getUuid()), summary);
        }
    }
}

From source file:pt.webdetails.cns.notifications.sparkl.SparklEndpointEventHandler.java

protected boolean sendToKtrEndpoint(INotificationEvent event) {

    final String COMMA = ",";

    if (StringUtils.isEmpty(getKtrEndpoint())) {
        logger.error("ktrEndpoint is null");
        return false;
    } else if (event == null) {
        logger.error("event is null");
        return false;
    }//from   ww  w .j a va2s  .c om

    try {

        String commaSeparatedRecipientList = null;
        String eventSubType = null;

        switch (event.getRecipientType()) {

        case ALL:
            commaSeparatedRecipientList = StringUtils.join(SessionUtils.getAllUsers(), COMMA);
            break;

        case ROLE:
            eventSubType = event.getRecipient();
            commaSeparatedRecipientList = StringUtils.join(SessionUtils.getUsersInRole(event.getRecipient()),
                    COMMA);
            break;

        default:
            /* USER */
            commaSeparatedRecipientList = event.getRecipient();
        }

        Response r = HttpConnectionHelper.invokeEndpoint("cns", ktrEndpoint, "GET",
                toKtrParamMap(event, commaSeparatedRecipientList, eventSubType));

        return r != null
                && (HttpStatus.SC_OK == r.getStatusCode() || HttpStatus.SC_NO_CONTENT == r.getStatusCode());

    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        return false;
    }
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testCorrectlyCreateBucketOnPutThenRemoveAndCreateBucketAgain() throws Exception {
    // Do not change the bucket name: it is required to ensure operations will be executed on the expected node!
    String bucket = "bucket1";
    ////  w ww.j a va2s  . c o  m

    TestValue value = new TestValue("value", 1);

    // This will be executed on node 1:
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();

    // This will be executed on node 2:
    DeleteMethod deleteBucket = makeDeleteMethod(NODE2_PORT, bucket);
    HTTP_CLIENT.executeMethod(deleteBucket);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    deleteBucket.releaseConnection();

    // This will be executed on node 1:
    GetMethod getBuckets = makeGetMethod(NODE1_PORT, "");
    HTTP_CLIENT.executeMethod(getBuckets);
    assertEquals(HttpStatus.SC_OK, getBuckets.getStatusCode());
    assertTrue(getBuckets.getResponseBodyAsString().indexOf(bucket) == -1);
    getBuckets.releaseConnection();

    // This will be executed on node 1:
    putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();

    // This will be executed on node 1:
    getBuckets = makeGetMethod(NODE1_PORT, "");
    HTTP_CLIENT.executeMethod(getBuckets);
    assertEquals(HttpStatus.SC_OK, getBuckets.getStatusCode());
    assertTrue(getBuckets.getResponseBodyAsString().indexOf(bucket) > -1);
    getBuckets.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testPutValueAndGetOnOtherNode() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();/*w w w  . j a  v a 2  s.  c o m*/

    GetMethod getValue = makeGetMethod(NODE2_PORT, bucket + "/value");
    HTTP_CLIENT.executeMethod(getValue);
    assertEquals(HttpStatus.SC_OK, getValue.getStatusCode());
    TestValue returned = fromJsonToObject(getValue.getResponseBodyAsString());
    assertEquals(value, returned);
    getValue.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testPutValueAndConditionallyGetWithSuccess() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();/*  w  w w.j a  va  2 s . c  o m*/

    GetMethod getValue = makeGetMethodWithPredicate(NODE2_PORT, bucket + "/value",
            "jxpath:/stringField[.='value']");
    HTTP_CLIENT.executeMethod(getValue);
    assertEquals(HttpStatus.SC_OK, getValue.getStatusCode());
    TestValue returned = fromJsonToObject(getValue.getResponseBodyAsString());
    assertEquals(value, returned);
    getValue.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testPutValueAndConditionallyGetNotFound() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();/*from w w  w  .ja v  a 2 s.  co  m*/

    GetMethod getValue = makeGetMethodWithPredicate(NODE2_PORT, bucket + "/value",
            "jxpath:/stringField[.='wrong']");
    HTTP_CLIENT.executeMethod(getValue);
    assertEquals(HttpStatus.SC_NOT_FOUND, getValue.getStatusCode());
    getValue.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testPutValueAndConditionallyPutAgainWithSuccess() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value1", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();/* w w  w  .j a  va2s.c  o m*/

    TestValue newValue = new TestValue("value2", 1);
    PutMethod conditionallyPutValue = makePutMethodWithPredicate(NODE1_PORT, bucket + "/value",
            "jxpath:/stringField[.='value1']");
    conditionallyPutValue
            .setRequestEntity(new StringRequestEntity(fromObjectToJson(newValue), "application/json", null));
    HTTP_CLIENT.executeMethod(conditionallyPutValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, conditionallyPutValue.getStatusCode());
    conditionallyPutValue.releaseConnection();

    GetMethod getValue = makeGetMethod(NODE2_PORT, bucket + "/value");
    HTTP_CLIENT.executeMethod(getValue);
    assertEquals(HttpStatus.SC_OK, getValue.getStatusCode());
    TestValue returned = fromJsonToObject(getValue.getResponseBodyAsString());
    assertEquals(newValue, returned);
    getValue.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testPutValueAndConditionallyPutAgainWithConflict() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value1", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();/*  w  w  w.j  av a  2 s  .co  m*/

    TestValue newValue = new TestValue("value2", 1);
    PutMethod conditionallyPutValue = makePutMethodWithPredicate(NODE1_PORT, bucket + "/value",
            "jxpath:/stringField[.='wrong']");
    conditionallyPutValue
            .setRequestEntity(new StringRequestEntity(fromObjectToJson(newValue), "application/json", null));
    HTTP_CLIENT.executeMethod(conditionallyPutValue);
    assertEquals(HttpStatus.SC_CONFLICT, conditionallyPutValue.getStatusCode());
    conditionallyPutValue.releaseConnection();

    GetMethod getValue = makeGetMethod(NODE2_PORT, bucket + "/value");
    HTTP_CLIENT.executeMethod(getValue);
    assertEquals(HttpStatus.SC_OK, getValue.getStatusCode());
    TestValue returned = fromJsonToObject(getValue.getResponseBodyAsString());
    assertEquals(value, returned);
    getValue.releaseConnection();
}