當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。