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.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java

@Override
public void updateConfig(Long operatorId, Map<OperatorConfigParamDTO, String> config) {
    PutMethod method = new PutMethod(String.format(baseUrl + UPDATE_CONFIG, operatorId));
    prepareMethod(method);/*from  w ww . j av  a 2s  .c om*/
    try {
        String data = serialize(config);
        method.setRequestEntity(new StringRequestEntity(data, "application/json", "UTF-8"));

        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return;
        }
        assertResponseCodeOK(method, statusCode);

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:fr.paris.lutece.plugins.libraryelastic.util.Elastic.java

/**
 * Check if a given index exists//from   ww  w . ja v a  2  s . c  om
 * 
 * @param strIndex
 *            The index
 * @return if th index exists
 * @throws ElasticClientException
 *             If a problem occurs connecting Elastic
 */
public boolean isExists(String strIndex) throws ElasticClientException {
    try {
        String strURI = getURI(strIndex);
        _connexion.GET(strURI);
    } catch (InvalidResponseStatus ex) {
        if (ex.getResponseStatus() == HttpStatus.SC_NOT_FOUND) {
            return false;
        }
        throw new ElasticClientException("ElasticLibrary : Error getting index : " + ex.getMessage(), ex);
    } catch (HttpAccessException ex) {
        throw new ElasticClientException("ElasticLibrary : Error getting index : " + ex.getMessage(), ex);
    }
    return true;
}

From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java

@Override
public void updateAccount(Account account) {
    String resource = String.format(baseUrl + ACCOUNT, account.getId());
    PutMethod method = new PutMethod(resource);
    try {/*  w w  w .  j  a va  2s  .  co m*/
        String data = serialize(account);
        method.setRequestEntity(new StringRequestEntity(data, MIME_TYPE_JSON, DEFAULT_CHAR_ENCODING));
        // Execute the HTTP Call
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return;
        }
        assertResponseCodeOK(method, statusCode);

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

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

@Override
public User getUserById(Long userId) {
    // Create a method instance.
    String resource = String.format(baseUrl + USER, userId);
    GetMethod method = createGetMethod(resource);

    try {/*from w  w  w .  ja va  2  s.c o m*/
        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        assertResponseCodeOK(method, statusCode);
        // Read the response body.
        InputStream body = method.getResponseBodyAsStream();

        return parseJson(body, User.class);

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

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

@Synchronized
@Override//from   ww  w  .j a  va  2 s  . com
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request) {
    Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
    if (partMap == null) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    try {
        partMap.forEach((index, copyPart) -> {
            if (copyPart.getKey() != copyPart.getSourceKey()) {
                Path sourcePath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getSourceKey());
                Path targetPath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getKey());
                try (FileChannel sourceChannel = FileChannel.open(sourcePath, StandardOpenOption.READ);
                        FileChannel targetChannel = FileChannel.open(targetPath, StandardOpenOption.WRITE)) {
                    targetChannel.transferFrom(sourceChannel, Files.size(targetPath),
                            copyPart.getSourceRange().getLast() + 1 - copyPart.getSourceRange().getFirst());
                    targetChannel.close();
                    AclSize aclMap = this.aclMap.get(copyPart.getKey());
                    this.aclMap.put(copyPart.getKey(), aclMap.withSize(Files.size(targetPath)));
                } catch (IOException e) {
                    throw new S3Exception("NoSuchKey", 404, "NoSuchKey", "");
                }
            }
        });
    } finally {
        multipartUploads.remove(request.getKey());
    }

    return new CompleteMultipartUploadResult();
}

From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java

@Override
public void updateConfig(Long operatorId, OperatorConfigParamDTO key, String value) {
    PutMethod method = new PutMethod(
            String.format(baseUrl + UPDATE_CONFIG_PARAM, operatorId, key.name(), value));
    prepareMethod(method);/*from  w  ww.  j av  a2  s  . c  o  m*/
    method.setRequestHeader("content-type", "text/plain;charset=UTF-8;");
    try {
        String data = value;
        method.setRequestEntity(new StringRequestEntity(data, "text/plain", "UTF-8"));

        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return;
        }
        assertResponseCodeOK(method, statusCode);

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.hp.alm.ali.rest.client.AliRestClient.java

@Override
public synchronized void login() {
    // exclude the NTLM authentication scheme (requires NTCredentials we don't supply)
    List<String> authPrefs = new ArrayList<String>(2);
    authPrefs.add(AuthPolicy.DIGEST);/*from w  w w. ja  v a2s.co  m*/
    authPrefs.add(AuthPolicy.BASIC);
    httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

    // first try Apollo style login
    String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate");
    String authXml = createAuthXml();
    PostMethod post = initPostMethod(authPoint, authXml);
    ResultInfo resultInfo = ResultInfo.create(null);
    executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet());

    if (resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) {
        // try Maya style login
        Credentials cred = new UsernamePasswordCredentials(userName, password);
        AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
        httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8");
        httpClient.getState().setCredentials(scope, cred);

        authPoint = pathJoin("/", location, "/authentication-point/authenticate");
        GetMethod get = new GetMethod(authPoint);
        resultInfo = ResultInfo.create(null);
        executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet());
    }
    HttpStatusBasedException.throwForError(resultInfo);
    if (resultInfo.getHttpStatus() != 200) {
        // during login we only accept 200 status (to avoid redirects and such as seemingly correct login)
        throw new AuthenticationFailureException(resultInfo);
    }

    Cookie[] cookies = httpClient.getState().getCookies();
    Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME);
    addTenantCookie(ssoCookie);

    //Since ALM 12.00 it is required explicitly ask for QCSession calling "/rest/site-session"
    //For all the rest of HP ALM / AGM versions it is optional
    String siteSessionPoint = pathJoin("/", location, "/rest/site-session");
    String sessionParamXml = createRestSessionXml();
    post = initPostMethod(siteSessionPoint, sessionParamXml);
    resultInfo = ResultInfo.create(null);
    executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet());
    //AGM throws 403
    if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) {
        HttpStatusBasedException.throwForError(resultInfo);
    }

    cookies = httpClient.getState().getCookies();
    Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME);
    sessionContext = new SessionContext(location, ssoCookie, qcCookie);
}

From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java

@Override
public AccountBalanceResult getAccountBalance(Long accountId) throws AccountNotFoundException {
    String resource = String.format(baseUrl + ACCOUNT_BALANCE, accountId);
    GetMethod method = createGetMethod(resource);

    try {//from  w w  w  .  ja va2 s. c om
        // Execute the method.
        int statusCode = getClient().executeMethod(method);

        if (statusCode == HttpStatus.SC_OK) {
            // Read the response body.
            InputStream body = method.getResponseBodyAsStream();
            if (body == null) {
                return null;
            }
            return parseJson(body, AccountBalanceResult.class);
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            throw new AccountNotFoundException("GetAccountBalance failed. Account[" + accountId
                    + "] was not found remotely (HTTP 404 for '" + resource + "'");

        } else {
            throw new HttpException("Method failed: " + method.getStatusLine());
        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

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

@Override
public User getUserByExternalId(String externalId, Long operatorId) {
    // Create a method instance.
    String resource = String.format(baseUrl + EXTERNAL_USER, operatorId, externalId);
    GetMethod method = createGetMethod(resource);

    try {/*from ww w .  ja v a  2 s  .  com*/
        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        assertResponseCodeOK(method, statusCode);
        // Read the response body.
        InputStream body = method.getResponseBodyAsStream();
        return parseJson(body, User.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.sun.faban.harness.util.CLI.java

private void makeRequest(HttpMethodBase method) throws IOException {
    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
    int status = client.executeMethod(method);
    String enc = method.getResponseCharSet();

    InputStream response = method.getResponseBodyAsStream();

    if (status == HttpStatus.SC_NOT_FOUND) {
        System.err.println("Not found!");
        return;/*w w w  .  j  a  v  a  2  s.  co m*/
    } else if (status == HttpStatus.SC_NO_CONTENT) {
        System.err.println("Empty!");
        return;
    } else if (response != null) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(response, enc));
        String line = null;
        while ((line = reader.readLine()) != null)
            System.out.println(line);
    } else if (status != HttpStatus.SC_OK)
        throw new IOException(HttpStatus.getStatusText(status));
}