Search in sources :

Example 1 with FileDataBodyPart

use of com.sun.jersey.multipart.file.FileDataBodyPart in project coprhd-controller by CoprHD.

the class StorageDriver method upgradeDriver.

public ClientResponse upgradeDriver(String driverName, File driverFile, boolean force) {
    FormDataMultiPart multiPart = new FormDataMultiPart();
    multiPart.bodyPart(new FileDataBodyPart(DRIVER_KEY_NAME, driverFile, MediaType.APPLICATION_OCTET_STREAM_TYPE));
    multiPart.field("force", Boolean.toString(force));
    return client.postMultiPart(ClientResponse.class, multiPart, PathConstants.STORAGE_DRIVER_UPGRADE_URL, driverName);
}
Also used : FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FileDataBodyPart(com.sun.jersey.multipart.file.FileDataBodyPart)

Example 2 with FileDataBodyPart

use of com.sun.jersey.multipart.file.FileDataBodyPart in project coprhd-controller by CoprHD.

the class StorageDriver method installDriver.

public ClientResponse installDriver(File f) {
    FormDataMultiPart multiPart = new FormDataMultiPart();
    multiPart.bodyPart(new FileDataBodyPart(DRIVER_KEY_NAME, f, MediaType.APPLICATION_OCTET_STREAM_TYPE));
    return client.postMultiPart(ClientResponse.class, multiPart, PathConstants.STORAGE_DRIVER_INSTALL_URL);
}
Also used : FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FileDataBodyPart(com.sun.jersey.multipart.file.FileDataBodyPart)

Example 3 with FileDataBodyPart

use of com.sun.jersey.multipart.file.FileDataBodyPart 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 4 with FileDataBodyPart

use of com.sun.jersey.multipart.file.FileDataBodyPart 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 5 with FileDataBodyPart

use of com.sun.jersey.multipart.file.FileDataBodyPart 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));
    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));
    WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
    return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, formData);
}
Also used : FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) 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)

Aggregations

FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)6 FileDataBodyPart (com.sun.jersey.multipart.file.FileDataBodyPart)6 File (java.io.File)3 Client (com.sun.jersey.api.client.Client)2 WebResource (com.sun.jersey.api.client.WebResource)2 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 MultiPart (com.sun.jersey.multipart.MultiPart)1 StreamDataBodyPart (com.sun.jersey.multipart.file.StreamDataBodyPart)1