Package com.sun.jersey.multipart

Examples of com.sun.jersey.multipart.MultiPart


        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        for (int i = 0; i < 900 * 1024; i++)
            baos.write(65);

        MultiPart multiPartInput = new MultiPart().
                bodyPart(new ByteArrayInputStream("01234567890123456789012345678901234567890123456789".getBytes()), MediaType.APPLICATION_OCTET_STREAM_TYPE).
                bodyPart(baos.toByteArray(), MediaType.APPLICATION_OCTET_STREAM_TYPE);

        client.setChunkedEncodingSize(1024);
        client.resource(getUri()).
View Full Code Here


    public void testOne() {
        WebResource.Builder builder = client.resource(getUri())
                .path("multipart/one").accept("multipart/mixed");
        try {
            MultiPart result = builder.get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(1, result.getBodyParts().size());
            BodyPart part = result.getBodyParts().get(0);
            checkMediaType(new MediaType("text", "plain"), part.getMediaType());
            checkEntity("This is the only segment", (BodyPartEntity) part.getEntity());

            result.getParameterizedHeaders();
            result.cleanup();
        } catch (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch(ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    public void testETag() {
        WebResource.Builder builder = client.resource(getUri())
                .path("multipart/etag").accept("multipart/mixed");
        try {
            MultiPart result = builder.get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(1, result.getBodyParts().size());
            BodyPart part = result.getBodyParts().get(0);
            checkMediaType(new MediaType("text", "plain"), part.getMediaType());
            checkEntity("This is the only segment", (BodyPartEntity) part.getEntity());
            assertEquals("\"value\"", part.getHeaders().getFirst("ETag"));

            result.getParameterizedHeaders();
            result.cleanup();
        } catch (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch(ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    // just to avoid concurrency issues if this arg is mutable
    final ArrayList<AttachmentInput> myAttachments = Lists.newArrayList(attachments);
    invoke(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        final MultiPart multiPartInput = new MultiPart();
        for (AttachmentInput attachment : myAttachments) {
          BodyPart bp = new BodyPart(attachment.getInputStream(), MediaType.APPLICATION_OCTET_STREAM_TYPE);
          FormDataContentDisposition.FormDataContentDispositionBuilder dispositionBuilder =
              FormDataContentDisposition.name(FILE_ATTACHMENT_CONTROL_NAME);
          dispositionBuilder.fileName(attachment.getFilename());
          final FormDataContentDisposition formDataContentDisposition = dispositionBuilder.build();
          bp.setContentDisposition(formDataContentDisposition);
          multiPartInput.bodyPart(bp);
        }

        postFileMultiPart(multiPartInput, attachmentsUri);
        return null;
      }
View Full Code Here

  public void addAttachments(ProgressMonitor progressMonitor, final URI attachmentsUri, File... files) {
    final ArrayList<File> myFiles = Lists.newArrayList(files); // just to avoid concurrency issues if this arg is mutable
    invoke(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        final MultiPart multiPartInput = new MultiPart();
        for (File file : myFiles) {
          FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(FILE_ATTACHMENT_CONTROL_NAME, file);
          multiPartInput.bodyPart(fileDataBodyPart);
        }
        postFileMultiPart(multiPartInput, attachmentsUri);
        return null;
      }
View Full Code Here

    public void testOne() {
        WebResource.Builder builder = client.resource(getUri())
                .path("multipart/one").accept("multipart/mixed");
        try {
            MultiPart result = builder.get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(1, result.getBodyParts().size());
            BodyPart part = result.getBodyParts().get(0);
            checkMediaType(new MediaType("text", "plain"), part.getMediaType());
            checkEntity("This is the only segment", (BodyPartEntity) part.getEntity());

            result.getParameterizedHeaders();
            result.cleanup();
        } catch (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch(ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    public void testTwo() {
        WebResource.Builder builder = client.resource(getUri())
                .path("multipart/two").accept("multipart/mixed");
        try {
            MultiPart result = builder.get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(2, result.getBodyParts().size());
            BodyPart part1 = result.getBodyParts().get(0);
            checkMediaType(new MediaType("text", "plain"), part1.getMediaType());
            checkEntity("This is the first segment", (BodyPartEntity) part1.getEntity());
            BodyPart part2 = result.getBodyParts().get(1);
            checkMediaType(new MediaType("text", "xml"), part2.getMediaType());
            checkEntity("<outer><inner>value</inner></outer>", (BodyPartEntity) part2.getEntity());

            result.getParameterizedHeaders();
            result.cleanup();
        } catch (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch(ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    public void testThree() {
        WebResource.Builder builder = client.resource(getUri())
                .path("multipart/three").accept("multipart/mixed");
        try {
            MultiPart result = builder.get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(2, result.getBodyParts().size());
            BodyPart part1 = result.getBodyParts().get(0);
            checkMediaType(new MediaType("text", "plain"), part1.getMediaType());
            checkEntity("This is the first segment", (BodyPartEntity) part1.getEntity());
            BodyPart part2 = result.getBodyParts().get(1);
            checkMediaType(new MediaType("x-application", "x-format"), part2.getMediaType());
            MultiPartBean entity = part2.getEntityAs(MultiPartBean.class);
            assertEquals("myname", entity.getName());
            assertEquals("myvalue", entity.getValue());

            result.getParameterizedHeaders();
            result.cleanup();
        } catch (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch(ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    public void testFour() {
        WebResource.Builder builder = client.resource(getUri())
                .path("multipart/four").accept("text/plain").type("multipart/mixed");
        try {
            MultiPartBean bean = new MultiPartBean("myname", "myvalue");
            MultiPart entity = new MultiPart().
              bodyPart("This is the first segment", new MediaType("text", "plain")).
              bodyPart(bean, new MediaType("x-application", "x-format"));
            String response = builder.put(String.class, entity);
            if (!response.startsWith("SUCCESS:")) {
                fail("Response is '" + response + "'");
View Full Code Here

    public void testFourBiz() {
        WebResource.Builder builder = client.resource(getUri())
                .path("multipart/four").accept("text/plain").header("Content-Type", "multipart/mixed");
        try {
            MultiPartBean bean = new MultiPartBean("myname", "myvalue");
            MultiPart entity = new MultiPart().
              bodyPart("This is the first segment", new MediaType("text", "plain")).
              bodyPart(bean, new MediaType("x-application", "x-format"));
            String response = builder.put(String.class, entity);
            if (!response.startsWith("SUCCESS:")) {
                fail("Response is '" + response + "'");
View Full Code Here

TOP

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

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.