private static String fromContentDisposition ( final String field ) { if ( field == null || field.isEmpty () ) { return null; } try { final ContentDisposition cd = new ContentDisposition ( field ); return cd.getParameter ( "filename" ); } catch ( final ParseException e ) { return null; } }
@Override public boolean isAttachment() { boolean result = false; String dispositionString = conn.getHeaderField(HEADER_CONTENT_DISPOSITION); if (dispositionString != null) { try { ContentDisposition disposition = new ContentDisposition(dispositionString); result = disposition.getDisposition().equals(DISPOSITION_ATTACHMENT); } catch (ParseException e) { } } return result; }
/** * Extract the form name from the Content-Disposition in a * multipart/form-data request. */ public static String getFieldName(BodyPart part) throws MessagingException { String[] values = part.getHeader("Content-Disposition"); String name = null; if (values != null && values.length > 0) { name = new ContentDisposition(values[0]).getParameter("name"); } return (name != null) ? name : "unknown"; }
public MultipartWrapper(HttpServletRequest request, String enc) throws IOException, IllegalArgumentException { super(request); if(null != enc) { encoding = enc; "".getBytes(enc); } Logger.debug("MultipartWrapper: parsing input data ..."); InputStreamDataSource ds = new InputStreamDataSource(new BufferedInputStream(request.getInputStream()), request.getContentType()); try { multipart = new MimeMultipart(ds); params = new Hashtable(request.getParameterMap()); int count = multipart.getCount(); for (int i = 0; i < count; i++) { MimeBodyPart body = (MimeBodyPart) multipart.getBodyPart(i); ContentDisposition disp = new ContentDisposition(body.getHeader("content-disposition", null)); String name = disp.getParameter("name"); if (body.getContentType().startsWith("text/plain")) { String value = new String(((String) body.getContent()).getBytes("iso-8859-1"), encoding); String[] values = (String[]) params.get(name); if (null == values) { params.put(name, new String[]{value}); } else { String[] tmp = new String[values.length + 1]; System.arraycopy(values, 0, tmp, 0, values.length); tmp[tmp.length - 1] = value; params.put(name, tmp); } } files.put(name, body); } } catch (MessagingException e) { Logger.warn("Error parsing request (not multipart/form-data)", e); throw new IllegalArgumentException("Error parsing request (not multipart/form-data?)"); } Logger.debug("MultipartWrapper: finished parsing input data ..."); }
private static String GetHttpResponseFileName(HttpResponse webResponse) throws ParseException { Header[] dispositions = webResponse.getHeaders("Content-Disposition"); if (dispositions == null || dispositions.length == 0) return null; return new ContentDisposition(dispositions[0].getValue()).getParameter("filename"); }