Example usage for org.apache.commons.httpclient URIException printStackTrace

List of usage examples for org.apache.commons.httpclient URIException printStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.httpclient URIException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Print this HttpException and its stack trace to the standard error stream.

Usage

From source file:com.github.jobs.api.GithubJobsApi.java

public static Job getJob(String id, boolean markdown) {
    String baseUrl = String.format(ApiConstants.JOB_URL, id);
    ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
    if (markdown) {
        pairs.add(new NameValuePair(ApiConstants.MARKDOWN, String.valueOf(markdown)));
    }//from  www . java  2s. c  o m
    try {
        String url = createUrl(baseUrl, pairs);
        String response = HttpHandler.getInstance().getRequest(url);

        // convert json to object
        Gson gson = new Gson();
        return gson.fromJson(response, Job.class);
    } catch (URIException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.github.jobs.api.GithubJobsApi.java

public static List<Job> search(Search search) {
    ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
    if (search.getSearch() != null) {
        pairs.add(new NameValuePair(ApiConstants.SEARCH, search.getSearch()));
    }//from  ww w  .  j a va  2s  . c  om
    if (search.getLocation() != null) {
        pairs.add(new NameValuePair(ApiConstants.LOCATION, search.getLocation()));
    } else if (search.getLatitude() != 0 && search.getLongitude() != 0) {
        pairs.add(new NameValuePair(ApiConstants.LATITUDE, String.valueOf(search.getLatitude())));
        pairs.add(new NameValuePair(ApiConstants.LONGITUDE, String.valueOf(search.getLongitude())));
    }
    if (search.getPage() > 0) {
        pairs.add(new NameValuePair(ApiConstants.PAGE, String.valueOf(search.getPage())));
    }
    if (search.isFullTime()) {
        pairs.add(new NameValuePair(ApiConstants.FULL_TIME, String.valueOf(search.isFullTime())));
    }
    try {
        String url = createUrl(ApiConstants.POSITIONS_URL, pairs);
        String response = HttpHandler.getInstance().getRequest(url);
        if (response == null) {
            throw new RuntimeException("Error calling API; it returned null.");
        }

        // convert json to object
        Gson gson = new Gson();
        JSONArray jsonArray = new JSONArray(response);
        List<Job> jobs = new ArrayList<Job>();
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject object = jsonArray.getJSONObject(i);
            jobs.add(gson.fromJson(object.toString(), Job.class));
        }
        return jobs;
    } catch (URIException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:dk.netarkivet.harvester.harvesting.OnNSDomainsDecideRule.java

/**
 * Convert a URI to its domain.// w w w .j  a  v a2 s .  c  o m
 * @param uri URL to convert to Top most domain-name according to
 * NetarchiveSuite definition
 * @return Domain name
 */
public static String convertToDomain(String uri) {
    ArgumentNotValid.checkNotNullOrEmpty(uri, "String uri");
    DomainnameQueueAssignmentPolicy policy = new DomainnameQueueAssignmentPolicy();

    UURI uuri = null;
    try {
        uuri = UURIFactory.getInstance(uri);
    } catch (URIException e) {
        e.printStackTrace();
        // allow to continue with original string uri  
        // FIXME/TODO 
        // AD "allow to continue with original string uri"
        // We cannot do that any more, as the argument to getClassKey is now CrawlURI, except for
        // the string

    }
    try {
        return policy.getClassKey(new CrawlURI(uuri));
    } catch (Throwable e) {
        // illegal URI - return a SURT that will not match any real URIs
        return NON_VALID_DOMAIN;
    }
}

From source file:dk.netarkivet.wayback.batch.copycode.NetarchiveSuiteUrlOperations.java

/**
 * @param baseUrl/*  ww w.  j  av  a2s  .com*/
 * @param url
 * @return url resolved against baseUrl, unless it is absolute already
 */
public static String resolveUrl(String baseUrl, String url) {
    for (final String scheme : ALL_SCHEMES) {
        if (url.startsWith(scheme)) {
            try {
                return NetarchiveSuiteUURIFactory.getInstance(url).getEscapedURI();
            } catch (URIException e) {
                e.printStackTrace();
                // can't let a space exist... send back close to whatever
                // came
                // in...
                return url.replace(" ", "%20");
            }
        }
    }
    UURI absBaseURI;
    UURI resolvedURI = null;
    try {
        absBaseURI = NetarchiveSuiteUURIFactory.getInstance(baseUrl);
        resolvedURI = NetarchiveSuiteUURIFactory.getInstance(absBaseURI, url);
    } catch (URIException e) {
        e.printStackTrace();
        return url.replace(" ", "%20");
    }
    return resolvedURI.getEscapedURI();
}

From source file:com.cyberway.issue.util.SurtPrefixSet.java

/**
 * Given a plain URI or hostname/hostname+path, deduce an implied SURT 
 * prefix from it. Results may be unpredictable on strings that cannot
 * be interpreted as URIs. //w  ww  . java2 s  .c  om
 * 
 * UURI 'fixup' is applied to the URI that is built. 
 *
 * @param u URI or almost-URI to consider
 * @return implied SURT prefix form
 */
public static String prefixFromPlain(String u) {
    u = ArchiveUtils.addImpliedHttpIfNecessary(u);
    u = coerceFromHttpsForComparison(u);
    boolean trailingSlash = u.endsWith("/");
    // ensure all typical UURI cleanup (incl. IDN-punycoding) is done
    try {
        u = UURIFactory.getInstance(u).toString();
    } catch (URIException e) {
        e.printStackTrace();
        // allow to continue with original string uri
    }
    // except: don't let UURI-fixup add a trailing slash
    // if it wasn't already there (presence or absence of
    // such slash has special meaning specifying implied
    // SURT prefixes)
    if (!trailingSlash && u.endsWith("/")) {
        u = u.substring(0, u.length() - 1);
    }
    // convert to full SURT
    u = SURT.fromURI(u);
    // truncate to implied prefix
    u = SurtPrefixSet.asPrefix(u);
    return u;
}

From source file:com.cyberway.issue.crawler.frontier.RecoveryJournal.java

/**
 * Import just the SUCCESS (and possibly FAILURE) URIs from the given
 * recovery log into the frontier as considered included. 
 * //from  ww w . j av a 2  s. com
 * @param source recovery log file to use
 * @param frontier frontier to update
 * @param retainFailures whether failure ('Ff') URIs should count as done
 * @return number of lines in recovery log (for reference)
 * @throws IOException
 */
private static int importCompletionInfoFromLog(File source, CrawlController controller, boolean retainFailures)
        throws IOException {
    Frontier frontier = controller.getFrontier();
    boolean checkScope = (Boolean) controller.getOrder().getUncheckedAttribute(null,
            CrawlOrder.ATTR_RECOVER_SCOPE_INCLUDES);
    CrawlScope scope = checkScope ? controller.getScope() : null;
    // Scan log for all 'Fs' lines: add as 'alreadyIncluded'
    BufferedInputStream is = getBufferedInput(source);
    // create MutableString of good starting size (will grow if necessary)
    MutableString read = new MutableString(UURI.MAX_URL_LENGTH);
    int lines = 0;
    try {
        while (readLine(is, read)) {
            lines++;
            boolean wasSuccess = read.startsWith(F_SUCCESS);
            if (wasSuccess || (retainFailures && read.startsWith(F_FAILURE))) {
                try {
                    CandidateURI cauri = CandidateURI.fromString(read.substring(F_SUCCESS.length()).toString());
                    if (checkScope) {
                        if (!scope.accepts(cauri)) {
                            // skip out-of-scope URIs.
                            continue;
                        }
                    }
                    frontier.considerIncluded(cauri.getUURI());
                    if (wasSuccess) {
                        if (frontier.getFrontierJournal() != null) {
                            frontier.getFrontierJournal().finishedSuccess(cauri);
                        }
                    } else {
                        // carryforward failure, in case future recovery
                        // wants to no retain them as finished 
                        if (frontier.getFrontierJournal() != null) {
                            frontier.getFrontierJournal().finishedFailure(cauri);
                        }
                    }
                } catch (URIException e) {
                    e.printStackTrace();
                }
            }
            if ((lines % PROGRESS_INTERVAL) == 0) {
                // every 1 million lines, print progress
                LOGGER.info("at line " + lines + " alreadyIncluded count = " + frontier.discoveredUriCount());
            }
        }
    } catch (EOFException e) {
        // expected in some uncleanly-closed recovery logs; ignore
    } finally {
        is.close();
    }
    return lines;
}

From source file:com.icloud.framework.http.URLUtil.java

public static String getRequestUrlString(HttpServletRequest request) {

    String fullURL = "";

    try {//from w  ww .jav  a 2 s  .co m

        String urlString = request.getRequestURL().toString();

        String encodedRequestURL = URIUtil.encodePath(urlString);

        String queryString = request.getQueryString();

        if (null == queryString) {
            fullURL = encodedRequestURL;
        } else {
            fullURL = encodedRequestURL + "?" + queryString;
        }

    } catch (URIException e1) {
        e1.printStackTrace();
    }
    // http://robinkin:8280/jproxy-feeder/urlset/add

    // request.getPathTranslated();
    // //
    // /home/liangwang/repo/mobile/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/jproxy/jproxy-feeder/urlset/add
    //
    // request.getPathInfo();
    // // /jproxy-feeder/urlset/add
    //
    // request.getRequestURI();
    // // /jproxy-feeder/urlset/add
    //
    // request.getContextPath();
    // /

    // url=http%3A%2F%2Fnews.sohu.com%2F20040723%2Fn221153893.shtml&setname=test

    // HttpGet will translate a urlString into a URI, so , we should do the
    // check first,
    // if failed, call the encoder
    //      try {
    //         URI url = new URI(fullURL);
    //      } catch (URISyntaxException e) {
    //         try {
    //            fullURL = URIUtil.encodePathQuery(fullURL);
    //         } catch (URIException e1) {
    //            e1.printStackTrace();
    //         }
    //      }

    return fullURL;
}

From source file:gov.tva.sparky.util.indexer.HistorianArchiveLookupTable.java

public static int RetrieveAndIncArchiveRowCount() {

    int iRowCount = RetrieveFileArchiveRowCount();

    iRowCount++;//  w  ww. j  a  va2 s .  com

    // now update the table

    byte[] arBytes = HDFSPointBlockPointer.intToByteArray(iRowCount);

    try {
        RestProxy.InsertHbaseIndexBucket(HBASE_HDFSARCHIVELOOKUPTABLE_TABLE_NAME,
                HBASE_HDFSARCHIVELOOKUPTABLE_TRACKING_ROWCOUNT_KEY,
                HBASE_HDFSARCHIVELOOKUPTABLE_TRACKING_COL_NAME, HBASE_HDFSARCHIVELOOKUPTABLE_TRACKING_QUAL_NAME,
                arBytes);
    } catch (URIException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return iRowCount;

}

From source file:gov.tva.sparky.util.indexer.HistorianArchiveLookupTable.java

private static boolean Update_Hbase_ReverseLookupTable(String strHdfsPath_ReverseKey, int iNewRowID) {

    String strForwardRowKey = CalculateRowKeyString(iNewRowID);

    byte[] arBytePayload = strForwardRowKey.getBytes();

    System.out.println("ReverseLookupTable > Update > Path: "
            + HistorianArchiveLookupTableEntry.DecodeKeyFromBase64String(strHdfsPath_ReverseKey));
    System.out.println(/*from www  . j ava  2s.co  m*/
            "ReverseLookupTable > Update > Row Key: " + strHdfsPath_ReverseKey + " => " + strForwardRowKey);

    try {
        RestProxy.InsertHbaseIndexBucket(HBASE_HDFSARCHIVE_REVERSE_LOOKUPTABLE_TABLE_NAME,
                strHdfsPath_ReverseKey, HBASE_HDFSARCHIVE_REVERSE_LOOKUPTABLE_FILELOOKUP_COL_NAME,
                HBASE_HDFSARCHIVE_REVERSE_LOOKUPTABLE_FILELOOKUP_QUAL_FID_NAME, arBytePayload);
    } catch (URIException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    return true;

}

From source file:de.fuberlin.wiwiss.marbles.dataproviders.SPARQLProviderBase.java

public org.apache.commons.httpclient.URI getQueryURL(Resource resource) {
    org.apache.commons.httpclient.URI queryURL = null;
    try {/*from  www. ja v a2s  .com*/
        if (!(resource instanceof BNode))
            queryURL = new org.apache.commons.httpclient.URI(
                    getEndpoint() + "?query=" + URLEncoder.encode(getQuery(resource), "UTF-8"),
                    true /* is now escaped!! */);
    } catch (URIException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return queryURL;
}