Java Code Examples for org.apache.commons.httpclient.HttpStatus#SC_NOT_MODIFIED

The following examples show how to use org.apache.commons.httpclient.HttpStatus#SC_NOT_MODIFIED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SOLRAPIClient.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setStatus()
{
    int status = response.getStatus();
    if(status == HttpStatus.SC_NOT_MODIFIED)
    {
        this.status = SolrApiContentStatus.NOT_MODIFIED;
    }
    else if(status == HttpStatus.SC_INTERNAL_SERVER_ERROR)
    {
        this.status = SolrApiContentStatus.GENERAL_FAILURE;
    }
    else if(status == HttpStatus.SC_OK)
    {
        this.status = SolrApiContentStatus.OK;
    }
    else if(status == HttpStatus.SC_NO_CONTENT)
    {
        if(transformStatusStr == null)
        {
            this.status = SolrApiContentStatus.UNKNOWN;
        }
        else
        {
            if(transformStatusStr.equals("noTransform"))
            {
                this.status = SolrApiContentStatus.NO_TRANSFORM;
            }
            else if(transformStatusStr.equals("transformFailed"))
            {
                this.status = SolrApiContentStatus.TRANSFORM_FAILED;
            }
            else
            {
                this.status = SolrApiContentStatus.UNKNOWN;
            }
        }
    }
}
 
Example 2
Source File: MorphologicalServiceDEImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
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.isDebugEnabled()) {
        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);
    }
    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.isDebugEnabled()) {
                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;
}
 
Example 3
Source File: MorphologicalServiceFRImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
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 (log.isDebugEnabled()) {
        String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + GLOSS_TERM_PARAM + "=" + word;
        log.debug("Send GET request to morph-service with URL: " + url);
    }
    method.setQueryString(new NameValuePair[] { wordValues });
    try {
        client.executeMethod(method);
        int status = method.getStatusCode();
        if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
            if (log.isDebugEnabled()) {
                log.debug("got a valid reply!");
            }
        } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            log.error("Morphological Service unavailable (404)::" + method.getStatusLine().toString(), null);
        } else {
            log.error("Unexpected HTTP Status::" + method.getStatusLine().toString(), null);
        }
    } 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!", null);
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
    InputStream inputStream = mr.getInputStream();

    return inputStream;
}
 
Example 4
Source File: MorphologicalServiceDEImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
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.isDebugEnabled()) {
        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);
    }
    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.isDebugEnabled()) {
                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;
}
 
Example 5
Source File: MorphologicalServiceFRImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
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 (log.isDebugEnabled()) {
        String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + GLOSS_TERM_PARAM + "=" + word;
        log.debug("Send GET request to morph-service with URL: " + url);
    }
    method.setQueryString(new NameValuePair[] { wordValues });
    try {
        client.executeMethod(method);
        int status = method.getStatusCode();
        if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
            if (log.isDebugEnabled()) {
                log.debug("got a valid reply!");
            }
        } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            log.error("Morphological Service unavailable (404)::" + method.getStatusLine().toString(), null);
        } else {
            log.error("Unexpected HTTP Status::" + method.getStatusLine().toString(), null);
        }
    } 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!", null);
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
    InputStream inputStream = mr.getInputStream();

    return inputStream;
}
 
Example 6
Source File: SystemRegistrationWorker.java    From olat with Apache License 2.0 4 votes vote down vote up
protected boolean doTheWork(String registrationData, String url, String version) {
    String registrationKey = propertyService.getStringProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY);
    boolean regStatus = 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);

        log.info("URL:" + url, null);
        final PutMethod method = new PutMethod(url);
        if (registrationKey != null) {
            // updating
            method.setRequestHeader("Authorization", registrationKey);
            if (log.isDebugEnabled()) {
                log.debug("Authorization: " + registrationKey, null);
            } else {
                log.debug("Authorization: EXISTS", null);
            }
        } else {
            log.info("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) {
                log.info("Successfully registered OLAT installation on olat.org server, thank you for your support!", null);
                registrationKey = method.getResponseBodyAsString();
                propertyService.setProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY, registrationKey);
                regStatus = true;
            } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                log.error("File could be created not on registration server::" + method.getStatusLine().toString(), null);
                regStatus = false;
            } else if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
                log.info(method.getResponseBodyAsString() + method.getStatusText());
                regStatus = false;
            } else {
                log.error("Unexpected HTTP Status::" + method.getStatusLine().toString() + " during registration call", null);
                regStatus = false;
            }
        } catch (final Exception e) {
            log.error("Unexpected exception during registration call", e);
            regStatus = false;
        }
    } else {
        log.warn(
                "****************************************************************************************************************************************************************************",
                null);
        log.warn(
                "* This OLAT installation is not registered. Please, help us with your statistical data and register your installation under Adminisration - Systemregistration. THANK YOU! *",
                null);
        log.warn(
                "****************************************************************************************************************************************************************************",
                null);
    }
    return regStatus;
}
 
Example 7
Source File: SystemRegistrationWorker.java    From olat with Apache License 2.0 4 votes vote down vote up
protected boolean doTheWork(String registrationData, String url, String version) {
    String registrationKey = propertyService.getStringProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY);
    boolean regStatus = 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);

        log.info("URL:" + url, null);
        final PutMethod method = new PutMethod(url);
        if (registrationKey != null) {
            // updating
            method.setRequestHeader("Authorization", registrationKey);
            if (log.isDebugEnabled()) {
                log.debug("Authorization: " + registrationKey, null);
            } else {
                log.debug("Authorization: EXISTS", null);
            }
        } else {
            log.info("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) {
                log.info("Successfully registered OLAT installation on olat.org server, thank you for your support!", null);
                registrationKey = method.getResponseBodyAsString();
                propertyService.setProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY, registrationKey);
                regStatus = true;
            } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                log.error("File could be created not on registration server::" + method.getStatusLine().toString(), null);
                regStatus = false;
            } else if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
                log.info(method.getResponseBodyAsString() + method.getStatusText());
                regStatus = false;
            } else {
                log.error("Unexpected HTTP Status::" + method.getStatusLine().toString() + " during registration call", null);
                regStatus = false;
            }
        } catch (final Exception e) {
            log.error("Unexpected exception during registration call", e);
            regStatus = false;
        }
    } else {
        log.warn(
                "****************************************************************************************************************************************************************************",
                null);
        log.warn(
                "* This OLAT installation is not registered. Please, help us with your statistical data and register your installation under Adminisration - Systemregistration. THANK YOU! *",
                null);
        log.warn(
                "****************************************************************************************************************************************************************************",
                null);
    }
    return regStatus;
}