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.operations.ExistenceCheckOperation.java

@Override
protected RemoteOperationResult run(WebdavClient client) {
    if (!isOnline()) {
        return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION);
    }//from w  w w .j a v  a  2 s.com
    RemoteOperationResult result = null;
    HeadMethod head = null;
    try {
        head = new HeadMethod(client.getBaseUri() + WebdavUtils.encodePath(mPath));
        int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
        client.exhaustResponse(head.getResponseBodyAsStream());
        boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent)
                || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
        result = new RemoteOperationResult(success, status, head.getResponseHeaders());
        Log_OC.d(TAG,
                "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for "
                        + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status "
                        + status + (!success ? "(FAIL)" : ""));

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG,
                "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for "
                        + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(),
                result.getException());

    } finally {
        if (head != null)
            head.releaseConnection();
    }
    return result;
}

From source file:com.discogs.api.webservice.impl.HttpClientWebService.java

@Override
public Resp doGet(String url) throws WebServiceException {
    HttpMethod method = new GZipCapableGetMethod(url);
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
    method.setDoAuthentication(true);/*ww  w. j a v  a  2  s  . c o m*/

    try {
        // execute the method
        int statusCode = this.httpClient.executeMethod(method);

        if (logger.isDebugEnabled()) {
            logger.debug(method.getResponseBodyAsString());
        }

        switch (statusCode) {
        case HttpStatus.SC_OK:
            return createResp(method.getResponseBodyAsStream());

        case HttpStatus.SC_NOT_FOUND:
            throw new ResourceNotFoundException("Resource not found.", method.getResponseBodyAsString());

        case HttpStatus.SC_BAD_REQUEST:
            throw new RequestException(method.getResponseBodyAsString());

        case HttpStatus.SC_FORBIDDEN:
            throw new AuthorizationException(method.getResponseBodyAsString());

        case HttpStatus.SC_UNAUTHORIZED:
            throw new AuthorizationException(method.getResponseBodyAsString());

        default:
            String em = "web service returned unknown status '" + statusCode + "', response was: "
                    + method.getResponseBodyAsString();
            logger.error(em);
            throw new WebServiceException(em);
        }
    } catch (HttpException e) {
        logger.error("Fatal protocol violation: " + e.getMessage());
        throw new WebServiceException(e.getMessage(), e);
    } catch (IOException e) {
        logger.error("Fatal transport error: " + e.getMessage());
        throw new WebServiceException(e.getMessage(), e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.owncloud.android.lib.resources.files.RemoveTrashbinFileOperation.java

/**
 * Performs the remove operation.// w  w w.j  a v  a  2s.c om
 *
 * @param client Client object to communicate with the remote ownCloud server.
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result;
    DeleteMethod delete = null;

    try {
        delete = new DeleteMethod(client.getNewWebdavUri() + WebdavUtils.encodePath(remotePath));
        int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);

        delete.getResponseBodyAsString(); // exhaust the response, although not interesting
        result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), delete);
        Log_OC.i(TAG, "Remove " + remotePath + ": " + result.getLogMessage());

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Remove " + remotePath + ": " + result.getLogMessage(), e);

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

    return result;
}

From source file:com.bbva.arq.devops.ae.mirrorgate.jenkins.plugin.service.DefaultMirrorGateServiceTest.java

@Test
public void testFailedPublishBuildDataTest() throws IOException {
    when(htppClient.executeMethod(any(PostMethod.class))).thenReturn(HttpStatus.SC_NOT_FOUND);

    MirrorGateResponse response = service.publishBuildData(makeBuildRequest());

    assertEquals(HttpStatus.SC_NOT_FOUND, response.getResponseCode());
}

From source file:com.owncloud.android.operations.RemoveFileOperation.java

/**
 * Performs the remove operation/* ww  w .  j  a  v  a  2 s .  c o m*/
 * 
 * @param   client      Client object to communicate with the remote ownCloud server.
 */
@Override
protected RemoteOperationResult run(WebdavClient client) {
    RemoteOperationResult result = null;
    DeleteMethod delete = null;
    try {
        delete = new DeleteMethod(client.getBaseUri() + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));
        int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
        if (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND) {
            if (mFileToRemove.isDirectory()) {
                mDataStorageManager.removeDirectory(mFileToRemove, true, mDeleteLocalCopy);
            } else {
                mDataStorageManager.removeFile(mFileToRemove, mDeleteLocalCopy);
            }
        }
        delete.getResponseBodyAsString(); // exhaust the response, although not interesting
        result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status,
                delete.getResponseHeaders());
        Log_OC.i(TAG, "Remove " + mFileToRemove.getRemotePath() + ": " + result.getLogMessage());

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Remove " + mFileToRemove.getRemotePath() + ": " + result.getLogMessage(), e);

    } finally {
        if (delete != null)
            delete.releaseConnection();
    }
    return result;
}

From source file:com.cerema.cloud2.lib.resources.files.RemoveRemoteFileOperation.java

/**
 * Performs the rename operation.//from w w w  .j  a  va2s  .  c  o  m
 * 
 * @param client   Client object to communicate with the remote ownCloud server.
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    DeleteMethod delete = null;

    try {
        delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
        int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);

        delete.getResponseBodyAsString(); // exhaust the response, although not interesting
        result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status,
                delete.getResponseHeaders());
        Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage());

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e);

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

    return result;
}

From source file:net.sf.ufsc.http.HttpFile.java

/**
 * @see net.sf.ufsc.File#exists()//w ww  .  ja  v a  2s.  c  om
 */
public boolean exists() throws java.io.IOException {
    HeadMethod method = new HeadMethod(this.uri.toString());

    int status = this.client.executeMethod(method);

    if (status == HttpStatus.SC_OK) {
        return true;
    } else if (status == HttpStatus.SC_NOT_FOUND) {
        return false;
    } else {
        throw new IOException(method.getStatusText());
    }
}

From source file:com.sap.netweaver.porta.core.nw7.FileUploaderImpl.java

public String[] upload(File[] archives) throws CoreException {
    // check if there are any credentials already set
    if (client == null) {
        // trigger the mechanism for requesting user for credentials
        throw new NotAuthorizedException(FAULT_UNAUTHORIZED.getFaultReason());
    }/*from  w w w . j a va  2  s.  c  om*/

    PostMethod method = null;
    try {
        Part[] parts = new Part[archives.length];
        for (int i = 0; i < archives.length; i++) {
            parts[i] = new FilePart(archives[i].getName(), archives[i]);
        }

        method = new PostMethod(url);
        method.setDoAuthentication(true);
        method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));

        int statusCode = client.executeMethod(method);
        if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
            throw new NotAuthorizedException(FAULT_INVALID_CREDENTIALS.getFaultReason());
        } else if (statusCode == HttpStatus.SC_FORBIDDEN) {
            throw new NotAuthorizedException(FAULT_PERMISSION_DENIED.getFaultReason());
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            throw new NoWSGateException(null, url);
        } else if (statusCode != HttpStatus.SC_OK) {
            throw new CoreException(method.getStatusText());
        }

        InputStream responseStream = method.getResponseBodyAsStream();
        BufferedReader responseReader = new BufferedReader(new InputStreamReader(responseStream));
        String line;
        List<String> paths = new ArrayList<String>();
        while ((line = responseReader.readLine()) != null) {
            paths.add(line);
        }
        responseReader.close();
        responseStream.close();

        return paths.toArray(new String[] {});
    } catch (HttpException e) {
        throw new CoreException(e);
    } catch (IOException e) {
        throw new CoreException(e);
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }
}

From source file:jetbrains.buildServer.symbols.DownloadSymbolsControllerTest.java

@Test
public void request_pdb_simple() throws Throwable {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    SUser user = myFixture.getUserModel().getGuestUser();
    user.addRole(RoleScope.projectScope(myProject.getProjectId()), getProjectDevRole());
    assertTrue(//from   w w w .j  a  v  a 2s  .co  m
            user.isPermissionGrantedForProject(myProject.getProjectId(), Permission.VIEW_BUILD_RUNTIME_DATA));

    myRequest.setRequestURI("mock", getRegisterPdbUrl("secur32.pdb", "8EF4E863187C45E78F4632152CC82FEB"));

    doGet();

    assertEquals(HttpStatus.SC_NOT_FOUND, myResponse.getStatus());
    assertEquals("Symbol file not found", myResponse.getStatusText());
}

From source file:com.owncloud.android.lib.resources.files.CheckEtagOperation.java

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    try {//from  w  ww .j  a va2  s  .c om
        DavPropertyNameSet propSet = new DavPropertyNameSet();
        propSet.add(DavPropertyName.GETETAG);

        PropFindMethod propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(path),
                propSet, 0);
        int status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

        if (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK) {
            MultiStatusResponse resp = propfind.getResponseBodyAsMultiStatus().getResponses()[0];

            String etag = WebdavUtils.parseEtag(
                    (String) resp.getProperties(HttpStatus.SC_OK).get(DavPropertyName.GETETAG).getValue());

            if (etag.equals(expectedEtag)) {
                return new RemoteOperationResult(RemoteOperationResult.ResultCode.ETAG_UNCHANGED);
            } else {
                RemoteOperationResult result = new RemoteOperationResult(
                        RemoteOperationResult.ResultCode.ETAG_CHANGED);

                ArrayList<Object> list = new ArrayList<>();
                list.add(etag);
                result.setData(list);

                return result;
            }
        }

        if (status == HttpStatus.SC_NOT_FOUND) {
            return new RemoteOperationResult(RemoteOperationResult.ResultCode.FILE_NOT_FOUND);
        }
    } catch (Exception e) {
        Log_OC.e(TAG, "Error while retrieving eTag");
    }

    return new RemoteOperationResult(RemoteOperationResult.ResultCode.ETAG_CHANGED);
}