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:com.owncloud.android.authenticator.ConnectionCheckerRunnable.java

private boolean tryConnection(String urlSt) {
    boolean retval = false;
    GetMethod get = null;//w w  w .  jav  a  2  s.  co  m
    try {
        WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(urlSt));
        get = new GetMethod(urlSt);
        int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
        String response = get.getResponseBodyAsString();
        switch (status) {
        case HttpStatus.SC_OK: {
            JSONObject json = new JSONObject(response);
            if (!json.getBoolean("installed")) {
                mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
                break;
            }
            mOCVersion = new OwnCloudVersion(json.getString("version"));
            if (!mOCVersion.isVersionValid()) {
                mLatestResult = ResultType.BAD_OC_VERSION;
                break;
            }
            retval = true;
            break;
        }
        case HttpStatus.SC_NOT_FOUND:
            mLatestResult = ResultType.FILE_NOT_FOUND;
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
            break;
        default:
            mLatestResult = ResultType.UNKNOWN_ERROR;
            Log.e(TAG, "Not handled status received from server: " + status);
        }

    } catch (JSONException e) {
        mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
        Log.e(TAG, "JSON exception while trying connection (instance not configured) ", e);

    } catch (SocketException e) {
        mLatestResult = ResultType.WRONG_CONNECTION;
        Log.e(TAG, "Socket exception while trying connection", e);

    } catch (SocketTimeoutException e) {
        mLatestResult = ResultType.TIMEOUT;
        Log.e(TAG, "Socket timeout exception while trying connection", e);

    } catch (MalformedURLException e) {
        mLatestResult = ResultType.INCORRECT_ADDRESS;
        Log.e(TAG, "Connect exception while trying connection", e);

    } catch (UnknownHostException e) {
        mLatestResult = ResultType.HOST_NOT_AVAILABLE;
        Log.e(TAG, "Unknown host exception while trying connection", e);

    } catch (SSLPeerUnverifiedException e) { // specially meaningful SSLException
        mLatestResult = ResultType.SSL_UNVERIFIED_SERVER;
        Log.e(TAG, "SSL Peer Unverified exception while trying connection", e);

    } catch (SSLException e) {
        mLatestResult = ResultType.SSL_INIT_ERROR;
        Log.e(TAG, "SSL exception while trying connection", e);

    } catch (ConnectTimeoutException e) { // timeout specific exception from org.apache.commons.httpclient
        mLatestResult = ResultType.TIMEOUT;
        Log.e(TAG, "Socket timeout exception while trying connection", e);

    } catch (HttpException e) { // other specific exceptions from org.apache.commons.httpclient
        mLatestResult = ResultType.UNKNOWN_ERROR;
        Log.e(TAG, "HTTP exception while trying connection", e);

    } catch (IOException e) { // UnkownsServiceException, and any other transport exceptions that could occur
        mLatestResult = ResultType.UNKNOWN_ERROR;
        Log.e(TAG, "I/O exception while trying connection", e);

    } catch (Exception e) {
        mLatestResult = ResultType.UNKNOWN_ERROR;
        Log.e(TAG, "Unexpected exception while trying connection", e);

    } finally {
        if (get != null)
            get.releaseConnection();
    }

    return retval;
}

From source file:com.kagilum.intellij.icescrum.IceScrumRepository.java

private void checkServerStatus(int code) throws IOException {
    switch (code) {
    case HttpStatus.SC_SERVICE_UNAVAILABLE:
        throw new IOException("Web services aren't activated on your project...");
    case HttpStatus.SC_UNAUTHORIZED:
        throw new IOException("Wrong login/pass...");
    case HttpStatus.SC_FORBIDDEN:
        throw new IOException("You haven't access to this project...");
    case HttpStatus.SC_NOT_FOUND:
        throw new IOException("No project or iceScrum server found...");
    default://from w ww. ja va2  s . com
        throw new IOException("Server error (" + HttpStatus.getStatusText(code) + ")");
    }
}

From source file:com.cerema.cloud2.lib.common.operations.RemoteOperationResult.java

private RemoteOperationResult(boolean success, int httpCode) {
    mSuccess = success;//from  w w w .j a  v a  2 s  . c o m
    mHttpCode = httpCode;

    if (success) {
        mCode = ResultCode.OK;

    } else if (httpCode > 0) {
        switch (httpCode) {
        case HttpStatus.SC_UNAUTHORIZED:
            mCode = ResultCode.UNAUTHORIZED;
            break;
        case HttpStatus.SC_NOT_FOUND:
            mCode = ResultCode.FILE_NOT_FOUND;
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
            break;
        case HttpStatus.SC_CONFLICT:
            mCode = ResultCode.CONFLICT;
            break;
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
            mCode = ResultCode.QUOTA_EXCEEDED;
            break;
        case HttpStatus.SC_FORBIDDEN:
            mCode = ResultCode.FORBIDDEN;
            break;
        default:
            mCode = ResultCode.UNHANDLED_HTTP_CODE;
            Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
        }
    }
}

From source file:com.cubeia.backoffice.users.client.UserServiceClientHTTP.java

@Override
public String ping() {
    GetMethod method = createGetMethod(baseUrl + PING);

    try {//from ww w  . j  a  v a2 s  .  c o m
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        assertResponseCodeOK(method, statusCode);
        return method.getResponseBodyAsString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:io.pravega.segmentstore.storage.impl.extendeds3.S3FileSystemImpl.java

@Override
public AccessControlList getObjectAcl(String bucketName, String key) {
    AclSize retVal = aclMap.get(key);/*from  w w w  .j a v a2 s . c  o m*/
    if (retVal == null) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
    }
    return retVal.getAcl();
}

From source file:de.pdark.dsmp.ProxyDownload.java

/**
 * Do the download./*  ww w . j  a v  a  2  s.co m*/
 * 
 * @throws IOException
 * @throws DownloadFailed
 */
public void download() throws IOException, DownloadFailed {
    if (!config.isAllowed(url)) {
        throw new DownloadFailed(
                "HTTP/1.1 " + HttpStatus.SC_FORBIDDEN + " Download denied by rule in DSMP config");
    }

    // If there is a status file in the cache, return it instead of trying it again
    // As usual with caches, this one is a key area which will always cause
    // trouble.
    // TODO There should be a simple way to get rid of the cached statuses
    // TODO Maybe retry a download after a certain time?
    File statusFile = new File(dest.getAbsolutePath() + ".status");
    if (statusFile.exists()) {
        try {
            FileReader r = new FileReader(statusFile);
            char[] buffer = new char[(int) statusFile.length()];
            int len = r.read(buffer);
            r.close();
            String status = new String(buffer, 0, len);
            throw new DownloadFailed(status);
        } catch (IOException e) {
            log.warn("Error writing 'File not found'-Status to " + statusFile.getAbsolutePath(), e);
        }
    }

    mkdirs();

    HttpClient client = new HttpClient();

    String msg = "";
    if (config.useProxy(url)) {
        Credentials defaultcreds = new UsernamePasswordCredentials(config.getProxyUsername(),
                config.getProxyPassword());
        AuthScope scope = new AuthScope(config.getProxyHost(), config.getProxyPort(), AuthScope.ANY_REALM);
        HostConfiguration hc = new HostConfiguration();
        hc.setProxy(config.getProxyHost(), config.getProxyPort());
        client.setHostConfiguration(hc);
        client.getState().setProxyCredentials(scope, defaultcreds);
        msg = "via proxy ";
    }
    log.info("Downloading " + msg + "to " + dest.getAbsolutePath());

    GetMethod get = new GetMethod(url.toString());
    get.setFollowRedirects(true);
    try {
        int status = client.executeMethod(get);

        log.info("Download status: " + status);
        if (0 == 1 && log.isDebugEnabled()) {
            Header[] header = get.getResponseHeaders();
            for (Header aHeader : header)
                log.debug(aHeader.toString().trim());
        }

        log.info("Content: " + valueOf(get.getResponseHeader("Content-Length")) + " bytes; "
                + valueOf(get.getResponseHeader("Content-Type")));

        if (status != HttpStatus.SC_OK) {
            // Remember "File not found"
            if (status == HttpStatus.SC_NOT_FOUND) {
                try {
                    FileWriter w = new FileWriter(statusFile);
                    w.write(get.getStatusLine().toString());
                    w.close();
                } catch (IOException e) {
                    log.warn("Error writing 'File not found'-Status to " + statusFile.getAbsolutePath(), e);
                }
            }
            throw new DownloadFailed(get);
        }

        File dl = new File(dest.getAbsolutePath() + ".new");
        OutputStream out = new BufferedOutputStream(new FileOutputStream(dl));
        IOUtils.copy(get.getResponseBodyAsStream(), out);
        out.close();

        File bak = new File(dest.getAbsolutePath() + ".bak");
        if (bak.exists())
            bak.delete();
        if (dest.exists())
            dest.renameTo(bak);
        dl.renameTo(dest);
    } finally {
        get.releaseConnection();
    }
}

From source file:io.pravega.segmentstore.storage.impl.extendeds3.S3ProxyImpl.java

@Synchronized
@Override/* www  . j  a va2  s . c o  m*/
public void putObject(String bucketName, String key, Range range, Object content) {
    byte[] totalByes = new byte[Math.toIntExact(range.getLast() + 1)];
    try {
        if (range.getFirst() != 0) {
            int bytesRead = client.getObject(bucketName, key).getObject().read(totalByes, 0,
                    Math.toIntExact(range.getFirst()));
            if (bytesRead != range.getFirst()) {
                throw new IllegalStateException("Unable to read from the object " + key);
            }
        }
        int bytesRead = ((InputStream) content).read(totalByes, Math.toIntExact(range.getFirst()),
                Math.toIntExact(range.getLast() + 1 - range.getFirst()));

        if (bytesRead != range.getLast() + 1 - range.getFirst()) {
            throw new IllegalStateException("Not able to read from input stream.");
        }
        client.putObject(new PutObjectRequest(bucketName, key, (Object) new ByteArrayInputStream(totalByes)));
        aclMap.put(key, aclMap.get(key).withSize(range.getLast() - 1));
    } catch (IOException e) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
    }
}

From source file:br.org.acessobrasil.nucleuSilva.util.PegarPaginaWEB.java

/**
 * Independente de Relatorio/*from   w  ww  . ja v a 2  s  .  c om*/
 * @param url
 * @return
 * @throws IOException 
 * @throws HttpException 
 * @throws NotHTML
 * @throws TempoExcedido
 * @throws IOException 
 * @throws HttpException 
 */
public String getContent(String url) throws HttpException, IOException {
    metodo = new GetMethod(url);
    metodo.setRequestHeader("user-agent", "Mozilla/5.0");
    metodo.setFollowRedirects(true);
    int status = httpClient.executeMethod(metodo);
    String type = getContentType(metodo);
    String location = getLocation(metodo);
    //Verificar os possveis erros
    if (status != HttpStatus.SC_OK) {
        //No foi aceito, ocorreu um erro 500 404
        if (status == HttpStatus.SC_NOT_FOUND) {
        }
        return "";
    }
    if ((status == HttpStatus.SC_OK) && (type.toUpperCase().indexOf("TEXT/HTML") == -1)) {
        //No  do tipo texto/html
        return "";
    }
    //Verifica redirecionamento
    if (location != "") {
        //System.out.print(url+" to "+location+"\n");
    }
    String conteudoHTML = metodo.getResponseBodyAsString();

    return conteudoHTML;
}

From source file:com.thoughtworks.go.server.service.PipelinePauseServiceTest.java

@Test
public void shouldPopulateHttpResult404WhenPipelineIsNotFoundForPause() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(goConfigFileDao.load()).thenReturn(new BasicCruiseConfig());

    pipelinePauseService.pause(INVALID_PIPELINE, "cause", VALID_USER, result);

    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(HttpStatus.SC_NOT_FOUND));
    verify(pipelineDao, never()).pause(INVALID_PIPELINE, "cause", "admin");
}

From source file:io.pravega.segmentstore.storage.impl.extendeds3.S3FileSystemImpl.java

@Override
public CopyPartResult copyPart(CopyPartRequest request) {
    Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
    if (partMap == null) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }/*from   w  w  w .  j  a  v  a 2 s  .  com*/
    partMap.put(request.getPartNumber(), request);
    CopyPartResult result = new CopyPartResult();
    result.setPartNumber(request.getPartNumber());
    result.setETag(request.getUploadId());
    return result;
}