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

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

Introduction

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

Prototype

int SC_NOT_MODIFIED

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

Click Source Link

Document

<tt>304 Not Modified</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 av  a2  s.c om
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 w  ww .  j a  v  a  2  s  .  com*/
    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  ww . ja v a  2s  .  c  o  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.opens.tanaguru.util.http.HttpRequestHandler.java

private int computeStatus(int status) {
    switch (status) {
    case HttpStatus.SC_FORBIDDEN:
    case HttpStatus.SC_METHOD_NOT_ALLOWED:
    case HttpStatus.SC_BAD_REQUEST:
    case HttpStatus.SC_UNAUTHORIZED:
    case HttpStatus.SC_PAYMENT_REQUIRED:
    case HttpStatus.SC_NOT_FOUND:
    case HttpStatus.SC_NOT_ACCEPTABLE:
    case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
    case HttpStatus.SC_REQUEST_TIMEOUT:
    case HttpStatus.SC_CONFLICT:
    case HttpStatus.SC_GONE:
    case HttpStatus.SC_LENGTH_REQUIRED:
    case HttpStatus.SC_PRECONDITION_FAILED:
    case HttpStatus.SC_REQUEST_TOO_LONG:
    case HttpStatus.SC_REQUEST_URI_TOO_LONG:
    case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE:
    case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
    case HttpStatus.SC_EXPECTATION_FAILED:
    case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE:
    case HttpStatus.SC_METHOD_FAILURE:
    case HttpStatus.SC_UNPROCESSABLE_ENTITY:
    case HttpStatus.SC_LOCKED:
    case HttpStatus.SC_FAILED_DEPENDENCY:
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
    case HttpStatus.SC_NOT_IMPLEMENTED:
    case HttpStatus.SC_BAD_GATEWAY:
    case HttpStatus.SC_SERVICE_UNAVAILABLE:
    case HttpStatus.SC_GATEWAY_TIMEOUT:
    case HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED:
    case HttpStatus.SC_INSUFFICIENT_STORAGE:
        return 0;
    case HttpStatus.SC_CONTINUE:
    case HttpStatus.SC_SWITCHING_PROTOCOLS:
    case HttpStatus.SC_PROCESSING:
    case HttpStatus.SC_OK:
    case HttpStatus.SC_CREATED:
    case HttpStatus.SC_ACCEPTED:
    case HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION:
    case HttpStatus.SC_NO_CONTENT:
    case HttpStatus.SC_RESET_CONTENT:
    case HttpStatus.SC_PARTIAL_CONTENT:
    case HttpStatus.SC_MULTI_STATUS:
    case HttpStatus.SC_MULTIPLE_CHOICES:
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_MOVED_TEMPORARILY:
    case HttpStatus.SC_SEE_OTHER:
    case HttpStatus.SC_NOT_MODIFIED:
    case HttpStatus.SC_USE_PROXY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return 1;
    default:/*ww w  .  j  a  v a  2  s .c  o  m*/
        return 1;
    }
}

From source file:org.opensaml.saml2.metadata.provider.HTTPMetadataProvider.java

/**
 * Gets the metadata document from the remote server.
 * //from  www.  j  ava2 s.c  o  m
 * @return the metadata from remote server, or null if the metadata document has not changed since the last
 *         retrieval
 * 
 * @throws MetadataProviderException thrown if there is a problem retrieving the metadata from the remote server
 */
protected byte[] fetchMetadata() throws MetadataProviderException {
    GetMethod getMethod = buildGetMethod();

    try {
        log.debug("Attempting to fetch metadata document from '{}'", metadataURI);
        httpClient.executeMethod(getMethod);
        int httpStatus = getMethod.getStatusCode();

        if (httpStatus == HttpStatus.SC_NOT_MODIFIED) {
            log.debug("Metadata document from '{}' has not changed since last retrieval", getMetadataURI());
            return null;
        }

        if (getMethod.getStatusCode() != HttpStatus.SC_OK) {
            String errMsg = "Non-ok status code " + getMethod.getStatusCode()
                    + " returned from remote metadata source " + metadataURI;
            log.error(errMsg);
            throw new MetadataProviderException(errMsg);
        }

        processConditionalRetrievalHeaders(getMethod);

        byte[] rawMetadata = getMetadataBytesFromResponse(getMethod);
        log.debug("Successfully fetched {}bytes of metadata from {}", rawMetadata.length, getMetadataURI());

        return rawMetadata;
    } catch (IOException e) {
        String errMsg = "Error retrieving metadata from " + metadataURI;
        log.error(errMsg, e);
        throw new MetadataProviderException(errMsg, e);
    } finally {
        getMethod.releaseConnection();
    }
}

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;//from   ww w .  j a v  a  2  s . c o m
    }
    EntityTemplate body = createEntity();
    body.setContentType(contentType);
    response.setEntity(body);
}

From source file:pl.nask.hsn2.service.urlfollower.ProcessedPage.java

private void checkServerSideRedirect() {
    if (responseCode >= HttpStatus.SC_MULTIPLE_CHOICES && responseCode <= HttpStatus.SC_TEMPORARY_REDIRECT
            && responseCode != HttpStatus.SC_NOT_MODIFIED) {
        // At this point response code is 300, 301, 302, 303, 305, 306 or 307 (but no 304).
        serverSideRedirectLocation = page.getWebResponse().getResponseHeaderValue("Location");

        // Server side redirection could be relative, so we have to make sure it is set correctly.
        URL requestUrl = page.getUrl();
        if (serverSideRedirectLocation == null || serverSideRedirectLocation.isEmpty()) {
            // It could happen location header is empty. This is not valid redirect.
            serverSideRedirectLocation = null;
        } else if (!(serverSideRedirectLocation.startsWith("http://")
                && serverSideRedirectLocation.startsWith("https://"))) {
            // It could happen location header is relative. This is not valid redirect but web
            // browsers seem to follow it, so WebClient do.
            serverSideRedirectLocation = UrlUtils.resolveUrl(requestUrl, serverSideRedirectLocation);
        }//  ww w  . ja v a 2 s  .c o  m
    }
}

From source file:pl.nask.hsn2.service.urlfollower.WebWindowListenerImpl.java

private boolean isServerRedirect(Page page) {
    int responseCode = page.getWebResponse().getStatusCode();
    // returns 300, 301, 302, 303, 305, 306 or 307 (but no 304).
    return responseCode >= HttpStatus.SC_MULTIPLE_CHOICES && responseCode <= HttpStatus.SC_TEMPORARY_REDIRECT
            && responseCode != HttpStatus.SC_NOT_MODIFIED;
}