Example usage for javax.activation DataHandler getInputStream

List of usage examples for javax.activation DataHandler getInputStream

Introduction

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

Prototype

public InputStream getInputStream() throws IOException 

Source Link

Document

Get the InputStream for this object.

Usage

From source file:com.vnet.demo.rest.StorageRestService.java

@POST
@Path("/image")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces(MediaType.APPLICATION_JSON)//ww  w . ja  va  2  s .c o m
public Response uploadImageFile(@Multipart(value = "file") Attachment attachment,
        @Multipart(value = "file-length") Long fileLength) throws Exception {
    DataHandler dataHandler = attachment.getDataHandler();
    String fileName = attachment.getContentDisposition().getParameter("filename");
    InputStream inputStream = dataHandler.getInputStream();
    Storage storage = azureStorgeService.uploadBlobImage(inputStream, fileName, fileLength);
    storage.setPath(azureStorgeService.getPubAccessUrl() + "/" + storage.getPath());
    return Response.ok(storage).build();
}

From source file:de.extra_standard.namespace.webservice.ExtraServiceImpl.java

@Override
@WebMethod(action = "http://www.extra-standard.de/namespace/webservice/execute")
@WebResult(name = "Transport", targetNamespace = "http://www.extra-standard.de/namespace/response/1", partName = "response")
public ResponseTransport execute(
        @WebParam(name = "Transport", targetNamespace = "http://www.extra-standard.de/namespace/request/1", partName = "request") final de.drv.dsrv.extrastandard.namespace.request.RequestTransport request)
        throws ExtraFault {
    try {//from ww  w  .  jav a2  s .  co m
        logger.info("receive Extra ResponseTransport");
        final Base64CharSequenceType base64CharSequence = request.getTransportBody().getData()
                .getBase64CharSequence();
        final DataHandler dataHandler = base64CharSequence.getValue();
        final InputStream inputStream = dataHandler.getInputStream();
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        final String dateSuffix = sdf.format(new Date(System.currentTimeMillis()));
        final String dataHandlerName = dataHandler.getName();
        logger.info("Receiving File : " + dataHandlerName);
        final File receivedFile = new File(outputDirectory, dataHandlerName + "_" + dateSuffix);
        final FileOutputStream fileOutputStream = new FileOutputStream(receivedFile);
        IOUtils.copyLarge(inputStream, fileOutputStream);
        logger.info("Input file is stored under " + receivedFile.getAbsolutePath());
        logger.info("ChecksumCRC32 " + FileUtils.checksumCRC32(receivedFile));
        logger.info("Filesize: " + FileUtils.sizeOf(receivedFile));
    } catch (final IOException e) {
        logger.error("IOException in Server:", e);
    }
    // TODO TestTransport erzeugen!!
    final ResponseTransport responseTransport = new ResponseTransport();
    final ResponseTransportBody responseTransportBody = new ResponseTransportBody();
    final DataType dataType = new DataType();
    final Base64CharSequenceType base64CharSequenceType = new Base64CharSequenceType();
    final DataSource ds = new FileDataSource(testDataFile);
    final DataHandler dataHandler = new DataHandler(ds);
    base64CharSequenceType.setValue(dataHandler);
    dataType.setBase64CharSequence(base64CharSequenceType);
    responseTransportBody.setData(dataType);
    responseTransport.setTransportBody(responseTransportBody);
    return responseTransport;
}

From source file:it.cnr.icar.eric.server.security.authorization.RegistryPolicyFinderModule.java

/**
 * Loads a policy from the DataHandler, using the specified
 * <code>PolicyFinder</code> to help with instantiating PolicySets.
 *
 * @param DataHandler the DataHandler to load the policy from
 * @param finder a PolicyFinder used to help in instantiating PolicySets
 * @param handler an error handler used to print warnings and errors
 *                during parsing/*from w  w  w .j  av a  2 s.c  o m*/
 *
 * @return a policy associated with the specified DataHandler
 *
 * @throws RegistryException exception thrown if there is a problem reading the DataHandler's input stream
 */
private static AbstractPolicy loadPolicy(DataHandler dh, PolicyFinder finder) throws RegistryException {
    AbstractPolicy policy = null;

    try {
        // create the factory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setIgnoringComments(true);

        DocumentBuilder db = null;

        // set the factory to work the way the system requires
        // we're not doing any validation
        factory.setNamespaceAware(false);
        factory.setValidating(false);

        db = factory.newDocumentBuilder();

        // try to load the policy file
        Document doc = db.parse(dh.getInputStream());

        // handle the policy, if it's a known type
        Element root = doc.getDocumentElement();
        String name = root.getTagName();

        if (name.equals("Policy")) {
            policy = Policy.getInstance(root);
        } else if (name.equals("PolicySet")) {
            policy = PolicySet.getInstance(root, finder);
        } else {
            // this isn't a root type that we know how to handle
            throw new RegistryException(ServerResourceBundle.getInstance()
                    .getString("message.unknownRootDocumentType", new Object[] { name }));
        }
    } catch (Exception e) {
        log.error(ServerResourceBundle.getInstance().getString("message.FailedToLoadPolicy"), e);
        throw new RegistryException(e);
    }

    return policy;
}

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

public void set(RegistryObjectImpl ro, Locale locale) throws JSONException, JAXRException {

    /*/*from  w w w . j  av  a 2 s.co  m*/
     * Convert extrinsic object
     */
    super.set(ro, locale);

    /*
     * Convert "subject" and "from"
     */
    String from = "";
    String subject = "";

    String message = "";

    try {

        ExtrinsicObjectImpl eo = (ExtrinsicObjectImpl) ro;
        DataHandler dataHandler = eo.getRepositoryItem();

        InputStream stream = dataHandler.getInputStream();
        byte[] bytes = FileUtil.getByteArrayFromInputStream(stream);

        JSONObject jMail = new JSONObject(new String(bytes, GlobalConstants.UTF_8));

        from = jMail.getString(JaxrConstants.RIM_FROM);
        subject = jMail.getString(JaxrConstants.RIM_SUBJECT);

        message = jMail.getString(JaxrConstants.RIM_MESSAGE);

    } catch (Exception e) {
        e.printStackTrace();

    }

    put(JaxrConstants.RIM_FROM, from);
    put(JaxrConstants.RIM_SUBJECT, subject);

    /*
     * Mail body
     */
    put(JaxrConstants.RIM_MESSAGE, message);

    /*
     * Convert icon
     */
    put(JaxrConstants.RIM_ICON, IconConstants.MAIL);

}

From source file:org.wso2.am.admin.clients.template.SequenceTemplateAdminServiceClient.java

public void addSequenceTemplate(DataHandler dh) throws IOException, XMLStreamException {
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement template = builder.getDocumentElement();
    templateAdminStub.addTemplate(template);
}

From source file:org.wso2.am.admin.clients.template.SequenceTemplateAdminServiceClient.java

public void addDynamicSequenceTemplate(String key, DataHandler dh) throws IOException, XMLStreamException {
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement template = builder.getDocumentElement();
    templateAdminStub.addDynamicTemplate(key, template);
}

From source file:org.wso2.am.admin.clients.template.EndpointTemplateAdminServiceClient.java

public void addEndpointTemplate(DataHandler dh) throws IOException, XMLStreamException {
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement endpointTemplate = builder.getDocumentElement();
    endpointTemplateAdminStub.addEndpointTemplate(endpointTemplate.toString());
}

From source file:org.wso2.am.admin.clients.template.EndpointTemplateAdminServiceClient.java

public void addDynamicEndpointTemplate(String key, DataHandler dh) throws IOException, XMLStreamException {
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement endpointTemplate = builder.getDocumentElement();
    endpointTemplateAdminStub.addDynamicEndpointTemplate(key, endpointTemplate.toString());
}

From source file:org.wso2.esb.integration.common.clients.mediation.ConfigServiceAdminClient.java

public void addExistingConfiguration(DataHandler dh)
        throws IOException, LocalEntryAdminException, XMLStreamException {
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement configSourceElem = builder.getDocumentElement();
    configServiceAdminStub.addExistingConfiguration(configSourceElem.toString());

}

From source file:samples.mediators.BinaryExtractMediator.java

public boolean mediate(MessageContext msgCtx) {
    try {/*from w ww  .  ja  va 2  s.  c om*/
        log.debug("BinaryExtractMediator Process, with offset: " + offset + " ,length " + length);
        SOAPBody soapBody = msgCtx.getEnvelope().getBody();
        OMElement firstElement = soapBody.getFirstElement();
        log.debug("First Element : " + firstElement.getLocalName());
        log.debug("First Element Text : " + firstElement.getText());
        OMText binaryNode = (OMText) firstElement.getFirstOMChild();
        log.debug("First Element Node Text : " + binaryNode.getText());
        DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler();
        InputStream inputStream = dataHandler.getInputStream();
        byte[] searchByte = new byte[length];
        inputStream.skip(offset - 1);
        int readBytes = inputStream.read(searchByte, 0, length);
        String outString = new String(searchByte, binaryEncoding);
        msgCtx.setProperty(variableName, outString);
        log.debug("Set property to MsgCtx, " + variableName + " = " + outString);
        inputStream.close();
    } catch (IOException e) {
        log.error("Excepton on mediation : " + e.getMessage());
    }
    return true;
}