本文整理匯總了Java中org.glassfish.jersey.media.multipart.FormDataContentDisposition.name方法的典型用法代碼示例。如果您正苦於以下問題:Java FormDataContentDisposition.name方法的具體用法?Java FormDataContentDisposition.name怎麽用?Java FormDataContentDisposition.name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.glassfish.jersey.media.multipart.FormDataContentDisposition
的用法示例。
在下文中一共展示了FormDataContentDisposition.name方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: uploadFileToOpenTOSCA
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //導入方法依賴的package包/類
/**
* Uploads a CsarFile and triggers its processing
*
* @param csarFile
* @return the location where the instance was created
*/
public String uploadFileToOpenTOSCA(File file, String fileName) throws DeploymentException {
try {
if (!file.exists()) {
throw new DeploymentException(String.format("File %s doesn't exist", file.getAbsolutePath()));
}
// build the message
FormDataMultiPart multiPart = new FormDataMultiPart();
FormDataContentDisposition.FormDataContentDispositionBuilder dispositionBuilder = FormDataContentDisposition
.name("file");
dispositionBuilder.fileName(fileName);
dispositionBuilder.size(file.getTotalSpace());
FormDataContentDisposition formDataContentDisposition = dispositionBuilder.build();
multiPart.bodyPart(new FormDataBodyPart("file", file, MediaType.APPLICATION_OCTET_STREAM_TYPE)
.contentDisposition(formDataContentDisposition));
Entity<FormDataMultiPart> entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
// submit the request
WebTarget path = baseWebTarget.path("CSARs");
Builder request = path.request();
Response response = request.post(entity);
// handle response
if (Status.CREATED.getStatusCode() == response.getStatus()) {
return response.getHeaderString("location");
} else {
LOGGER.warn("Failed to deploy: " + file.getAbsolutePath() + " to " + path);
throw new DeploymentException("Deployment failed - OpenTOSCA Server returned " + response.getStatus());
}
} catch (ProcessingException e) {
LOGGER.warn("Failed to upload CSAR: Server - server was not reachable", e);
throw new DeploymentException("Deletion failed - OpenTOSCA Server was not reachable");
}
}
示例2: uploadToWinery
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //導入方法依賴的package包/類
public void uploadToWinery(CsarFile file) throws Exception {
FileSystem fs = new FileSystem();
File f = fs.getFile(file.getHashedFile().getFilename());
if (f == null) {
throw new FileNotFoundException(file.getName() + " not found");
}
// build form data
FormDataMultiPart multiPart = new FormDataMultiPart();
FormDataContentDisposition.FormDataContentDispositionBuilder dispositionBuilder = FormDataContentDisposition
.name("file");
dispositionBuilder.fileName(file.getName());
dispositionBuilder.size(f.getTotalSpace());
FormDataContentDisposition formDataContentDisposition = dispositionBuilder.build();
multiPart.bodyPart(new FormDataBodyPart("file", f, MediaType.APPLICATION_OCTET_STREAM_TYPE)
.contentDisposition(formDataContentDisposition));
Entity<FormDataMultiPart> entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
// send request
WebTarget target = client.target(this.url);
Builder request = target.request();
request.accept("application/json");
Response response = request.post(entity);
// handle response
if (Status.NO_CONTENT.getStatusCode() == response.getStatus()) {
return;
}
if (Status.BAD_REQUEST.getStatusCode() == response.getStatus()) {
String json = response.readEntity(String.class);
List<String> errors = this.parseErrorsJson(json);
throw new Exception(StringUtils.join(errors));
}
throw new Exception("failed to push to winery");
}