Search in sources :

Example 21 with FormDataMultiPart

use of com.sun.jersey.multipart.FormDataMultiPart in project pwinty-java-sdk by OddPrints.

the class Pwinty method addPhotoToOrder.

/**
 * Either the File or URL must be supplied
 */
private Photo addPhotoToOrder(int orderId, InputStream photoData, File photo, URL photoUrl, Photo.Type type, int copies, Sizing sizing) {
    @SuppressWarnings("resource") FormDataMultiPart form = new FormDataMultiPart().field("type", type.toString()).field("sizing", sizing.toString()).field("copies", "" + copies);
    if (photoData != null) {
        form.bodyPart(new StreamDataBodyPart("file", photoData));
    } else if (photo != null) {
        form.bodyPart(new FileDataBodyPart("file", photo, MediaType.APPLICATION_OCTET_STREAM_TYPE));
    } else {
        form = form.field("url", photoUrl.toExternalForm());
    }
    ClientResponse response = webResource.path("Orders/" + orderId + "/Photos").type(MediaType.MULTIPART_FORM_DATA_TYPE).header("X-Pwinty-MerchantId", merchantId).header("X-Pwinty-REST-API-Key", apiKey).post(ClientResponse.class, form);
    throwIfBad(response);
    return createReponse(response, Photo.class);
}
Also used : StreamDataBodyPart(com.sun.jersey.multipart.file.StreamDataBodyPart) ClientResponse(com.sun.jersey.api.client.ClientResponse) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FileDataBodyPart(com.sun.jersey.multipart.file.FileDataBodyPart)

Example 22 with FormDataMultiPart

use of com.sun.jersey.multipart.FormDataMultiPart in project teammates by TEAMMATES.

the class MailgunService method parseToEmail.

/**
 * {@inheritDoc}
 */
@Override
public FormDataMultiPart parseToEmail(EmailWrapper wrapper) {
    FormDataMultiPart formData = new FormDataMultiPart();
    String sender = wrapper.getSenderName() == null || wrapper.getSenderName().isEmpty() ? wrapper.getSenderEmail() : wrapper.getSenderName() + " <" + wrapper.getSenderEmail() + ">";
    formData.field("from", sender);
    formData.field("to", wrapper.getRecipient());
    if (wrapper.getBcc() != null && !wrapper.getBcc().isEmpty()) {
        formData.field("bcc", wrapper.getBcc());
    }
    formData.field("h:Reply-To", wrapper.getReplyTo());
    formData.field("subject", wrapper.getSubject());
    formData.field("html", wrapper.getContent());
    return formData;
}
Also used : FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart)

Example 23 with FormDataMultiPart

use of com.sun.jersey.multipart.FormDataMultiPart in project data-access by pentaho.

the class DataSourcePublishIT method testAnalysis_ACL.

@Test
public void testAnalysis_ACL() throws Exception {
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final String catalogID = "FoodMart";
    final InputStream uploadAnalysis = new FileInputStream("target/test-classes/schema.xml");
    final boolean overwrite = true;
    final boolean xmlaEnabledFlag = false;
    final String parameters = "DataSource=" + catalogID + ";EnableXmla=" + xmlaEnabledFlag + ";overwrite=" + overwrite;
    MultiPart part = new FormDataMultiPart().field("catalogName", catalogID).field("datasourceName", catalogID).field("overwrite", String.valueOf(overwrite)).field("xmlaEnabledFlag", String.valueOf(xmlaEnabledFlag)).field("parameters", parameters).bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("uploadAnalysis").fileName("schema.xml").size(uploadAnalysis.available()).build(), uploadAnalysis, MediaType.TEXT_XML_TYPE));
    WebResource webResource = resource();
    final ClientResponse noAnalysis = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.CONFLICT.getStatusCode(), noAnalysis.getStatus());
    ClientResponse postAnalysis = webResource.path("data-access/api/mondrian/postAnalysis").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, part);
    assertEquals(Response.Status.OK.getStatusCode(), postAnalysis.getStatus());
    final ClientResponse noACL = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), noACL.getStatus());
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkAnalysis(webResource, catalogID, true);
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final ClientResponse changeACL = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "/acl").put(ClientResponse.class, generateACL(USERNAME_SUZY, RepositoryFileSid.Type.USER));
    assertEquals(Response.Status.OK.getStatusCode(), changeACL.getStatus());
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkAnalysis(webResource, catalogID, true);
    final ClientResponse noAccessACL = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), noAccessACL.getStatus());
    final ClientResponse noAccessACLNoDS = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "_not_exist/acl").get(ClientResponse.class);
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), noAccessACLNoDS.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultiPart(com.sun.jersey.multipart.MultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) FileInputStream(java.io.FileInputStream) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Aggregations

FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)23 ClientResponse (com.sun.jersey.api.client.ClientResponse)14 WebResource (com.sun.jersey.api.client.WebResource)14 FileInputStream (java.io.FileInputStream)10 MultiPart (com.sun.jersey.multipart.MultiPart)7 Test (org.junit.Test)7 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)6 FileDataBodyPart (com.sun.jersey.multipart.file.FileDataBodyPart)6 JerseyTest (com.sun.jersey.test.framework.JerseyTest)6 File (java.io.File)6 InputStream (java.io.InputStream)5 Client (com.sun.jersey.api.client.Client)3 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)3 IOException (java.io.IOException)3 ZipInputStream (java.util.zip.ZipInputStream)3 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)3 MalformedURLException (java.net.MalformedURLException)2 ParseException (org.apache.commons.cli.ParseException)2 StreamDataBodyPart (com.sun.jersey.multipart.file.StreamDataBodyPart)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1