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.olat.admin.registration.SystemRegistrationManager.java

/**
 * Send the registration data now. If the user configured nothing to send, nothing will be sent.
 *///from   w w w.  j  a  v  a 2 s .c o m
public void sendRegistrationData() {
    // Do it optimistic and try to generate the XML message. If the message
    // doesn't contain anything, the user does not want to register this
    // instance
    final String registrationData = getRegistrationPropertiesMessage(null);
    String registrationKey = persitedProperties.getStringPropertyValue(CONF_SECRETKEY, false);
    if (StringHelper.containsNonWhitespace(registrationData)) {
        // only send when there is something to send
        final HttpClient client = HttpClientFactory.getHttpClientInstance();
        client.getParams().setParameter("http.useragent", "OLAT Registration Agent ; " + VERSION);
        final String url = REGISTRATION_SERVER
                + persitedProperties.getStringPropertyValue(CONF_KEY_IDENTIFYER, false) + "/";
        logInfo("URL:" + url, null);
        final PutMethod method = new PutMethod(url);
        if (registrationKey != null) {
            // updating
            method.setRequestHeader("Authorization", registrationKey);
            if (isLogDebugEnabled()) {
                logDebug("Authorization: " + registrationKey, null);
            } else {
                logDebug("Authorization: EXISTS", null);
            }
        } else {
            logInfo("Authorization: NONE", null);
        }
        method.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
        try {
            method.setRequestEntity(new StringRequestEntity(registrationData, "application/xml", "UTF8"));
            client.executeMethod(method);
            final int status = method.getStatusCode();
            if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
                logInfo("Successfully registered OLAT installation on olat.org server, thank you for your support!",
                        null);
                registrationKey = method.getResponseBodyAsString();
                persitedProperties.setStringProperty(CONF_SECRETKEY, registrationKey, false);
                persitedProperties.savePropertiesAndFireChangedEvent();
            } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                logError("File could be created not on registration server::"
                        + method.getStatusLine().toString(), null);
            } else if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
                logInfo(method.getResponseBodyAsString(), method.getStatusText());
            } else {
                logError("Unexpected HTTP Status::" + method.getStatusLine().toString()
                        + " during registration call", null);
            }
        } catch (final Exception e) {
            logError("Unexpected exception during registration call", e);
        }
    } else {
        logWarn("****************************************************************************************************************************************************************************",
                null);
        logWarn("* This OLAT installation is not registered. Please, help us with your statistical data and register your installation under Adminisration - Systemregistration. THANK YOU! *",
                null);
        logWarn("****************************************************************************************************************************************************************************",
                null);
    }
}

From source file:org.olat.core.commons.modules.glossary.morphService.MorphologicalServiceDEImpl.java

private InputStream retreiveXMLReply(String partOfSpeech, String word) {
    HttpClient client = HttpClientFactory.getHttpClientInstance();
    HttpMethod method = new GetMethod(MORPHOLOGICAL_SERVICE_ADRESS);
    NameValuePair posValues = new NameValuePair(PART_OF_SPEECH_PARAM, partOfSpeech);
    NameValuePair wordValues = new NameValuePair(GLOSS_TERM_PARAM, word);
    if (log.isDebug()) {
        String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + PART_OF_SPEECH_PARAM + "=" + partOfSpeech + "&"
                + GLOSS_TERM_PARAM + "=" + word;
        log.debug("Send GET request to morph-service with URL: " + url);
    }//from www. ja  v a  2  s.c  o m
    method.setQueryString(new NameValuePair[] { posValues, wordValues });
    try {
        client.executeMethod(method);
        int status = method.getStatusCode();
        if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
            if (log.isDebug()) {
                log.debug("got a valid reply!");
            }
        } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            log.error("Morphological Service unavailable (404)::" + method.getStatusLine().toString());
        } else {
            log.error("Unexpected HTTP Status::" + method.getStatusLine().toString());
        }
    } catch (Exception e) {
        log.error("Unexpected exception trying to get flexions!", e);
    }
    Header responseHeader = method.getResponseHeader("Content-Type");
    if (responseHeader == null) {
        // error
        log.error("URL not found!");
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
    InputStream inputStream = mr.getInputStream();

    return inputStream;
}

From source file:org.olat.core.commons.modules.glossary.morphService.MorphologicalServiceFRImpl.java

private InputStream retreiveXMLReply(String word) {
    HttpClient client = HttpClientFactory.getHttpClientInstance();
    HttpMethod method = new GetMethod(MORPHOLOGICAL_SERVICE_ADRESS);
    NameValuePair wordValues = new NameValuePair(GLOSS_TERM_PARAM, word);
    if (isLogDebugEnabled()) {
        String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + GLOSS_TERM_PARAM + "=" + word;
        logDebug("Send GET request to morph-service with URL: " + url);
    }/*from  w w  w.  j a va2 s .co m*/
    method.setQueryString(new NameValuePair[] { wordValues });
    try {
        client.executeMethod(method);
        int status = method.getStatusCode();
        if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
            if (isLogDebugEnabled()) {
                logDebug("got a valid reply!");
            }
        } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            logError("Morphological Service unavailable (404)::" + method.getStatusLine().toString(), null);
        } else {
            logError("Unexpected HTTP Status::" + method.getStatusLine().toString(), null);
        }
    } catch (Exception e) {
        logError("Unexpected exception trying to get flexions!", e);
    }
    Header responseHeader = method.getResponseHeader("Content-Type");
    if (responseHeader == null) {
        // error
        logError("URL not found!", null);
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
    InputStream inputStream = mr.getInputStream();

    return inputStream;
}

From source file:org.onebusaway.nextbus.util.HttpUtilTest.java

@Test
public void testBadStatusError() {
    when(response.getEntity()).thenReturn(null);
    when(response.getStatusLine()).thenReturn(statusLine);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NOT_FOUND);
    try {/*from w  w w.  java  2s. c  om*/
        httpUtil.getEntity(response);
    } catch (Exception e) {
        assertEquals("HTTP Response: " + HttpStatus.SC_NOT_FOUND, e.getMessage());
    }
}

From source file:org.opencastproject.adminui.endpoint.BlacklistsEndpointTest.java

@Test
public void testGetPeriod() throws ParseException {
    given().pathParam("periodId", 0).log().all().expect().statusCode(HttpStatus.SC_NOT_FOUND).when()
            .get(rt.host("/{periodId}"));

    String periodResponse = given().pathParam("periodId", 1).log().all().expect().statusCode(HttpStatus.SC_OK)
            .when().get(rt.host("/{periodId}")).asString();
    JSONObject period = (JSONObject) parser.parse(periodResponse);
    long id = Long.parseLong(period.get("id").toString());
    Assert.assertEquals(1L, id);/*from   w w w. j  av a 2  s  .  c om*/
    Assert.assertEquals("2014-05-11T13:24:31Z", period.get("start"));
    Assert.assertEquals("2014-05-11T13:30:00Z", period.get("end"));
    Assert.assertEquals("Sick", period.get("purpose"));
    Assert.assertEquals("Flu", period.get("comment"));
}

From source file:org.opencastproject.adminui.endpoint.BlacklistsEndpointTest.java

@Test
public void testGetEventsCountInputInvalidBlacklistIdExpectsNotFound() {
    given().log().all().queryParam("blacklistedId", "Not a valid id").queryParam("type", Person.TYPE)
            .queryParam("start", DateTimeSupport.toUTC(TestBlacklistEndpoint.START_DATE.getTime()))
            .queryParam("end", DateTimeSupport.toUTC(TestBlacklistEndpoint.END_DATE.getTime())).expect()
            .statusCode(HttpStatus.SC_NOT_FOUND).when().get(rt.host("/blacklistCount"));
}

From source file:org.opencastproject.adminui.endpoint.BlacklistsEndpointTest.java

@Test
public void testGetEventsCountsInputInvalidBlacklistIdExpectsBadRequest() {
    given().log().all().queryParam("blacklistedId", "Not a valid id").queryParam("type", Person.TYPE)
            .queryParam("start", DateTimeSupport.toUTC(TestBlacklistEndpoint.START_DATE.getTime()))
            .queryParam("end", DateTimeSupport.toUTC(TestBlacklistEndpoint.END_DATE.getTime())).expect()
            .statusCode(HttpStatus.SC_NOT_FOUND).when().get(rt.host("/blacklistCount"));
}

From source file:org.opencastproject.adminui.endpoint.BlacklistsEndpointTest.java

@Test
public void testPostBlacklist() throws ParseException, IOException {
    given().log().all().expect().statusCode(HttpStatus.SC_BAD_REQUEST).when().post(rt.host("/"));
    given().formParam("start", "123").log().all().expect().statusCode(HttpStatus.SC_BAD_REQUEST).when()
            .post(rt.host("/"));
    given().formParam("start", "2014-05-11T13:35:20Z").formParam("end", "2014-05-11T13:40:00Z")
            .formParam("type", "test").log().all().expect().statusCode(HttpStatus.SC_BAD_REQUEST).when()
            .post(rt.host("/"));
    given().formParam("start", "2014-05-11T13:35:20Z").formParam("end", "2014-05-11T13:40:00Z")
            .formParam("type", "person").formParam("blacklistedId", 0).log().all().expect()
            .statusCode(HttpStatus.SC_NOT_FOUND).when().post(rt.host("/"));
    // Start time after end time should be a bad request.
    given().formParam("start", "2016-05-11T13:35:20Z").formParam("end", "2014-05-11T13:40:00Z")
            .formParam("type", "person").formParam("blacklistedId", 5).log().all().expect()
            .statusCode(HttpStatus.SC_BAD_REQUEST).when().post(rt.host("/")).asString();
    String responseString = given().formParam("start", "2014-05-11T13:35:20Z")
            .formParam("end", "2014-05-11T13:40:00Z").formParam("type", "person").formParam("blacklistedId", 5)
            .log().all().expect().statusCode(HttpStatus.SC_CREATED).when().post(rt.host("/")).asString();

    JSONObject responseJson = (JSONObject) parser.parse(responseString);
    Assert.assertNotNull(responseJson);/*w ww . ja v  a  2 s .c  om*/
    long id = Long.parseLong(responseJson.get("id").toString());
    Assert.assertEquals(27L, id);
    Assert.assertEquals("2014-05-11T13:35:20Z", responseJson.get("start"));
    Assert.assertEquals("2014-05-11T13:40:00Z", responseJson.get("end"));

    responseString = given().formParam("start", "2014-05-11T13:35:20Z").formParam("end", "2014-05-11T13:40:00Z")
            .formParam("type", "person").formParam("blacklistedId", 7).log().all().expect()
            .statusCode(HttpStatus.SC_CREATED).when().post(rt.host("/")).asString();

    responseJson = (JSONObject) parser.parse(responseString);
    Assert.assertNotNull(responseJson);
    id = Long.parseLong(responseJson.get("id").toString());
    Assert.assertEquals(27L, id);
    Assert.assertEquals("2014-05-11T13:35:20Z", responseJson.get("start"));
    Assert.assertEquals("2014-05-11T13:40:00Z", responseJson.get("end"));
}

From source file:org.opencastproject.adminui.endpoint.BlacklistsEndpointTest.java

@Test
public void testPutPeriod() throws ParseException {
    given().pathParam("periodId", 0).log().all().expect().statusCode(HttpStatus.SC_NOT_FOUND).when()
            .put(rt.host("/{periodId}"));

    String start = "2000-05-11T13:35:20Z";
    String end = "2014-05-11T13:35:20Z";
    String purpose = "Under construction";
    String comment = "A comment about the current period.";

    // Make sure that you cannot update a period with a later start time than the end time.
    given().pathParam("periodId", 1).formParam("start", end).formParam("end", start)
            .formParam("purpose", purpose).formParam("comment", comment).log().all().expect()
            .statusCode(HttpStatus.SC_BAD_REQUEST).when().put(rt.host("/{periodId}")).asString();

    String periodResponse = given().pathParam("periodId", 1).formParam("start", start).formParam("end", end)
            .formParam("purpose", purpose).formParam("comment", comment).log().all().expect()
            .statusCode(HttpStatus.SC_OK).when().put(rt.host("/{periodId}")).asString();
    JSONObject period = (JSONObject) parser.parse(periodResponse);
    long id = (Long) period.get("id");
    Assert.assertEquals(1L, id);/*from   w  w w .  j  av  a  2s .  c  om*/
    Assert.assertEquals(start, period.get("start"));
    Assert.assertEquals(end, period.get("end"));
    Assert.assertEquals(purpose, period.get("purpose"));
    Assert.assertEquals(comment, period.get("comment"));
}

From source file:org.opencastproject.adminui.endpoint.BlacklistsEndpointTest.java

@Test
public void testDeletePeriod() throws ParseException {
    given().pathParam("periodId", 0).log().all().expect().statusCode(HttpStatus.SC_NOT_FOUND).when()
            .delete(rt.host("/{periodId}"));
    given().pathParam("periodId", 1).log().all().expect().statusCode(HttpStatus.SC_NO_CONTENT).when()
            .delete(rt.host("/{periodId}")).asString();
}