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.wallet.client.WalletServiceClientHTTP.java

@Override
public Account getAccount(Long userId, String currencyCode) {
    String resource = String.format(baseUrl + LOOKUP_ACCOUNT_ID, userId, currencyCode);
    GetMethod method = createGetMethod(resource);

    try {/*from ww  w .j a  v  a 2  s .  c  om*/
        // 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, Account.class);

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

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

/**
 * Pega o cdigo css//  w  w w.  jav a 2 s.c  o m
 * @param url
 * @return
 * @throws Exception 
 */
public String getCssContent(String url) throws Exception {
    metodo = new GetMethod(url);
    metodo.setRequestHeader("user-agent", "Mozilla/5.0");
    metodo.setFollowRedirects(true);
    int status = httpClient.executeMethod(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) {
        }
        throw new Exception("Erro de http " + status + " para url='" + url + "'");
        //return "";
    }
    //Verifica redirecionamento
    if (location != "") {
        //System.out.print(url+" to "+location+"\n");
    }
    String conteudoHTML = metodo.getResponseBodyAsString();

    return conteudoHTML;
}

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

@Override
public CopyPartResult copyPart(CopyPartRequest request) {
    if (aclMap.get(request.getKey()) == null) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", request.getKey());
    }/*from www  .  j  a  v  a2 s  . c  om*/
    return client.copyPart(request);
}

From source file:edu.unc.lib.dl.admin.controller.MODSController.java

/**
 * Retrieves the MD_DESCRIPTIVE datastream, containing MODS, for this item if one is present. If it is not present,
 * then returns a blank MODS document.//from  www.ja v  a2s  .  c om
 *
 * @param idPrefix
 * @param id
 * @return
 */
@RequestMapping(value = "{pid}/mods", method = RequestMethod.GET)
public @ResponseBody String getMods(@PathVariable("pid") String pid) {
    String mods = null;
    String dataUrl = swordUrl + "em/" + pid + "/" + ContentModelHelper.Datastream.MD_DESCRIPTIVE;

    HttpClient client = HttpClientUtil.getAuthenticatedClient(dataUrl, swordUsername, swordPassword);
    client.getParams().setAuthenticationPreemptive(true);
    GetMethod method = new GetMethod(dataUrl);

    // Pass the users groups along with the request
    AccessGroupSet groups = GroupsThreadStore.getGroups();
    method.addRequestHeader(HttpClientUtil.FORWARDED_GROUPS_HEADER, groups.joinAccessGroups(";"));

    try {
        client.executeMethod(method);
        if (method.getStatusCode() == HttpStatus.SC_OK) {
            try {
                mods = method.getResponseBodyAsString();
            } catch (IOException e) {
                log.info("Problem uploading MODS for " + pid + ": " + e.getMessage());
            } finally {
                method.releaseConnection();
            }
        } else {
            if (method.getStatusCode() == HttpStatus.SC_BAD_REQUEST
                    || method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                // Ensure that the object actually exists
                PID existingPID = tripleStoreQueryService.verify(new PID(pid));
                if (existingPID != null) {
                    // MODS doesn't exist, so pass back an empty record.
                    mods = "<mods:mods xmlns:mods=\"http://www.loc.gov/mods/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"></mods:mods>";
                } else {
                    throw new Exception(
                            "Unable to retrieve MODS.  Object " + pid + " does not exist in the repository.");
                }
            } else {
                throw new Exception("Failure to retrieve fedora content due to response of: "
                        + method.getStatusLine().toString() + "\nPath was: " + method.getURI().getURI());
            }
        }
    } catch (Exception e) {
        log.error("Error while attempting to stream Fedora content for " + pid, e);
    }
    return mods;
}

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

@Override
public ListObjectsResult listObjects(String bucketName, String prefix) {
    ListObjectsResult result = new ListObjectsResult();
    ArrayList<S3Object> list = new ArrayList<>();
    Path path = Paths.get(this.baseDir, bucketName, prefix);
    try {//  w w  w  . ja v  a 2s.  c  om
        if (Files.exists(path)) {
            if (Files.isDirectory(path)) {
                Files.list(path).forEach((file) -> {
                    addFileAsObjectToList(file, list, bucketName);
                });
            } else {
                addFileAsObjectToList(path, list, bucketName);
            }
        }
    } catch (IOException e) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    result.setObjects(list);
    return result;
}

From source file:ke.go.moh.oec.adt.Daemon.java

private static boolean sendMessage(String url, String filename) {
    int returnStatus = HttpStatus.SC_CREATED;
    HttpClient httpclient = new HttpClient();
    HttpConnectionManager connectionManager = httpclient.getHttpConnectionManager();
    connectionManager.getParams().setSoTimeout(120000);

    PostMethod httpPost = new PostMethod(url);

    RequestEntity requestEntity;/*from ww w  .jav  a  2 s  . c o m*/
    try {
        FileInputStream message = new FileInputStream(filename);
        Base64InputStream message64 = new Base64InputStream(message, true, -1, null);
        requestEntity = new InputStreamRequestEntity(message64, "application/octet-stream");
    } catch (FileNotFoundException e) {
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "File not found.", e);
        return false;
    }
    httpPost.setRequestEntity(requestEntity);
    try {
        httpclient.executeMethod(httpPost);
        returnStatus = httpPost.getStatusCode();
    } catch (SocketTimeoutException e) {
        returnStatus = HttpStatus.SC_REQUEST_TIMEOUT;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Request timed out.  Not retrying.", e);
    } catch (HttpException e) {
        returnStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "HTTP exception.  Not retrying.", e);
    } catch (ConnectException e) {
        returnStatus = HttpStatus.SC_SERVICE_UNAVAILABLE;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Service unavailable.  Not retrying.", e);
    } catch (UnknownHostException e) {
        returnStatus = HttpStatus.SC_NOT_FOUND;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Not found.  Not retrying.", e);
    } catch (IOException e) {
        returnStatus = HttpStatus.SC_GATEWAY_TIMEOUT;
        Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "IO exception.  Not retrying.", e);
    } finally {
        httpPost.releaseConnection();
    }
    return returnStatus == HttpStatus.SC_OK;
}

From source file:ch.ksfx.web.services.spidering.http.HttpClientHelper.java

private HttpMethod executeMethod(HttpMethod httpMethod) {
    for (Header header : this.headers.getHeaders()) {
        httpMethod.setRequestHeader(header);
    }/*from  w  w  w .j  a  v  a  2 s  .c  o  m*/

    httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new KsfxHttpRetryHandler(retryCount, retryDelay));

    try {
        int tryCount = 0;
        int statusCode;
        do {
            if (tryCount > 1) {
                httpMethod = createNewHttpMethod(httpMethod);
                try {
                    if (retryDelay == 0) {
                        retryDelay = DEFAULT_RETRY_DELAY;
                    }
                    Thread.sleep(retryDelay);
                } catch (InterruptedException e) {
                    logger.severe("InterruptedException");
                }
            }

            //PROXY Configuration
            /*
            if (torify) {
                    
            String proxyHost = "";
            Integer proxyPort = 0;
                    
            try {
                    proxyHost = SpiderConfiguration.getConfiguration().getString("torifyHost");
                    proxyPort = SpiderConfiguration.getConfiguration().getInt("torifyPort");
            } catch (Exception e) {
                logger.severe("Cannot get Proxy information");
            }
                    
            this.httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
            }
            */

            statusCode = this.httpClient.executeMethod(httpMethod);
            tryCount++;
        } while (!(statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_FORBIDDEN
                || statusCode == HttpStatus.SC_NOT_FOUND) && tryCount < retryCount);
        if (statusCode != HttpStatus.SC_OK) {
            System.out.println("HTTP method failed: " + httpMethod.getStatusLine() + " - "
                    + httpMethod.getURI().toString());
        }
    } catch (HttpException e) {
        e.printStackTrace();
        httpMethod.abort();
        try {
            logger.log(Level.SEVERE, "Redirrex " + e.getClass(), e);
            if (e.getClass().equals(RedirectException.class)) {
                logger.log(Level.SEVERE, "Is real redirect exception", e);
                throw new RuntimeException("HttpRedirectException");
            }
            logger.log(Level.SEVERE, "HTTP protocol error for URL: " + httpMethod.getURI().toString(), e);
        } catch (URIException e1) {
            e.printStackTrace();
            logger.log(Level.SEVERE, "URI exception", e);
        }
        throw new RuntimeException("HttpException");
    } catch (IOException e) {
        try {
            e.printStackTrace();
            logger.log(Level.SEVERE, "HTTP transport error for URL: " + httpMethod.getURI().toString(), e);

        } catch (URIException e1) {
            e.printStackTrace();
            logger.log(Level.SEVERE, "URI exception", e);

        }
        throw new RuntimeException("IOException");
    }
    return httpMethod;
}

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

@Override
public void createOperator(OperatorDTO operator) {
    PostMethod method = new PostMethod(baseUrl + CREATE_OPERATOR);
    prepareMethod(method);/*from ww w .  j a  va2  s  .c o m*/
    try {

        String data = serialize(operator);
        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:net.sourceforge.jwbf.actions.HttpActionClient.java

/**
 * Process a GET Message./*from  ww w  . j  av a2s.  c om*/
 * 
 * @param authgets
 *            a
 * @param cp
 *            a
 * @return a returning message, not null
 * @throws IOException on problems
 * @throws CookieException on problems
 * @throws ProcessException on problems
 */
protected String get(HttpMethod authgets, ContentProcessable cp)
        throws IOException, CookieException, ProcessException {
    showCookies(client);
    String out = "";
    authgets.getParams().setParameter("http.protocol.content-charset", MediaWikiBot.CHARSET);
    //      System.err.println(authgets.getParams().getParameter("http.protocol.content-charset"));

    client.executeMethod(authgets);
    cp.validateReturningCookies(client.getState().getCookies(), authgets);
    LOG.debug(authgets.getURI());
    LOG.debug("GET: " + authgets.getStatusLine().toString());

    out = authgets.getResponseBodyAsString();

    out = cp.processReturningText(out, authgets);
    // release any connection resources used by the method
    authgets.releaseConnection();
    int statuscode = authgets.getStatusCode();

    if (statuscode == HttpStatus.SC_NOT_FOUND) {
        LOG.warn("Not Found: " + authgets.getQueryString());

        throw new FileNotFoundException(authgets.getQueryString());
    }

    return out;
}

From source file:com.kagilum.plugins.icescrum.IceScrumSession.java

private void checkServerStatus(int code) throws IOException {
    switch (code) {
    case HttpStatus.SC_SERVICE_UNAVAILABLE:
        throw new IOException(Messages.IceScrumSession_icescrum_http_unavailable());
    case HttpStatus.SC_UNAUTHORIZED:
        throw new IOException(Messages.IceScrumSession_icescrum_http_unauthorized());
    case HttpStatus.SC_FORBIDDEN:
        throw new IOException(Messages.IceScrumSession_icescrum_http_forbidden());
    case HttpStatus.SC_NOT_FOUND:
        throw new IOException(Messages.IceScrumSession_icescrum_http_notfound());
    default:/*  w  w w .  j  av a  2  s . c o  m*/
        throw new IOException(
                Messages.IceScrumSession_icescrum_http_error() + " (" + HttpStatus.getStatusText(code) + ")");
    }
}