Package org.apache.cxf.jaxrs.ext.multipart

Examples of org.apache.cxf.jaxrs.ext.multipart.Attachment


            dh = new DataHandler((DataSource)obj);
        } else if (File.class.isAssignableFrom(obj.getClass())) {
            File f = (File)obj;
            ContentDisposition cd = mainMediaType.startsWith(MediaType.MULTIPART_FORM_DATA)
                ? new ContentDisposition("form-data;name=file;filename=" + f.getName()) null;
            return new Attachment(AttachmentUtil.BODY_ATTACHMENT_ID, new FileInputStream(f), cd);
        } else if (Attachment.class.isAssignableFrom(obj.getClass())) {
            Attachment att = (Attachment)obj;
            if (att.getObject() == null) {
                return att;
            }
            dh = getHandlerForObject(att.getObject(),
                                     att.getObject().getClass(), new Annotation[]{},
                                     att.getContentType().toString(), id);
            return new Attachment(att.getContentId(), dh, att.getHeaders());
        } else if (byte[].class.isAssignableFrom(obj.getClass())) {
            ByteDataSource source = new ByteDataSource((byte[])obj);
            source.setContentType(mimeType);
            dh = new DataHandler(source);
        } else {
            dh = getHandlerForObject(obj, cls, genericType, anns, mimeType, id);
        }
        String contentId = getContentId(anns, id);
       
        return new Attachment(contentId, dh, new MetadataMap<String, String>());
    }
View Full Code Here


        List<Attachment> atts = new LinkedList<Attachment>();
        List<Parameter> fm = getParameters(map, ParameterType.REQUEST_BODY);
        for (Parameter p : fm) {
            Multipart part = getMultipart(ori, p.getIndex());
            if (part != null) {
                atts.add(new Attachment(part.value(), part.type(), params[p.getIndex()]));
            }
        }
        return atts;       
    }
View Full Code Here

   
    private void doTestNullPart(String address) throws Exception {
        WebClient client = WebClient.create(address);
        client.type("multipart/form-data").accept("text/plain");
        List<Attachment> atts = new LinkedList<Attachment>();
        atts.add(new Attachment("somepart", "text/plain", "hello there"));
        Response r = client.postCollection(atts, Attachment.class);
        assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
        assertEquals("nobody home", IOUtils.readStringFromStream((InputStream)r.getEntity()));
    }
View Full Code Here

    public void testNullableParamsPrimitive() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/books/testnullpartprimitive";
        WebClient client = WebClient.create(address);
        client.type("multipart/form-data").accept("text/plain");
        List<Attachment> atts = new LinkedList<Attachment>();
        atts.add(new Attachment("somepart", "text/plain", "hello there"));
        Response r = client.postCollection(atts, Attachment.class);
        assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
        assertEquals((Integer)0, Integer.valueOf(IOUtils.readStringFromStream((InputStream)r.getEntity())));
    }
View Full Code Here

        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
        headers.putSingle("Content-Type", "application/xml");
        headers.putSingle("Content-ID", "theroot");
        headers.putSingle("Content-Transfer-Encoding", "customxml");
        Attachment attJaxb = new Attachment(headers, jaxb);
       
        headers = new MetadataMap<String, String>();
        headers.putSingle("Content-Type", "application/json");
        headers.putSingle("Content-ID", "thejson");
        headers.putSingle("Content-Transfer-Encoding", "customjson");
        Attachment attJson = new Attachment(headers, json);
       
        headers = new MetadataMap<String, String>();
        headers.putSingle("Content-Type", "application/octet-stream");
        headers.putSingle("Content-ID", "theimage");
        headers.putSingle("Content-Transfer-Encoding", "customstream");
        Attachment attIs = new Attachment(headers, is1);
       
        objects.put(MediaType.APPLICATION_XML, attJaxb);
        objects.put(MediaType.APPLICATION_JSON, attJson);
        objects.put(MediaType.APPLICATION_OCTET_STREAM, attIs);
       
View Full Code Here

        Book jaxb = new Book("jaxb", 1L);
        Book json = new Book("json", 2L);
        InputStream is1 =
            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
        List<Attachment> objects = new ArrayList<Attachment>();
        objects.add(new Attachment("<theroot>", MediaType.APPLICATION_XML, jaxb));
        objects.add(new Attachment("thejson", MediaType.APPLICATION_JSON, json));
        objects.add(new Attachment("theimage", MediaType.APPLICATION_OCTET_STREAM, is1));
        Collection<? extends Attachment> coll = client.postAndGetCollection(objects, Attachment.class);
        List<Attachment> result = new ArrayList<Attachment>(coll);
        Book jaxb2 = readBookFromInputStream(result.get(0).getDataHandler().getInputStream());
        assertEquals("jaxb", jaxb2.getName());
        assertEquals(1L, jaxb2.getId());
View Full Code Here

        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
        headers.putSingle("Content-ID", "image");
        headers.putSingle("Content-Disposition", cd.toString());
        headers.putSingle("Content-Location", "http://host/bar");
        headers.putSingle("custom-header", "custom");
        Attachment att = new Attachment(is1, headers);
       
        MultipartBody body = new MultipartBody(att);
        MultipartBody body2 = client.post(body, MultipartBody.class);
        InputStream is2 = body2.getRootAttachment().getDataHandler().getInputStream();
        byte[] image1 = IOUtils.readBytesFromStream(
View Full Code Here

        client.type("multipart/form-data").accept("text/plain");
       
        ContentDisposition cd = new ContentDisposition("attachment;name=\"a\";filename=\"a;txt\"");
        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
        headers.putSingle("Content-Disposition", cd.toString());
        Attachment att = new Attachment(new ByteArrayInputStream("file name with semicolon".getBytes()),
                                        headers);
       
        MultipartBody body = new MultipartBody(att);
        String partContent = client.post(body, String.class);
        assertEquals("file name with semicolon, filename:" + "a;txt", partContent);
View Full Code Here

   
    @GET
    @Path("/content/string")
    @Produces("multipart/mixed")
    public Attachment getAttachmentWithStringContent() throws Exception {
        Attachment respXMLPayloadAttachment = new Attachment("Response_XML_Payload",
                                                             "application/xml",
                                                             "<Book><id>888</id></Book>");
        return respXMLPayloadAttachment;
    }
View Full Code Here

   
    @GET
    @Path("/content/bytes")
    @Produces("multipart/mixed")
    public Attachment getAttachmentWithByteContent() throws Exception {
        Attachment respXMLPayloadAttachment = new Attachment("Response_XML_Payload",
                                                             "application/xml",
                                                             "<Book><id>888</id></Book>".getBytes());
        return respXMLPayloadAttachment;
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.ext.multipart.Attachment

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.