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);
}
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;
}
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());
}
Aggregations