Search in sources :

Example 36 with ContentDisposition

use of org.apache.cxf.jaxrs.ext.multipart.ContentDisposition in project cxf by apache.

the class JAXRSMultipartTest method testUploadImageFromForm.

@Test
public void testUploadImageFromForm() throws Exception {
    InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
    String address = "http://localhost:" + PORT + "/bookstore/books/formimage";
    WebClient client = WebClient.create(address);
    HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
    conduit.getClient().setReceiveTimeout(1000000);
    conduit.getClient().setConnectionTimeout(1000000);
    client.type("multipart/form-data").accept("multipart/form-data");
    ContentDisposition cd = new ContentDisposition("attachment;filename=java.jpg");
    MultivaluedMap<String, String> headers = new MetadataMap<>();
    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(getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
    byte[] image2 = IOUtils.readBytesFromStream(is2);
    assertArrayEquals(image1, image2);
    ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
    assertEquals("attachment;filename=java.jpg", cd2.toString());
    assertEquals("java.jpg", cd2.getParameter("filename"));
    assertEquals("http://host/location", body2.getRootAttachment().getHeader("Content-Location"));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ContentDisposition(org.apache.cxf.jaxrs.ext.multipart.ContentDisposition) PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 37 with ContentDisposition

use of org.apache.cxf.jaxrs.ext.multipart.ContentDisposition in project cxf by apache.

the class JAXRSClientServerTikaTest method testUploadIndexAndSearchPdfFileUsingUserDefinedDatePattern.

@Test
public void testUploadIndexAndSearchPdfFileUsingUserDefinedDatePattern() {
    final WebClient wc = createWebClient("/catalog").type(MediaType.MULTIPART_FORM_DATA);
    final ContentDisposition disposition = new ContentDisposition("attachment;filename=testPDF.pdf");
    final Attachment attachment = new Attachment("root", getClass().getResourceAsStream("/files/testPDF.pdf"), disposition);
    wc.post(new MultipartBody(attachment));
    // Use user-defined date pattern
    final Collection<ScoreDoc> hits = search("dcterms:modified=le=2007/09/16");
    assertEquals(hits.size(), 1);
}
Also used : ContentDisposition(org.apache.cxf.jaxrs.ext.multipart.ContentDisposition) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) WebClient(org.apache.cxf.jaxrs.client.WebClient) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Aggregations

ContentDisposition (org.apache.cxf.jaxrs.ext.multipart.ContentDisposition)37 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)25 Test (org.junit.Test)18 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)15 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ArrayList (java.util.ArrayList)11 CatalogFramework (ddf.catalog.CatalogFramework)10 IOException (java.io.IOException)10 InputStream (java.io.InputStream)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)7 InputTransformer (ddf.catalog.transform.InputTransformer)7 BundleContext (org.osgi.framework.BundleContext)7 ServiceReference (org.osgi.framework.ServiceReference)7 Metacard (ddf.catalog.data.Metacard)6 URI (java.net.URI)6 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)6 CoreAttributes (ddf.catalog.data.impl.types.CoreAttributes)5 Response (javax.ws.rs.core.Response)5 File (java.io.File)4 WebClient (org.apache.cxf.jaxrs.client.WebClient)4