Get file item values from the request allowing for multi part form fields.

@param request the request being processed
@param key the file parameter key to return
@return the file item values
12084
public static FileItem[] getRequestFileItemValues(final HttpServletRequest request, final String key) {
		return getRequestFileItems(request).get(key);
	}
264153
public static String getToken(final HttpServletRequest request, final String key) {
		return (String) request.getSession(true).getAttribute(key);
	}
700522
public static Map<String, String> getRequestHeaders(final HttpServletRequest request) {
        val headers = new LinkedHashMap<String, Object>();
        val headerNames = request.getHeaderNames();
        if (headerNames != null) {
            while (headerNames.hasMoreElements()) {
                val headerName = headerNames.nextElement();
                val headerValue = StringUtils.stripToEmpty(request.getHeader(headerName));
                headers.put(headerName, headerValue);
            }
        }
        return (Map) headers;
    }
686713
private MultipartParsingResult parseRequest(HttpRequest request) throws MultipartException {
        String encoding = determineEncoding(request);
        FileUpload fileUpload = prepareFileUpload(encoding);
        try {
            RequestBody body = request.getBody();
            Assert.notNull(body, "The body cannot be null.");
            List<FileItem> fileItems = fileUpload.parseRequest(new BodyContext(body));
            return parseFileItems(fileItems, encoding);
        } catch (FileUploadBase.SizeLimitExceededException ex) {
            throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex);
        } catch (FileUploadBase.FileSizeLimitExceededException ex) {
            throw new MaxUploadSizeExceededException(fileUpload.getFileSizeMax(), ex);
        } catch (FileUploadException ex) {
            throw new MultipartException("Failed to parse multipart servlet request.", ex);
        }
    }
128711
public static Map<String, Object> createRequestParamsMap(HttpServletRequest request) {
        Map<String, Object> paramsMap = new HashMap<>();
        for (Enumeration paramNameEnum = request.getParameterNames(); paramNameEnum.hasMoreElements(); ) {
            String paramName = (String)paramNameEnum.nextElement();
            String[] paramValues = request.getParameterValues(paramName);

            if (paramValues.length == 1) {
                paramsMap.put(paramName, paramValues[0]);
            } else {
                paramsMap.put(paramName, paramValues);
            }
        }

        return paramsMap;
    }
522588
public GetMediaInfoOfFileResponse getMediaInfoOfFile(GetMediaInfoOfFileRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");
        checkStringNotEmpty(request.getBucket(), "The parameter bucket should NOT be null or empty string.");
        checkStringNotEmpty(request.getKey(), "The parameter key should NOT be null or empty string.");
        InternalRequest internalRequest = createRequest(HttpMethodName.GET, request, MEDIAINFO);
        internalRequest.addParameter("bucket", request.getBucket());
        internalRequest.addParameter("key", request.getKey());
        return invokeHttpClient(internalRequest, GetMediaInfoOfFileResponse.class);
    }
444475
@Override
    public ResponseCtx getCacheItem(String request) {
        String hash = null;
        ResponseCtx response = null;

        try {
            hash = makeHash(request);

            // thread-safety on cache operations
            synchronized (requestCache) {

                if (logger.isDebugEnabled()) {
                    logger.debug("Getting Cache Item (" + requestCache.size() + "/"
                                 + requestCacheUsageTracker.size() + "/"
                                 + requestCacheTimeTracker.size() + "): " + hash);
                }

                response = requestCache.get(hash);

                if (response == null) {
                    return null;
                }

                // if this item is older than CACHE_ITEM_TTL then we can't use it
                long usedLast =
                    System.currentTimeMillis()
                    - requestCacheTimeTracker.get(hash).longValue();
                if (usedLast > TTL) {
                    requestCache.remove(hash);
                    requestCacheUsageTracker.remove(hash);
                    requestCacheTimeTracker.remove(hash);

                    if (logger.isDebugEnabled()) {
                        logger.debug("CACHE_ITEM_TTL exceeded: " + hash);
                    }

                    return null;
                }

                // we just used this item, move it to the end of the list (items at
                // beginning get removed...)
                requestCacheUsageTracker.add(requestCacheUsageTracker
                                             .remove(requestCacheUsageTracker.indexOf(hash)));
            }
        } catch (Exception e) {
            logger.warn("Error getting cache item: " + e.getMessage(), e);
            response = null;
        }

        return response;
    }
973204
public static Map<String, Object> getParametersMap(ContainerRequestContext requestContext,HttpServletRequest request)
			throws IOException {
		
		if(isMultipartContent(request)){
			return buildQueryParamsMap(request);
		}
		
		Map<String, Object> parameters = buildQueryParamsMap(request);
		
		if (RestConst.GET_METHOD.equals(request.getMethod())) {
			return parameters;
		}else if (RestConst.POST_METHOD.equals(request.getMethod())) {
			
			byte[] byteArray = IOUtils.toByteArray(requestContext.getEntityStream());
			//reset InputStream
			requestContext.setEntityStream(new ByteArrayInputStream(byteArray));
			
			if(byteArray == null || byteArray.length == 0)return parameters;
			String content = new String(byteArray);
			//JSON 
//			try {
//				return JsonUtils.toObject(content, Map.class);
//			} catch (Exception e) {}
			if(content.contains("{")){
				content = StringUtils.left(content, 2048).trim();
				if(!content.endsWith("}"))content = content + "...\n}";
				parameters.put("data", content);
				return parameters;
			}
			
			String[] split = content.split("\\&");
			for (String s : split) {
				String[] split2 = s.split("=");
				if (split2.length == 2 && StringUtils.isNotBlank(split2[1])) {
					parameters.put(split2[0], split2[1]);
				}
			}
			return parameters;
		
		}
		return null;
	}
192530
public static String[] getRequestParameterValues(final HttpServletRequest request, final String key) {
		return getRequestParameters(request).get(key);
	}
445574
public static boolean isMultipart(HttpServletRequest request) {
		if (!"post".equals(request.getMethod().toLowerCase())) {
			return false;
		}
		String contentType = request.getContentType();
		return contentType != null && contentType.toLowerCase().startsWith("multipart/");
	}
1208706
public static void setupRequestParameters(final HttpServletRequest request) {

		// Check already processed
		if (request.getAttribute(REQUEST_PROCESSED_KEY) != null) {
			return;
		}

		Map<String, String[]> parameters = new HashMap<>();
		Map<String, FileItem[]> files = new HashMap<>();

		extractParameterMap(request, parameters, files);

		request.setAttribute(REQUEST_PROCESSED_KEY, "Y");
		request.setAttribute(REQUEST_PARAMETERS_KEY, Collections.unmodifiableMap(parameters));
		request.setAttribute(REQUEST_FILES_KEY, Collections.unmodifiableMap(files));
	}
679119
protected void parseRequest(HttpServletRequest request,
                                HttpServletResponse response) {
        requestParams = new HashMap<String, Object>();
        listFiles = new ArrayList<FileItemStream>();
        listFileStreams = new ArrayList<ByteArrayOutputStream>();

        // Parse the request
        if (ServletFileUpload.isMultipartContent(request)) {
            // multipart request
            try {
                ServletFileUpload upload = new ServletFileUpload();
                FileItemIterator iter = upload.getItemIterator(request);
                while (iter.hasNext()) {
                    FileItemStream item = iter.next();
                    String name = item.getFieldName();
                    InputStream stream = item.openStream();
                    if (item.isFormField()) {
                        requestParams.put(name,
                                          Streams.asString(stream));
                    } else {
                        String fileName = item.getName();
                        if (fileName != null && !"".equals(fileName.trim())) {
                            listFiles.add(item);

                            ByteArrayOutputStream os = new ByteArrayOutputStream();
                            IOUtils.copy(stream,
                                         os);
                            listFileStreams.add(os);
                        }
                    }
                }
            } catch (Exception e) {
                logger.error("Unexpected error parsing multipart content",
                             e);
            }
        } else {
            // not a multipart
            for (Object mapKey : request.getParameterMap().keySet()) {
                String mapKeyString = (String) mapKey;

                if (mapKeyString.endsWith("[]")) {
                    // multiple values
                    String values[] = request.getParameterValues(mapKeyString);
                    List<String> listeValues = new ArrayList<String>();
                    for (String value : values) {
                        listeValues.add(value);
                    }
                    requestParams.put(mapKeyString,
                                      listeValues);
                } else {
                    // single value
                    String value = request.getParameter(mapKeyString);
                    requestParams.put(mapKeyString,
                                      value);
                }
            }
        }
    }
821017
public static Map<String, FileItem[]> getRequestFileItems(final HttpServletRequest request) {
		if (request.getAttribute(REQUEST_PROCESSED_KEY) == null) {
			setupRequestParameters(request);
		}
		return (Map<String, FileItem[]>) request.getAttribute(REQUEST_FILES_KEY);
	}
775549
protected Map<String,String> convertParametersTextToMap(HTTPRequest request)
    {
        //init data structure
        Map<String,String> map=new HashMap<String,String>();

        //get parameters text
        String parametersText=request.getParametersText();
        
        if(parametersText!=null)
        {
            //split to key/value pairs (key=value)
            String[] keyValuePairs=parametersText.split("&");
            
            //get amount
            int pairsAmount=keyValuePairs.length;
            
            String keyValuePair=null;
            String[] parts=null;
            String key=null;
            String value=null;
            for(int index=0;index<pairsAmount;index++)
            {
                //get next key/value pair
                keyValuePair=keyValuePairs[index];
                
                //split to key and value
                parts=keyValuePair.split("=");
                if(parts.length==2)
                {
                    //get key
                    key=parts[0];
                    if(key.length()>0)
                    {
                        //decode key
                        key=SpiUtil.urlDecode(key);

                        //get value
                        value=parts[1].trim();

                        //decode value
                        value=SpiUtil.urlDecode(value);
                        
                        //put in data structure
                        map.put(key,value);
                    }
                }
            }
        }
        
        return map;
    }
1333762
public static Map<String, String[]> getRequestParameters(final HttpServletRequest request) {
		if (request.getAttribute(REQUEST_PROCESSED_KEY) == null) {
			setupRequestParameters(request);
		}
		return (Map<String, String[]>) request.getAttribute(REQUEST_PARAMETERS_KEY);
	}
985829
public static MultipartFormData getMultipart(ServletRequest request, UploadSetting uploadSetting) throws IORuntimeException {
		final MultipartFormData formData = new MultipartFormData(uploadSetting);
		try {
			formData.parseRequest(request);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}

		return formData;
	}
891633
public function get_file(Request $request)
    {
        $filepath = $request->input('filepath');
        $data = file_get_contents(base_path($filepath));
        echo $data;
    }