List of usage examples for javax.activation DataHandler DataHandler
public DataHandler(URL url)
DataHandler
instance referencing a URL. From source file:edu.harvard.i2b2.fr.ws.FileRepositoryService.java
public OMElement recvfileRequest(OMElement request) { LoaderQueryRequestDelegate queryDelegate = new LoaderQueryRequestDelegate(); OMElement responseElement = null;/* w w w . j a v a 2s . c om*/ FileDataSource fileDataSource; DataHandler fileDataHandler; try { String requestXml = request.toString(); if (requestXml.indexOf("<soapenv:Body>") > -1) { requestXml = requestXml.substring(requestXml.indexOf("<soapenv:Body>") + 14, requestXml.indexOf("</soapenv:Body>")); } RecvfileRequestHandler handler = new RecvfileRequestHandler(requestXml); String response = queryDelegate.handleRequest(requestXml, handler); String filename = handler.getFilename(); // We can obtain the request (incoming) MessageContext as follows MessageContext inMessageContext = MessageContext.getCurrentMessageContext(); // We can obtain the operation context from the request message // context OperationContext operationContext = inMessageContext.getOperationContext(); MessageContext outMessageContext = operationContext .getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); outMessageContext.setDoingSwA(true); outMessageContext.setDoingREST(false); if (!filename.equals("")) { fileDataSource = new FileDataSource(filename); fileDataHandler = new DataHandler(fileDataSource); // use requested filename as content ID outMessageContext.addAttachment(handler.getRequestedFilename(), fileDataHandler); outMessageContext.setDoingMTOM(false); outMessageContext.setDoingSwA(true); responseElement = buildOMElementFromString(response, fileDataHandler.getName()); } else { log.error("where did the file go? "); } } catch (XMLStreamException e) { log.error("xml stream exception", e); } catch (I2B2Exception e) { log.error("i2b2 exception", e); } catch (Throwable e) { log.error("Throwable", e); } return responseElement; }
From source file:org.cleverbus.core.common.asynch.notification.EmailServiceCamelSmtpImpl.java
@Override public void sendEmail(final Email email) { Assert.notNull(email, "email can not be null"); Assert.notEmpty(email.getRecipients(), "email must have at least one recipients"); Assert.hasText(email.getSubject(), "subject in email can not be empty"); Assert.hasText(email.getBody(), "body in email can not be empty"); producerTemplate.send("smtp://" + smtp, new Processor() { @Override// w w w. j a va 2s .c om public void process(final Exchange exchange) throws Exception { Message in = exchange.getIn(); in.setHeader("To", StringUtils.join(email.getRecipients(), ",")); in.setHeader("From", StringUtils.isBlank(email.getFrom()) ? from : email.getFrom()); in.setHeader("Subject", email.getSubject()); in.setHeader("contentType", email.getContentType().getContentType()); in.setBody(email.getBody()); if (email.getAllAtachments() != null && !email.getAllAtachments().isEmpty()) { for (EmailAttachment attachment : email.getAllAtachments()) { in.addAttachment(attachment.getFileName(), new DataHandler(new ByteArrayDataSource(attachment.getContent(), "*/*"))); } } } }); }
From source file:de.kp.ames.web.function.domain.model.ProductObject.java
/** * Create ProductObject// ww w .j a v a2 s . co m * * @param data * @param stream * @return * @throws Exception */ public RegistryObjectImpl create(String data, InputStream stream) throws Exception { /* * Initialize data */ JSONObject jForm = new JSONObject(data); /* * Create extrinsic object that serves as a wrapper * for the respective product */ // ExtrinsicObjectImpl eo = jaxrLCM.createExtrinsicObject(); if (eo == null) throw new JAXRException("[ProductObject] Creation of ExtrinsicObject failed."); /* * Identifier */ String eid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.PRODUCT_PRE); eo.setLid(eid); eo.getKey().setId(eid); /* * Home url */ String home = jaxrHandle.getEndpoint().replace("/saml", ""); eo.setHome(home); /* * Name & description */ String name = jForm.getString(RIM_NAME); String desc = jForm.getString(RIM_DESC); String dtime = jForm.getString(RIM_DATE); name = name.trim() + ", " + dtime.trim(); eo.setName(jaxrLCM.createInternationalString(name)); eo.setDescription(jaxrLCM.createInternationalString(desc)); /* * Classifications */ ClassificationImpl classification = jaxrLCM.createClassification(ClassificationConstants.FNC_ID_Product); eo.addClassification(classification); /* * Mimetype & repository item */ String mimetype = GlobalConstants.MT_XML; eo.setMimeType(mimetype); byte[] bytes = FileUtil.getByteArrayFromInputStream(stream); DataHandler handler = new DataHandler(FileUtil.createByteArrayDataSource(bytes, mimetype)); eo.setRepositoryItem(handler); /* * Indicate as created */ this.created = true; return eo; }
From source file:org.ambraproject.wombat.service.FreemarkerMailServiceImpl.java
private static DataHandler createBodyPartDataHandler(byte[] data, String contentType) { Objects.requireNonNull(data); Objects.requireNonNull(contentType); return new DataHandler(new DataSource() { @Override// www . j av a 2s .co m public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(data); } @Override public OutputStream getOutputStream() throws IOException { throw new IOException("Read-only data"); } @Override public String getContentType() { return contentType; } @Override public String getName() { return "main"; } }); }
From source file:org.infoglue.common.util.mail.MailService.java
/** * *//*from w w w. ja v a 2 s .c o m*/ private Message createMessage(String from, String to, String subject, String content) throws SystemException { try { final Message message = new MimeMessage(this.session); message.setContent(content, "text/html"); message.setFrom(createInternetAddress(from)); message.setRecipient(Message.RecipientType.TO, createInternetAddress(to)); message.setSubject(subject); message.setText(content); message.setDataHandler(new DataHandler(new StringDataSource(content, "text/html"))); return message; } catch (MessagingException e) { throw new SystemException("Unable to create the message.", e); } }
From source file:org.wso2.appserver.integration.resources.resource.test.NonXMLResourceAddTestCase.java
@Test(groups = { "wso2.as" }) public void testAddNoneXmlResource() throws ResourceAdminServiceExceptionException, IOException, XPathExpressionException { //add a collection to the registry String collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH, RES_FILE_FOLDER, "", "contains Text Res Files"); String authorUserName = resourceAdminServiceClient.getResource((PARENT_PATH + RES_FILE_FOLDER))[0] .getAuthorUserName();/*w w w. j a va2 s.c o m*/ assertTrue(asServer.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(authorUserName), PARENT_PATH + RES_FILE_FOLDER + " creation failure"); log.info("collection added to " + collectionPath); // Changing media type collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH, RES_FILE_FOLDER, "application/vnd.wso2.esb", "application/vnd.wso2.esb media type collection"); authorUserName = resourceAdminServiceClient.getResource((PARENT_PATH + RES_FILE_FOLDER))[0] .getAuthorUserName(); assertTrue(asServer.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(authorUserName), PARENT_PATH + RES_FILE_FOLDER + " updating failure"); log.info("collection updated in " + collectionPath); String resource = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "AS" + File.separator + "txt" + File.separator + "sampleText.txt"; DataHandler dh = new DataHandler(new URL("file:///" + resource)); resourceAdminServiceClient.addResource(PARENT_PATH + RES_FILE_FOLDER + "/" + TEXT_FILE_NAME, "text/html", "txtDesc", dh); String textContent = resourceAdminServiceClient .getTextContent(PARENT_PATH + RES_FILE_FOLDER + "/" + TEXT_FILE_NAME); assertTrue(dh.getContent().toString().equalsIgnoreCase(textContent), "Text file has not been added properly "); }
From source file:org.wso2.appserver.integration.tests.sampleservices.axis2module.Axis2ModuleTestCase.java
@Test(groups = "wso2.as", description = "HelloService - engage logmodule") public void engageModule() throws Exception { super.init(); moduleAdminServiceClient = new ModuleAdminServiceClient(backendURL, sessionCookie); URL url = new URL("file://" + FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "AS" + File.separator + "mar" + File.separator + "LogModule-1.0.0.mar"); DataHandler dh = new DataHandler(url); moduleAdminServiceClient.uploadModule(dh); // upload logmodule serverConfigurationManager.restartGracefully(); // server restart point after engaging the module super.init(); moduleAdminServiceClient = new ModuleAdminServiceClient(backendURL, sessionCookie); ModuleMetaData[] moduleMetaData = moduleAdminServiceClient.listModulesForService("HelloService"); boolean moduleExists = false; // checking the availability of logmodule module for the service for (ModuleMetaData aModuleMetaData : moduleMetaData) { if (aModuleMetaData.getModulename().equals("logmodule")) { moduleExists = true;//from w w w .j a va2 s . c o m //engaging the logmodule to the service assertTrue(moduleAdminServiceClient.engageModule("logmodule", "HelloService")); break; } } assertTrue(moduleExists, "module engagement failure due to the unavailability of logmodule" + " module at service level context"); }
From source file:org.cerberus.service.soap.impl.SoapService.java
@Override public void addAttachmentPart(SOAPMessage input, String path) throws CerberusException { URL url;/*from ww w . j a v a2s . co m*/ try { url = new URL(path); DataHandler handler = new DataHandler(url); //TODO: verify if this code is necessary /*String str = ""; StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); while (null != (str = br.readLine())) { sb.append(str); }*/ AttachmentPart attachPart = input.createAttachmentPart(handler); input.addAttachmentPart(attachPart); } catch (MalformedURLException ex) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.SOAPLIB_MALFORMED_URL)); } catch (IOException ex) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.SOAPLIB_MALFORMED_URL)); } }
From source file:org.wso2.appserver.integration.tests.carbonappservice.WSAS1798CAppWarUndeployTest.java
/** * Upload the CApp and check whether the CApp uploaded successfully * * @return boolean/*from www.j a v a 2s . c om*/ * @throws Exception */ private boolean isCAppApllcationUplodedSuccessfully() throws Exception { CarbonAppUploaderClient carbonAppClient = new CarbonAppUploaderClient(backendURL, sessionCookie); URL url = new URL("file://" + FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "AS" + File.separator + "car" + File.separator + "WarCApp_1.0.0.car"); DataHandler dataHandler = new DataHandler(url); carbonAppClient.uploadCarbonAppArtifact("WarCApp_1.0.0.car", dataHandler); return WebAppDeploymentUtil.isWebApplicationDeployed(backendURL, sessionCookie, "appServer-valid-deploymant-1.0.0"); }
From source file:com.jwm123.loggly.reporter.ReportMailer.java
public MimeBodyPart addReportAttachment() throws MessagingException { MimeBodyPart mimeBodyPart = new MimeBodyPart(); String mimeType = "application/vnd.ms-excel"; if (fileName.endsWith(".xlsx")) { mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; }/*w ww .ja va 2 s.co m*/ mimeBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(reportContent, mimeType))); mimeBodyPart.setDisposition("attachment"); mimeBodyPart.setFileName(fileName); return mimeBodyPart; }