List of usage examples for org.apache.http.entity.mime.content FileBody FileBody
public FileBody(final File file)
From source file:org.openecomp.sdc.ci.tests.utils.rest.ImportRestUtils.java
public static RestResponse importTestResource(ImportTestTypesEnum resource, UserRoleEnum userRole) throws IOException { Config config = Utils.getConfig();/*from w ww .ja va2 s. c om*/ CloseableHttpResponse response = null; MultipartEntityBuilder mpBuilder = MultipartEntityBuilder.create(); mpBuilder.addPart("resourceZip", new FileBody(getTestZipFile(resource.getFolderName()))); mpBuilder.addPart("resourceMetadata", new StringBody( getTestJsonStringOfFile(resource.getFolderName(), resource.getFolderName() + ".json"), ContentType.APPLICATION_JSON)); String url = String.format(Urls.IMPORT_RESOURCE_NORMATIVE, config.getCatalogBeHost(), config.getCatalogBePort()); CloseableHttpClient client = HttpClients.createDefault(); try { HttpPost httpPost = new HttpPost(url); RestResponse restResponse = new RestResponse(); httpPost.addHeader("USER_ID", UserRoleEnum.ADMIN.getUserId()); httpPost.setEntity(mpBuilder.build()); response = client.execute(httpPost); HttpEntity entity = response.getEntity(); String responseBody = null; if (entity != null) { InputStream instream = entity.getContent(); StringWriter writer = new StringWriter(); IOUtils.copy(instream, writer); responseBody = writer.toString(); try { } finally { instream.close(); } } restResponse.setErrorCode(response.getStatusLine().getStatusCode()); // restResponse.setResponse(response.getEntity().toString()); restResponse.setResponse(responseBody); return restResponse; } finally { closeResponse(response); closeHttpClient(client); } }
From source file:org.openecomp.sdc.ci.tests.utils.rest.ImportRestUtils.java
public static RestResponse importNewGroupTypeByName(String groupTypeName, UserRoleEnum userRole) throws IOException { Config config = Utils.getConfig();//from w w w . ja v a 2 s . c o m MultipartEntityBuilder mpBuilder = MultipartEntityBuilder.create(); mpBuilder.addPart("groupTypesZip", new FileBody(getGroupTypeZipFile(groupTypeName))); HttpEntity requestEntity = mpBuilder.build(); String url = String.format(Urls.IMPORT_GROUP_TYPE, config.getCatalogBeHost(), config.getCatalogBePort()); Map<String, String> headers = new HashMap<String, String>(); headers.put("USER_ID", userRole.getUserId()); return HttpRequest.sendHttpPostWithEntity(requestEntity, url, headers); }
From source file:org.openecomp.sdc.uici.tests.utilities.OnboardUtility.java
private static RestResponse uploadHeatPackage(String filepath, String filename, String vspid, String userId) throws Exception { Config config = Utils.getConfig();/* www . j av a 2s.c o m*/ CloseableHttpResponse response = null; MultipartEntityBuilder mpBuilder = MultipartEntityBuilder.create(); mpBuilder.addPart("resourceZip", new FileBody(getTestZipFile(filepath, filename))); String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products/%s/upload", config.getCatalogBeHost(), config.getCatalogBePort(), vspid); Map<String, String> headersMap = prepareHeadersMap(userId); headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "multipart/form-data"); CloseableHttpClient client = HttpClients.createDefault(); try { HttpPost httpPost = new HttpPost(url); RestResponse restResponse = new RestResponse(); Iterator<String> iterator = headersMap.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); String value = headersMap.get(key); httpPost.addHeader(key, value); } httpPost.setEntity(mpBuilder.build()); response = client.execute(httpPost); HttpEntity entity = response.getEntity(); String responseBody = null; if (entity != null) { InputStream instream = entity.getContent(); StringWriter writer = new StringWriter(); IOUtils.copy(instream, writer); responseBody = writer.toString(); try { } finally { instream.close(); } } restResponse.setErrorCode(response.getStatusLine().getStatusCode()); restResponse.setResponse(responseBody); return restResponse; } finally { closeResponse(response); closeHttpClient(client); } }
From source file:org.openml.apiconnector.io.OpenmlConnector.java
/** * Uploads a new dataset/* w ww .ja va 2s . com*/ * * @param description - xml file describing the dataset, according to XSD * @param dataset - arff file representing the dataset. optional. * @return The id under which the dataset was uploaded * @throws Exception */ public UploadDataSet dataUpload(File description, File dataset) throws Exception { MultipartEntity params = new MultipartEntity(); params.addPart("description", new FileBody(description)); if (dataset != null) { params.addPart("dataset", new FileBody(dataset)); } Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "data/", params, getApiKey(), verboseLevel); if (apiResult instanceof UploadDataSet) { return (UploadDataSet) apiResult; } else { throw new DataFormatException("Casting Api Object to UploadDataSet"); } }
From source file:org.openml.apiconnector.io.OpenmlConnector.java
/** * Uploads data features (requires admin account) * //from www . j a v a 2 s.c om * @param description - the features * @return * @throws Exception */ public DataFeatureUpload dataFeaturesUpload(File description) throws Exception { MultipartEntity params = new MultipartEntity(); params.addPart("description", new FileBody(description)); if (verboseLevel >= Constants.VERBOSE_LEVEL_ARFF) { System.out.println(Conversion.fileToString(description) + "\n==========\n"); } Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "data/features", params, getApiKey(), verboseLevel); if (apiResult instanceof DataFeatureUpload) { return (DataFeatureUpload) apiResult; } else { throw new DataFormatException("Casting Api Object to DataFeatureUpload"); } }
From source file:org.openml.apiconnector.io.OpenmlConnector.java
/** * Uploads data qualities (requires admin account) * /*from ww w .ja va2s. c o m*/ * @param description - the qualitues (or meta-features) * @return * @throws Exception */ public DataQualityUpload dataQualitiesUpload(File description) throws Exception { MultipartEntity params = new MultipartEntity(); params.addPart("description", new FileBody(description)); Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "data/qualities", params, getApiKey(), verboseLevel); if (apiResult instanceof DataQualityUpload) { return (DataQualityUpload) apiResult; } else { throw new DataFormatException("Casting Api Object to DataQualityUpload"); } }
From source file:org.openml.apiconnector.io.OpenmlConnector.java
/** * Uploads a task/* w w w .ja v a2s.co m*/ * * @param description - task description. * @return * @throws Exception */ public UploadTask taskUpload(File description) throws Exception { MultipartEntity params = new MultipartEntity(); params.addPart("description", new FileBody(description)); Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "task/", params, getApiKey(), verboseLevel); if (apiResult instanceof UploadTask) { return (UploadTask) apiResult; } else { throw new DataFormatException("Casting Api Object to UploadTask"); } }
From source file:org.openml.apiconnector.io.OpenmlConnector.java
/** * Uploads a flow/*from w w w . j a v a 2s. c om*/ * * @param description * - An XML file describing the implementation. See documentation * at openml.org. * @param binary * - A file containing the implementation binary. * @param source * - A file containing the implementation source. * @return UploadImplementation - An object containing information on the * implementation upload. * @throws Exception * - Can be: API Error (see documentation at openml.org), server * down, etc. */ public UploadFlow flowUpload(File description, File binary, File source) throws Exception { MultipartEntity params = new MultipartEntity(); params.addPart("description", new FileBody(description)); if (source != null) params.addPart("source", new FileBody(source)); if (binary != null) params.addPart("binary", new FileBody(binary)); Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "flow", params, getApiKey(), verboseLevel); if (apiResult instanceof UploadFlow) { return (UploadFlow) apiResult; } else { throw new DataFormatException("Casting Api Object to UploadImplementation"); } }
From source file:org.openml.apiconnector.io.OpenmlConnector.java
/** * Uploads a run/* w w w . jav a 2s.c o m*/ * * @param description * - An XML file describing the run. See documentation at * openml.org. * @param output_files * - A Map<String,File> containing all relevant output files. Key * "predictions" usually contains the predictions that were * generated by this run. * @return UploadRun - An object containing information on the * implementation upload. * @throws Exception * - Can be: API Error (see documentation at openml.org), server * down, etc. */ public UploadRun runUpload(File description, Map<String, File> output_files) throws Exception { MultipartEntity params = new MultipartEntity(); if (verboseLevel >= Constants.VERBOSE_LEVEL_ARFF) { System.out.println(Conversion.fileToString(output_files.get("predictions")) + "\n==========\n"); } if (verboseLevel >= Constants.VERBOSE_LEVEL_XML) { System.out.println(Conversion.fileToString(description) + "\n=========="); } params.addPart("description", new FileBody(description)); for (String s : output_files.keySet()) { params.addPart(s, new FileBody(output_files.get(s))); } Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "run/", params, getApiKey(), verboseLevel); if (apiResult instanceof UploadRun) { return (UploadRun) apiResult; } else { throw new DataFormatException("Casting Api Object to UploadRun"); } }
From source file:org.openml.apiconnector.io.OpenmlConnector.java
/** * Stores evaluation measures of a run (admin rights required, typically executed by evaluation engine) * //from w w w. j ava2s. c om * @param description - description file (complying to xsd) * @return * @throws Exception */ public RunEvaluate runEvaluate(File description) throws Exception { MultipartEntity params = new MultipartEntity(); params.addPart("description", new FileBody(description)); Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "run/evaluate", params, getApiKey(), verboseLevel); if (apiResult instanceof RunEvaluate) { return (RunEvaluate) apiResult; } else { throw new DataFormatException("Casting Api Object to RunEvaluate"); } }