Examples of FormDataBodyPart


Examples of com.sun.jersey.multipart.FormDataBodyPart

    @Test
    public void testPart() {
        WebResource webResource = resource().path("form/part");

        FormDataMultiPart mp = new FormDataMultiPart();
        FormDataBodyPart p = new FormDataBodyPart(FormDataContentDisposition.name("part").build(), "CONTENT");
        mp.bodyPart(p);

        String s = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, mp);
        Assert.assertEquals("CONTENT", s);
    }
View Full Code Here

Examples of com.sun.jersey.multipart.FormDataBodyPart

    @Test
    public void testPartWithFileName() {
        WebResource webResource = resource().path("form/part-file-name");

        FormDataMultiPart mp = new FormDataMultiPart();
        FormDataBodyPart p = new FormDataBodyPart(FormDataContentDisposition.name("part").fileName("file").build(), "CONTENT");
        mp.bodyPart(p);

        String s = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, mp);
        Assert.assertEquals("CONTENT:file", s);
    }
View Full Code Here

Examples of com.sun.jersey.multipart.FormDataBodyPart

    @Test
    public void testXmlJAXBPart() {
        WebResource webResource = resource().path("form/xml-jaxb-part");

        FormDataMultiPart mp = new FormDataMultiPart();
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("bean").fileName("bean").build(),
                new Bean("BEAN"),
                MediaType.APPLICATION_XML_TYPE));
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("string").fileName("string").build(),
                "STRING"));

        String s = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, mp);
        Assert.assertEquals("STRING:string,BEAN:bean", s);
    }
View Full Code Here

Examples of com.sun.jersey.multipart.FormDataBodyPart

                                  //@FormDataParam("file") InputStream fileStream,
                                  //@FormDataParam("portfolioName") String portfolioName,
                                  //@FormDataParam("dataField") String dataField
                                  //@FormDataParam("dataProvider") String dataProvider
  ) throws IOException {
    FormDataBodyPart fileBodyPart = getBodyPart(formData, "file");
    FormDataBodyPart filexmlBodyPart = getBodyPart(formData, "filexml");

    if (filexmlBodyPart.getFormDataContentDisposition().getFileName().toLowerCase().endsWith("xml")) {
      // xml can contain multiple portfolios
      Object filexmlEntity = filexmlBodyPart.getEntity();
      InputStream filexmlStream = new WorkaroundInputStream(((BodyPartEntity) filexmlEntity).getInputStream());
      for (PortfolioReader portfolioReader : returnPorfolioReader(filexmlStream)) {
        xmlPortfolioCopy(portfolioReader);
      }
      return Response.ok("Upload complete").build();
View Full Code Here

Examples of com.sun.jersey.multipart.FormDataBodyPart

  private Iterable<? extends PortfolioReader> returnPorfolioReader(InputStream fileStream) {
    return new XmlFileReader(fileStream, new SchemaRegister());
  }

  private static FormDataBodyPart getBodyPart(FormDataMultiPart formData, String fieldName) {
    FormDataBodyPart bodyPart = formData.getField(fieldName);
    if (bodyPart == null) {
      Response response = Response.status(Response.Status.BAD_REQUEST).entity("Missing form field: " + fieldName).build();
      throw new WebApplicationException(response);
    }
    return bodyPart;
View Full Code Here

Examples of com.sun.jersey.multipart.FormDataBodyPart

    }
    return bodyPart;
  }

  private static String getString(FormDataMultiPart formData, String fieldName) {
    FormDataBodyPart bodyPart = getBodyPart(formData, fieldName);
    String value = bodyPart.getValue();
    if (StringUtils.isEmpty(value)) {
      Response response = Response.status(Response.Status.BAD_REQUEST).entity("Missing form value: " + fieldName).build();
      throw new WebApplicationException(response);
    }
    return value;
View Full Code Here

Examples of com.sun.jersey.multipart.FormDataBodyPart

    // the SOAP1.2 interface will be triggered. See the SOAP 1.2 response format description at
    //  http://validator.w3.org/docs/api.html#requestformat
    form.field("output", "soap12");
   
    // 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

Examples of org.glassfish.jersey.media.multipart.FormDataBodyPart

        @Override
        public FormDataContentDisposition provide() {
            FormDataMultiPart formDataMultiPart = getEntity(getContainerRequest());

            FormDataBodyPart formDataBodyPart = formDataMultiPart.getField(name);
            if (formDataBodyPart == null) {
                return null;
            }

            return formDataMultiPart.getField(name).getFormDataContentDisposition();
View Full Code Here

Examples of org.glassfish.jersey.media.multipart.FormDataBodyPart

            // Return the field value for the field specified by the sourceName property.
            final ContainerRequest request = getContainerRequest();
            final FormDataMultiPart formDataMultiPart = getEntity(request);

            List<FormDataBodyPart> formDataBodyParts = formDataMultiPart.getFields(parameter.getSourceName());
            FormDataBodyPart formDataBodyPart = (formDataBodyParts != null) ? formDataBodyParts.get(0) : null;

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

            MessageBodyWorkers messageBodyWorkers = request.getWorkers();

            MessageBodyReader reader = messageBodyWorkers.getMessageBodyReader(
                    parameter.getRawType(),
                    parameter.getType(),
                    parameter.getAnnotations(),
                    mediaType);

            if (reader != null && !isPrimitiveType(parameter.getRawType())) {
                InputStream in;
                if (formDataBodyPart == null) {
                    if (parameter.getDefaultValue() != null) {
                        // Convert default value to bytes.
                        in = new ByteArrayInputStream(parameter.getDefaultValue().getBytes());
                    } else {
                        return null;
                    }
                } else {
                    in = ((BodyPartEntity) formDataBodyPart.getEntity()).getInputStream();
                }


                try {
                    //noinspection unchecked
View Full Code Here

Examples of org.glassfish.jersey.media.multipart.FormDataBodyPart

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

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

            // Configure providers.
            bodyPart.setMessageBodyWorkers(workers);

            // Copy headers.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.