Example usage for org.apache.commons.httpclient.util EncodingUtil getAsciiBytes

List of usage examples for org.apache.commons.httpclient.util EncodingUtil getAsciiBytes

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util EncodingUtil getAsciiBytes.

Prototype

public static byte[] getAsciiBytes(final String data) 

Source Link

Document

Converts the specified string to byte array of ASCII characters.

Usage

From source file:org.openxdm.xcap.server.slee.auth.RFC2617ChallengeParamGenerator.java

public String getNonce(String seed) throws InternalServerErrorException {
    if (nonceDigestSecret == null) {
        nonceDigestSecret = generateOpaque();
    }//from w ww. ja  v a2s .  com
    MessageDigest messageDigest = null;
    try {
        messageDigest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new InternalServerErrorException(
                "failed to get instance of MD5 digest, used in " + RFC2617AuthQopDigest.class.getName());
    }
    return AsciiHexStringEncoder
            .encode(messageDigest.digest(EncodingUtil.getAsciiBytes(seed + ":" + nonceDigestSecret)));
}

From source file:org.parosproxy.paros.network.GenericMethod.java

/**
 * Generates a request entity from the post parameters, if present.  Calls
 * {@link EntityEnclosingMethod#generateRequestBody()} if parameters have not been set.
 * /*  www.  ja  v a2  s . c  om*/
 * @since 3.0
 */
@Override
protected RequestEntity generateRequestEntity() {
    if (!this.params.isEmpty()) {
        // Use a ByteArrayRequestEntity instead of a StringRequestEntity.
        // This is to avoid potential encoding issues.  Form url encoded strings
        // are ASCII by definition but the content type may not be.  Treating the content
        // as bytes allows us to keep the current charset without worrying about how
        // this charset will effect the encoding of the form url encoded string.
        String content = EncodingUtil.formUrlEncode(getParameters(), getRequestCharSet());
        ByteArrayRequestEntity entity = new ByteArrayRequestEntity(EncodingUtil.getAsciiBytes(content),
                FORM_URL_ENCODED_CONTENT_TYPE);
        return entity;
    }
    return super.generateRequestEntity();
}