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

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

Introduction

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

Prototype

int SC_NOT_FOUND

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

Click Source Link

Document

<tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:org.eclipse.buckminster.jnlp.MaterializationUtils.java

/**
 * Checks HTTP response code and throws JNLPException if there is a problem
 * //from   ww  w  .  j a  v a  2s .co  m
 * @param connection
 * @throws JNLPException
 * @throws IOException
 */
public static void checkConnection(int status, String originalURL) throws JNLPException {
    if (status != HttpStatus.SC_OK) {
        String errorCode;

        switch (status) {
        case HttpStatus.SC_FORBIDDEN:

            errorCode = ERROR_CODE_403_EXCEPTION;
            break;

        case HttpStatus.SC_NOT_FOUND:

            errorCode = ERROR_CODE_404_EXCEPTION;
            break;

        case HttpStatus.SC_INTERNAL_SERVER_ERROR:

            errorCode = ERROR_CODE_500_EXCEPTION;
            break;

        default:
            errorCode = ERROR_CODE_REMOTE_IO_EXCEPTION;
            break;
        }

        throw new JNLPException(Messages.cannot_read_materialization_specification, errorCode,
                BuckminsterException.fromMessage("%s - %s", originalURL, HttpStatus.getStatusText(status))); //$NON-NLS-1$
    }
}

From source file:org.eclipse.buckminster.jnlp.p2.MaterializationUtils.java

/**
 * Checks HTTP response code and throws JNLPException if there is a problem
 * /*  ww w  .  jav  a  2  s . c o m*/
 * @param connection
 * @throws JNLPException
 * @throws IOException
 */
public static void checkConnection(int status, String originalURL) throws JNLPException {
    if (status != HttpStatus.SC_OK) {
        String errorCode;

        switch (status) {
        case HttpStatus.SC_FORBIDDEN:

            errorCode = ERROR_CODE_403_EXCEPTION;
            break;

        case HttpStatus.SC_NOT_FOUND:

            errorCode = ERROR_CODE_404_EXCEPTION;
            break;

        case HttpStatus.SC_INTERNAL_SERVER_ERROR:

            errorCode = ERROR_CODE_500_EXCEPTION;
            break;

        default:
            errorCode = ERROR_CODE_REMOTE_IO_EXCEPTION;
            break;
        }

        throw new JNLPException("Cannot read materialization specification", errorCode,
                BuckminsterException.fromMessage("%s - %s", originalURL, HttpStatus.getStatusText(status)));
    }
}

From source file:org.eclipse.ecr.core.storage.sql.net.BinaryManagerClient.java

@Override
public Binary getBinary(String digest) {
    Binary binary = binaryManager.getBinary(digest);
    if (binary != null) {
        return binary;
    }//from  w  w w .  ja v a 2  s  .  co  m

    GetMethod m = new GetMethod(url + getQuery(digest));
    try {
        int status = httpClient.executeMethod(m);
        if (status == HttpStatus.SC_NOT_FOUND) {
            return null;
        } else if (status != HttpStatus.SC_OK) {
            log.error(String.format("Could not get remote binary on server %s (%s)", url,
                    String.valueOf(status)));
            return null;
        } else {
            binary = binaryManager.getBinary(m.getResponseBodyAsStream());
        }
    } catch (IOException e) {
        log.error(String.format("Could not get remote binary on server %s (%s)", url, e.toString()), e);
        return null;
    } finally {
        m.releaseConnection();
    }

    if (binary.getDigest().equals(digest)) {
        return binary;
    } else {
        log.error("Remote binary digest  mismatch: '" + digest + "' vs '" + binary.getDigest() + "'");
        return null;
    }
}

From source file:org.eclipse.mylyn.internal.discovery.core.util.HttpClientTransportService.java

/**
 * Verify availability of resources at the given web locations. Normally this would be done using an HTTP HEAD.
 * //from  w w w.ja v a  2s . c  o  m
 * @param locations
 *            the locations of the resource to verify
 * @param one
 *            indicate if only one of the resources must exist
 * @param monitor
 *            the monitor
 * @return true if the resource exists
 */
public long getLastModified(java.net.URI uri, IProgressMonitor monitor) throws CoreException, IOException {
    WebLocation location = new WebLocation(uri.toString());
    monitor = Policy.monitorFor(monitor);
    monitor.beginTask(NLS.bind(Messages.WebUtil_task_retrievingUrl, location.getUrl()),
            IProgressMonitor.UNKNOWN);
    try {
        HttpClient client = new HttpClient();
        org.eclipse.mylyn.commons.net.WebUtil.configureHttpClient(client, ""); //$NON-NLS-1$

        HeadMethod method = new HeadMethod(location.getUrl());
        try {
            HostConfiguration hostConfiguration = org.eclipse.mylyn.commons.net.WebUtil
                    .createHostConfiguration(client, location, monitor);
            int result = org.eclipse.mylyn.commons.net.WebUtil.execute(client, hostConfiguration, method,
                    monitor);
            if (result == HttpStatus.SC_OK) {
                Header lastModified = method.getResponseHeader("Last-Modified"); //$NON-NLS-1$
                if (lastModified != null) {
                    try {
                        return DateUtil.parseDate(lastModified.getValue()).getTime();
                    } catch (DateParseException e) {
                        // fall through
                    }
                }
                return 0;
            } else if (result == HttpStatus.SC_NOT_FOUND) {
                throw new FileNotFoundException(
                        NLS.bind(Messages.WebUtil_cannotDownload, location.getUrl(), result));
            } else {
                throw new IOException(NLS.bind(Messages.WebUtil_cannotDownload, location.getUrl(), result));
            }
        } finally {
            method.releaseConnection();
        }
    } finally {
        monitor.done();
    }
}

From source file:org.eclipse.mylyn.internal.gerrit.core.client.GerritClient29.java

private UserIdentity setUserIdentity(String name, UserIdentity userIdentity, String user,
        IProgressMonitor monitor) {//  w w  w. j  ava 2s. c o m
    org.eclipse.mylyn.internal.gerrit.core.client.rest.AccountInfo accountInfo = null;
    try {
        accountInfo = getAccountInfo(name, monitor);
        Account.Id accountId = new Account.Id(accountInfo.getId());
        userIdentity.setAccount(accountId);
    } catch (GerritException gerritException) {
        if (gerritException.getMessage().indexOf(HttpStatus.SC_NOT_FOUND) != 0) {
            StatusHandler.log(new Status(IStatus.WARNING, GerritCorePlugin.PLUGIN_ID,
                    NLS.bind("GerritException {0} not found", user), gerritException)); //$NON-NLS-1$
        }
    } catch (URIException uriException) {
        StatusHandler.log(new Status(IStatus.ERROR, GerritCorePlugin.PLUGIN_ID,
                NLS.bind("{0} URIException: ", user), uriException)); //$NON-NLS-1$
    }
    return userIdentity;
}

From source file:org.eclipse.mylyn.internal.gerrit.core.client.GerritHttpClient.java

private void authenticate(String openIdProvider, IProgressMonitor monitor) throws GerritException, IOException {
    while (true) {
        AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY);

        int code;
        if (openIdProvider != null) {
            code = authenticateOpenIdService(openIdProvider, monitor);
            if (code == -1) {
                continue;
            }/*from  w w w.  jav a 2 s.com*/
        } else if (credentials != null) {
            // try form based authentication first
            code = authenticateForm(credentials, monitor);
            if (code == -1) {
                continue;
            } else if (code == HttpStatus.SC_NOT_FOUND) {
                code = authenticateUserPassService(credentials, monitor);
                if (code == -1) {
                    continue;
                } else if (code == HttpStatus.SC_NOT_FOUND) {
                    code = authenticateDevelopmentMode(credentials, monitor);
                    if (code == -1) {
                        continue;
                    }
                }
            }
        } else {
            throw new GerritLoginException();
        }

        // Location: http://egit.eclipse.org/r/#SignInFailure,SIGN_IN,Session cookie not available
        validateAuthenticationState(httpClient);

        // success since no exception was thrown
        break;
    }
}

From source file:org.eclipse.mylyn.internal.gerrit.core.client.GerritHttpClient.java

private int authenticateDevelopmentMode(AuthenticationCredentials credentials, IProgressMonitor monitor)
        throws IOException, GerritException {
    // try to detect if user name is user id, email or account id
    String key;//from w ww.j a v a2 s  .  c o m
    if (credentials.getUserName().contains("@")) { //$NON-NLS-1$
        key = "preferred_email"; //$NON-NLS-1$
    } else {
        try {
            Long.parseLong(credentials.getUserName());
            key = "account_id"; //$NON-NLS-1$
        } catch (NumberFormatException e) {
            key = "user_name"; //$NON-NLS-1$
        }
    }

    String repositoryUrl = getUrl();
    String gerrit_2_5_RequestPath = WebUtil.getRequestPath(repositoryUrl + BECOME_URL + "?" + key + "=" //$NON-NLS-1$ //$NON-NLS-2$
            + credentials.getUserName());
    String gerrit_2_6_RequestPath = WebUtil.getRequestPath(repositoryUrl + LOGIN_URL + "?" + key + "=" //$NON-NLS-1$ //$NON-NLS-2$
            + credentials.getUserName());
    for (String requestPath : new String[] { gerrit_2_5_RequestPath, gerrit_2_6_RequestPath }) {
        GetMethod method = new GetMethod(requestPath);
        method.setFollowRedirects(false);
        try {
            int code = WebUtil.execute(httpClient, hostConfiguration, method, monitor);
            if (needsReauthentication(code, monitor)) {
                return -1;
            }

            if (code == HttpStatus.SC_OK) {
                // authentication failed
                return code;
            }
            if (code == HttpStatus.SC_NOT_FOUND) {
                continue;
            }
            if (code != HttpStatus.SC_MOVED_TEMPORARILY && code != HttpStatus.SC_MOVED_TEMPORARILY) {
                throw new GerritHttpException(code);
            }
            return code;
        } finally {
            WebUtil.releaseConnection(method, monitor);
        }
    }
    return HttpStatus.SC_NOT_FOUND;
}

From source file:org.eclipse.mylyn.internal.gerrit.core.client.GerritHttpClient.java

private int authenticateForm(AuthenticationCredentials credentials, IProgressMonitor monitor)
        throws IOException, GerritException {
    // try standard basic/digest/ntlm authentication first
    String repositoryUrl = getUrl();
    AuthScope authScope = new AuthScope(WebUtil.getHost(repositoryUrl), WebUtil.getPort(repositoryUrl), null,
            AuthScope.ANY_SCHEME);/*  w  w w  .ja  va  2s  .  c  o  m*/
    Credentials httpCredentials = WebUtil.getHttpClientCredentials(credentials, WebUtil.getHost(repositoryUrl));
    httpClient.getState().setCredentials(authScope, httpCredentials);

    HttpMethodBase[] methods = getFormAuthMethods(repositoryUrl, credentials);
    for (HttpMethodBase method : methods) {
        int code;
        try {
            code = WebUtil.execute(httpClient, hostConfiguration, method, monitor);
            if (code == HttpStatus.SC_METHOD_NOT_ALLOWED) {
                continue; // try next http method
            } else if (needsReauthentication(code, monitor)) {
                return -1;
            } else if (code == HttpStatus.SC_MOVED_TEMPORARILY) {
                Header locationHeader = method.getResponseHeader("Location"); //$NON-NLS-1$
                if (locationHeader != null) {
                    if (locationHeader.getValue()
                            .endsWith("SignInFailure,SIGN_IN,Session cookie not available.")) { //$NON-NLS-1$
                        // try different authentication method
                        return HttpStatus.SC_NOT_FOUND;
                    }
                }
            } else if (code == HttpStatus.SC_OK) {
                // try different authentication method as the server maybe using development mode authentication
                return HttpStatus.SC_NOT_FOUND;
            } else if (code != HttpStatus.SC_NOT_FOUND) {
                throw new GerritHttpException(code);
            }
            return code;
        } finally {
            WebUtil.releaseConnection(method, monitor);
        }
    }
    return HttpStatus.SC_NOT_FOUND;
}

From source file:org.elasticsearch.hadoop.rest.RestClient.java

public List<List<Map<String, Object>>> targetShards(String query) throws IOException {
    List<List<Map<String, Object>>> shardsJson = null;

    if (indexReadMissingAsEmpty) {
        GetMethod get = new GetMethod(query);
        byte[] content = execute(get, false);
        if (get.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            shardsJson = Collections.emptyList();
        } else {/*from   w  w  w  .j a  v a2 s.c  o m*/
            shardsJson = parseContent(content, "shards");
        }
    } else {
        shardsJson = get(query, "shards");
    }

    return shardsJson;
}

From source file:org.exoplatform.addons.es.client.ElasticIndexingClient.java

/**
 * Send request to ES to create a new index
 *///www.jav  a  2 s.  c  o  m
public void sendCreateIndexRequest(String index, String settings) {
    String url = urlClient + "/" + index;
    ElasticResponse responseExists = sendHttpGetRequest(url);
    if (responseExists.getStatusCode() == HttpStatus.SC_OK) {
        LOG.info("Index {} already exists. Index creation requests will not be sent.", index);
    } else if (responseExists.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        LOG.info("Index {} doesn't exist. Index creation requests will be sent.", index);

        long startTime = System.currentTimeMillis();
        ElasticResponse responseCreate = sendHttpPostRequest(url, settings);
        auditTrail.audit(ElasticIndexingAuditTrail.CREATE_INDEX, null, index, null,
                responseCreate.getStatusCode(), responseCreate.getMessage(),
                (System.currentTimeMillis() - startTime));
    } else {
        LOG.error("Index exists: Unsupported HttpStatusCode {}. url={}", responseExists.getStatusCode(), url);
    }
}