Example usage for javax.mail.internet MimeBodyPart MimeBodyPart

List of usage examples for javax.mail.internet MimeBodyPart MimeBodyPart

Introduction

In this page you can find the example usage for javax.mail.internet MimeBodyPart MimeBodyPart.

Prototype

public MimeBodyPart(InternetHeaders headers, byte[] content) throws MessagingException 

Source Link

Document

Constructs a MimeBodyPart using the given header and content bytes.

Usage

From source file:es.pode.administracion.presentacion.noticias.crear.CrearControllerImpl.java

public String tratamientoImagen(FormFile imagenFile) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("Realizamos el tratamiento de la imagen [" + imagenFile + "]");
    ImagenVO imagen = new ImagenVO();
    InternetHeaders ih = new InternetHeaders();
    MimeBodyPart mbp = new MimeBodyPart(ih, imagenFile.getFileData());

    DataSource source = new MimePartDataSource(mbp);
    DataHandler dImagen = new DataHandler(source);

    imagen.setDatos(dImagen);//from  ww w  .j a va 2s. c  om
    imagen.setNombre(imagenFile.getFileName());
    imagen.setMimeType(imagenFile.getContentType());
    String sUrlImagen = this.getSrvNoticiasService().almacenarImagenNoticia(imagen);
    return sUrlImagen;
}

From source file:com.boundlessgeo.geoserver.AppIntegrationTest.java

void createMultiPartFormContent(MockHttpServletRequest request, String contentDisposition, String contentType,
        byte[] content) throws Exception {
    MimeMultipart body = new MimeMultipart();
    request.setContentType(body.getContentType());
    InternetHeaders headers = new InternetHeaders();
    headers.setHeader("Content-Disposition", contentDisposition);
    headers.setHeader("Content-Type", contentType);
    body.addBodyPart(new MimeBodyPart(headers, content));

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    body.writeTo(bout);//from  w  ww  .j  av a 2s.c o  m
    request.setContent(bout.toByteArray());
}

From source file:com.boundlessgeo.geoserver.AppIntegrationTest.java

MimeMultipart appendMultiPartFormContent(MimeMultipart body, String contentDisposition, String contentType,
        byte[] content) throws Exception {
    InternetHeaders headers = new InternetHeaders();
    headers.setHeader("Content-Disposition", contentDisposition);
    headers.setHeader("Content-Type", contentType);
    body.addBodyPart(new MimeBodyPart(headers, content));

    return body;// ww w . ja v a2  s.co m
}

From source file:es.pode.catalogadorWeb.presentacion.catalogadorBasico.CatBasicoControllerImpl.java

public String submitImportar(ActionMapping mapping, SubmitImportarForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String accion = form.getAccion();
    String resAction = "";
    ResourceBundle datosResources = I18n.getInstance().getResource("application-resources",
            (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE));
    if (datosResources.getString("catalogadorBasico.importar.aceptar").equals(accion)) {
        resAction = "Aceptar";

        if (form.getFichero() == null || form.getFichero().getFileName().equals(""))
            throw new ValidatorException("{catalogadorBasico.importar.error.ficherovacio}");

        //crear el datahandler
        InternetHeaders ih = new InternetHeaders();
        MimeBodyPart mbp = null;/*from   w  w  w .j  a  v  a  2s.  c  o  m*/
        DataSource source = null;
        DataHandler dh = null;
        try {
            FormFile ff = (FormFile) form.getFichero();
            mbp = new MimeBodyPart(ih, ff.getFileData());
            source = new MimePartDataSource(mbp);
            dh = new DataHandler(source);
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("error al crear el datahandler");
            }
            throw new ValidatorException("{catalogadorBasico.importar.error}");
        }

        //validar el fichero
        Boolean valido = new Boolean(false);
        try {
            valido = this.getSrvValidadorService().obtenerValidacionLomes(dh);
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("error al llamar al servicio de validacin");
            }
            throw new ValidatorException("{catalogadorBasico.importar.error.novalido}");
        }

        if (!valido.booleanValue())
            throw new ValidatorException("{catalogadorBasico.importar.error.novalido}");

        //agregar el datahandler a sesion
        this.getCatalogadorBSession(request).setLomesImportado(dh);

    } else if (datosResources.getString("catalogadorBasico.importar.cancelar").equals(accion)) {
        resAction = "Cancelar";
    }

    return resAction;

}