Example usage for org.apache.commons.httpclient.methods HeadMethod setQueryString

List of usage examples for org.apache.commons.httpclient.methods HeadMethod setQueryString

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods HeadMethod setQueryString.

Prototype

@Override
public void setQueryString(String queryString) 

Source Link

Document

Sets the query string of this HTTP method.

Usage

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

private HeadMethod connectHead(String requestURL, IProgressMonitor monitor) throws IOException, CoreException {
    hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor);
    for (int attempt = 0; attempt < 2; attempt++) {
        // force authentication
        authenticate(monitor);/*ww w . ja  va 2s .  co m*/

        HeadMethod headMethod = new HeadMethod(WebUtil.getRequestPath(requestURL));
        if (requestURL.contains(QUERY_DELIMITER)) {
            headMethod.setQueryString(requestURL.substring(requestURL.indexOf(QUERY_DELIMITER)));
        }

        headMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" //$NON-NLS-1$ //$NON-NLS-2$
                + getCharacterEncoding());

        // WARNING!! Setting browser compatability breaks Bugzilla
        // authentication
        // getMethod.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

        //         headMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new BugzillaRetryHandler());
        headMethod.setDoAuthentication(true);

        int code;
        try {
            code = WebUtil.execute(httpClient, hostConfiguration, headMethod, monitor);
        } catch (IOException e) {
            //            ignore the response
            WebUtil.releaseConnection(headMethod, monitor);
            throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
                    RepositoryStatus.ERROR_IO, repositoryUrl.toString(), e));
        }

        if (code == HttpURLConnection.HTTP_OK) {
            return headMethod;
        } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
            //            ignore the response
            WebUtil.releaseConnection(headMethod, monitor);
            loggedIn = false;
            authenticate(monitor);
        } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
            loggedIn = false;
            //            ignore the response
            WebUtil.releaseConnection(headMethod, monitor);
            throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
                    RepositoryStatus.ERROR_REPOSITORY_LOGIN, repositoryUrl.toString(),
                    "Proxy authentication required")); //$NON-NLS-1$
        } else {
            //            ignore the response
            WebUtil.releaseConnection(headMethod, monitor);
            throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
                    RepositoryStatus.ERROR_NETWORK, "Http error: " + HttpStatus.getStatusText(code))); //$NON-NLS-1$
            // throw new IOException("HttpClient connection error response
            // code: " + code);
        }
    }

    throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
            RepositoryStatus.ERROR_REPOSITORY_LOGIN, "All connection attempts to " + repositoryUrl.toString() //$NON-NLS-1$
                    + " failed. Please verify connection and authentication information.")); //$NON-NLS-1$
}