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

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

Introduction

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

Prototype

int SC_SERVICE_UNAVAILABLE

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

Click Source Link

Document

<tt>503 Service Unavailable</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:org.devproof.portal.module.bookmark.panel.DeliciousSyncPanel.java

private ProgressBar createProgressBar() {
    ProgressionModel progressionModel = createProgressionModel();
    progressBar = new ProgressBar("bar", progressionModel) {
        private static final long serialVersionUID = 1L;

        @Override//from   w  ww.  j  av  a2 s .c om
        protected void onFinished(AjaxRequestTarget target) {
            if (deliciousBean != null && deliciousBean.hasError()) {
                if (deliciousBean.getHttpCode() == HttpStatus.SC_UNAUTHORIZED) {
                    error(getString("loginFailed"));
                } else if (deliciousBean.getHttpCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
                    error(getString("serviceNotAvailable"));
                } else {
                    error(deliciousBean.getErrorMessage());
                }
            } else {
                info(new StringResourceModel("syncFinished", this, null,
                        new Object[] { newBookmarksCount, modifiedBookmarksCount, deletedBookmarksCount })
                                .getString());
            }
            target.addComponent(feedbackPanel);
        }
    };
    return progressBar;
}

From source file:org.eclipse.mylyn.internal.jira.core.service.web.JiraWebClient.java

protected void handleErrorMessage(HttpMethodBase method) throws JiraException {
    try {//from  ww w. ja v  a  2s  . c om
        String response = method.getResponseBodyAsString();
        // TODO consider logging the error

        if (method.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
            throw new JiraRemoteException("JIRA system error", null); //$NON-NLS-1$
        }

        if (response == null) {
            throw new JiraRemoteMessageException("Error making JIRA request: " + method.getStatusCode(), ""); //$NON-NLS-1$ //$NON-NLS-2$
        }

        StringReader reader = new StringReader(response);
        try {
            StringBuilder msg = new StringBuilder();
            HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(reader, null);
            for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer
                    .nextToken()) {
                if (token.getType() == Token.TAG) {
                    HtmlTag tag = (HtmlTag) token.getValue();

                    String classValue = tag.getAttribute("class"); //$NON-NLS-1$
                    if (classValue != null) {
                        if (tag.getTagType() == Tag.DIV) {
                            if (classValue.startsWith("infoBox")) { //$NON-NLS-1$
                                throw new JiraRemoteMessageException(getContent(tokenizer, Tag.DIV));
                            } else if (classValue.startsWith("errorArea")) { //$NON-NLS-1$
                                throw new JiraRemoteMessageException(getContent(tokenizer, Tag.DIV));
                            }
                        } else if (tag.getTagType() == Tag.SPAN) {
                            if (classValue.startsWith("errMsg")) { //$NON-NLS-1$
                                msg.append(getContent(tokenizer, Tag.SPAN));
                            }
                        }
                    }
                }
            }
            if (msg.length() == 0) {
                throw new JiraRemoteMessageException(response);
            } else {
                throw new JiraRemoteMessageException(msg.toString());
            }
        } catch (ParseException e) {
            throw new JiraRemoteMessageException("Error parsing JIRA response: " + method.getStatusCode(), ""); //$NON-NLS-1$ //$NON-NLS-2$
        } finally {
            reader.close();
        }
    } catch (IOException e) {
        throw new JiraException(e);
    }
}

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:/* www  . ja v  a 2s.  co m*/
        return 1;
    }
}

From source file:org.wso2.carbon.appfactory.jenkins.api.JenkinsBuildStatusProvider.java

public String getLastSuccessfulBuildId(String applicationId, String version, String userName, String repoFrom)
        throws BuildStatusProviderException {

    String jobName = JenkinsUtility.getJobName(applicationId, version);

    String buildUrl = "";
    try {/*ww  w. j  av a 2 s.  c  o  m*/
        buildUrl = AppFactoryUtil.getAppfactoryConfiguration()
                .getFirstProperty("ContinuousIntegrationProvider.jenkins.Property.BaseURL");
    } catch (AppFactoryException e) {
        String msg = "Error occuered while calling the API";
        throw new BuildStatusProviderException(msg);
    }
    String tenantDomain = Utils.getEnvironmentVariable("TENANT_DOMAIN");
    buildUrl += "/t/" + tenantDomain + "/webapps/jenkins/" + "job/" + jobName + "/api/xml";
    String lastSuccessBuildId = null;
    GetMethod checkJobExistsMethod = new GetMethod(buildUrl);
    try {
        getHttpClient().getState().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(
                        AppFactoryUtil.getAppfactoryConfiguration()
                                .getFirstProperty(Constants.JENKINS_ADMIN_USERNAME_PATH),
                        AppFactoryUtil.getAppfactoryConfiguration()
                                .getFirstProperty(Constants.JENKINS_ADMIN_PASSWORD_PATH)));
    } catch (AppFactoryException e) {
        String msg = "Error occuered while calling the API";
        throw new BuildStatusProviderException(msg);
    }
    getHttpClient().getParams().setAuthenticationPreemptive(true);

    try {
        int httpStatusCode = getHttpClient().executeMethod(checkJobExistsMethod);

        if (HttpStatus.SC_SERVICE_UNAVAILABLE == httpStatusCode) {
            httpStatusCode = resendRequest(checkJobExistsMethod);
        }

        if (HttpStatus.SC_OK != httpStatusCode) {
            final String errorMsg = String.format(
                    "Unable to check the status  of build: [%s]" + ". jenkins returned, http status : %d",
                    buildUrl, httpStatusCode);

            log.error(errorMsg);
            throw new BuildStatusProviderException(errorMsg);
        }

        StAXOMBuilder builder = new StAXOMBuilder(checkJobExistsMethod.getResponseBodyAsStream());
        OMElement resultElement = builder.getDocumentElement();

        if (resultElement != null) {
            OMElement lastSuccessfulBuild = (resultElement
                    .getFirstChildWithName(new QName("lastSuccessfulBuild")));
            if (lastSuccessfulBuild != null) {
                lastSuccessBuildId = lastSuccessfulBuild.getFirstChildWithName(new QName("number")).getText();
            }
        }

    } catch (Exception ex) {
        String errorMsg = "Error while checking the status of build: " + buildUrl;
        log.error(errorMsg, ex);
        throw new BuildStatusProviderException(errorMsg);
    } finally {
        checkJobExistsMethod.releaseConnection();
    }

    return lastSuccessBuildId;
}