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.wso2.brs.rule.test.HealthCareServiceTestCase.java

@Test(groups = { "wso2.brs" })
public void uploadHealthCareService() throws Exception {
    String samplesDir = System.getProperty("samples.dir");
    String HealthCareServiceAAR = samplesDir + File.separator
            + "healthcare.service/service/target/HealthCareService.aar";
    log.info(HealthCareServiceAAR);/*  w w w. j  a  va2 s. c o m*/
    FileDataSource fileDataSource = new FileDataSource(HealthCareServiceAAR);
    DataHandler dataHandler = new DataHandler(fileDataSource);
    getRuleServiceFileUploadClient().uploadService("HealthCareService.aar", dataHandler);

}

From source file:com.consol.citrus.ws.message.SoapAttachmentTest.java

@Test
public void testFromBinaryAttachment() throws Exception {
    reset(attachment);/*  w w  w  .  ja v a 2 s.  com*/

    expect(attachment.getContentId()).andReturn("img").once();
    expect(attachment.getContentType()).andReturn("application/octet-stream").times(2);

    expect(attachment.getDataHandler()).andReturn(new DataHandler(
            new StaticTextDataSource("This is img text content!", "application/octet-stream", "UTF-8", "img")));

    replay(attachment);

    SoapAttachment soapAttachment = SoapAttachment.from(attachment);

    Assert.assertEquals(soapAttachment.getContentId(), "img");
    Assert.assertEquals(soapAttachment.getContentType(), "application/octet-stream");
    Assert.assertEquals(soapAttachment.getContent(),
            Base64.encodeBase64String("This is img text content!".getBytes(Charset.forName("UTF-8"))));
    Assert.assertEquals(soapAttachment.getCharsetName(), Charset.defaultCharset().displayName());
    Assert.assertNotNull(soapAttachment.getDataHandler());
    Assert.assertEquals(soapAttachment.getSize(), 25L);

    soapAttachment.setEncodingType(SoapAttachment.ENCODING_BASE64_BINARY);
    Assert.assertEquals(soapAttachment.getContent(),
            Base64.encodeBase64String("This is img text content!".getBytes(Charset.forName("UTF-8"))));

    soapAttachment.setEncodingType(SoapAttachment.ENCODING_HEX_BINARY);
    Assert.assertEquals(soapAttachment.getContent(),
            Hex.encodeHexString("This is img text content!".getBytes(Charset.forName("UTF-8"))).toUpperCase());

    verify(attachment);
}

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

@Test(groups = { "wso2.brs" })
public void uploadInsuranceService() throws Exception {
    String samplesDir = System.getProperty("samples.dir");
    String InsuranceServiceAAR = samplesDir + File.separator
            + "insurance.service/service/target/InsuranceService.aar";
    log.info(InsuranceServiceAAR);/*from   ww w .  ja  v  a2s  .co  m*/
    FileDataSource fileDataSource = new FileDataSource(InsuranceServiceAAR);
    DataHandler dataHandler = new DataHandler(fileDataSource);
    getRuleServiceFileUploadClient().uploadService("InsuranceService.aar", dataHandler);

}

From source file:com.adaptris.core.MimeEncoderImpl.java

protected MimeBodyPart payloadAsMimePart(AdaptrisMessage m) throws Exception {
    MimeBodyPart p = new MimeBodyPart();
    p.setDataHandler(new DataHandler(new MessageDataSource(m)));
    if (!isEmpty(getPayloadEncoding())) {
        p.setHeader(MimeConstants.HEADER_CONTENT_ENCODING, getPayloadEncoding());
    }//from  w  w  w. j  a  va  2 s.  c o  m
    return p;
}

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

/**
 * Converts the {@link File} into a {@link DataHandler}
 *///from w  ww . j  a v a2 s .  c o m
@Override
public DataHandler marshal(File cDocFile) throws Exception {
    if (cDocFile == null)
        return null;
    return new DataHandler(new FileDataSource(cDocFile));
}

From source file:org.nuxeo.ecm.automation.client.jaxrs.impl.MultipartRequestEntity.java

protected void setBlob(Blob blob, String id) throws MessagingException, IOException {
    MimeBodyPart part = new MimeBodyPart();
    if (blob instanceof HasFile) {
        part.attachFile(((HasFile) blob).getFile());
    } else {/* w  w  w  .j  a v a  2  s .  co m*/
        part.setDataHandler(new DataHandler(new BlobDataSource(blob)));
        part.setFileName(blob.getFileName());
    }
    part.setHeader("Content-Type", blob.getMimeType());
    part.setHeader("Content-Transfer-Encoding", "binary");
    int length = blob.getLength();
    if (length > -1) {
        part.setHeader("Content-Length", Integer.toString(length));
    }
    part.setContentID(id);
    mp.addBodyPart(part);
}

From source file:de.extra.client.core.builder.impl.components.TransportBodyFileInputBase64CharSequenceBuilder.java

@Override
public Object buildXmlFragment(final IInputDataContainer senderData, final IExtraProfileConfiguration config) {
    LOG.debug("Base64CharSequenceType aufbauen");
    final Base64CharSequenceType base64CharSequence = new Base64CharSequenceType();
    final IContentInputDataContainer fileInputdata = senderData.cast(IContentInputDataContainer.class);
    final List<ISingleContentInputData> inputDataList = fileInputdata.getInputData();
    // Es kann nicht in RequestTransport mehrere Datenstze bertragen
    // werden!!// w w  w. ja  v  a  2 s .c om
    Assert.isTrue(inputDataList.size() == 1, "Unexpected InputData size.");
    final ISingleContentInputData singleInputData = inputDataList.get(0);

    final DataHandler dataHandler = new DataHandler(singleInputData.getInputDataAsDataSource());
    base64CharSequence.setValue(dataHandler);
    return base64CharSequence;
}

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

public OMElement processDocument(InputStream inputStream, String contentType, MessageContext msgContext)
        throws AxisFault {
    Parameter wrapperParam = msgContext.getAxisService().getParameter(BaseConstants.WRAPPER_PARAM);
    QName wrapperQName;// ww w .  j ava 2  s.  c o  m
    if (wrapperParam != null) {
        wrapperQName = BaseUtils.getQNameFromString(wrapperParam.getValue());
    } else {
        wrapperQName = BaseConstants.DEFAULT_BINARY_WRAPPER;
    }
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement wrapper = factory.createOMElement(wrapperQName, null);
    byte[] msgBytes;
    try {
        msgBytes = IOUtils.toByteArray(inputStream);
    } catch (IOException ex) {
        throw new AxisFault("Unable to read message payload", ex);
    }
    DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(msgBytes));
    wrapper.addChild(factory.createOMText(dataHandler, true));
    msgContext.setDoingMTOM(true);
    return wrapper;
}

From source file:org.wso2.carbon.attachment.mgt.ui.SampleAttachmentMgtClient.java

private static String uploadAttachment() throws RemoteException, AttachmentMgtException {
    AttachmentMgtServiceStub stub = new AttachmentMgtServiceStub();

    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:9763/services/AttachmentMgtService/"));
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Boolean.TRUE);
    stub._getServiceClient().setOptions(options);

    TAttachment att = new TAttachment();
    //att.setId("ContentId");
    //att.setCreatedTime(Calendar.getInstance());
    att.setName("ContentName");
    att.setCreatedBy("DenisAuthor");
    att.setContentType("text/plain");

    //FileDataSource dataSource = new FileDataSource(new File("/home/denis/Desktop/note.txt"));
    FileDataSource dataSource = new FileDataSource(new File("/home/denis/Desktop/fromSoapUI.xml"));
    DataHandler fileDataHandler = new DataHandler(dataSource);
    att.setContent(fileDataHandler);//from ww  w.  j ava 2 s  .c o  m

    String id = stub.add(att);
    if (log.isDebugEnabled()) {
        log.debug("Attachment uploaded with id: " + id);
    }

    return id;

}

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

@Test(groups = { "wso2.brs" })
public void uploadShoppingService() throws Exception {
    String samplesDir = System.getProperty("samples.dir");
    String ShoppingServiceAAR = samplesDir + File.separator
            + "shopping.service/service/target/ShoppingService.aar";
    log.info(ShoppingServiceAAR);//from  ww w .j  av a2  s .  c om
    FileDataSource fileDataSource = new FileDataSource(ShoppingServiceAAR);
    DataHandler dataHandler = new DataHandler(fileDataSource);
    getRuleServiceFileUploadClient().uploadService("ShoppingService.aar", dataHandler);

}