@Override public void parseRequestParameters( final Map<String, String> params, final Map<String, com.bradmcevoy.http.FileItem> files) throws RequestParseException { try { if (isMultiPart()) { parseQueryString(params, req.getQueryString()); @SuppressWarnings("unchecked") final List<FileItem> items = new ServletFileUpload().parseRequest(req); for (final FileItem item : items) { if (item.isFormField()) params.put(item.getFieldName(), item.getString()); else files.put(item.getFieldName(), new FileItemWrapper(item)); } } else { final Enumeration<String> en = req.getParameterNames(); while (en.hasMoreElements()) { final String nm = en.nextElement(); final String val = req.getParameter(nm); params.put(nm, val); } } } catch (final FileUploadException ex) { throw new RequestParseException("FileUploadException", ex); } catch (final Throwable ex) { throw new RequestParseException(ex.getMessage(), ex); } }
@Override public Map<String, String> getHeaders() { final Map<String, String> map = new HashMap<>(); final Enumeration<String> en = req.getHeaderNames(); while (en.hasMoreElements()) { final String name = en.nextElement(); final String val = req.getHeader(name); map.put(name, val); } return map; }
public static String headersToString(HttpServletRequest request) { final StringBuffer sb = new StringBuffer(); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); ) { final String name = (String) e.nextElement(); sb.append(name); sb.append("="); for (Enumeration f = request.getHeaders(name); f.hasMoreElements(); ) { final String value = (String) f.nextElement(); sb.append(value); if (f.hasMoreElements()) sb.append(","); } if (e.hasMoreElements()) sb.append("|"); } return sb.toString(); }