List of usage examples for javax.activation MimeType MimeType
public MimeType(String rawdata) throws MimeTypeParseException
From source file:org.codice.ddf.spatial.ogc.catalog.resource.impl.ResourceReaderTest.java
/** * Tests the case in which the Resource in the ResourceResponse returned by the URLResourceReader * has a text/html mime type./* w w w . jav a2 s.c o m*/ */ @Test public void testRetrieveResourceMimeTypeTextHtml() throws Exception { // Setup String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH; URI uri = new URI(httpUriStr); Response mockResponse = getMockResponse(); setupMockWebClient(mockResponse); ResourceResponse mockResourceResponse = getMockResourceResponse(new MimeType("application/octet-stream")); URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse); setupMockTika(MediaType.TEXT_HTML); OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(mockUrlResourceReader, mockTika); HashMap<String, Serializable> arguments = new HashMap<String, Serializable>(); // Perform Test ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments); // Verify StringWriter writer = new StringWriter(); IOUtils.copy(resourceResponse.getResource().getInputStream(), writer, MOCK_HTTP_SERVER_ENCODING); String responseString = writer.toString(); LOGGER.info("Response {}", responseString); assertThat(responseString, is("<html><script type=\"text/javascript\">window.location.replace(\"" + httpUriStr + "\");</script></html>")); }
From source file:org.codice.ddf.catalog.transformer.zip.ZipCompression.java
private String getFileExtensionFromService(ServiceReference<MetacardTransformer> serviceRef) { Object mimeTypeProperty = serviceRef.getProperty("mime-type"); if (mimeTypeProperty == null) { return ""; }//from w w w .j av a2s .c o m String mimeTypeStr = mimeTypeProperty.toString(); try { MimeType exportMimeType = new MimeType(mimeTypeStr); return exportMimeType.getSubType(); } catch (MimeTypeParseException e) { LOGGER.debug("Failed to parse mime type {}", mimeTypeStr, e); return ""; } }
From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java
@Validated @Test/* w w w . jav a 2 s .co m*/ public final void testRemoveAllAttachments() throws Exception { SOAPMessage message = getFactory().createMessage(); for (int i = 0; i < 5; i++) { AttachmentPart att = message.createAttachmentPart("test" + i, "text/plain"); message.addAttachmentPart(att); } assertEquals(5, message.countAttachments()); message.removeAllAttachments(); assertEquals(0, message.countAttachments()); if (message.saveRequired()) { message.saveChanges(); } String[] contentType = message.getMimeHeaders().getHeader("Content-Type"); assertNotNull(contentType); assertEquals(1, contentType.length); assertEquals(messageSet.getVersion().getContentType(), new MimeType(contentType[0]).getBaseType()); }
From source file:org.codice.alliance.imaging.chip.transformer.CatalogOutputAdapter.java
/** * @param image the BufferedImage to be converted. * @return a BinaryContent object containing the image data. * @throws IOException when the BufferedImage can't be written to temporary in-memory space. * @throws MimeTypeParseException thrown if the mime type is invalid *///from w ww . j a va 2 s. c o m @SuppressWarnings("WeakerAccess") public BinaryContent getBinaryContent(BufferedImage image) throws IOException, MimeTypeParseException { validateArgument(image, "image"); BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = rgbImage.createGraphics(); graphics.drawImage(image, 0, 0, null); InputStream fis = new ByteArrayInputStream(createJpg(rgbImage)); return new BinaryContentImpl(fis, new MimeType(IMAGE_JPG)); }
From source file:org.codice.ddf.spatial.ogc.catalog.resource.impl.TestResourceReader.java
/** * Tests the case in which the Resource in the ResourceResponse returned by the * URLResourceReader has an application/unknown mime type. */// w w w.java2 s .c om @Test public void testRetrieveResourceApplicationUnknownResourceMimeType() throws Exception { // Setup String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH; URI uri = new URI(httpUriStr); Response mockResponse = getMockResponse(); setupMockWebClient(mockResponse); ResourceResponse mockResourceResponse = getMockResourceResponse(new MimeType("application/octet-stream")); URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse); setupMockTika(MediaType.TEXT_HTML); OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(mockUrlResourceReader, mockTika); HashMap<String, Serializable> arguments = new HashMap<String, Serializable>(); // Perform Test ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments); // Verify StringWriter writer = new StringWriter(); IOUtils.copy(resourceResponse.getResource().getInputStream(), writer, MOCK_HTTP_SERVER_ENCODING); String responseString = writer.toString(); LOGGER.info("Response " + responseString); assertThat(responseString, is("<html><script type=\"text/javascript\">window.location.replace(\"" + httpUriStr + "\");</script></html>")); }
From source file:org.codice.ddf.spatial.ogc.catalog.resource.impl.ResourceReaderTest.java
/** * Tests the case in which the Resource in the ResourceResponse returned by the URLResourceReader * has an application/unknown mime type. *//* w w w.j ava 2 s. c o m*/ @Test public void testRetrieveResourceApplicationUnknownResourceMimeType() throws Exception { // Setup String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH; URI uri = new URI(httpUriStr); Response mockResponse = getMockResponse(); setupMockWebClient(mockResponse); ResourceResponse mockResourceResponse = getMockResourceResponse(new MimeType("application/octet-stream")); URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse); setupMockTika(MediaType.TEXT_HTML); OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(mockUrlResourceReader, mockTika); HashMap<String, Serializable> arguments = new HashMap<String, Serializable>(); // Perform Test ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments); // Verify StringWriter writer = new StringWriter(); IOUtils.copy(resourceResponse.getResource().getInputStream(), writer, MOCK_HTTP_SERVER_ENCODING); String responseString = writer.toString(); LOGGER.info("Response {}", responseString); assertThat(responseString, is("<html><script type=\"text/javascript\">window.location.replace(\"" + httpUriStr + "\");</script></html>")); }
From source file:org.osaf.cosmo.dav.impl.StandardDavRequest.java
private Document getSafeRequestDocument(boolean requireDocument) throws DavException { try {// w ww.j a v a 2 s . com if (StringUtils.isBlank(getContentType())) { if (requireDocument) throw new BadRequestException("No Content-Type specified"); return null; } MimeType mimeType = new MimeType(getContentType()); if (!(mimeType.match(APPLICATION_XML) || mimeType.match(TEXT_XML))) throw new UnsupportedMediaTypeException( "Expected Content-Type " + APPLICATION_XML + " or " + TEXT_XML); return getRequestDocument(); } catch (MimeTypeParseException e) { throw new UnsupportedMediaTypeException(e.getMessage()); } catch (IllegalArgumentException e) { Throwable cause = e.getCause(); String msg = cause != null ? cause.getMessage() : null; if (msg == null) msg = "Unknown error parsing request document"; throw new BadRequestException(msg); } }
From source file:org.mule.transformer.AbstractTransformer.java
public void setMimeType(String mimeType) throws MimeTypeParseException { if (mimeType == null) { this.mimeType = null; } else {/*from w w w. j ava 2 s.com*/ MimeType mt = new MimeType(mimeType); this.mimeType = mt.getPrimaryType() + "/" + mt.getSubType(); } if (returnType != null) { returnType.setMimeType(mimeType); } }
From source file:eu.fusepool.p3.transformer.client.TransformerClientImpl.java
private Entity getResponseEntity(HttpURLConnection connection) throws IOException, MimeTypeParseException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (connection.getResponseCode() < 400) { IOUtils.copy(connection.getInputStream(), baos); } else {/*ww w. j a v a 2 s . c o m*/ IOUtils.copy(connection.getErrorStream(), baos); } final byte[] bytes = baos.toByteArray(); final String resultContentTypeString = connection.getHeaderField("Content-Type"); final MimeType resultType = resultContentTypeString != null ? new MimeType(resultContentTypeString) : new MimeType("application", "octet-stream"); return new InputStreamEntity() { @Override public MimeType getType() { return resultType; } @Override public InputStream getData() throws IOException { return new ByteArrayInputStream(bytes); } }; }
From source file:ddf.content.plugin.video.TestVideoThumbnailPlugin.java
@Test public void testCreatedItemNotVideoFile() throws Exception { mockContentItem = mock(ContentItem.class); doReturn(new MimeType("image/jpeg")).when(mockContentItem).getMimeType(); final CreateResponse mockCreateResponse = mock(CreateResponse.class); doReturn(mockContentItem).when(mockCreateResponse).getCreatedContentItem(); final CreateResponse processedCreateResponse = videoThumbnailPlugin.process(mockCreateResponse); assertThat(getAttributeMapFromResponse(processedCreateResponse), not(hasKey(Metacard.THUMBNAIL))); }