当前位置: 首页>>代码示例>>Java>>正文


Java FormDataContentDisposition.name方法代码示例

本文整理汇总了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");
	}
}
 
开发者ID:CloudCycle2,项目名称:CSAR_Repository,代码行数:45,代码来源:ContainerApiClient.java

示例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");
}
 
开发者ID:CloudCycle2,项目名称:CSAR_Repository,代码行数:44,代码来源:WineryApiClient.java


注:本文中的org.glassfish.jersey.media.multipart.FormDataContentDisposition.name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。