Search in sources :

Example 6 with FormDataMultiPart

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;
}
Also used : FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart)

Example 7 with FormDataMultiPart

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();
}
Also used : FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) Map(java.util.Map) Test(org.junit.Test)

Example 8 with FormDataMultiPart

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);
}
Also used : WebResource(com.sun.jersey.api.client.WebResource) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) File(java.io.File) FileDataBodyPart(com.sun.jersey.multipart.file.FileDataBodyPart)

Example 9 with FormDataMultiPart

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);
}
Also used : MultiPart(com.sun.jersey.multipart.MultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) File(java.io.File) FileDataBodyPart(com.sun.jersey.multipart.file.FileDataBodyPart)

Example 10 with FormDataMultiPart

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());
    }
}
Also used : MailgunService(teammates.logic.core.MailgunService) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.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