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

The following examples show how to use org.apache.commons.httpclient.HttpStatus#SC_INTERNAL_SERVER_ERROR . 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: HttpSOAPClient.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void send(String endpoint, SOAPMessageContext messageContext) throws SOAPException, SecurityException {
    PostMethod post = null;
    try {
        post = createPostMethod(endpoint, (HttpSOAPRequestParameters) messageContext.getSOAPRequestParameters(),
                (Envelope) messageContext.getOutboundMessage());

        int result = httpClient.executeMethod(post);
        log.debug("Received HTTP status code of {} when POSTing SOAP message to {}", result, endpoint);

        if (result == HttpStatus.SC_OK) {
            processSuccessfulResponse(post, messageContext);
        } else if (result == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
            processFaultResponse(post, messageContext);
        } else {
            throw new SOAPClientException("Received " + result + " HTTP response status code from HTTP request to "
                    + endpoint);
        }
    } catch (IOException e) {
        throw new SOAPClientException("Unable to send request to " + endpoint, e);
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}
 
Example 2
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 3
Source File: MSNPropertyHandler.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
*/
  @SuppressWarnings({ "unchecked" })
  @Override
  public boolean isValid(final FormItem formItem, final Map formContext) {
      boolean result;
      final TextElement textElement = (TextElement) formItem;

      if (StringHelper.containsNonWhitespace(textElement.getValue())) {

          // Use an HttpClient to fetch a profile information page from MSN.
          final HttpClient httpClient = HttpClientFactory.getHttpClientInstance();
          final HttpClientParams httpClientParams = httpClient.getParams();
          httpClientParams.setConnectionManagerTimeout(2500);
          httpClient.setParams(httpClientParams);
          final HttpMethod httpMethod = new GetMethod(MSN_NAME_VALIDATION_URL);
          final NameValuePair idParam = new NameValuePair(MSN_NAME_URL_PARAMETER, textElement.getValue());
          httpMethod.setQueryString(new NameValuePair[] { idParam });
          // Don't allow redirects since otherwise, we won't be able to get the correct status
          httpMethod.setFollowRedirects(false);
          try {
              // Get the user profile page
              httpClient.executeMethod(httpMethod);
              final int httpStatusCode = httpMethod.getStatusCode();
              // Looking at the HTTP status code tells us whether a user with the given MSN name exists.
              if (httpStatusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
                  // If the user exists, we get a 301...
                  result = true;
              } else if (httpStatusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
                  // ...and if the user doesn't exist, MSN sends a 500.
                  textElement.setErrorKey("form.name.msn.error", null);
                  result = false;
              } else {
                  // For HTTP status codes other than 301 and 500 we will assume that the given MSN name is valid, but inform the user about this.
                  textElement.setExampleKey("form.example.msnname.notvalidated", null);
                  log.warn("MSN name validation: Expected HTTP status 301 or 500, but got " + httpStatusCode);
                  result = true;
              }
          } catch (final Exception e) {
              // In case of any exception, assume that the given MSN name is valid (The opposite would block easily upon network problems), and inform the user about
              // this.
              textElement.setExampleKey("form.example.msnname.notvalidated", null);
              log.warn("MSN name validation: Exception: " + e.getMessage());
              result = true;
          }
      } else {
          result = true;
      }
      return result;
  }
 
Example 4
Source File: MSNPropertyHandler.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
*/
  @SuppressWarnings({ "unchecked" })
  @Override
  public boolean isValid(final FormItem formItem, final Map formContext) {
      boolean result;
      final TextElement textElement = (TextElement) formItem;

      if (StringHelper.containsNonWhitespace(textElement.getValue())) {

          // Use an HttpClient to fetch a profile information page from MSN.
          final HttpClient httpClient = HttpClientFactory.getHttpClientInstance();
          final HttpClientParams httpClientParams = httpClient.getParams();
          httpClientParams.setConnectionManagerTimeout(2500);
          httpClient.setParams(httpClientParams);
          final HttpMethod httpMethod = new GetMethod(MSN_NAME_VALIDATION_URL);
          final NameValuePair idParam = new NameValuePair(MSN_NAME_URL_PARAMETER, textElement.getValue());
          httpMethod.setQueryString(new NameValuePair[] { idParam });
          // Don't allow redirects since otherwise, we won't be able to get the correct status
          httpMethod.setFollowRedirects(false);
          try {
              // Get the user profile page
              httpClient.executeMethod(httpMethod);
              final int httpStatusCode = httpMethod.getStatusCode();
              // Looking at the HTTP status code tells us whether a user with the given MSN name exists.
              if (httpStatusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
                  // If the user exists, we get a 301...
                  result = true;
              } else if (httpStatusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
                  // ...and if the user doesn't exist, MSN sends a 500.
                  textElement.setErrorKey("form.name.msn.error", null);
                  result = false;
              } else {
                  // For HTTP status codes other than 301 and 500 we will assume that the given MSN name is valid, but inform the user about this.
                  textElement.setExampleKey("form.example.msnname.notvalidated", null);
                  log.warn("MSN name validation: Expected HTTP status 301 or 500, but got " + httpStatusCode);
                  result = true;
              }
          } catch (final Exception e) {
              // In case of any exception, assume that the given MSN name is valid (The opposite would block easily upon network problems), and inform the user about
              // this.
              textElement.setExampleKey("form.example.msnname.notvalidated", null);
              log.warn("MSN name validation: Exception: " + e.getMessage());
              result = true;
          }
      } else {
          result = true;
      }
      return result;
  }