List of usage examples for javax.mail BodyPart getContentType
public String getContentType() throws MessagingException;
From source file:org.geoserver.wcs.GetCoverageTest.java
@Test public void testReadNoGridCRS() throws Exception { String request = // " <wcs:GetCoverage service=\"WCS\" version=\"1.1.1\" " + " xmlns:wcs=\"http://www.opengis.net/wcs/1.1.1\" " + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:ows=\"http://www.opengis.net/ows/1.1\" >\n" + " <ows:Identifier>" + getLayerId(MockData.TASMANIA_DEM) + " </ows:Identifier>\n" + " <wcs:DomainSubset>\n" + " <ows:BoundingBox crs=\"http://www.opengis.net/gml/srs/epsg.xml#4326\">\n" + " <ows:LowerCorner>-180.0 -90.0</ows:LowerCorner>\n" + " <ows:UpperCorner>180.0 90.0</ows:UpperCorner>\n" + " </ows:BoundingBox>\n" // + " </wcs:DomainSubset>\n" + " <wcs:Output format=\"image/tiff\"/>\n" + " </wcs:GetCoverage>"; MockHttpServletResponse response = postAsServletResponse("wcs", request); // parse the multipart, check there are two parts Multipart multipart = getMultipart(response); assertEquals(2, multipart.getCount()); BodyPart coveragePart = multipart.getBodyPart(1); assertEquals("image/tiff", coveragePart.getContentType()); assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]); // make sure we can read the coverage back ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next(); reader.setInput(ImageIO.createImageInputStream(coveragePart.getInputStream())); RenderedImage image = reader.read(0); }
From source file:org.geoserver.wcs.GetCoverageTest.java
/** * This tests just ended up throwing an exception as the coverage being encoded * was too large due to a bug in the scales estimation * //from w ww . j a v a 2s .c o m * @throws Exception */ @Test public void testRotatedPost() throws Exception { String request = "<GetCoverage xmlns=\"http://www.opengis.net/wcs/1.1.1\" xmlns:gml=\"http://www.opengis.net/gml\"\n" + " xmlns:ows11=\"http://www.opengis.net/ows/1.1\"\n" + " xmlns:ows=\"http://www.opengis.net/ows/1.1\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \r\n" + // " xmlns:wcs=\"http://schemas.opengis.net/wcs/1.1.1\"\n" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" + " service=\"WCS\"\n" + " version=\"1.1.1\"\n" + " xsi:schemaLocation=\"http://www.opengis.net/wcs/1.1.1 http://schemas.opengis.net/wcs/1.1.1/wcsAll.xsd\">\n" + " <ows11:Identifier>RotatedCad</ows11:Identifier>\n" + " <DomainSubset>\n" + " <ows11:BoundingBox crs=\"urn:ogc:def:crs:OGC:1.3:CRS84\">\n" + " <ows11:LowerCorner>7.7634301664746515 45.14713380418506</ows11:LowerCorner>\n" + " <ows11:UpperCorner>7.764350661575157 45.14763319238466</ows11:UpperCorner>\n" + " </ows11:BoundingBox>\n" + " </DomainSubset>\n" + " <Output format=\"image/tiff\"/>\n" + "</GetCoverage>"; MockHttpServletResponse response = postAsServletResponse("wcs", request); // parse the multipart, check there are two parts Multipart multipart = getMultipart(response); assertEquals(2, multipart.getCount()); BodyPart coveragePart = multipart.getBodyPart(1); assertEquals("image/tiff", coveragePart.getContentType()); assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]); // make sure we can read the coverage back ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next(); reader.setInput(ImageIO.createImageInputStream(coveragePart.getInputStream())); RenderedImage image = reader.read(0); // check the image is suitably small (without requiring an exact size) assertTrue(image.getWidth() < 1000); assertTrue(image.getHeight() < 1000); }
From source file:org.geoserver.wcs.GetCoverageTest.java
/** * This tests just ended up throwing an exception as the coverage being encoded * was too large due to a bug in the scales estimation * /* w w w . j a v a 2 s.co m*/ * @throws Exception */ @Test public void testRotatedGet() throws Exception { String request = "wcs?&service=WCS&request=GetCoverage&version=1.1.1&identifier=RotatedCad&BoundingBox=7.7634071540971386,45.14712131948007,7.76437367395267,45.14764567708965,urn:ogc:def:crs:OGC:1.3:CRS84&Format=image/tiff"; MockHttpServletResponse response = getAsServletResponse(request); // parse the multipart, check there are two parts Multipart multipart = getMultipart(response); assertEquals(2, multipart.getCount()); BodyPart coveragePart = multipart.getBodyPart(1); assertEquals("image/tiff", coveragePart.getContentType()); assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]); // make sure we can read the coverage back ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next(); reader.setInput(ImageIO.createImageInputStream(coveragePart.getInputStream())); RenderedImage image = reader.read(0); // check the image is suitably small (without requiring an exact size) assertTrue(image.getWidth() < 1000); assertTrue(image.getHeight() < 1000); }
From source file:org.ikasan.component.endpoint.email.producer.EmailProducerTest.java
@Test public void test_successful_email_withoutAttachment() throws MessagingException, IOException { EmailProducerConfiguration emailProducerConfiguration = getConfiguration(false, null); EmailProducer emailProducer = new EmailProducer(); ((Configured) emailProducer).setConfiguration(emailProducerConfiguration); ((ManagedResource) emailProducer).startManagedResource(); emailProducer.invoke(getEmailPayload(false, null)); List<WiserMessage> messages = wiser.getMessages(); Assert.assertTrue("Should be three messages - one per addressee", messages.size() == 3); for (WiserMessage message : wiser.getMessages()) { Assert.assertTrue("sender should be " + sender, sender.equals(message.getEnvelopeSender())); MimeMessage mimeMessage = message.getMimeMessage(); MimeMultipart mimeMultipart = (MimeMultipart) mimeMessage.getContent(); Assert.assertTrue("should be only 1 bodypart", mimeMultipart.getCount() == 1); BodyPart bodyPart = mimeMultipart.getBodyPart(0); String content = (String) bodyPart.getContent(); Assert.assertTrue("The email content should be empty", content.isEmpty()); Assert.assertTrue("Should fild email format as \"text/plain\"", bodyPart.getContentType().contains("text/plain")); }/*from w w w .j ava 2s .co m*/ }
From source file:org.ikasan.component.endpoint.email.producer.EmailProducerTest.java
@Test public void test_successful_email_contentFromConfig() throws MessagingException, IOException { EmailProducerConfiguration emailProducerConfiguration = getConfiguration(false, "This content is from config"); EmailProducer emailProducer = new EmailProducer(); ((Configured) emailProducer).setConfiguration(emailProducerConfiguration); ((ManagedResource) emailProducer).startManagedResource(); emailProducer.invoke(getEmailPayload(false, null)); List<WiserMessage> messages = wiser.getMessages(); Assert.assertTrue("Should be three messages - one per addressee", messages.size() == 3); for (WiserMessage message : wiser.getMessages()) { Assert.assertTrue("sender should be " + sender, sender.equals(message.getEnvelopeSender())); MimeMessage mimeMessage = message.getMimeMessage(); MimeMultipart mimeMultipart = (MimeMultipart) mimeMessage.getContent(); Assert.assertTrue("should be only 1 bodypart", mimeMultipart.getCount() == 1); BodyPart bodyPart = mimeMultipart.getBodyPart(0); String content = (String) bodyPart.getContent(); Assert.assertEquals("The email content should be from config", "This content is from config", content); Assert.assertTrue("Should find email format as \"text/plain\"", bodyPart.getContentType().contains("text/plain")); }/* ww w. j ava2 s .co m*/ }
From source file:org.ikasan.component.endpoint.email.producer.EmailProducerTest.java
@Test public void test_successful_email_contentFromPayload() throws MessagingException, IOException { EmailProducerConfiguration emailProducerConfiguration = getConfiguration(false, "This content is from config"); EmailProducer emailProducer = new EmailProducer(); ((Configured) emailProducer).setConfiguration(emailProducerConfiguration); ((ManagedResource) emailProducer).startManagedResource(); emailProducer.invoke(getEmailPayload(false, "The content is from payload")); List<WiserMessage> messages = wiser.getMessages(); Assert.assertTrue("Should be three messages - one per addressee", messages.size() == 3); for (WiserMessage message : wiser.getMessages()) { Assert.assertTrue("sender should be " + sender, sender.equals(message.getEnvelopeSender())); MimeMessage mimeMessage = message.getMimeMessage(); MimeMultipart mimeMultipart = (MimeMultipart) mimeMessage.getContent(); Assert.assertTrue("should be only 1 bodypart", mimeMultipart.getCount() == 1); BodyPart bodyPart = mimeMultipart.getBodyPart(0); String content = (String) bodyPart.getContent(); Assert.assertEquals("The email content should be from payload", "The content is from payload", content); Assert.assertTrue("Should find email format as \"text/plain\"", bodyPart.getContentType().contains("text/plain")); }//from w w w .ja v a2 s. c om }
From source file:org.ikasan.component.endpoint.email.producer.EmailProducerTest.java
@Test public void test_successful_email_withAttachment() throws MessagingException, IOException { EmailProducerConfiguration emailProducerConfiguration = getConfiguration(true, null); EmailProducer emailProducer = new EmailProducer(); ((Configured) emailProducer).setConfiguration(emailProducerConfiguration); ((ManagedResource) emailProducer).startManagedResource(); emailProducer.invoke(getEmailPayload(true, null)); List<WiserMessage> messages = wiser.getMessages(); Assert.assertTrue("Should be three messages - one per addressee", messages.size() == 3); for (WiserMessage message : wiser.getMessages()) { Assert.assertTrue("sender should be " + sender, sender.equals(message.getEnvelopeSender())); MimeMessage mimeMessage = message.getMimeMessage(); MimeMultipart mimeMultipart = (MimeMultipart) mimeMessage.getContent(); Assert.assertTrue("should be 2 bodypart", mimeMultipart.getCount() == 2); BodyPart bodyPart = mimeMultipart.getBodyPart(0); String content = (String) bodyPart.getContent(); Assert.assertTrue("The email content should be empty", content.isEmpty()); BodyPart attachment = mimeMultipart.getBodyPart(1); Assert.assertEquals("Check attachment file name", "testAttachment", attachment.getFileName()); Assert.assertTrue("Check file content", IOUtils.toString(attachment.getDataHandler().getDataSource().getInputStream()) .contains("1997,Ford,E350")); Assert.assertTrue("Should find email format as \"text/plain\"", bodyPart.getContentType().contains("text/plain")); }//w w w . j a v a 2 s.c o m }
From source file:org.mule.module.http.internal.HttpParser.java
public static Collection<HttpPart> parseMultipartContent(InputStream content, String contentType) throws IOException { MimeMultipart mimeMultipart = null;/*from w w w . j av a 2s . c om*/ List<HttpPart> parts = Lists.newArrayList(); try { mimeMultipart = new MimeMultipart(new ByteArrayDataSource(content, contentType)); } catch (MessagingException e) { throw new IOException(e); } try { int partCount = mimeMultipart.getCount(); for (int i = 0; i < partCount; i++) { BodyPart part = mimeMultipart.getBodyPart(i); String filename = part.getFileName(); String partName = filename; String[] contentDispositions = part.getHeader(CONTENT_DISPOSITION_PART_HEADER); if (contentDispositions != null) { String contentDisposition = contentDispositions[0]; if (contentDisposition.contains(NAME_ATTRIBUTE)) { partName = contentDisposition.substring( contentDisposition.indexOf(NAME_ATTRIBUTE) + NAME_ATTRIBUTE.length() + 2); partName = partName.substring(0, partName.indexOf("\"")); } } HttpPart httpPart = new HttpPart(partName, filename, IOUtils.toByteArray(part.getInputStream()), part.getContentType(), part.getSize()); Enumeration<Header> headers = part.getAllHeaders(); while (headers.hasMoreElements()) { Header header = headers.nextElement(); httpPart.addHeader(header.getName(), header.getValue()); } parts.add(httpPart); } } catch (MessagingException e) { throw new IOException(e); } return parts; }
From source file:org.mule.service.http.impl.service.server.grizzly.HttpParser.java
public static Collection<HttpPart> parseMultipartContent(InputStream content, String contentType) throws IOException { MimeMultipart mimeMultipart = null;/* w ww .j ava 2 s . c o m*/ List<HttpPart> parts = Lists.newArrayList(); try { mimeMultipart = new MimeMultipart(new ByteArrayDataSource(content, contentType)); } catch (MessagingException e) { throw new IOException(e); } try { int partCount = mimeMultipart.getCount(); for (int i = 0; i < partCount; i++) { BodyPart part = mimeMultipart.getBodyPart(i); String filename = part.getFileName(); String partName = filename; String[] contentDispositions = part.getHeader(CONTENT_DISPOSITION); if (contentDispositions != null) { String contentDisposition = contentDispositions[0]; if (contentDisposition.contains(NAME_ATTRIBUTE)) { partName = contentDisposition.substring( contentDisposition.indexOf(NAME_ATTRIBUTE) + NAME_ATTRIBUTE.length() + 2); partName = partName.substring(0, partName.indexOf("\"")); } } if (partName == null && mimeMultipart.getContentType().contains(MULTIPART_RELATED.toString())) { String[] contentIdHeader = part.getHeader(CONTENT_ID); if (contentIdHeader != null && contentIdHeader.length > 0) { partName = contentIdHeader[0]; } } HttpPart httpPart = new HttpPart(partName, filename, IOUtils.toByteArray(part.getInputStream()), part.getContentType(), part.getSize()); Enumeration<Header> headers = part.getAllHeaders(); while (headers.hasMoreElements()) { Header header = headers.nextElement(); httpPart.addHeader(header.getName(), header.getValue()); } parts.add(httpPart); } } catch (MessagingException e) { throw new IOException(e); } return parts; }
From source file:org.nuxeo.ecm.automation.jaxrs.io.operations.MultiPartFormRequestReader.java
public static Blob readBlob(HttpServletRequest request, BodyPart part) throws MessagingException, IOException { String ctype = part.getContentType(); String fname = part.getFileName(); InputStream pin = part.getInputStream(); final File tmp = Framework.createTempFile("nx-automation-upload-", ".tmp"); FileUtils.copyToFile(pin, tmp);/*from w ww . ja v a 2 s . com*/ Blob blob = Blobs.createBlob(tmp, ctype, null, fname); RequestContext.getActiveContext(request).addRequestCleanupHandler(new RequestCleanupHandler() { @Override public void cleanup(HttpServletRequest req) { tmp.delete(); } }); return blob; }