Java Code Examples for org.apache.tomcat.util.buf.MessageBytes#setCharset()

The following examples show how to use org.apache.tomcat.util.buf.MessageBytes#setCharset() . 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: Response.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void addHeader(String name, String value, Charset charset) {
    char cc=name.charAt(0);
    if( cc=='C' || cc=='c' ) {
        if( checkSpecialHeader(name, value) )
        return;
    }
    MessageBytes mb = headers.addValue(name);
    if (charset != null) {
        mb.setCharset(charset);
    }
    mb.setString(value);
}
 
Example 2
Source File: ApplicationHttpRequest.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Merge the parameters from the saved query parameter string (if any), and
 * the parameters already present on this request (if any), such that the
 * parameter values from the query string show up first if there are
 * duplicate parameter names.
 */
private void mergeParameters() {

    if ((queryParamString == null) || (queryParamString.length() < 1))
        return;

    // Parse the query string from the dispatch target
    Parameters paramParser = new Parameters();
    MessageBytes queryMB = MessageBytes.newInstance();
    queryMB.setString(queryParamString);

    String encoding = getCharacterEncoding();
    // No need to process null value, as ISO-8859-1 is the default encoding
    // in MessageBytes.toBytes().
    if (encoding != null) {
        try {
            queryMB.setCharset(B2CConverter.getCharset(encoding));
        } catch (UnsupportedEncodingException ignored) {
            // Fall-back to ISO-8859-1
        }
    }

    paramParser.setQuery(queryMB);
    paramParser.setQueryStringEncoding(encoding);
    paramParser.handleQueryParameters();

    // Insert the additional parameters from the dispatch target
    Enumeration<String> dispParamNames = paramParser.getParameterNames();
    while (dispParamNames.hasMoreElements()) {
        String dispParamName = dispParamNames.nextElement();
        String[] dispParamValues = paramParser.getParameterValues(dispParamName);
        String[] originalValues = parameters.get(dispParamName);
        if (originalValues == null) {
            parameters.put(dispParamName, dispParamValues);
            continue;
        }
        parameters.put(dispParamName, mergeValues(dispParamValues, originalValues));
    }
}
 
Example 3
Source File: ApplicationHttpRequest.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Merge the parameters from the saved query parameter string (if any), and
 * the parameters already present on this request (if any), such that the
 * parameter values from the query string show up first if there are
 * duplicate parameter names.
 */
private void mergeParameters() {

    if ((queryParamString == null) || (queryParamString.length() < 1))
        return;

    // Parse the query string from the dispatch target
    Parameters paramParser = new Parameters();
    MessageBytes queryMB = MessageBytes.newInstance();
    queryMB.setString(queryParamString);

    // TODO
    // - Should only use body encoding if useBodyEncodingForURI is true
    // - Otherwise, should use URIEncoding
    // - The problem is that the connector is not available...

    String encoding = getCharacterEncoding();
    Charset charset = null;
    if (encoding != null) {
        try {
            charset = B2CConverter.getCharset(encoding);
            queryMB.setCharset(charset);
        } catch (UnsupportedEncodingException e) {
            // Fall-back to default (ISO-8859-1)
            charset = StandardCharsets.ISO_8859_1;
        }
    }

    paramParser.setQuery(queryMB);
    paramParser.setQueryStringCharset(charset);
    paramParser.handleQueryParameters();

    // Insert the additional parameters from the dispatch target
    Enumeration<String> dispParamNames = paramParser.getParameterNames();
    while (dispParamNames.hasMoreElements()) {
        String dispParamName = dispParamNames.nextElement();
        String[] dispParamValues = paramParser.getParameterValues(dispParamName);
        String[] originalValues = parameters.get(dispParamName);
        if (originalValues == null) {
            parameters.put(dispParamName, dispParamValues);
            continue;
        }
        parameters.put(dispParamName, mergeValues(dispParamValues, originalValues));
    }
}