Package com.sun.jersey.multipart

Examples of com.sun.jersey.multipart.FormDataBodyPart


                FormDataContentDisposition dispo = FormDataContentDisposition
                        .name("file")
                        .fileName(fileForImport.getFileName())
                        .size(fileForImport.getFile().length())
                        .build();
                FormDataBodyPart bodyPart = new FormDataBodyPart(dispo, fileForImport.getFile(), MediaType.MULTIPART_FORM_DATA_TYPE);
                mp.bodyPart(bodyPart);
            }
            postBody = mp;

            try {
View Full Code Here


            Map<String, List<FormDataBodyPart>> m1 = formData.getFields();

            Set<String> ss = m1.keySet();
            for (String fieldName : ss) {
                FormDataBodyPart n = formData.getField(fieldName);
                Logger.getLogger(TemplateResource.class.getName()).log(Level.INFO, "fieldName=" + fieldName);


                if (n.getContentDisposition().getFileName() != null) {//we have a file
                    //save it and mark it as delete on exit.
                    InputStream fileStream = n.getValueAs(InputStream.class);
                    String mimeType = n.getMediaType().toString();
                    File f = saveFile(n.getContentDisposition().getFileName(), mimeType, fileStream);
                    f.deleteOnExit();
                    //put only the local path of the file in the same field.
                    data.put(fieldName, f.getAbsolutePath());

                } else {
                    try {
                        Logger.getLogger(TemplateResource.class.getName()).log(Level.INFO, "Values=" + fieldName + " === " + n.getValue());

                        data.put(fieldName, n.getValue());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
View Full Code Here

    if (matcher.find()) {
       html = matcher.replaceAll("");
    }
   
    // The document to validate, POSTed as multipart/form-data
    FormDataBodyPart fdp = new FormDataBodyPart("uploaded_file",
        IOUtils.toInputStream(html),
        // new FileInputStream(tmpHtml),
        MediaType.APPLICATION_OCTET_STREAM_TYPE);
   
    // attach the inputstream as upload info to the form
View Full Code Here

        @Override
        public FormDataContentDisposition getValue(HttpContext context) {
            FormDataMultiPart fdmp = (FormDataMultiPart)
                    context.getProperties().get(FORM_MULTIPART_PROPERTY);

            FormDataBodyPart fdbp = fdmp.getField(name);
            if (fdbp == null)
                return null;
           
            return fdmp.getField(name).getFormDataContentDisposition();
        }
View Full Code Here

            // sourceName property
            FormDataMultiPart fdmp = (FormDataMultiPart)
                    context.getProperties().get(FORM_MULTIPART_PROPERTY);
           
            List<FormDataBodyPart> fdbps = fdmp.getFields(param.getSourceName());
            FormDataBodyPart fdbp = (fdbps != null) ? fdbps.get(0) : null;

            MediaType mediaType = (fdbp != null)
                    ? fdbp.getMediaType() : MediaType.TEXT_PLAIN_TYPE;

            MessageBodyReader reader = mbws.getMessageBodyReader(
                    param.getParameterClass(),
                    param.getParameterType(),
                    param.getAnnotations(),
                    mediaType);
          
            if (reader != null) {
                InputStream in = null;
                if (fdbp == null) {
                    if (param.getDefaultValue() != null) {
                        // Convert default value to bytes
                        in = new ByteArrayInputStream(param.getDefaultValue().getBytes());
                    } else {
                        return null;
                    }
                } else {
                    in = ((BodyPartEntity) fdbp.getEntity()).getInputStream();
                }

                try {
                    return reader.readFrom(
                            param.getParameterClass(),
View Full Code Here

            String userAgent = headers.getFirst(HttpHeaders.USER_AGENT);
            fileNameFix = userAgent != null && userAgent.contains(" MSIE ");
        }

        for (MIMEPart mp : mm.getAttachments()) {
            BodyPart bodyPart = formData ? new FormDataBodyPart(fileNameFix) : new BodyPart();

            // Configure providers
            bodyPart.setProviders(providers);

            // Copy headers
View Full Code Here

    File tempFile = File.createTempFile(fileName, fileExtension);
    BufferedWriter bw = new BufferedWriter(new FileWriter(tempFile));
    bw.write(fileContent);
    bw.close();
    InputStream content = new FileInputStream(tempFile);
    FormDataBodyPart inputStreamBody = new FormDataBodyPart(
        FormDataContentDisposition.name("file")
            .fileName(fileName + fileExtension).build(), content,
        MediaType.APPLICATION_OCTET_STREAM_TYPE);

    Response response = fileBrowserService.upload().uploadFile(content,
        inputStreamBody.getFormDataContentDisposition(), "/tmp/");
    return response;
  }
View Full Code Here

        // In this case we setup the parameter from a multipart request
        File file = null;
        for (BodyPart bpart : data.getBodyParts()) {
            log.debug("is a {}", bpart.getClass());
            if (bpart instanceof FormDataBodyPart) {
                FormDataBodyPart dbp = (FormDataBodyPart) bpart;
                if (dbp.getName().equals("file")) {
                    file = bpart.getEntityAs(File.class);
                }
                // We put all the parameters field
                // XXX We supports here only simple fields
                // We do NOT support the sent of additional files, for
                // example
                if (dbp.isSimple()) {
                    if (this.parameters.containsKey(dbp.getName())) {
                        this.parameters.get(dbp.getName()).add(dbp.getValue());
                    } else {
                        List<String> values = new ArrayList<String>();
                        values.add(dbp.getValue());
                        this.parameters.put(dbp.getName(), values);
                    }
                }
            }
        }
        // Then add the file
View Full Code Here

        String format = null;
        Set<String> keys = new HashSet<String>();
        for (BodyPart bpart : data.getBodyParts()) {
            log.debug("is a {}", bpart.getClass());
            if (bpart instanceof FormDataBodyPart) {
                FormDataBodyPart dbp = (FormDataBodyPart) bpart;
                String name = dbp.getName();
                if (name.equals("file")) file = bpart.getEntityAs(File.class);
                else {
                    String value = dbp.getValue();
                    if (name.equals("format") && !value.equals("auto")) format = value;
                    else if (name.equals("url")) try {
                        URI.create(value); // To throw 400 if malformed.
                        location = IRI.create(value);
                    } catch (Exception ex) {
View Full Code Here

        String format = null;
        List<OWLOntologyID> aliases = new ArrayList<OWLOntologyID>();
        for (BodyPart bpart : data.getBodyParts()) {
            log.debug("is a {}", bpart.getClass());
            if (bpart instanceof FormDataBodyPart) {
                FormDataBodyPart dbp = (FormDataBodyPart) bpart;
                String name = dbp.getName();
                if (name.equals("file")) {
                    file = bpart.getEntityAs(File.class);
                } else {
                    String value = dbp.getValue();
                    if (name.equals("format") && !value.equals("auto")) {
                        format = value;
                    } else if (name.equals("url")) {
                        try {
                            URI.create(value); // To throw 400 if malformed.
View Full Code Here

TOP

Related Classes of com.sun.jersey.multipart.FormDataBodyPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.