private ParameterMap getRequestParameterMapInternal()

in src/main/java/org/apache/sling/engine/impl/parameters/ParameterSupport.java [244:347]


    private ParameterMap getRequestParameterMapInternal() {
        if (this.postParameterMap == null) {

            // SLING-508 Try to force servlet container to decode parameters
            // as ISO-8859-1 such that we can recode later
            String encoding = getServletRequest().getCharacterEncoding();
            if (encoding == null) {
                encoding = Util.ENCODING_DIRECT;
                try {
                    getServletRequest().setCharacterEncoding(encoding);
                } catch (UnsupportedEncodingException uee) {
                    throw new SlingUnsupportedEncodingException(uee);
                }
            }

            // SLING-152 Get parameters from the servlet Container
            ParameterMap parameters = new ParameterMap();

            // fallback is only used if this request has been started by a service call
            boolean useFallback = getServletRequest().getAttribute(MARKER_IS_SERVICE_PROCESSING) != null;
            boolean addContainerParameters = false;
            // Query String
            final String query = getServletRequest().getQueryString();
            if (query != null) {
                try {
                    InputStream input = Util.toInputStream(query);
                    Util.parseQueryString(input, encoding, parameters, false);
                    addContainerParameters = checkForAdditionalParameters;
                } catch (IllegalArgumentException e) {
                    this.log.error("getRequestParameterMapInternal: Error parsing request", e);
                } catch (UnsupportedEncodingException e) {
                    throw new SlingUnsupportedEncodingException(e);
                } catch (IOException e) {
                    this.log.error("getRequestParameterMapInternal: Error parsing request", e);
                }
                useFallback = false;
            } else {
                addContainerParameters = checkForAdditionalParameters;
                useFallback = true;
            }

            // POST requests
            final boolean isPost = "POST".equals(this.getServletRequest().getMethod());
            if (isPost) {
                // WWW URL Form Encoded POST
                if (isWWWFormEncodedContent(this.getServletRequest())) {
                    try {
                        InputStream input = this.getServletRequest().getInputStream();
                        Util.parseQueryString(input, encoding, parameters, false);
                        addContainerParameters = checkForAdditionalParameters;
                    } catch (IllegalArgumentException e) {
                        this.log.error("getRequestParameterMapInternal: Error parsing request", e);
                    } catch (UnsupportedEncodingException e) {
                        throw new SlingUnsupportedEncodingException(e);
                    } catch (IOException e) {
                        this.log.error("getRequestParameterMapInternal: Error parsing request", e);
                    }
                    this.requestDataUsed = true;
                    useFallback = false;
                }

                // Multipart POST
                if (JakartaServletFileUpload.isMultipartContent(
                        new JakartaServletRequestContext(this.getServletRequest()))) {
                    if (isStreamed(parameters, this.getServletRequest())) {
                        // special case, the request is Multipart and streamed processing has been requested
                        try {
                            this.getServletRequest()
                                    .setAttribute(
                                            REQUEST_PARTS_ITERATOR_ATTRIBUTE,
                                            new RequestPartsIterator(this.getServletRequest()));
                            this.log.debug(
                                    "getRequestParameterMapInternal: Iterator<javax.servlet.http.Part> available as request attribute named request-parts-iterator");
                        } catch (IOException e) {
                            this.log.error(
                                    "getRequestParameterMapInternal: Error parsing multipart streamed request", e);
                        }
                        // The request data has been passed to the RequestPartsIterator, hence from a RequestParameter
                        // pov its been used, and must not be used again.
                        this.requestDataUsed = true;
                        // must not try and get anything from the request at this point so avoid jumping through the
                        // stream.
                        addContainerParameters = false;
                        useFallback = false;
                    } else {
                        this.parseMultiPartPost(parameters);
                        this.requestDataUsed = true;
                        addContainerParameters = checkForAdditionalParameters;
                        useFallback = false;
                    }
                }
            }
            if (useFallback) {
                getContainerParameters(parameters, encoding, true);
            } else if (addContainerParameters) {
                getContainerParameters(parameters, encoding, false);
            }
            // apply any form encoding (from '_charset_') in the parameter map
            Util.fixEncoding(parameters);

            this.postParameterMap = parameters;
        }
        return this.postParameterMap;
    }