Search in sources :

Example 56 with Attachment

use of org.apache.cxf.jaxrs.ext.multipart.Attachment in project tesb-rt-se by Talend.

the class RESTClient method createMultipartBody.

/**
 * Creates MultipartBody. It contains 3 parts, "book1", "book2" and "image".
 * These individual parts have their Content-Type set to application/xml,
 * application/json and application/octet-stream
 *
 * MultipartBody will use the Content-Type value of the individual
 * part to write its data by delegating to a matching JAX-RS MessageBodyWriter
 * provider
 *
 * @return
 * @throws Exception
 */
private MultipartBody createMultipartBody() throws Exception {
    List<Attachment> atts = new LinkedList<Attachment>();
    atts.add(new Attachment("book1", "application/xml", new Book("JAXB", 1L)));
    atts.add(new Attachment("book2", "application/json", new Book("JSON", 2L)));
    atts.add(new Attachment("image", "application/octet-stream", getClass().getResourceAsStream("/java.jpg")));
    return new MultipartBody(atts, true);
}
Also used : Book(common.attachment.Book) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) LinkedList(java.util.LinkedList)

Aggregations

Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)56 Test (org.junit.Test)20 InputStream (java.io.InputStream)19 Response (javax.ws.rs.core.Response)17 ArrayList (java.util.ArrayList)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)15 WebClient (org.apache.cxf.jaxrs.client.WebClient)14 ContentDisposition (org.apache.cxf.jaxrs.ext.multipart.ContentDisposition)14 IOException (java.io.IOException)10 PushbackInputStream (java.io.PushbackInputStream)8 POST (javax.ws.rs.POST)8 LinkedList (java.util.LinkedList)7 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)7 LinkedHashMap (java.util.LinkedHashMap)6 DataHandler (javax.activation.DataHandler)6 Path (javax.ws.rs.Path)6 QueryResponse (ddf.catalog.operation.QueryResponse)5 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)5 Consumes (javax.ws.rs.Consumes)5