Search in sources :

Example 6 with Parameters

use of org.apache.tomcat.util.http.Parameters in project tomcat70 by apache.

the class Request method parseParameters.

/**
 * Parse request parameters.
 */
protected void parseParameters() {
    parametersParsed = true;
    Parameters parameters = coyoteRequest.getParameters();
    boolean success = false;
    try {
        // Set this every time in case limit has been changed via JMX
        parameters.setLimit(getConnector().getMaxParameterCount());
        // getCharacterEncoding() may have been overridden to search for
        // hidden form field containing request encoding
        String enc = getCharacterEncoding();
        boolean useBodyEncodingForURI = connector.getUseBodyEncodingForURI();
        if (enc != null) {
            parameters.setEncoding(enc);
            if (useBodyEncodingForURI) {
                parameters.setQueryStringEncoding(enc);
            }
        } else {
            parameters.setEncoding(org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING);
            if (useBodyEncodingForURI) {
                parameters.setQueryStringEncoding(org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING);
            }
        }
        parameters.handleQueryParameters();
        if (usingInputStream || usingReader) {
            success = true;
            return;
        }
        if (!getConnector().isParseBodyMethod(getMethod())) {
            success = true;
            return;
        }
        String contentType = getContentType();
        if (contentType == null) {
            contentType = "";
        }
        int semicolon = contentType.indexOf(';');
        if (semicolon >= 0) {
            contentType = contentType.substring(0, semicolon).trim();
        } else {
            contentType = contentType.trim();
        }
        if ("multipart/form-data".equals(contentType)) {
            parseParts();
            success = true;
            return;
        }
        if (!("application/x-www-form-urlencoded".equals(contentType))) {
            success = true;
            return;
        }
        int len = getContentLength();
        if (len > 0) {
            int maxPostSize = connector.getMaxPostSize();
            if ((maxPostSize >= 0) && (len > maxPostSize)) {
                if (context.getLogger().isDebugEnabled()) {
                    context.getLogger().debug(sm.getString("coyoteRequest.postTooLarge"));
                }
                checkSwallowInput();
                parameters.setParseFailedReason(FailReason.POST_TOO_LARGE);
                return;
            }
            byte[] formData = null;
            if (len < CACHED_POST_LEN) {
                if (postData == null) {
                    postData = new byte[CACHED_POST_LEN];
                }
                formData = postData;
            } else {
                formData = new byte[len];
            }
            try {
                if (readPostBody(formData, len) != len) {
                    parameters.setParseFailedReason(FailReason.REQUEST_BODY_INCOMPLETE);
                    return;
                }
            } catch (IOException e) {
                // Client disconnect
                if (context.getLogger().isDebugEnabled()) {
                    context.getLogger().debug(sm.getString("coyoteRequest.parseParameters"), e);
                }
                parameters.setParseFailedReason(FailReason.CLIENT_DISCONNECT);
                return;
            }
            parameters.processParameters(formData, 0, len);
        } else if ("chunked".equalsIgnoreCase(coyoteRequest.getHeader("transfer-encoding"))) {
            byte[] formData = null;
            try {
                formData = readChunkedPostBody();
            } catch (IllegalStateException ise) {
                // chunkedPostTooLarge error
                parameters.setParseFailedReason(FailReason.POST_TOO_LARGE);
                Context context = getContext();
                if (context != null && context.getLogger().isDebugEnabled()) {
                    context.getLogger().debug(sm.getString("coyoteRequest.parseParameters"), ise);
                }
                return;
            } catch (IOException e) {
                // Client disconnect
                parameters.setParseFailedReason(FailReason.CLIENT_DISCONNECT);
                Context context = getContext();
                if (context != null && context.getLogger().isDebugEnabled()) {
                    context.getLogger().debug(sm.getString("coyoteRequest.parseParameters"), e);
                }
                return;
            }
            if (formData != null) {
                parameters.processParameters(formData, 0, formData.length);
            }
        }
        success = true;
    } finally {
        if (!success) {
            parameters.setParseFailedReason(FailReason.UNKNOWN);
        }
    }
}
Also used : ServletRequestContext(org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext) AsyncContext(javax.servlet.AsyncContext) Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) Parameters(org.apache.tomcat.util.http.Parameters) IOException(java.io.IOException)

Example 7 with Parameters

use of org.apache.tomcat.util.http.Parameters in project skywalking-java by apache.

the class TomcatInvokeInterceptor method collectHttpParam.

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 = TomcatPluginConfig.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD > 0 ? StringUtil.cut(tagValue, TomcatPluginConfig.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD) : tagValue;
        Tags.HTTP.PARAMS.set(span, tagValue);
    }
}
Also used : Parameters(org.apache.tomcat.util.http.Parameters) HashMap(java.util.HashMap)

Aggregations

Parameters (org.apache.tomcat.util.http.Parameters)7 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Charset (java.nio.charset.Charset)4 ServletRequestContext (org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext)4 Context (org.apache.catalina.Context)3 AsyncContext (jakarta.servlet.AsyncContext)2 ServletContext (jakarta.servlet.ServletContext)2 File (java.io.File)2 ApplicationPart (org.apache.catalina.core.ApplicationPart)2 MessageBytes (org.apache.tomcat.util.buf.MessageBytes)2 FileItem (org.apache.tomcat.util.http.fileupload.FileItem)2 DiskFileItemFactory (org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory)2 ServletFileUpload (org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload)2 MultipartConfigElement (jakarta.servlet.MultipartConfigElement)1 ServletException (jakarta.servlet.ServletException)1 HashMap (java.util.HashMap)1 AsyncContext (javax.servlet.AsyncContext)1 MultipartConfigElement (javax.servlet.MultipartConfigElement)1 ServletContext (javax.servlet.ServletContext)1