Java Code Examples for org.apache.commons.httpclient.URIException#printStackTrace()

The following examples show how to use org.apache.commons.httpclient.URIException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SURT.java    From webarchive-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Given a plain URI or hostname/hostname+path, give its SURT form.
 * Results may be unpredictable on strings that cannot
 * be interpreted as URIs. 
 * 
 * UURI 'fixup' is applied to the URI before conversion to SURT 
 * form. 
 *
 * @param u URI or almost-URI to consider
 * @return implied SURT prefix form
 */
public static String fromPlain(String u) {
    u = ArchiveUtils.addImpliedHttpIfNecessary(u);
    boolean trailingSlash = u.endsWith("/");
    // ensure all typical UURI cleanup (incl. IDN-punycoding) is done
    try {
        u = UsableURIFactory.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);
    return u;
}
 
Example 2
Source File: Proxy.java    From odo with Apache License 2.0 5 votes vote down vote up
/**
 * Log modified request
 *
 * @param httpMethodProxyRequest
 * @param httpServletResponse
 * @param history
 */
private void logRequestHistory(HttpMethod httpMethodProxyRequest, PluginResponse httpServletResponse,
                               History history) {
    try {
        if (requestInformation.get().handle && requestInformation.get().client.getIsActive()) {
            logger.info("Storing history");
            String createdDate;
            SimpleDateFormat sdf = new SimpleDateFormat();
            sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
            sdf.applyPattern("dd MMM yyyy HH:mm:ss");
            createdDate = sdf.format(new Date()) + " GMT";

            history.setCreatedAt(createdDate);
            history.setRequestURL(HttpUtilities.getURL(httpMethodProxyRequest.getURI().toString()));
            history.setRequestParams(httpMethodProxyRequest.getQueryString() == null ? ""
                                         : httpMethodProxyRequest.getQueryString());
            history.setRequestHeaders(HttpUtilities.getHeaders(httpMethodProxyRequest));
            history.setResponseHeaders(HttpUtilities.getHeaders(httpServletResponse));
            history.setResponseCode(Integer.toString(httpServletResponse.getStatus()));
            history.setResponseContentType(httpServletResponse.getContentType());
            history.setResponseData(httpServletResponse.getContentString());
            history.setResponseBodyDecoded(httpServletResponse.isContentDecoded());
            HistoryService.getInstance().addHistory(history);
            logger.info("Done storing");
        }
    } catch (URIException e) {
        e.printStackTrace();
    }
}