Example usage for org.apache.commons.codec.net URLCodec URLCodec

List of usage examples for org.apache.commons.codec.net URLCodec URLCodec

Introduction

In this page you can find the example usage for org.apache.commons.codec.net URLCodec URLCodec.

Prototype

public URLCodec() 

Source Link

Document

Default constructor.

Usage

From source file:NetUsage.java

public void start() throws EncoderException, DecoderException {

    String urlData1 = "This#is^a&String with reserved @/characters";

    URLCodec encoder = new URLCodec();

    String result = encoder.encode(urlData1);

    System.err.println("URL Encoding result: " + result);
    System.err.println("URL Decoding result: " + encoder.decode(result));
}

From source file:com.autonomy.aci.client.transport.gss.GssEncryptionCodecTest.java

@Test(expected = EncryptionCodecException.class)
public void testDecodeInternalDecoderException() throws UnsupportedEncodingException, EncryptionCodecException {
    final byte[] encoded = new URLCodec().encode("This is a $tring that n33ds % ", CharEncoding.UTF_8)
            .getBytes(CharEncoding.UTF_8);

    // Partially copy the encoded byte array, so it should fail on decoding...
    final byte[] bad = new byte[encoded.length - 2];
    System.arraycopy(encoded, 0, bad, 0, (encoded.length - 2));

    new GssEncryptionCodec(spy(GSSContext.class)).decodeInternal(bad);
    fail("Should've thrown a DecoderException...");
}

From source file:com.adavr.player.media.XVClient.java

@Override
public String getStreamURL(String url) throws ClientException {
    Map<String, String> flashVars = getFlashVars(url);
    if (flashVars == null) {
        return null;
    }//from  w  w w  .  ja  va 2s .  co  m
    String flvUrl = flashVars.get("flv_url");
    try {
        return new URLCodec().decode(flvUrl);
    } catch (DecoderException ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:com.att.api.webhooks.service.WebhooksService.java

/**
 * Creates a WebhooksService object.//from  w ww .  j  a v a 2 s .  c  om
 *
 * @param fqdn fully qualified domain name to use for sending requests
 * @param token OAuth token to use for authorization
 */
public WebhooksService(String fqdn, OAuthToken token) {
    super(fqdn, token);
    codec = new URLCodec();
}

From source file:jp.dip.komusubi.botter.util.TinyUrlUtil.java

@Override
public String shorten(String url) {
    String responseLine = null;//from w  w  w . jav  a 2 s.c  o  m
    try {
        URLCodec codec = new URLCodec();
        String requestUrl = SHORTEN_SERVICE_URL + "?url=" + codec.decode(url);
        responseLine = UrlAccessDelegate.readFirstLine(requestUrl);
        if (responseLine == null)
            logger.warn("tinyurl response is null, URL is :{}", requestUrl);
    } catch (DecoderException e) {
        throw new BotterException(e);
    }
    return responseLine;
}

From source file:jp.dip.komusubi.botter.util.TrimUrlUtil.java

@Override
public String shorten(String url) {
    String responseLine = null;/* ww  w.ja  v a 2s  .  c om*/
    try {
        URLCodec codec = new URLCodec();
        String requestUrl = SHORTEN_SERVICE_URL + "?url=" + codec.encode(url);
        responseLine = UrlAccessDelegate.readFirstLine(requestUrl);
        if (responseLine == null)
            logger.warn("tr.im response is null, URL is :{}", requestUrl);
    } catch (EncoderException e) {
        throw new BotterException(e);
    }
    return responseLine;
}

From source file:de.mirkosertic.desktopsearch.SearchServlet.java

private void fillinSearchResult(HttpServletRequest aRequest, HttpServletResponse aResponse)
        throws ServletException, IOException {

    URLCodec theURLCodec = new URLCodec();

    String theQueryString = aRequest.getParameter("querystring");
    String theBasePath = basePath;
    String theBackLink = basePath;
    if (!StringUtils.isEmpty(theQueryString)) {
        try {//  ww w  . j  av a2  s.co m
            theBasePath = theBasePath + "/" + theURLCodec.encode(theQueryString);
            theBackLink = theBackLink + "/" + theURLCodec.encode(theQueryString);
        } catch (EncoderException e) {
            LOGGER.error("Error encoding query string " + theQueryString, e);
        }
    }
    Map<String, String> theDrilldownDimensions = new HashMap<>();

    String thePathInfo = aRequest.getPathInfo();
    if (!StringUtils.isEmpty(thePathInfo)) {
        String theWorkingPathInfo = thePathInfo;

        // First component is the query string
        if (theWorkingPathInfo.startsWith("/")) {
            theWorkingPathInfo = theWorkingPathInfo.substring(1);
        }
        String[] thePaths = StringUtils.split(theWorkingPathInfo, "/");
        for (int i = 0; i < thePaths.length; i++) {
            try {
                String theDecodedValue = thePaths[i].replace('+', ' ');
                String theEncodedValue = theURLCodec.encode(theDecodedValue);
                theBasePath = theBasePath + "/" + theEncodedValue;
                if (i < thePaths.length - 1) {
                    theBackLink = theBackLink + "/" + theEncodedValue;
                }
                if (i == 0) {
                    theQueryString = theDecodedValue;
                } else {
                    FacetSearchUtils.addToMap(theDecodedValue, theDrilldownDimensions);
                }
            } catch (EncoderException e) {
                LOGGER.error("Error while decoding drilldown params for " + aRequest.getPathInfo(), e);
            }
        }
        if (basePath.equals(theBackLink)) {
            theBackLink = null;
        }
    } else {
        theBackLink = null;
    }

    if (!StringUtils.isEmpty(theQueryString)) {
        aRequest.setAttribute("querystring", theQueryString);
        try {
            aRequest.setAttribute("queryResult",
                    backend.performQuery(theQueryString, theBackLink, theBasePath, theDrilldownDimensions));
        } catch (Exception e) {
            LOGGER.error("Error running query " + theQueryString, e);
        }
    } else {
        aRequest.setAttribute("querystring", "");
    }

    aRequest.setAttribute("serverBase", serverBase);

    aRequest.getRequestDispatcher("/index.ftl").forward(aRequest, aResponse);
}

From source file:ch.iterate.openstack.swift.model.Region.java

private static String encode(String object, boolean preserveslashes) {
    URLCodec codec = new URLCodec();
    try {//from   w w  w.  j a  v  a 2  s .  c o m
        final String encoded = codec.encode(object).replaceAll("\\+", "%20");
        if (preserveslashes) {
            return encoded.replaceAll("%2F", "/");
        }
        return encoded;
    } catch (EncoderException ee) {
        return object;
    }
}

From source file:com.neovisionaries.security.AESCipherTest.java

@Test
public void test4() {
    doTest("hello", "key", null, new URLCodec());
}

From source file:jp.dip.komusubi.botter.util.BitlyUrlUtil.java

@Override
public String shorten(String url) {
    parameters.put(PARAMETER_NAME_LONGURL, url);
    StringBuilder builder = new StringBuilder(SHORTEN_SERVICE_URL);
    URLCodec codec = new URLCodec();

    String responseLine = null;//from  w  w w .  j  ava  2s .c  om
    boolean done = false;
    for (Entry<String, String> entry : parameters.entrySet()) {
        if (done == false) {
            builder.append("?");
            done = true;
        } else {
            builder.append("&");
        }
        try {
            builder.append(codec.encode(entry.getKey())).append("=").append(codec.encode(entry.getValue()));
        } catch (EncoderException e) {
            throw new BotterException(e);
        }
    }
    responseLine = UrlAccessDelegate.readFirstLine(builder.toString());
    if (responseLine == null)
        logger.warn("bit.ly response is null, URL is :{}", builder.toString());
    return responseLine;
}