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.wso2.carbon.appfactory.git.repository.provider.GithubRepositoryProvider.java

@Override
public void provisionUser(String applicationKey, String username) throws RepositoryMgtException {

    if (!isUserRegisteredInGit(username)) {
        String msg = "User:" + username + " account is not registered with github.";
        log.error(msg);/* w  w  w  .ja v a 2s . co  m*/
        throw new RepositoryMgtException(msg);
    }
    String teamName = "team_" + applicationKey;
    String teamId = getTeamId(teamName);
    if (teamId == null) {
        String msg = "Team is not created for application:" + applicationKey + " in github.";
        log.error(msg);
        throw new RepositoryMgtException(msg);
    }
    HttpClient client = new HttpClient();
    PutMethod put = new PutMethod("https://api.github.com/teams/" + teamId + "/members/" + username);

    put.setDoAuthentication(true);
    put.addRequestHeader("Authorization", "Basic " + githubAuthtoken);

    try {
        client.executeMethod(put);
        log.debug("HTTP status " + put.getStatusCode() + " creating repo\n\n");

        if (put.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
            log.debug("Repository creation successful");
        } else {
            String msg = "provisioning user:" + username + " is failed for" + applicationKey
                    + "Server returned status:" + put.getStatusCode();
            log.error(msg);
            throw new RepositoryMgtException(msg);
        }

    } catch (IOException e) {
        String msg = "Error while invoking gitHub API";
        log.error(msg, e);
        throw new RepositoryMgtException(msg, e);
    } finally {
        put.releaseConnection();
    }
}

From source file:org.wso2.carbon.appfactory.s4.integration.StratosRestService.java

public void addTenant(String admin, String firstName, String lastName, String password, String domain,
        String email) throws AppFactoryException {
    HttpClient httpClient = getNewHttpClient();
    try {//from   www .  ja  va 2  s  .com
        TenantInfoBean tenantInfo = new TenantInfoBean();
        tenantInfo.setAdmin(admin);
        tenantInfo.setFirstname(firstName);
        tenantInfo.setLastname(lastName);
        tenantInfo.setAdminPassword(password);
        tenantInfo.setTenantDomain(domain);
        tenantInfo.setEmail(email);

        GsonBuilder gsonBuilder = new GsonBuilder();
        Gson gson = gsonBuilder.create();

        String jsonString = gson.toJson(tenantInfo, TenantInfoBean.class);
        String completeJsonString = "{\"tenantInfoBean\":" + jsonString + "}";

        DomainMappingResponse response = doPost(httpClient, this.stratosManagerURL + ADD_TENANT_END_POINT,
                completeJsonString);

        if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            log.error("Authorization failed for the operation");
            return;
        } else if (response.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
            log.debug("Tenant added successfully");
            return;
        } else if (response.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
            log.error("Error occurred while adding tenant," + "server returned  " + response.getStatusCode());
            return;
        } else {
            System.out.println("Unhandle error");
            return;
        }

    } catch (Exception e) {
        log.error(e);
        handleException("Exception in creating tenant", e);
    }
}

From source file:org.wso2.carbon.automation.extensions.servers.httpserver.TestRequestHandler.java

private void writeContent(HttpRequest request, HttpResponse response) {
    // Check for edge cases as stated in the HTTP specs
    if ("HEAD".equals(request.getRequestLine().getMethod()) || statusCode == HttpStatus.SC_NO_CONTENT
            || statusCode == HttpStatus.SC_RESET_CONTENT || statusCode == HttpStatus.SC_NOT_MODIFIED) {
        return;/*  w  ww.ja va2  s  .c  o m*/
    }
    EntityTemplate body = createEntity();
    body.setContentType(contentType);
    response.setEntity(body);
}

From source file:org.wso2.carbon.device.mgt.iot.services.firealarm.FireAlarmControllerService.java

@Path("/readcontrols/{owner}/{deviceId}")
@GET/*from  ww w . j av  a 2s.c  o m*/
public String readControls(@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
        @Context HttpServletResponse response) {
    String result = null;
    LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);

    if (deviceControlList == null) {
        result = "No controls have been set for device " + deviceId + " of owner " + owner;
        response.setStatus(HttpStatus.SC_NO_CONTENT);
    } else {
        try {
            result = deviceControlList.remove();
            response.setStatus(HttpStatus.SC_ACCEPTED);
            response.addHeader("Control", result);
        } catch (NoSuchElementException ex) {
            result = "There are no more controls for device " + deviceId + " of owner " + owner;
            response.setStatus(HttpStatus.SC_NO_CONTENT);
        }
    }
    log.info(result);
    return result;
}

From source file:org.wso2.carbon.identity.provisioning.connector.salesforce.SalesforceProvisioningConnector.java

/**
 * @param provsionedId/* w  ww .  j a  v  a  2  s.co  m*/
 * @param entity
 * @return
 * @throws IdentityProvisioningException
 */
private void update(String provsionedId, JSONObject entity) throws IdentityProvisioningException {

    boolean isDebugEnabled = log.isDebugEnabled();

    try {

        PostMethod patch = new PostMethod(this.getUserObjectEndpoint() + provsionedId) {
            @Override
            public String getName() {
                return "PATCH";
            }
        };

        setAuthorizationHeader(patch);
        patch.setRequestEntity(new StringRequestEntity(entity.toString(), "application/json", null));

        try {
            HttpClient httpclient = new HttpClient();
            httpclient.executeMethod(patch);
            if (patch.getStatusCode() == HttpStatus.SC_OK
                    || patch.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
                if (isDebugEnabled) {

                    log.debug(
                            "HTTP status " + patch.getStatusCode() + " updating user " + provsionedId + "\n\n");
                }
            } else {
                log.error("recieved response status code :" + patch.getStatusCode() + " text : "
                        + patch.getStatusText());
                if (isDebugEnabled) {
                    log.debug("Error response : " + readResponse(patch));
                }
            }

        } catch (IOException e) {
            log.error("Error in invoking provisioning request");
            throw new IdentityProvisioningException(e);
        } finally {
            patch.releaseConnection();
        }

    } catch (UnsupportedEncodingException e) {
        log.error("Error in encoding provisioning request");
        throw new IdentityProvisioningException(e);
    }
}

From source file:org.wso2.carbon.identity.provisioning.connector.sample.SampleProvisioningConnector.java

/**
 * /*from www .j  a  v  a2  s .c  o  m*/
 * @param provsionedId
 * @param entity
 * @return
 * @throws IdentityProvisioningException
 */
private void update(String provsionedId, JSONObject entity) throws IdentityProvisioningException {

    boolean isDebugEnabled = log.isDebugEnabled();

    try {

        PostMethod patch = new PostMethod(this.getUserObjectEndpoint() + provsionedId) {
            @Override
            public String getName() {
                return "PATCH";
            }
        };

        setAuthorizationHeader(patch);
        patch.setRequestEntity(new StringRequestEntity(entity.toString(), "application/json", null));

        try {
            HttpClient httpclient = new HttpClient();
            httpclient.executeMethod(patch);
            if (patch.getStatusCode() == HttpStatus.SC_OK
                    || patch.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
                if (isDebugEnabled) {

                    log.debug(
                            "HTTP status " + patch.getStatusCode() + " updating user " + provsionedId + "\n\n");
                }
            } else {
                log.error("recieved response status code :" + patch.getStatusCode() + " text : "
                        + patch.getStatusText());
                if (isDebugEnabled) {
                    log.debug("Error response : " + readResponse(patch));
                }
            }

        } catch (HttpException e) {
            log.error("Error in invoking provisioning request");
            throw new IdentityProvisioningException(e);
        } catch (IOException e) {
            log.error("Error in invoking provisioning request");
            throw new IdentityProvisioningException(e);
        } finally {
            patch.releaseConnection();
        }

    } catch (UnsupportedEncodingException e) {
        log.error("Error in encoding provisioning request");
        throw new IdentityProvisioningException(e);
    }
}

From source file:org.xwiki.test.rest.AttachmentsResourceTest.java

@Before
public void setUp() throws Exception {
    super.setUp();

    this.wikiName = getWiki();
    this.spaces = Arrays.asList(getTestClassName());
    this.pageName = getTestMethodName();

    // Create a clean test page.
    DeleteMethod deleteMethod = executeDelete(buildURIForThisPage(PageResource.class),
            TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT,
            deleteMethod.getStatusCode());
    createPage(this.spaces, this.pageName, "");
}

From source file:org.xwiki.test.rest.AttachmentsResourceTest.java

@Test
public void testDELETEAttachment() throws Exception {
    String attachmentName = String.format("%d.txt", System.currentTimeMillis());
    String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);
    String content = "ATTACHMENT CONTENT";

    PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN,
            TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());

    GetMethod getMethod = executeGet(attachmentURI);
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());

    DeleteMethod deleteMethod = executeDelete(attachmentURI, TestUtils.ADMIN_CREDENTIALS.getUserName(),
            TestUtils.ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT,
            deleteMethod.getStatusCode());

    getMethod = executeGet(attachmentURI);
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
}

From source file:org.xwiki.test.rest.ObjectsResourceTest.java

@Test
public void testDELETEObject() throws Exception {
    Object objectToBeDeleted = createObjectIfDoesNotExists("XWiki.TagClass", MAIN_SPACE, "WebHome");

    DeleteMethod deleteMethod = executeDelete(
            buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome", objectToBeDeleted.getClassName(),
                    objectToBeDeleted.getNumber()).toString(),
            TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT,
            deleteMethod.getStatusCode());

    GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome",
            objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
}

From source file:org.xwiki.test.rest.PageResourceTest.java

@Test
public void testDELETEPage() throws Exception {
    final String pageName = String.format("Test-%d", random.nextLong());

    createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, pageName, "Test page");

    DeleteMethod deleteMethod = executeDelete(
            buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, pageName).toString(),
            TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT,
            deleteMethod.getStatusCode());

    GetMethod getMethod = executeGet(//from w w w  .  j  a  v a2  s  .  co  m
            buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, pageName).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
}