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

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

Introduction

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

Prototype

int SC_NOT_FOUND

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

Click Source Link

Document

<tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:org.wso2.ei.businessprocess.integration.common.clients.bpmn.ActivitiRestClient.java

/**
 * Method is used to acquire deployment details using the deployment ID
 *
 * @param deploymentID Deployment ID of the BPMN Package
 * @throws java.io.IOException/*  w w  w  .  j  a  v a2 s  .  co  m*/
 * @throws org.json.JSONException
 * @returns String Array with status, deploymentID and Name
 */
public String[] getDeploymentInfoById(String deploymentID)
        throws RestClientException, IOException, JSONException {
    String url = serviceURL + "repository/deployments/" + deploymentID;
    DefaultHttpClient httpClient = getHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpResponse response = httpClient.execute(httpget);
    String status = response.getStatusLine().toString();
    String responseData = EntityUtils.toString(response.getEntity());
    JSONObject jsonResponseObject = new JSONObject(responseData);
    if (status.contains(Integer.toString(HttpStatus.SC_CREATED))
            || status.contains(Integer.toString(HttpStatus.SC_OK))) {
        String depID = jsonResponseObject.getString(ID);
        String name = jsonResponseObject.getString(NAME);
        return new String[] { status, depID, name };
    } else if (status.contains(Integer.toString(HttpStatus.SC_NOT_FOUND))) {
        throw new RestClientException(NOT_AVAILABLE);
    } else {
        throw new RestClientException("Cannot find deployment");
    }
}

From source file:org.wso2.greg.plugin.client.GregManagerClient.java

/**
 * This method will return all registry resources of the given tenant domain
 *//*  w ww. ja v a2 s  .  co m*/
private JSONArray getRegistryResources(String hostName, String port, String resourceType, String userName,
        char[] password, String tenantDomain) throws GregReadyPluginException {

    HttpEntity entity;

    String registryUrl = "https://" + hostName + ":" + port + ResourceConstants.URLS.GOVERNANCE_API_URL;

    if (resourceType.equals(ResourceConstants.RESOURCE_TYPE_WSDL)) {
        registryUrl += ResourceConstants.URLS.RESOURCES_WSDLS;
    } else if (resourceType.equals(ResourceConstants.RESOURCE_TYPE_SWAGGER)) {
        registryUrl += ResourceConstants.URLS.RESOURCE_SWAGGERS;
    }

    if (tenantDomain != null && !tenantDomain.isEmpty()) {
        registryUrl += "?" + ResourceConstants.URLS.TENANT + "=" + tenantDomain;
    }

    HttpGet request = new HttpGet(registryUrl);
    String auth = userName + ":" + String.valueOf(password);
    byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1")));
    String authHeader = "Basic " + new String(encodedAuth);
    request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
    request.setHeader(HttpHeaders.ACCEPT, "application/json");

    HttpClient httpClient = Utils.getHttpClient();
    String responseString;
    HttpResponse response = null;

    try {
        response = httpClient.execute(request);
        entity = response.getEntity();
        responseString = EntityUtils.toString(entity, ResourceConstants.UTF_8);
    } catch (IOException ioEx) {
        log.error("Error occurred while fetch resource list", ioEx);
        throw new GregReadyPluginException("Error occurred while fetch resource list", ioEx);
    }

    if (HttpStatus.SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
        log.info(HelpMessageConstants.NO_RESOURCES_FOUND_MSG);
        throw new GregReadyPluginException(HelpMessageConstants.NO_RESOURCES_FOUND_MSG, null);
    }

    String[] errorSection = responseString.split(",");
    boolean isError = Boolean.parseBoolean(errorSection[0].split(":")[1].split("}")[0].trim());

    if (isError) {
        String errorMsg = errorSection[1].split(":")[1].split("}")[0].trim();
        log.info("Error occurred while getting the list of APIs " + errorMsg);
        throw new GregReadyPluginException("Error occurred while getting the list of Artifacts " + errorMsg);
    }

    JSONObject jsonObject = (JSONObject) JSONValue.parse(responseString);

    // We expect an JSON array for assets list
    JSONArray resourcesArray = (JSONArray) jsonObject.get("assets");
    return resourcesArray;
}

From source file:org.wso2.iot.integration.user.UserManagement.java

@Test(description = "Test getting user roles.", dependsOnMethods = { "testViewUser" })
public void testGetUserRoles() throws Exception {
    String url = Constants.UserManagement.USER_ENDPOINT + "/" + Constants.UserManagement.USER_NAME + "/roles";
    HttpResponse response = client.get(url);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    AssertUtil.jsonPayloadCompare(//from   www  .  j a  v a2 s.c o  m
            PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME,
                    Constants.UserManagement.GET_ROLES_METHOD).toString(),
            response.getData(), true);
    url = Constants.UserManagement.USER_ENDPOINT + "/" + NON_EXISTING_USERNAME + "/roles";
    response = client.get(url);
    Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getResponseCode());
}

From source file:org.wso2.mdm.integration.mobileDevice.OracleMobileDeviceManagement.java

@Test(dependsOnMethods = "addEnrollment", description = "Test response for invalid start record number")
public void testGetDevicesWithInvalidStartNumber() throws Exception {
    MDMResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT + "?start=");
    Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
}

From source file:org.xwiki.test.escaping.framework.AbstractEscapingTest.java

/**
 * Download a page from the server and return its content. Throws a {@link RuntimeException} on connection problems
 * etc./*from  www  .  j  av a2 s .  com*/
 * 
 * @param url URL of the page
 * @return content of the page
 */
protected static URLContent getUrlContent(String url) {
    GetMethod get = new GetMethod(url);
    get.setFollowRedirects(true);
    if (isLoggedIn()) {
        get.setDoAuthentication(true);
        get.addRequestHeader("Authorization",
                "Basic " + new String(Base64.encodeBase64("Admin:admin".getBytes())));
    }

    try {
        int statusCode = AbstractEscapingTest.getClient().executeMethod(get);
        switch (statusCode) {
        case HttpStatus.SC_OK:
            // everything is fine
            break;
        case HttpStatus.SC_UNAUTHORIZED:
            // do not fail on 401 (unauthorized), used in some tests
            System.out.println("WARNING, Ignoring status 401 (unauthorized) for URL: " + url);
            break;
        case HttpStatus.SC_CONFLICT:
            // do not fail on 409 (conflict), used in some templates
            System.out.println("WARNING, Ignoring status 409 (conflict) for URL: " + url);
            break;
        case HttpStatus.SC_NOT_FOUND:
            // ignore 404 (the page is still rendered)
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            // ignore 500 (internal server error), which is used by the standard exception.vm error display
            break;
        default:
            throw new RuntimeException("HTTP GET request returned status " + statusCode + " ("
                    + get.getStatusText() + ") for URL: " + url);
        }

        return new URLContent(get.getResponseHeader("Content-Type").getValue(), get.getResponseBody());
    } catch (IOException exception) {
        throw new RuntimeException("Error retrieving URL: " + url, exception);
    } finally {
        get.releaseConnection();
    }
}

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

protected void putAttachmentFilename(String attachmentName, String type) throws Exception {
    String content = "ATTACHMENT CONTENT";
    String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);

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

    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 = executeGet(attachmentURI);
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());

    Assert.assertEquals(content, getMethod.getResponseBodyAsString());
}

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

@Test
public void testPUTAttachmentNoRights() throws Exception {
    String attachmentName = String.format("%s.txt", UUID.randomUUID());
    String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);

    String content = "ATTACHMENT CONTENT";

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

    PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN);
    Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_UNAUTHORIZED, putMethod.getStatusCode());
}

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.framework.AbstractHttpTest.java

protected boolean createPageIfDoesntExist(List<String> spaces, String pageName, String content)
        throws Exception {
    String uri = buildURI(PageResource.class, getWiki(), spaces, pageName);

    GetMethod getMethod = executeGet(uri);

    if (getMethod.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        createPage(spaces, pageName, content);

        getMethod = executeGet(uri);/*from w  ww .j a v  a 2 s. c  om*/
        Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());

        return true;
    }

    return false;
}

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

@Test
public void testGETNotExistingObject() throws Exception {
    GetMethod getMethod = executeGet(// w  w w.  jav  a 2  s  .c o  m
            buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome", "NOTEXISTING", 0).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
}