org.apache.tomcat.util.http.Parameters Java Examples

The following examples show how to use org.apache.tomcat.util.http.Parameters. 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: 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 #2
Source File: TomcatInvokeInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void collectHttpParam(Request request, AbstractSpan span) {
    final Map<String, String[]> parameterMap = new HashMap<>();
    final org.apache.coyote.Request coyoteRequest = request.getCoyoteRequest();
    final Parameters parameters = coyoteRequest.getParameters();
    for (final Enumeration<String> names = parameters.getParameterNames(); names.hasMoreElements(); ) {
        final String name = names.nextElement();
        parameterMap.put(name, parameters.getParameterValues(name));
    }

    if (!parameterMap.isEmpty()) {
        String tagValue = CollectionUtil.toString(parameterMap);
        tagValue = Config.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD > 0 ? StringUtil.cut(tagValue, Config.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD) : tagValue;
        Tags.HTTP.PARAMS.set(span, tagValue);
    }
}
 
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));
    }
}
 
Example #4
Source File: Request.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public Parameters getParameters() {
    return parameters;
}
 
Example #5
Source File: Request.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public Parameters getParameters() {
    return parameters;
}
 
Example #6
Source File: ParametersTest.java    From JQF with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Fuzz
public void test(@From(ArbitraryLengthStringGenerator.class) @Size(max=100) String queryString) {
    Parameters parameters = new Parameters();
    parameters.processParameters(queryString.getBytes(), 0, queryString.length());
}
 
Example #7
Source File: Request.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public Parameters getParameters() {
    return parameters;
}