本文整理汇总了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");
}