Package com.sun.jersey.multipart

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


    @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

    @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

                                  //@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

  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

    }
    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

    // 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

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.