Java Code Examples for javax.mail.internet.MimeBodyPart#getHeader()
The following examples show how to use
javax.mail.internet.MimeBodyPart#getHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParseBlobUploadFilter.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
private Map<String, String> getInfoFromBody(String bodyContent, String key) throws MessagingException { MimeBodyPart part = new MimeBodyPart(new ByteArrayInputStream(bodyContent.getBytes())); Map<String, String> info = new HashMap<String, String>(6); info.put("key", key); info.put("content-type", part.getContentType()); info.put("creation-date", part.getHeader(UPLOAD_CREATION_HEADER)[0]); info.put("filename", part.getFileName()); info.put("size", part.getHeader(CONTENT_LENGTH_HEADER)[0]); // part.getSize() returns 0 info.put("md5-hash", part.getContentMD5()); String[] headers = part.getHeader(CLOUD_STORAGE_OBJECT_HEADER); if (headers != null && headers.length == 1) { info.put("gs-name", headers[0]); } return info; }
Example 2
Source File: MultipartMap.java From openxds with Apache License 2.0 | 5 votes |
/** * Constructor builds a MultipartMap object based upon the contents of an entire * HttpServletRequest object. * @param request An HttpServletRequest object that contains Multipart content. * @throws javax.mail.MessagingException Thrown if there is a problem parsing this input. * @throws java.io.IOException Thrown if there is an IO problem accessing this input. (Check that * HttpServletRequest is valid.) */ public MultipartMap(HttpServletRequest request) throws javax.mail.MessagingException, java.io.IOException { if (isMultipartForm(request)) { map = new HashMap(); typemap = new HashMap(); ByteArrayDataSource ds = new ByteArrayDataSource(request.getInputStream(), request.getContentType()); //ByteArrayDataSource ds; // this should be rewritten, ByteArrayDataSource will take directly from an input stream //String input = getStringFromInputStream(request.getInputStream()); //ds = new ByteArrayDataSource(input,request.getHeader("Content-Type")); mp = new javax.mail.internet.MimeMultipart(ds); for (int i=0; i<mp.getCount(); i++) { MimeBodyPart bp = (MimeBodyPart) mp.getBodyPart(i); ContentDisposition cd = new ContentDisposition(bp.getHeader("Content-Disposition")[0]); String name = stripQuotes(cd.get("name")); String filename = stripQuotes(cd.get("filename")); if (filename != null) map.put("filename", filename); //String name = getName(bp); typemap.put(name, bp.getContentType()); String type[] = bp.getContentType().split("/"); if (type[0].equals("text") && type[1].equals("plain")) { map.put(name, bp.getContent()); } else { map.put(name, bp.getInputStream()); //getDataHandler()); } } } else { throw new javax.mail.MessagingException("MultipartMap requires Multipart/Form format as input"); } }
Example 3
Source File: MultipartMap.java From openxds with Apache License 2.0 | 5 votes |
public MultipartMap(InputStream is, String contentType) throws Exception, java.io.IOException { try { //contentType = contentType.replaceFirst("boundary=--", "boundary="); map = new HashMap(); typemap = new HashMap(); boolean isMultipart = contentType.startsWith("multipart"); if (isMultipart) { ByteArrayDataSource ds = new ByteArrayDataSource(is, contentType); //ByteArrayDataSource ds; // this should be rewritten, ByteArrayDataSource will take directly from an input stream //String input = getStringFromInputStream(request.getInputStream()); //ds = new ByteArrayDataSource(input,request.getHeader("Content-Type")); //String ext =ds.getText(); //String xx = "------=_Part_2_9110923.1073664290010\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:d4bfb124-7922-45bc-a03d-823351eed716\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/transform.html\r\n------=_Part_2_9110923.1073664290010\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:45b90888-49c1-4b64-a8eb-e94f541368f0\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/rawSQL.html\r\n------=_Part_2_9110923.1073664290010--\r\n"; mp = new javax.mail.internet.MimeMultipart(ds); for (int i=0; i<mp.getCount(); i++) { MimeBodyPart bp = (MimeBodyPart) mp.getBodyPart(i); String name = null; String contentID[] = bp.getHeader("Content-ID"); if (contentID.length > 0) name = contentID[0]; if (name == null) name = "Part " + Integer.toString(i); typemap.put(name, bp.getContentType()); String type[] = bp.getContentType().split("/"); if (type[0].equals("text") && type[1].equals("plain")) { map.put(name, bp.getContent()); } else { map.put(name, bp.getInputStream()); //getDataHandler()); } } } else { map.put("Content", is); typemap.put("Content", contentType); } } catch (javax.mail.MessagingException me) { throw new Exception("messaging exception in parsing for MultipartMap"); } }
Example 4
Source File: MultipartMap.java From openxds with Apache License 2.0 | 5 votes |
public MultipartMap(HttpServletRequest request) throws javax.mail.MessagingException, java.io.IOException { if (isMultipartForm(request)) { map = new HashMap(); typemap = new HashMap(); ByteArrayDataSource ds = new ByteArrayDataSource(request.getInputStream(), request.getContentType()); //ByteArrayDataSource ds; // this should be rewritten, ByteArrayDataSource will take directly from an input stream //String input = getStringFromInputStream(request.getInputStream()); //ds = new ByteArrayDataSource(input,request.getHeader("Content-Type")); mp = new javax.mail.internet.MimeMultipart(ds); for (int i=0; i<mp.getCount(); i++) { MimeBodyPart bp = (MimeBodyPart) mp.getBodyPart(i); ContentDisposition cd = new ContentDisposition(bp.getHeader("Content-Disposition")[0]); String name = stripQuotes(cd.get("name")); String filename = stripQuotes(cd.get("filename")); if (filename != null) map.put("filename", filename); //String name = getName(bp); typemap.put(name, bp.getContentType()); String type[] = bp.getContentType().split("/"); if (type[0].equals("text") && type[1].equals("plain")) { map.put(name, bp.getContent()); } else { map.put(name, bp.getInputStream()); //getDataHandler()); } if (log.isDebugEnabled()) { log.debug("name = " + name); } } } else { throw new javax.mail.MessagingException("MultipartMap requires Multipart/Form format as input"); } }
Example 5
Source File: BCCryptoHelper.java From OpenAs2App with BSD 2-Clause "Simplified" License | 5 votes |
public String getHeaderValue(MimeBodyPart part, String headerName) { try { String[] values = part.getHeader(headerName); if (values == null) { return null; } return values[0]; } catch (MessagingException e) { return null; } }
Example 6
Source File: MultipartMap.java From openxds with Apache License 2.0 | 4 votes |
/** * Constructor. * @param is The content as an InputStream. * @param contentType The type of content this multipart piece is. * @throws java.lang.Exception Thrown if there is a problem parsing this input. * @throws java.io.IOException Thrown if there is an IO problem accessing this input. (Check that * InputStream is valid.) */ public MultipartMap(InputStream is, String contentType) throws Exception, java.io.IOException { try { //contentType = contentType.replaceFirst("boundary=--", "boundary="); map = new HashMap(); typemap = new HashMap(); positionmap = new HashMap<Integer, Object>(); positiontypemap = new HashMap<Integer, String>(); boolean isMultipart = contentType.startsWith("multipart"); if (isMultipart) { ByteArrayDataSource ds = new ByteArrayDataSource(is, contentType); //ByteArrayDataSource ds; // this should be rewritten, ByteArrayDataSource will take directly from an input stream //String input = getStringFromInputStream(request.getInputStream()); //ds = new ByteArrayDataSource(input,request.getHeader("Content-Type")); //String ext =ds.getText(); //String xx = "------=_Part_2_9110923.1073664290010\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:d4bfb124-7922-45bc-a03d-823351eed716\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/transform.html\r\n------=_Part_2_9110923.1073664290010\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:45b90888-49c1-4b64-a8eb-e94f541368f0\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/rawSQL.html\r\n------=_Part_2_9110923.1073664290010--\r\n"; mp = new javax.mail.internet.MimeMultipart(ds); for (int i=0; i<mp.getCount(); i++) { MimeBodyPart bp = (MimeBodyPart) mp.getBodyPart(i); String name = null; String contentID[] = bp.getHeader("Content-ID"); if (contentID.length > 0) name = contentID[0]; if (name == null) name = "Part " + Integer.toString(i); typemap.put(name, bp.getContentType()); positiontypemap.put(new Integer(i), bp.getContentType()); InputStream part_is = bp.getInputStream(); Object part_object = null; String type[] = bp.getContentType().split("/"); if (type[0].equals("text") && type[1].equals("plain")) { part_object = bp.getContent(); map.put(name, part_object); } else { map.put(name, part_is); part_object = part_is; } positionmap.put(new Integer(i), part_object); } } else { map.put("Content", is); typemap.put("Content", contentType); } } catch (javax.mail.MessagingException me) { throw new Exception("messaging exception in parsing for MultipartMap: " + ExceptionUtil.exception_details(me)); } }