Example usage for javax.activation DataHandler DataHandler

List of usage examples for javax.activation DataHandler DataHandler

Introduction

In this page you can find the example usage for javax.activation DataHandler DataHandler.

Prototype

public DataHandler(URL url) 

Source Link

Document

Create a DataHandler instance referencing a URL.

Usage

From source file:org.apache.axiom.attachments.lifecycle.impl.FileAccessor.java

public DataHandler getDataHandler(String contentType) throws MessagingException {
    if (log.isDebugEnabled()) {
        log.debug("getDataHandler()");
        log.debug("accessCount =" + accessCount);
    }//from  w w w. ja  va 2  s  . c o m
    CachedFileDataSource dataSource = new CachedFileDataSource(file);
    dataSource.setContentType(contentType);
    accessCount++;
    setChanged();
    notifyObservers();
    DataHandler dataHandler = new DataHandler(dataSource);
    return new DataHandlerExtImpl(dataHandler, manager);
}

From source file:es.caib.sgtsic.xml.XmlManager.java

public DataHandler generateXml(T item) throws JAXBException {

    byte[] b = marshal(item).toByteArray();
    String mimetype = "application/xml";
    DataSource ds = new ByteArrayDataSource(b, mimetype);
    return new DataHandler(ds);

}

From source file:org.openehealth.ipf.platform.camel.lbs.cxf.process.ServiceBean.java

private Object[] postMe(Exchange exchange) throws Exception {
    List<?> params = exchange.getIn().getBody(List.class);
    Holder<String> name = (Holder<String>) params.get(0);
    Holder<DataHandler> attachInfo = (Holder<DataHandler>) params.get(1);
    DataHandler onewayAttach = (DataHandler) params.get(2);

    name.value = "Greetings from Apache Camel!!!! Request was " + name.value;

    String contentType = attachInfo.value.getContentType();
    String resultContent = toString(attachInfo.value) + toString(onewayAttach);

    DataSource outDataSource = new ByteArrayDataSource(resultContent.getBytes(), contentType);
    attachInfo.value = new DataHandler(outDataSource);

    return new Object[] { null, name, attachInfo };
}

From source file:org.wso2.carbon.esb.template.endpointTemplate.EndpointTemplateSuspensionTest.java

@BeforeClass(alwaysRun = true)
public void init() throws Exception {
    super.init();
    //Deploy CAPP
    carbonAppUploaderClient = new CarbonAppUploaderClient(contextUrls.getBackEndUrl(), getSessionCookie());
    applicationAdminClient = new ApplicationAdminClient(contextUrls.getBackEndUrl(), getSessionCookie());

    carbonAppUploaderClient/*from  ww w  . ja va  2 s  .c om*/
            .uploadCarbonAppArtifact("templateEndpointInRegistryTestCapp_1.0.0.car",
                    new DataHandler(new URL("file:" + File.separator + File.separator + getESBResourceLocation()
                            + File.separator + "car" + File.separator
                            + "templateEndpointInRegistryTestCapp_1.0.0.car")));

    boolean cAppDeployed = Utils.isCarFileDeployed(cAppName, applicationAdminClient, 120000);
    Assert.assertTrue(cAppDeployed, "CApp templateEndpointInRegistryTestCapp_1.0.0.car deployment failed");
}

From source file:org.apache.axis2.format.BinaryBuilder.java

public OMElement processDocument(DataSource dataSource, String contentType, MessageContext msgContext)
        throws AxisFault {
    QName wrapperQName = BaseConstants.DEFAULT_BINARY_WRAPPER;
    if (msgContext.getAxisService() != null) {
        Parameter wrapperParam = msgContext.getAxisService().getParameter(BaseConstants.WRAPPER_PARAM);
        if (wrapperParam != null) {
            wrapperQName = BaseUtils.getQNameFromString(wrapperParam.getValue());
        }//ww w .  j a v a2s . c  om
    }
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement wrapper = factory.createOMElement(wrapperQName, null);
    DataHandler dataHandler = new DataHandler(dataSource);
    wrapper.addChild(factory.createOMText(dataHandler, true));
    msgContext.setDoingMTOM(true);
    return wrapper;
}

From source file:org.wso2.carbon.commons.admin.clients.WebAppAdminClient.java

/**
 * Upload a war file//from   w w  w  .j  a  v  a  2s .  c om
 *
 * @param filePath - file path of the war file
 * @throws RemoteException - Error when upload web applications
 */
public void warFileUploader(String filePath) throws RemoteException, MalformedURLException {
    File file = new File(filePath);
    String fileName = file.getName();
    URL url = new URL("file://" + filePath);
    DataHandler dh = new DataHandler(url);

    WebappUploadData webApp = new WebappUploadData();
    webApp.setFileName(fileName);
    webApp.setDataHandler(dh);
    webappAdminStub.uploadWebapp(new WebappUploadData[] { webApp });

    log.info("Webapp " + fileName + "uploaded successfully");
}

From source file:org.vosao.utils.EmailUtil.java

/**
 * Send email with html content and attachments.
 * @param htmlBody//from   ww  w  . j  ava2s. co  m
 * @param subject
 * @param fromAddress
 * @param fromText
 * @param toAddress
 * @return null if OK or error message.
 */
public static String sendEmail(final String htmlBody, final String subject, final String fromAddress,
        final String fromText, final String toAddress, final List<FileItem> files) {

    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    try {
        Multipart mp = new MimeMultipart();
        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setContent(htmlBody, "text/html");
        htmlPart.setHeader("Content-type", "text/html; charset=UTF-8");
        mp.addBodyPart(htmlPart);
        for (FileItem item : files) {
            MimeBodyPart attachment = new MimeBodyPart();
            attachment.setFileName(item.getFilename());
            String mimeType = MimeType.getContentTypeByExt(FolderUtil.getFileExt(item.getFilename()));
            if (mimeType.equals("text/plain")) {
                mimeType = MimeType.DEFAULT;
            }
            DataSource ds = new ByteArrayDataSource(item.getData(), mimeType);
            attachment.setDataHandler(new DataHandler(ds));
            mp.addBodyPart(attachment);
        }
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(fromAddress, fromText));
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddress, toAddress));
        msg.setSubject(subject, "UTF-8");
        msg.setContent(mp);
        Transport.send(msg);
        return null;
    } catch (AddressException e) {
        return e.getMessage();
    } catch (MessagingException e) {
        return e.getMessage();
    } catch (UnsupportedEncodingException e) {
        return e.getMessage();
    }
}

From source file:org.wso2.brs.rule.test.GetQuoteServiceTestCase.java

@Test(groups = { "wso2.brs" })
public void uploadGetQuoteService() throws Exception {
    String samplesDir = System.getProperty("samples.dir");
    String GetQuoteServiceAAR = samplesDir + File.separator
            + "quotation.service/service/target/GetQuoteService.aar";
    log.info(GetQuoteServiceAAR);/*from  w w  w  .j  a va  2s . c  om*/
    FileDataSource fileDataSource = new FileDataSource(GetQuoteServiceAAR);
    DataHandler dataHandler = new DataHandler(fileDataSource);
    getRuleServiceFileUploadClient().uploadService("GetQuoteService.aar", dataHandler);

}

From source file:org.wso2.brs.rule.test.MIPCalculateServiceTestCase.java

@Test(groups = { "wso2.brs" })
public void uploadMIPCalculateService() throws Exception {
    String samplesDir = System.getProperty("samples.dir");
    String MIPCalculateServiceAAR = samplesDir + File.separator
            + "MIPCalculate.service/service/target/MIPCalculateService.aar";
    log.info(MIPCalculateServiceAAR);/*from   ww  w .  j  a  v  a2  s. c  o m*/
    FileDataSource fileDataSource = new FileDataSource(MIPCalculateServiceAAR);
    DataHandler dataHandler = new DataHandler(fileDataSource);
    getRuleServiceFileUploadClient().uploadService("MIPCalculateService.aar", dataHandler);

}

From source file:org.wso2.brs.rule.test.CarRentalServiceTestCase.java

@Test(groups = { "wso2.brs" })
public void uploadCarRentalService() throws Exception {
    String samplesDir = System.getProperty("samples.dir");
    String CarRentalServiceAAR = samplesDir + File.separator
            + "carrental.service/service/target/CarRentalService.aar";
    log.info(CarRentalServiceAAR);//from  ww w . j  a  va 2s  . com
    FileDataSource fileDataSource = new FileDataSource(CarRentalServiceAAR);
    DataHandler dataHandler = new DataHandler(fileDataSource);
    getRuleServiceFileUploadClient().uploadService("CarRentalService.aar", dataHandler);

}