Example usage for javax.activation DataSource getInputStream

List of usage examples for javax.activation DataSource getInputStream

Introduction

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

Prototype

public InputStream getInputStream() throws IOException;

Source Link

Document

This method returns an InputStream representing the data and throws the appropriate exception if it can not do so.

Usage

From source file:com.webbfontaine.valuewebb.irms.action.mail.MailActionHandler.java

private static void attach(MultiPartEmail email, Attachable attachment) throws EmailException {
    try {//from  w w  w .ja  v  a2 s.  c o m
        DataSource source = attachment.getDataSource();
        InputStream inputStream = source.getInputStream();

        if (inputStream != null) {
            email.attach(dataSource(inputStream, source.getContentType()), attachment.getName(), "",
                    EmailAttachment.ATTACHMENT);
        } else {
            LOGGER.warn("Attached doc: {} content is empty, nothing to attach...", attachment.getName());
        }
    } catch (IOException e) {
        throw new EmailException(e);
    }
}

From source file:com.wavemaker.runtime.ws.HTTPBindingSupport.java

public static String getResponseString(QName serviceQName, QName portQName, String endpointAddress,
        HTTPRequestMethod method, DataSource postSource, BindingProperties bindingProperties,
        Map<String, Object> headerParams) throws WebServiceException {

    DataSource response = getResponse(serviceQName, portQName, endpointAddress, method, postSource,
            bindingProperties, DataSource.class, headerParams);
    try {//  w  w w . java2s .c o m
        InputStream inputStream = response.getInputStream();
        return convertStreamToString(inputStream);
    } catch (IOException e) {
        throw new WebServiceException(e);
    }
}

From source file:com.wavemaker.runtime.ws.HTTPBindingSupport.java

public static <T extends Object> T getResponseObject(QName serviceQName, QName portQName,
        String endpointAddress, HTTPRequestMethod method, String contentType, Object postData,
        Class<T> responseType, BindingProperties bindingProperties, String partnerName,
        Map<String, Object> headerParams) throws WebServiceException {

    String msg = postData == null ? null
            : postData instanceof String ? (String) postData : convertToXMLString(postData);

    DataSource postSource = null;
    byte[] bytes = null;
    if (method == HTTPRequestMethod.POST) {
        postSource = createDataSource(contentType, msg);
    }/*from w w  w.j  av a 2s . co m*/
    DataSource response = getResponse(serviceQName, portQName, endpointAddress, method, postSource,
            bindingProperties, DataSource.class, headerParams);

    try {
        InputStream is = new BufferedInputStream(response.getInputStream());
        bytes = IOUtils.toByteArray(is);
    } catch (IOException e) {
        throw new WebServiceException(e);
    }

    IPwsResponseProcessor respProcessor;
    if (partnerName == null || partnerName.length() == 0) {
        respProcessor = new DefaultResponseProcessor();
    } else {
        PwsResponseProcessorBeanFactory factory = (PwsResponseProcessorBeanFactory) RuntimeAccess.getInstance()
                .getSpringBean("pwsResponseProcessorBeanFactory");
        respProcessor = factory.getPwsResponseProcessor(partnerName);
    }

    respProcessor.detectExceptionsBeforeProcess(bytes);

    return respProcessor.processServiceResponse(bytes, responseType);
}

From source file:at.gv.egovernment.moa.id.auth.stork.STORKResponseProcessor.java

private static String getCitizienSignatureFromSignResponse(SignResponse dssSignResponse)
        throws IllegalArgumentException, TransformerConfigurationException, UtilsException,
        TransformerException, TransformerFactoryConfigurationError, IOException, ApiUtilsException {
    // fetch signed doc
    DataSource ds = LightweightSourceResolver.getDataSource(dssSignResponse);
    if (ds == null) {
        throw new ApiUtilsException("No datasource found in response");
    }// w ww  . j  a v  a2  s .c  om

    InputStream incoming = ds.getInputStream();
    String citizenSignature = IOUtils.toString(incoming);
    incoming.close();

    return citizenSignature;
}

From source file:de.extra.extraClientLight.helper.ExtraResponseHelper.java

public static ResponseExtraBean convertExtraResponse(TransportResponseType extraResponse) {
    responseBean = new ResponseExtraBean();

    responseBean//from   w ww .ja v  a2  s .  c o  m
            .setResponseId(extraResponse.getTransportHeader().getResponseDetails().getResponseID().getValue());
    responseBean.setRequestId(extraResponse.getTransportHeader().getRequestDetails().getRequestID().getValue());

    FlagType reportFlag = extraResponse.getTransportHeader().getResponseDetails().getReport().getFlag().get(0);

    getReportInformation(reportFlag);

    // TODO Attachments in Response auslesen.
    //TODO Body kann auch leer sein (v.a. im asynchronen Verfahren)
    try {

        DataSource nutzdatenDS = extraResponse.getTransportBody().getData().getBase64CharSequence().getValue()
                .getDataSource();

        InputStream in = null;
        if (nutzdatenDS instanceof ByteArrayDataSource) {
            in = extraResponse.getTransportBody().getData().getBase64CharSequence().getValue().getInputStream();

        }

        if (nutzdatenDS instanceof LazyDataSource) {

            in = nutzdatenDS.getInputStream();

        }

        responseBean.setData(in);
    } catch (IOException e) {
        LOGGER.error("Fehler beim Lesen des Datenstreams");
        responseBean.setReturnCode(9);
    }

    return responseBean;
}

From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java

public static void sendFile(DataSource ds, HttpServletResponse response) {
    response.setContentType(ds.getContentType());

    if (ds.getName() != null && ds.getName().length() > 0) {
        response.addHeader("Content-Disposition", "attachment; filename=" + ds.getName());
    }// w  ww.  j  av a 2s.com

    OutputStream outputStream = null;
    BufferedInputStream bufferedInputStream = null;
    try {
        outputStream = response.getOutputStream();

        bufferedInputStream = new BufferedInputStream(ds.getInputStream());
        int readBytes = 0;

        while ((readBytes = bufferedInputStream.read()) != -1) {
            outputStream.write(readBytes);
        }

        if (log.isDebugEnabled()) {
            log.debug("finished sending bytes");
        }

    } catch (IOException ex) {
        log.error("Error serving a file: " + ex.getMessage(), ex);
    } finally {
        if (outputStream != null)
            try {
                outputStream.close();
            } catch (Exception ex) {
            }
        if (bufferedInputStream != null)
            try {
                bufferedInputStream.close();
            } catch (Exception ex) {
            }
    }
}

From source file:org.shredzone.cilla.service.resource.ImageTools.java

/**
 * Creates an {@link ExifAnalyzer} that analyzes the given {@link DataSource}.
 *
 * @param src//from ww w.  j  a  v a  2 s .  co  m
 *            {@link DataSource} to analyze
 * @return {@link ExifAnalyzer}
 */
public ExifAnalyzer createExifAnalyzer(DataSource src) throws CillaServiceException {
    try {
        return ExifAnalyzer.create(src.getInputStream());
    } catch (IOException ex) {
        throw new CillaServiceException(ex);
    }
}

From source file:org.shredzone.cilla.service.resource.ImageTools.java

/**
 * Analyzes the dimension of the given image {@link DataSource}.
 *
 * @param src/*  w  w  w  .  j ava  2  s.co  m*/
 *            {@link DataSource} to analyze
 * @return image dimensions
 */
public Dimension analyzeDimension(DataSource src) throws CillaServiceException {
    try {
        BufferedImage image = ImageIO.read(src.getInputStream());
        return (image != null ? new Dimension(image.getWidth(), image.getHeight()) : null);
    } catch (IOException ex) {
        throw new CillaServiceException(ex);
    }
}

From source file:com.jaspersoft.jasperserver.remote.handlers.ContentResourceHandler.java

protected void readData(ContentResource resource, DataSource dataSource) throws ServiceException {

    boolean close = true;
    InputStream dataStream = null;
    try {// www  . ja v  a  2 s. com
        dataStream = dataSource.getInputStream();
        resource.readData(dataStream);

        close = false;
        dataStream.close();
    } catch (IOException e) {
        throw new ServiceException(e);
    } finally {
        if (close && dataStream != null) {
            try {
                dataStream.close();
            } catch (IOException e) {
                log.error("Error closing attachment stream", e);
            }
        }
    }
}

From source file:com.lin.umws.service.impl.UserServiceImpl.java

public void handlerUpload(DataHandler handler) {
    DataSource dataSource = handler.getDataSource();
    System.out.println("Content-Type: " + dataSource.getContentType());
    System.out.println("Name: " + dataSource.getName());

    try {/*  www .  j  a v  a  2s.  com*/
        IOUtils.copy(dataSource.getInputStream(), System.out);
    } catch (IOException e) {
        e.printStackTrace();
    }
}