List of usage examples for javax.activation DataHandler DataHandler
public DataHandler(URL url)
DataHandler
instance referencing a URL. From source file:es.pode.administracion.presentacion.estructuraseducativas.arboles.alta.AltaArbolesControllerImpl.java
public final void nuevoArbol(ActionMapping mapping, NuevoArbolForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { VdexVO[] resultado = null;/*from www.j a v a2s . co m*/ List ficheros = new ArrayList(); if (form.getFichero1() != null && form.getFichero1().getFileName() != null && !form.getFichero1().getFileName().equals(""))//&& form.getFichero1().getFileSize()>0 ficheros.add(form.getFichero1()); if (form.getFichero2() != null && form.getFichero2().getFileName() != null && !form.getFichero2().getFileName().equals("")) ficheros.add(form.getFichero2()); if (form.getFichero3() != null && form.getFichero3().getFileName() != null && !form.getFichero3().getFileName().equals("")) ficheros.add(form.getFichero3()); if (form.getFichero4() != null && form.getFichero4().getFileName() != null && !form.getFichero4().getFileName().equals("")) ficheros.add(form.getFichero4()); if (form.getFichero5() != null && form.getFichero5().getFileName() != null && !form.getFichero5().getFileName().equals("")) ficheros.add(form.getFichero5()); if (ficheros.size() == 0) { throw new ValidatorException("{estructuras.arboles.error.fichero.vacio}"); } List arrayParam = new ArrayList(); InternetHeaders ih = new InternetHeaders(); MimeBodyPart mbp = null; DataSource source = null; DataHandler dh = null; for (int i = 0; i < ficheros.size(); i++) { try { FormFile ff = (FormFile) ficheros.get(i); mbp = new MimeBodyPart(ih, ff.getFileData()); source = new MimePartDataSource(mbp); dh = new DataHandler(source); arrayParam.add(new ParamVdexVO(dh, ff.getFileName())); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("error al cargar la lista de paramVDEXVO"); } } } try { SrvEstructurasEducativasService servicio = this.getSrvEstructurasEducativasService(); resultado = servicio.subirArbolesCurriculares((ParamVdexVO[]) arrayParam.toArray(new ParamVdexVO[0])); for (int i = 0; i < resultado.length; i++) { String[] nombreVdex = new String[1]; nombreVdex[0] = ((FormFile) ficheros.get(i)).getFileName(); if (resultado[i].getCodigoError() != null && !resultado[i].getCodigoError().equals("")) { logger.debug("hubo un error al crear el nuevo arbol, se muestra el error en la jsp"); this.saveErrorMessage(request, "estructuras.error.alta." + resultado[i].getCodigoError(), nombreVdex); } else { this.saveSuccessMessage(request, "estructuras.arboles.alta.exito", nombreVdex); } } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("error al dar de alta lista de arboles"); } this.saveErrorMessage(request, "estructuras.error.alta.0"); } }
From source file:org.wso2.appserver.integration.tests.carbonappservice.WSAS1910CAppArtifactIdentificationTestCase.java
@Test(groups = "wso2.as", description = "Upload CApp which contains an axis2 service and check if setCAppArtifact is true") public void verifyIndicatorWebappCApp() throws Exception { URL urlAxisCApp = new URL( "file://" + FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "AS" + File.separator + "car" + File.separator + warCApp + "_" + appVersion + ".car"); DataHandler dataHandler = new DataHandler(urlAxisCApp); carbonAppClient.uploadCarbonAppArtifact(warCApp + "_" + appVersion + ".car", dataHandler); assertTrue(WebAppDeploymentUtil.isWebApplicationDeployed(backendURL, sessionCookie, "appServer-valid-deploymant-1.0.0")); WebappMetadata webappMetadata = webAppAdminClient.getWebAppInfo("appServer-valid-deploymant-1.0.0"); assertTrue(webappMetadata.getCAppArtifact(), "The Webapp is not incdicated as a CApp artifact"); }
From source file:com.tangfan.test.UserServiceTest.java
/** * testBinary webservice?/*from w w w . j a v a2 s. c o m*/ */ @Test public void testBinary() { DataHandler file = new DataHandler( new FileDataSource(new File("C:/Users/Administrator/Pictures/QQ20150206132707.jpg"))); port.binary(file); }
From source file:com.tdclighthouse.commons.mail.util.MailClient.java
protected void addAtachments(String[] attachments, Multipart multipart) throws MessagingException, AddressException { for (int i = 0; i < attachments.length; i++) { String filename = attachments[i]; MimeBodyPart attachmentBodyPart = new MimeBodyPart(); // use a JAF FileDataSource as it does MIME type detection DataSource source = new FileDataSource(filename); attachmentBodyPart.setDataHandler(new DataHandler(source)); // assume that the filename you want to send is the same as the // actual file name - could alter this to remove the file path attachmentBodyPart.setFileName(filename); // add the attachment multipart.addBodyPart(attachmentBodyPart); }//from w w w . j av a 2s .c o m }
From source file:de.kp.ames.web.function.domain.model.ImageObject.java
/** * Create RegistryObject representation of ImageObject * /*from w w w . j a v a2 s . c o m*/ * @param data * @return * @throws Exception */ public RegistryObjectImpl create(JSONObject jForm) throws Exception { /* * Create extrinsic object that serves as a wrapper * for the respective image */ // ExtrinsicObjectImpl eo = jaxrLCM.createExtrinsicObject(); if (eo == null) throw new JAXRException("[ImageObject] Creation of ExtrinsicObject failed."); /* * Identifier */ String eid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.IMAGE_PRE); eo.setLid(eid); eo.getKey().setId(eid); /* * Home url */ String home = jaxrHandle.getEndpoint().replace("/saml", ""); eo.setHome(home); /* * The document is actually transient and managed by the image cache */ ImageCacheManager cacheManager = ImageCacheManager.getInstance(); String key = jForm.getString(JsonConstants.J_KEY); DmsImage image = (DmsImage) cacheManager.getFromCache(key); if (image == null) throw new Exception("[ImageObject] Image with id <" + key + "> not found."); /* * Name & description */ String name = jForm.has(RIM_NAME) ? jForm.getString(RIM_NAME) : null; String desc = jForm.has(RIM_DESC) ? jForm.getString(RIM_DESC) : null; name = (name == null) ? image.getName() : name; int pos = name.lastIndexOf("."); if (pos != -1) name = name.substring(0, pos); eo.setName(jaxrLCM.createInternationalString(name)); desc = (desc == null) ? FncMessages.NO_DESCRIPTION_DESC : desc; eo.setDescription(jaxrLCM.createInternationalString(desc)); /* * Classifications */ JSONArray jClases = jForm.has(RIM_CLAS) ? new JSONArray(jForm.getString(RIM_CLAS)) : null; if (jClases != null) { List<ClassificationImpl> classifications = createClassifications(jClases); /* * Set composed object */ eo.addClassifications(classifications); } /* * Mimetype & repository item */ String mimetype = image.getMimetype(); DataHandler handler = new DataHandler(FileUtil.createByteArrayDataSource(image.getBytes(), mimetype)); eo.setMimeType(mimetype); eo.setRepositoryItem(handler); /* * Indicate as created */ this.created = true; return eo; }
From source file:se.inera.axel.shs.camel.LargeShsMessageTypeConverterTest.java
@DirtiesContext @Test//w w w .j a v a 2s . com public void testLargeStreamToShsMessage() throws Exception { Assert.assertNotNull(testShsMessage); ShsMessageMarshaller marshaller = new ShsMessageMarshaller(); InputStream largeInput = new NullInputStream(100_000_000); testShsMessage.getDataParts().remove(0); DataPart dataPart = new DataPart( new DataHandler(new InputStreamDataSource(largeInput, "application/x-iso9660-image"))); dataPart.setContentType("application/x-iso9660-image"); dataPart.setFileName("largefile"); dataPart.setTransferEncoding("base64"); dataPart.setDataPartType("iso"); testShsMessage.getDataParts().add(dataPart); File shsFile = File.createTempFile("axel", "test"); FileUtils.copyInputStreamToFile(marshaller.marshal(testShsMessage), shsFile); resultEndpoint.expectedMessageCount(1); template.sendBody("direct:convertFromStream", new BufferedInputStream(new FileInputStream(shsFile))); resultEndpoint.assertIsSatisfied(); List<Exchange> exchanges = resultEndpoint.getReceivedExchanges(); Exchange exchange = exchanges.get(0); ShsMessage shsMessage = exchange.getIn().getMandatoryBody(ShsMessage.class); Assert.assertNotSame(shsMessage, testShsMessage); ShsLabel label = shsMessage.getLabel(); Assert.assertNotNull(label, "label should not be null"); Assert.assertEquals(label.getSubject(), testShsMessage.getLabel().getSubject()); Assert.assertEquals(label.getDatetime().toString(), testShsMessage.getLabel().getDatetime().toString()); Assert.assertNotNull(testShsMessage.getDataParts()); DataPart dataPartResponse = testShsMessage.getDataParts().get(0); }
From source file:org.wf.dp.dniprorada.util.Mail.java
public Mail _Attach(DataSource oDataSource, String sFileName, String sDescription) { try {// w w w. ja v a 2 s . c o m MimeBodyPart oMimeBodyPart = new MimeBodyPart(); oMimeBodyPart.setHeader("Content-Type", "multipart/mixed"); oMimeBodyPart.setDataHandler(new DataHandler(oDataSource)); oMimeBodyPart.setFileName(MimeUtility.encodeText(sFileName)); oMultiparts.addBodyPart(oMimeBodyPart); log.info("[_Attach:oFile]:sFileName=" + sFileName + ",sDescription=" + sDescription); } catch (Exception oException) { log.error("[_Attach:oFile]sFileName=" + sFileName + ",sDescription=" + sDescription, oException); } return this; }
From source file:org.wso2.appserver.integration.resources.resource.test.RegistryResourceTestCase.java
@Test(groups = { "wso2.as" }, dependsOnMethods = "testCreateCollection") public void testAddResourceFromLocalFile() throws IOException, ResourceAdminServiceExceptionException { String RESOURCE_NAME = "sampleText.txt"; String resource = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "AS" + File.separator + "txt" + File.separator + RESOURCE_NAME; DataHandler dh = new DataHandler(new URL("file:///" + resource)); resourceAdminServiceClient.addResource(PARENT_PATH + "/" + WSO2_COLL + "/" + RESOURCE_NAME, "text/html", "txtDesc", dh); String textContent = resourceAdminServiceClient .getTextContent(PARENT_PATH + "/" + WSO2_COLL + "/" + RESOURCE_NAME); assertTrue(dh.getContent().toString().equalsIgnoreCase(textContent), "Added resource not found"); log.info("Resource successfully added to the registry and retrieved contents successfully"); }
From source file:com.warsaw.data.controller.LoginController.java
private Message buildEmail(Session session, String to) throws Exception { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(EMAIL)); // Set To: header field of the header. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); // Set Subject: header field message.setSubject("Testing Subject"); // This mail has 2 part, the BODY and the embedded image MimeMultipart multipart = new MimeMultipart("related"); // first part (the html) BodyPart messageBodyPart = new MimeBodyPart(); String htmlText = "<img style='width:800px' src=\"cid:image1\"><br/>" + "Dzie dobry,<br/><br/>" + "witamy na portalu TrasyPoWarszawsku.pl, na ktrym zostalo " + "zaoone konto<br/> dla osoby o danych: Jan Marian Ptak. W celu zakoczenia procesu tworzenia " + "konta prosimy uy linku aktywacyjnego:<br/><br/>" + "<a href='https://test.puesc.gov.pl?link=Gkhh&%JK.'>https://test.puesc.gov.pl?link=Gkhh&%JK.</a><br/><br/>" + "Na wywietlonym ekranie prosz wprowadzi zdefiniowane przez siebie haso awaryjne. Po prawidowym" + " wprowadzeniu danych<br/> oraz ustawieniu nowego hasa dostpowego konto na portalu PUESC zostanie aktywowane.<br/>" + "Link aktywacyjny pozostanie wany przez 24 godziny od momentu otrzymania niniejszej wiadomoci.<br/><br/>" + "<img style='width:800px' src=\"cid:image2\"><br/><br/>" + "Z powaaniem<br/><br/>" + "Zesp portalu PUESC<br/>" + "puesc@mofnet.gov.pl<br/>" + "<a href='http://puesc.gov.pl'>http://puesc.gov.pl</a>"; messageBodyPart.setContent(htmlText, "text/html; charset=ISO-8859-2"); // add it/* w ww . ja v a 2 s . co m*/ multipart.addBodyPart(messageBodyPart); // second part (the image) messageBodyPart = new MimeBodyPart(); DataSource fds = new FileDataSource("C:\\Users\\Pawel\\Desktop\\header.png"); messageBodyPart.setDataHandler(new DataHandler(fds)); messageBodyPart.setHeader("Content-ID", "<image1>"); // add image to the multipart multipart.addBodyPart(messageBodyPart); messageBodyPart = new MimeBodyPart(); // URL url = new URL("http://ns3342351.ovh.net:8080/seap_lf_graphicsLayout_theme/images/refresh.png"); // URLDataSource fds1 =new URLDataSource(url); messageBodyPart.setDataHandler(new DataHandler(fds)); messageBodyPart.setHeader("Content-ID", "<image2>"); multipart.addBodyPart(messageBodyPart); // put everything together message.setContent(multipart); ByteArrayOutputStream b = new ByteArrayOutputStream(); try { message.writeTo(b); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return message; }
From source file:org.apache.axis2.saaj.AttachmentTest.java
@Test public void testBadAttSize() throws Exception { MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); ByteArrayInputStream ins = new ByteArrayInputStream(new byte[5]); DataHandler dh = new DataHandler(new Src(ins, "text/plain")); AttachmentPart part = message.createAttachmentPart(dh); assertEquals("Size should match", 5, part.getSize()); }