Example usage for org.apache.commons.httpclient RedirectException RedirectException

List of usage examples for org.apache.commons.httpclient RedirectException RedirectException

Introduction

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

Prototype

public RedirectException(String paramString) 

Source Link

Usage

From source file:org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient.java

/**
 * calling method must release the connection on the returned PostMethod once finished.
 *
 * @throws CoreException/* w  w  w.j a va2 s  .  co  m*/
 */
private GzipPostMethod postFormData(String formUrl, NameValuePair[] formData, IProgressMonitor monitor)
        throws IOException, CoreException {

    GzipPostMethod postMethod = null;
    monitor = Policy.monitorFor(monitor);
    hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor);
    authenticate(monitor);

    postMethod = new GzipPostMethod(WebUtil.getRequestPath(repositoryUrl.toString() + formUrl), true);
    postMethod.setRequestHeader("Content-Type", //$NON-NLS-1$
            "application/x-www-form-urlencoded; charset=" + getCharacterEncoding()); //$NON-NLS-1$

    httpClient.getHttpConnectionManager().getParams().setSoTimeout(WebUtil.getConnectionTimeout());

    postMethod.setRequestBody(formData);
    postMethod.setDoAuthentication(true);
    int status = WebUtil.execute(httpClient, hostConfiguration, postMethod, monitor);
    if (status == HttpStatus.SC_OK) {
        return postMethod;
    } else if (status == HttpStatus.SC_MOVED_TEMPORARILY) {
        String redirectLocation;
        Header locationHeader = postMethod.getResponseHeader("location"); //$NON-NLS-1$
        if (locationHeader != null) {
            redirectLocation = locationHeader.getValue();
            WebUtil.releaseConnection(postMethod, monitor);
            throw new RedirectException(redirectLocation);
        }

    }
    WebUtil.releaseConnection(postMethod, monitor);
    throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
            RepositoryStatus.ERROR_IO, repositoryUrl.toString(), new IOException(
                    "Communication error occurred during upload. \n\n" + HttpStatus.getStatusText(status)))); //$NON-NLS-1$
}