Example usage for javax.activation FileDataSource FileDataSource

List of usage examples for javax.activation FileDataSource FileDataSource

Introduction

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

Prototype

public FileDataSource(String name) 

Source Link

Document

Creates a FileDataSource from the specified path name.

Usage

From source file:org.wso2.bps.integration.common.clients.humantasks.HumanTaskUploaderClient.java

private void deployPackage(String packageName, String resourceDir, HumanTaskUploaderStub htUploaderStub)
        throws RemoteException, InterruptedException {

    String sampleArchiveName = packageName + ".zip";
    log.info(resourceDir + File.separator + sampleArchiveName);
    DataSource humantaskDataSource = new FileDataSource(resourceDir + File.separator + sampleArchiveName);
    UploadedFileItem[] uploadedFileItems = new UploadedFileItem[1];
    uploadedFileItems[0] = getUploadedFileItem(new DataHandler(humantaskDataSource), sampleArchiveName, "zip");
    log.info("Deploying " + sampleArchiveName);
    htUploaderStub.uploadHumanTask(uploadedFileItems);
}

From source file:org.wso2.appserver.integration.tests.mtomservice.MTOMTestCase.java

/**
 * This method creates the payload/*  www .  j a  va 2s .  com*/
 *
 * @return OMElement
 */
public static OMElement createPayLoad() {
    String actualImageName = "wso2.jpeg"; // the actual image file
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = factory.createOMNamespace("http://ws.apache.org/axis2/mtomsample/", "ns");
    OMElement getOme = factory.createOMElement("AttachmentRequest", omNs);
    OMElement getOmeTwo = factory.createOMElement("fileName", omNs);
    getOmeTwo.setText(savedImageName);
    OMElement getOmeThree = factory.createOMElement("binaryData", omNs);
    // getting the image from the location
    FileDataSource fileDataSource = new FileDataSource(
            new File(FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "AS"
                    + File.separator + "images" + File.separator + actualImageName));
    DataHandler dataHandler = new DataHandler(fileDataSource); // creating the data handler fro the image
    OMText textData = factory.createOMText(dataHandler, true); // getting the OMNode
    getOmeThree.addChild(textData);
    getOme.addChild(getOmeTwo);
    getOme.addChild(getOmeThree);
    return getOme;
}

From source file:org.apache.padaf.integration.AbstractInvalidFileTester.java

@Test()
public final void validate() throws Exception {
    if (path == null) {
        logger.warn("This is an empty test");
        return;/*from  w  w  w  . j av  a  2s .  co m*/
    }
    ValidationResult result = null;
    try {
        FileDataSource bds = new FileDataSource(path);
        result = validator.validate(bds);
        Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", result.isValid());
        Assert.assertTrue(path + " : Should find at least one error", result.getErrorsList().size() > 0);
        // could contain more than one error
        boolean found = false;
        if (this.expectedError != null) {
            for (ValidationError error : result.getErrorsList()) {
                if (error.getErrorCode().equals(this.expectedError)) {
                    found = true;
                }
                if (outputResult != null) {
                    String log = path.getName().replace(".pdf", "") + "#" + error.getErrorCode() + "#"
                            + error.getDetails() + "\n";
                    outputResult.write(log.getBytes());
                }
            }
        }

        if (result.getErrorsList().size() > 0) {
            if (this.expectedError == null) {
                logger.info("File invalid as expected (no expected code) :" + this.path.getAbsolutePath());
            } else if (!found) {
                StringBuilder message = new StringBuilder(100);
                message.append(path).append(" : Invalid error code returned. Expected ");
                message.append(this.expectedError).append(", found ");
                for (ValidationError error : result.getErrorsList()) {
                    message.append(error.getErrorCode()).append(" ");
                }
                Assert.fail(message.toString());
            }
        } else {
            Assert.assertEquals(path + " : Invalid error code returned.", this.expectedError,
                    result.getErrorsList().get(0).getErrorCode());
        }
    } catch (ValidationException e) {
        throw new Exception(path + " :" + e.getMessage(), e);
    } finally {
        if (result != null) {
            result.closePdf();
        }
    }
}

From source file:org.wso2.bps.integration.common.clients.bpel.BpelUploaderClient.java

private void deployPackage(String packageName, String resourceDir, BPELUploaderStub bpelUploaderStub)
        throws RemoteException, InterruptedException {

    String sampleArchiveName = packageName + ".zip";
    log.info(resourceDir + File.separator + sampleArchiveName);
    DataSource bpelDataSource = new FileDataSource(resourceDir + File.separator + sampleArchiveName);
    UploadedFileItem[] uploadedFileItems = new UploadedFileItem[1];
    uploadedFileItems[0] = getUploadedFileItem(new DataHandler(bpelDataSource), sampleArchiveName, "zip");
    log.info("Deploying " + sampleArchiveName);
    bpelUploaderStub.uploadService(uploadedFileItems);
}

From source file:org.onesec.raven.ivr.vmail.impl.VMailBoxNodeTest.java

@Test
public void getNewMessages() throws Exception {
    assertTrue(vbox.getNewMessages().isEmpty());
    Date messDate = new Date();
    vbox.addMessage(new NewVMailMessageImpl("123", "333", messDate, new FileDataSource(testFile)));
    assertEquals(1, vbox.getNewMessages().size());
    List<SavableStoredVMailMessage> messages = vbox.getNewMessages();
    SavableStoredVMailMessage mess = messages.get(0);
    assertEquals(messDate, mess.getMessageDate());
    assertEquals("333", mess.getSenderPhoneNumber());
    assertTrue(IOUtils.contentEquals(new FileInputStream(testFile), mess.getAudioSource().getInputStream()));

    Thread.sleep(10);/*from  w  ww. j  a v a 2  s .c om*/
    vbox.addMessage(new NewVMailMessageImpl("123", "222", new Date(), new FileDataSource(testFile)));
    Thread.sleep(10);
    vbox.addMessage(new NewVMailMessageImpl("123", "111", new Date(), new FileDataSource(testFile)));

    messages = vbox.getNewMessages();
    assertEquals(3, messages.size());
    assertEquals("333", messages.get(0).getSenderPhoneNumber());
    assertEquals("222", messages.get(1).getSenderPhoneNumber());
    assertEquals("111", messages.get(2).getSenderPhoneNumber());
}

From source file:org.wso2.identity.integration.common.clients.entitlement.EntitlementPolicyServiceClient.java

public void addPolicies(File policyFile) throws IOException, ParserConfigurationException, TransformerException,
        SAXException, EntitlementPolicyAdminServiceEntitlementException {

    DataHandler policydh = new DataHandler(new FileDataSource(policyFile));
    String policy = convertXMLFileToString(policyFile);

    PolicyDTO policySetDTO = new PolicyDTO();
    policySetDTO.setPolicy(policy);// www . j  a v  a  2  s.c  o  m
    policySetDTO.setActive(true);
    entitlementPolicyAdminServiceStub.addPolicy(policySetDTO);
}

From source file:org.paxle.core.doc.impl.jaxb.JaxbFieldMapAdapter.java

private DataHandler convert(Field<?> key, Serializable value) throws IOException {
    if (value == null)
        return null;

    DataSource source = null;//  www .j a  v  a 2 s. co m
    if (key.getType().isAssignableFrom(File.class)) {
        source = new FileDataSource((File) value);
    } else {
        source = new JaxbSerializableDataSource(key.getName(), value);
    }
    return new DataHandler(source);
}

From source file:com.autentia.tnt.mail.DefaultMailService.java

public void sendFiles(String to, String subject, String text, Collection<File> attachments)
        throws MessagingException {

    MimeMessage message = new MimeMessage(session);
    Transport t = session.getTransport("smtp");

    message.setFrom(new InternetAddress(configurationUtil.getMailUsername()));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);//from   w ww  .  j a v a2  s  .c o m
    message.setSentDate(new Date());
    if (attachments == null || attachments.size() < 1) {
        message.setText(text);
    } else {
        // create the message part 
        MimeBodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText(text);
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);
        for (File attachment : attachments) {

            messageBodyPart = new MimeBodyPart();
            DataSource source = new FileDataSource(attachment);
            messageBodyPart.setDataHandler(new DataHandler(source));
            messageBodyPart.setFileName(attachment.getName());
            multipart.addBodyPart(messageBodyPart);
        }
        message.setContent(multipart);
    }

    t.connect(configurationUtil.getMailUsername(), configurationUtil.getMailPassword());

    t.sendMessage(message, message.getAllRecipients());
    t.close();
}

From source file:eu.planets_project.services.datatypes.ImmutableContent.java

/**
 * @param reference The content reference, as a file.
 *//*from  w ww.  java  2 s  .  c o  m*/
ImmutableContent(final File reference) {
    if (reference == null)
        throw new IllegalArgumentException("File parameter must not be null!");
    FileDataSource ds = new FileDataSource(reference);
    ds.setFileTypeMap(FileTypeMap.getDefaultFileTypeMap());
    DataHandler dh = new DataHandler(ds);
    this.length = reference.length();
    this.dataHandler = dh;
    log.info("Created Content from file: " + reference.getAbsolutePath() + "': " + this.length
            + " bytes in length.");
}

From source file:org.apache.axis2.mtom.EchoRawMTOMTest.java

protected OMElement createEnvelope() throws Exception {

    DataHandler expectedDH;/*from  www.ja  va 2s . c  o m*/
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement rpcWrapEle = fac.createOMElement("echoOMElement", omNs);
    OMElement data = fac.createOMElement("data", omNs);
    FileDataSource fileDataSource = new FileDataSource(
            TestingUtils.prefixBaseDirectory("test-resources/mtom/test.jpg"));
    expectedDH = new DataHandler(fileDataSource);
    expectedTextData = new OMTextImpl(expectedDH, true, fac);
    data.addChild(expectedTextData);
    rpcWrapEle.addChild(data);
    return rpcWrapEle;

}