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:de.kp.ames.web.function.domain.model.ChatObject.java

/**
 * Create RegistryObject representation of ChatObject
 * //from   w w w  . j  a v a2  s .com
 * @param data
 * @return
 * @throws Exception
 */
public RegistryObjectImpl create(String data) throws Exception {

    /*
     * Initialize data
     */
    JSONObject jForm = new JSONObject(data);

    /* 
     * A chat message is a certain extrinsic object that holds all 
     * relevant and related information in a single JSON repository item
     */

    ExtrinsicObjectImpl eo = null;

    /* 
     * Create extrinsic object that serves as a wrapper for
     * the respective chat message
     */
    eo = jaxrLCM.createExtrinsicObject();
    if (eo == null)
        throw new JAXRException("[ChatObject] Creation of ExtrinsicObject failed.");

    /* 
     * Identifier
     */
    String eid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.CHAT_PRE);

    eo.setLid(eid);
    eo.getKey().setId(eid);

    /*
     * Name using default locale
     */
    String name = "[CHAT] " + jForm.getString(JaxrConstants.RIM_MESSAGE_ID);
    eo.setName(jaxrLCM.createInternationalString(name));

    /* 
     * Home url
     */
    String home = jaxrHandle.getEndpoint().replace("/saml", "");
    eo.setHome(home);

    /* 
     * Mime type & handler
     */
    String mimetype = GlobalConstants.MT_JSON;
    eo.setMimeType(mimetype);

    byte[] bytes = data.getBytes(GlobalConstants.UTF_8);

    DataHandler handler = new DataHandler(FileUtil.createByteArrayDataSource(bytes, mimetype));
    eo.setRepositoryItem(handler);

    /*
     * Create classification
     */
    ClassificationImpl c = jaxrLCM.createClassification(ClassificationConstants.FNC_ID_Chat);
    c.setName(jaxrLCM.createInternationalString(Locale.US, "Chat Classification"));

    /* 
     * Associate classification and chat message
     */
    eo.addClassification(c);

    /*
     * Indicate as created
     */
    this.created = true;

    return eo;

}

From source file:de.kp.ames.web.function.domain.model.MailObject.java

/**
 * Create RegistryObject representation of MailObject
 * /*from  w w w .  j  av  a2  s .  c  om*/
 * @param data
 * @return
 * @throws Exception
 */
public RegistryObjectImpl create(String data) throws Exception {

    /*
     * Initialize data
     */
    JSONObject jForm = new JSONObject(data);

    /* 
     * A mail message is a certain extrinsic object that holds all 
     * relevant and related information in a single JSON repository item
     */

    ExtrinsicObjectImpl eo = null;

    /* 
     * Create extrinsic object that serves as a container for
     * the respective mail message
     */
    eo = jaxrLCM.createExtrinsicObject();
    if (eo == null)
        throw new JAXRException("[MailObject] Creation of ExtrinsicObject failed.");

    /* 
     * Identifier
     */
    String eid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.MAIL_PRE);

    eo.setLid(eid);
    eo.getKey().setId(eid);

    /*
     * Name using default locale
     */
    String name = "[MAIL] " + jForm.getString(JaxrConstants.RIM_MESSAGE_ID);
    eo.setName(jaxrLCM.createInternationalString(name));

    /* 
     * Home url
     */
    String home = jaxrHandle.getEndpoint().replace("/saml", "");
    eo.setHome(home);

    /* 
     * Mime type & handler
     */
    String mimetype = GlobalConstants.MT_JSON;
    eo.setMimeType(mimetype);

    byte[] bytes = data.getBytes(GlobalConstants.UTF_8);

    DataHandler handler = new DataHandler(FileUtil.createByteArrayDataSource(bytes, mimetype));
    eo.setRepositoryItem(handler);

    /*
     * Create classification
     */
    ClassificationImpl c = jaxrLCM.createClassification(ClassificationConstants.FNC_ID_Mail);
    c.setName(jaxrLCM.createInternationalString(Locale.US, "Mail Classification"));

    /* 
     * Associate classification and mail message
     */
    eo.addClassification(c);

    /*
     * Indicate as created
     */
    this.created = true;

    return eo;

}

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

private Collection<ResourceDataSource> extractFromParams(String subUnit, List<Object> params)
        throws IOException {
    List<ResourceDataSource> resources = new ArrayList<ResourceDataSource>();
    for (int idx = 0; idx < params.size(); ++idx) {
        Object param = params.get(idx);
        if (param instanceof DataHandler) {
            DataHandler dataHandler = (DataHandler) param;
            ResourceDataSource dataSource = extractFromDataHandler(subUnit, dataHandler, idx);
            resources.add(dataSource);/*from   w ww. jav a 2 s .c o  m*/
            params.set(idx, new DataHandler(dataSource));
        } else if (param instanceof Holder) {
            @SuppressWarnings("unchecked") // Ok, because of instanceof check  
            Holder<DataHandler> holder = (Holder<DataHandler>) param;
            if (holder.value instanceof DataHandler) {
                DataHandler dataHandler = holder.value;
                ResourceDataSource dataSource = extractFromDataHandler(subUnit, dataHandler, idx);
                resources.add(dataSource);
                holder.value = new DataHandler(dataSource);
            }
        }
    }
    return resources;
}

From source file:org.apache.synapse.format.hessian.HessianMessageBuilder.java

/**
 * Returns an OMElement from a Hessian encoded message
 *
 * @param inputStream stream containing the Hessian message to be built
 * @param contentType content type of the message
 * @param messageContext message to which the hessian message has to be attached
 * @return OMElement containing Hessian data handler keeping the message
 * @throws AxisFault in case of a failure in building the hessian message
 *
 * @see org.apache.axis2.builder.Builder#processDocument(java.io.InputStream,
 * String, org.apache.axis2.context.MessageContext)
 *///from   ww w  .  j  a va2  s .c o  m
public OMElement processDocument(final InputStream inputStream, final String contentType,
        final MessageContext messageContext) throws AxisFault {

    if (log.isDebugEnabled()) {
        log.debug("Start building the hessian message in to a HessianDataSource");
    }

    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace(HessianConstants.HESSIAN_NAMESPACE_URI,
            HessianConstants.HESSIAN_NS_PREFIX);
    OMElement element = factory.createOMElement(HessianConstants.HESSIAN_ELEMENT_LOCAL_NAME, ns);

    try {

        Parameter synEnv = messageContext.getConfigurationContext().getAxisConfiguration()
                .getParameter(SynapseConstants.SYNAPSE_ENV);

        PushbackInputStream pis = detectAndMarkMessageFault(messageContext, inputStream);

        DataHandler dataHandler;
        if (synEnv != null && synEnv.getValue() != null) {
            dataHandler = new DataHandler(
                    new SynapseBinaryDataSource(pis, contentType, (SynapseEnvironment) synEnv.getValue()));
        } else {
            // add Hessian data inside a data handler
            dataHandler = new DataHandler(new SynapseBinaryDataSource(pis, contentType));
        }
        OMText textData = factory.createOMText(dataHandler, true);
        element.addChild(textData);

        // indicate that message faults shall be handled as http 200
        messageContext.setProperty(NhttpConstants.FAULTS_AS_HTTP_200, NhttpConstants.TRUE);

    } catch (IOException e) {
        String msg = "Unable to create the HessianDataSource";
        log.error(msg, e);
        throw new AxisFault(msg, e);
    }

    if (log.isDebugEnabled()) {
        log.debug("Building the hessian message using HessianDataSource is successful");
    }

    return element;
}

From source file:no.digipost.api.handlers.ForsendelseSender.java

private void attachFile(final SoapMessage soapMessage) throws IOException {
    if (digitalPostformidling.getDokumentpakkefingeravtrykk() == null) {
        lagFingeravtrykk(forsendelse, digitalPostformidling);
    }/*from  w  ww  .j  av a 2  s.  co m*/
    DataHandler handler = new DataHandler(forsendelse.getDokumentpakke());
    soapMessage.addAttachment(generateContentId(), handler);
}

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

/**
 * @param reference The content reference, as a file.
 *///from w ww .  j a  va 2 s. c om
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;/*  w ww .  j a  v a 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;

}

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

private OMElement createPayload() {

    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement rpcWrapEle = fac.createOMElement("echoMTOMtoBase64", omNs);
    OMElement data = fac.createOMElement("data", omNs);
    byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, 98 };
    DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
    expectedTextData = new OMTextImpl(dataHandler, true, fac);
    data.addChild(expectedTextData);//from   ww  w.j  a va2  s  .c  o m
    rpcWrapEle.addChild(data);
    return rpcWrapEle;
}

From source file:org.wso2.appserver.integration.resources.resource.test.XMLResourceAddTestCase.java

@Test(groups = { "wso2.as" })
public void testAddArtifacts() throws ResourceAdminServiceExceptionException, RemoteException,
        MalformedURLException, XPathExpressionException {

    log.debug("Running SuccessCase");
    //add a collection to the registry
    String collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH, RES_FILES_COLLECTION, "",
            "contains ResFiles");
    String authorUserName = resourceAdminServiceClient.getResource(PARENT_PATH + "/" + RES_FILES_COLLECTION)[0]
            .getAuthorUserName();//  w  ww .j  av  a 2  s.co m
    assertTrue(asServer.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(authorUserName),
            PARENT_PATH + "/" + RES_FILES_COLLECTION + " creation failure");
    log.info("collection added to " + collectionPath);
    // Changing media type
    resourceAdminServiceClient.addCollection(PARENT_PATH, RES_FILES_COLLECTION, ESB_MEDIATYPE,
            ESB_MEDIATYPE + " type collection");
    String resource = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "AS"
            + File.separator + "xml" + File.separator + RESOURCE_NAME;
    DataHandler dh = new DataHandler(new URL("file:///" + resource));
    resourceAdminServiceClient.addResource(PARENT_PATH + "/" + RES_FILES_COLLECTION + "/" + RESOURCE_NAME,
            "application/xml", "resDesc", dh);
    String textContent = resourceAdminServiceClient
            .getTextContent(PARENT_PATH + "/" + RES_FILES_COLLECTION + "/" + RESOURCE_NAME);
    assertNotNull(textContent, "Unable to get text content");

}

From source file:org.wso2.appserver.integration.lazy.loading.artifacts.CarbonAppGhostDeploymentTestCase.java

@BeforeClass(alwaysRun = true)
public void init() throws Exception {
    super.init();
    tenant1WebApp1URL = webAppURL + "/t/" + tenantDomain1 + "/webapps/" + CARBON_APP1_WEB_APP_NAME + "/";
    URL carbonApp1FileURL = new URL("file://" + artifactsLocation + CARBON_APP_FILE1);
    carbonApp1URLDataHandler = new DataHandler(carbonApp1FileURL);
    tenant1WebApp2URL = webAppURL + "/t/" + tenantDomain1 + "/webapps/" + CARBON_APP2_WEB_APP_NAME + "/";
    URL carbonApp2FileURL = new URL("file://" + artifactsLocation + CARBON_APP_FILE2);
    carbonApp2URLDataHandler = new DataHandler(carbonApp2FileURL);

}