use of com.sun.jersey.multipart.FormDataMultiPart in project activityinfo by bedatadriven.
the class PoEditorClient method upload.
/**
* Uploads a list of terms along with English translations.
* @param projectId the PoEditor project id
* @param terms the list of terms to update
* @param sync
*/
public PoUploadResponse upload(int projectId, List<PoTermUpdate> terms, boolean sync) throws IOException {
FormDataMultiPart form = new FormDataMultiPart();
form.field("api_token", token);
form.field("action", "upload");
form.field("id", Integer.toString(projectId));
form.field("updating", "terms_definitions");
form.field("language", "en");
form.field("overwrite", "1");
form.field("sync_terms", sync ? "1" : "0");
form.bodyPart(createUpload(terms));
String responseText = client.resource("https://poeditor.com/api/").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, form);
PoUploadResponse response = objectMapper.readValue(responseText, PoUploadResponse.class);
if (response.getResponse().getCode() != 200) {
System.err.println(responseText);
throw new RuntimeException("Failed: " + response.getResponse().getMessage());
}
return response;
}
use of com.sun.jersey.multipart.FormDataMultiPart in project activityinfo by bedatadriven.
the class GcsUploadCredentialBuilderTest method test.
@Test
public void test() throws Exception {
UploadCredentials credentials = new GcsUploadCredentialBuilder(new TestingIdentityService(PRIVATE_KEY_FILE_PATH), "file.png").setCreatorId(CuidAdapter.userId(1)).setOwnerId(ResourceId.generateId()).setBucket("ai-dev-field-blob-test").setKey(BlobId.generate().asString()).setMaxContentLengthInMegabytes(10).expireAfter(Duration.standardMinutes(5)).build();
FormDataMultiPart form = new FormDataMultiPart();
for (Map.Entry<String, String> entry : credentials.getFormFields().entrySet()) {
form.field(entry.getKey(), entry.getValue());
}
form.field("file", Resources.asByteSource(Resources.getResource(getClass(), "goabout.png")).read(), MediaType.valueOf(PNG.toString()));
Client.create().resource(credentials.getUrl()).entity(form, MediaType.MULTIPART_FORM_DATA_TYPE).post();
}
use of com.sun.jersey.multipart.FormDataMultiPart in project java-docs-samples by GoogleCloudPlatform.
the class MailgunServlet method sendComplexMessage.
// [END simple]
// [START complex]
private ClientResponse sendComplexMessage(String recipient) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
FormDataMultiPart formData = new FormDataMultiPart();
formData.field("from", "Mailgun User <mailgun@" + MAILGUN_DOMAIN_NAME + ">");
formData.field("to", recipient);
formData.field("subject", "Complex Mailgun Example");
formData.field("html", "<html>HTML <strong>content</strong></html>");
ClassLoader classLoader = getClass().getClassLoader();
File txtFile = new File(classLoader.getResource("example-attachment.txt").getFile());
formData.bodyPart(new FileDataBodyPart("attachment", txtFile, MediaType.TEXT_PLAIN_TYPE));
return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, formData);
}
use of com.sun.jersey.multipart.FormDataMultiPart in project atlas by apache.
the class AtlasBaseClient method importData.
public AtlasImportResult importData(AtlasImportRequest request, String absoluteFilePath) throws AtlasServiceException {
FileDataBodyPart filePart = new FileDataBodyPart("data", new File(absoluteFilePath));
MultiPart multipartEntity = new FormDataMultiPart().field("request", AtlasType.toJson(request), MediaType.APPLICATION_JSON_TYPE).bodyPart(filePart);
return callAPI(IMPORT, AtlasImportResult.class, multipartEntity);
}
use of com.sun.jersey.multipart.FormDataMultiPart in project teammates by TEAMMATES.
the class EmailSenderTest method testConvertToMailgun.
@Test
public void testConvertToMailgun() throws Exception {
EmailWrapper wrapper = getTypicalEmailWrapper();
try (FormDataMultiPart formData = new MailgunService().parseToEmail(wrapper)) {
assertEquals(wrapper.getSenderName() + " <" + wrapper.getSenderEmail() + ">", formData.getField("from").getValue());
assertEquals(wrapper.getRecipient(), formData.getField("to").getValue());
assertEquals(wrapper.getBcc(), formData.getField("bcc").getValue());
assertEquals(wrapper.getReplyTo(), formData.getField("h:Reply-To").getValue());
assertEquals(wrapper.getSubject(), formData.getField("subject").getValue());
assertEquals(wrapper.getContent(), formData.getField("html").getValue());
}
}
Aggregations