use of com.sun.jersey.multipart.FormDataMultiPart in project pentaho-kettle by pentaho.
the class RepositoryCleanupUtil method purge.
/**
* Create parameters and send HTTP request to purge REST endpoint
*
* @param options
*/
public void purge(String[] options) {
FormDataMultiPart form = null;
try {
Map<String, String> parameters = parseExecutionOptions(options);
validateParameters(parameters);
authenticateLoginCredentials();
String serviceURL = createPurgeServiceURL();
form = createParametersForm();
WebResource resource = client.resource(serviceURL);
ClientResponse response = resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
if (response != null && response.getStatus() == 200) {
String resultLog = response.getEntity(String.class);
String logName = writeLog(resultLog);
writeOut(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.INFO_0001.OP_SUCCESS", logName), false);
} else {
writeOut(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0001.OP_FAILURE"), true);
}
} catch (Exception e) {
if (e.getMessage() != null) {
System.out.println(e.getMessage());
} else {
if (!(e instanceof NormalExitException)) {
e.printStackTrace();
}
}
} finally {
if (client != null) {
client.destroy();
}
if (form != null) {
form.cleanup();
}
}
}
use of com.sun.jersey.multipart.FormDataMultiPart 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);
}
use of com.sun.jersey.multipart.FormDataMultiPart 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);
}
use of com.sun.jersey.multipart.FormDataMultiPart in project pentaho-platform by pentaho.
the class CommandLineProcessor method performMetadataDatasourceImport.
/**
* --import --url=http://localhost:8080/pentaho --username=admin --password=password --file-path=metadata.xmi
* --resource-type=DATASOURCE --datasource-type=METADATA --overwrite=true --metadata-domain-id=steel-wheels
*
* @param contextURL
* @param metadataDatasourceFile
* @param overwrite
* @throws ParseException
* @throws IOException
*/
private void performMetadataDatasourceImport(String contextURL, File metadataDatasourceFile, String overwrite) throws ParseException, IOException {
File metadataFileInZip = null;
InputStream metadataFileInZipInputStream = null;
String metadataImportURL = contextURL + METADATA_DATASOURCE_IMPORT;
String domainId = getOptionValue(INFO_OPTION_METADATA_DOMAIN_ID_NAME, true, false);
WebResource resource = client.resource(metadataImportURL);
FormDataMultiPart part = new FormDataMultiPart();
final String name = RepositoryFilenameUtils.separatorsToRepository(metadataDatasourceFile.getName());
final String ext = RepositoryFilenameUtils.getExtension(name);
try {
if (ext.equals(ZIP_EXT)) {
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(metadataDatasourceFile));
ZipEntry entry = zipInputStream.getNextEntry();
while (entry != null) {
final String entryName = RepositoryFilenameUtils.separatorsToRepository(entry.getName());
final String extension = RepositoryFilenameUtils.getExtension(entryName);
File tempFile = null;
boolean isDir = entry.getSize() == 0;
if (!isDir) {
tempFile = File.createTempFile("zip", null);
tempFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempFile);
IOUtils.copy(zipInputStream, fos);
fos.close();
}
if (extension.equals(METADATA_DATASOURCE_EXT)) {
if (metadataFileInZip == null) {
metadataFileInZip = new File(entryName);
metadataFileInZipInputStream = new FileInputStream(metadataFileInZip);
}
}
zipInputStream.closeEntry();
entry = zipInputStream.getNextEntry();
}
zipInputStream.close();
part.field("overwrite", "true".equals(overwrite) ? "true" : "false", MediaType.MULTIPART_FORM_DATA_TYPE);
part.field("domainId", domainId, MediaType.MULTIPART_FORM_DATA_TYPE).field("metadataFile", metadataFileInZipInputStream, MediaType.MULTIPART_FORM_DATA_TYPE);
// If the import service needs the file name do the following.
part.getField("metadataFile").setContentDisposition(FormDataContentDisposition.name("metadataFile").fileName(metadataFileInZip.getName()).build());
// Response response
ClientResponse response = resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, part);
if (response != null) {
String message = response.getEntity(String.class);
System.out.println(Messages.getInstance().getString("CommandLineProcessor.INFO_REST_RESPONSE_RECEIVED", message));
}
} else {
FileInputStream metadataDatasourceInputStream = new FileInputStream(metadataDatasourceFile);
part.field("overwrite", "true".equals(overwrite) ? "true" : "false", MediaType.MULTIPART_FORM_DATA_TYPE);
part.field("domainId", domainId, MediaType.MULTIPART_FORM_DATA_TYPE).field("metadataFile", metadataDatasourceInputStream, MediaType.MULTIPART_FORM_DATA_TYPE);
// If the import service needs the file name do the following.
part.getField("metadataFile").setContentDisposition(FormDataContentDisposition.name("metadataFile").fileName(metadataDatasourceFile.getName()).build());
// Response response
ClientResponse response = resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, part);
if (response != null) {
String message = response.getEntity(String.class);
System.out.println(Messages.getInstance().getString("CommandLineProcessor.INFO_REST_RESPONSE_RECEIVED", message));
}
metadataDatasourceInputStream.close();
}
} finally {
metadataFileInZipInputStream.close();
part.cleanup();
}
}
use of com.sun.jersey.multipart.FormDataMultiPart in project pentaho-platform by pentaho.
the class RepositoryPublishResourceIT method testImportsSuccessfully.
private void testImportsSuccessfully(String path, String filename) throws Exception {
String full = path + '/' + filename;
FormDataMultiPart part = new FormDataMultiPart();
part.field("importPath", URLEncoder.encode(full, "UTF-8"), MULTIPART_FORM_DATA_TYPE);
part.field("fileUpload", new ByteArrayInputStream(new byte[0]), MULTIPART_FORM_DATA_TYPE);
part.field("overwriteFile", "true", MULTIPART_FORM_DATA_TYPE);
part.getField("fileUpload").setContentDisposition(FormDataContentDisposition.name("fileUpload").fileName(URLEncoder.encode(filename, "UTF-8")).build());
ClientResponse response = resource().path("repo/publish/file").type(MediaType.MULTIPART_FORM_DATA).accept(TEXT_PLAIN).post(ClientResponse.class, part);
assertResponse(response, ClientResponse.Status.OK, MediaType.TEXT_PLAIN);
ArgumentCaptor<IPlatformImportBundle> captor = ArgumentCaptor.forClass(IPlatformImportBundle.class);
verify(importer).importFile(captor.capture());
IPlatformImportBundle bundle = captor.getValue();
assertEquals(path, bundle.getPath());
assertEquals(filename, bundle.getName());
}
Aggregations