List of usage examples for org.apache.http.entity.mime MultipartEntityBuilder build
public HttpEntity build()
From source file:io.swagger.client.api.DefaultApi.java
/** * Movie sync availability/*w w w.j a v a2 s . co m*/ * Checks whether a list of client movie identifiers (Video On Demand) are available to be synchronized using the Dive API * @param authorization Authorization token ('Bearer <token>') * @param clientMovieIdList List of client movie IDs, provided as a comma separated list * @param acceptLanguage Client locale, as <language>-<country> * @param contentType application/json * @return List<MovieStatus> */ public List<MovieStatus> getReadyMovies(String authorization, List<String> clientMovieIdList, String acceptLanguage, String contentType) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'authorization' is set if (authorization == null) { throw new ApiException(400, "Missing the required parameter 'authorization' when calling getReadyMovies"); } // verify the required parameter 'clientMovieIdList' is set if (clientMovieIdList == null) { throw new ApiException(400, "Missing the required parameter 'clientMovieIdList' when calling getReadyMovies"); } // create path and map variables String localVarPath = "/movies/{client_movie_id_list}/ready".replaceAll("\\{format\\}", "json").replaceAll( "\\{" + "client_movie_id_list" + "\\}", apiInvoker.escapeString(clientMovieIdList.toString())); // query params List<Pair> localVarQueryParams = new ArrayList<Pair>(); // header params Map<String, String> localVarHeaderParams = new HashMap<String, String>(); // form params Map<String, String> localVarFormParams = new HashMap<String, String>(); localVarHeaderParams.put("Authorization", ApiInvoker.parameterToString(authorization)); localVarHeaderParams.put("Accept-Language", ApiInvoker.parameterToString(acceptLanguage)); localVarHeaderParams.put("Content-Type", ApiInvoker.parameterToString(contentType)); String[] localVarContentTypes = { "application/json" }; String localVarContentType = localVarContentTypes.length > 0 ? localVarContentTypes[0] : "application/json"; if (localVarContentType.startsWith("multipart/form-data")) { // file uploading MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create(); localVarPostBody = localVarBuilder.build(); } else { // normal form params } try { String localVarResponse = apiInvoker.invokeAPI(basePath, localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarContentType); if (localVarResponse != null) { return (List<MovieStatus>) ApiInvoker.deserialize(localVarResponse, "array", MovieStatus.class); } else { return null; } } catch (ApiException ex) { throw ex; } }
From source file:io.swagger.client.api.DefaultApi.java
/** * One-shot channel scene// w w w . ja va 2 s . c o m * Retrieves the list of cards related to the content currently being broadcasted in the provided channel * @param authorization Authorization token ('Bearer <token>') * @param channelId Client channel ID * @param acceptLanguage Client locale, as <language>-<country> * @param contentType application/json * @param relations Indicates if the received scene cards should contain the scene hierarchy (true) or be a flat list of the main scene items (false) * @param imageSize Size of the images returned in the response * @return List<Card> */ public List<Card> getStaticChannelScene(String authorization, String channelId, String acceptLanguage, String contentType, Boolean relations, String imageSize) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'authorization' is set if (authorization == null) { throw new ApiException(400, "Missing the required parameter 'authorization' when calling getStaticChannelScene"); } // verify the required parameter 'channelId' is set if (channelId == null) { throw new ApiException(400, "Missing the required parameter 'channelId' when calling getStaticChannelScene"); } // create path and map variables String localVarPath = "/channels/{channel_id}/static".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "channel_id" + "\\}", apiInvoker.escapeString(channelId.toString())); // query params List<Pair> localVarQueryParams = new ArrayList<Pair>(); // header params Map<String, String> localVarHeaderParams = new HashMap<String, String>(); // form params Map<String, String> localVarFormParams = new HashMap<String, String>(); localVarQueryParams.addAll(ApiInvoker.parameterToPairs("", "relations", relations)); localVarQueryParams.addAll(ApiInvoker.parameterToPairs("", "image_size", imageSize)); localVarHeaderParams.put("Authorization", ApiInvoker.parameterToString(authorization)); localVarHeaderParams.put("Accept-Language", ApiInvoker.parameterToString(acceptLanguage)); localVarHeaderParams.put("Content-Type", ApiInvoker.parameterToString(contentType)); String[] localVarContentTypes = { "application/json" }; String localVarContentType = localVarContentTypes.length > 0 ? localVarContentTypes[0] : "application/json"; if (localVarContentType.startsWith("multipart/form-data")) { // file uploading MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create(); localVarPostBody = localVarBuilder.build(); } else { // normal form params } try { String localVarResponse = apiInvoker.invokeAPI(basePath, localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarContentType); if (localVarResponse != null) { return (List<Card>) ApiInvoker.deserialize(localVarResponse, "array", Card.class); } else { return null; } } catch (ApiException ex) { throw ex; } }
From source file:com.ibm.sbt.services.client.Request.java
/** * Method to retrieve the request body./* w w w .j a v a 2 s. c o m*/ * @return The request body */ public Object getBody() { if (body != null) { return body; } if (!bodyParts.isEmpty()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); for (BodyPart bodyPart : bodyParts) { builder.addPart(bodyPart.getName(), bodyPart.getData()); } return builder.build(); } return null; }
From source file:io.swagger.client.api.DefaultApi.java
/** * Full card detail/*w w w. ja v a 2s. c o m*/ * Retrieves a full card detail, and optionally its relations to other cards * @param authorization Authorization token ('Bearer <token>') * @param cardId Provided card ID (value of the 'card_id' field) * @param version Provided card version (value of the 'version' field) * @param acceptLanguage Client locale, as <language>-<country> * @param contentType application/json * @param relations Indicates if the received scene cards should contain the scene hierarchy (true) or be a flat list of the main scene items (false) * @param imageSize Size of the images returned in the response * @return Card */ public Card getCardVersion(String authorization, String cardId, String version, String acceptLanguage, String contentType, Boolean relations, String imageSize) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'authorization' is set if (authorization == null) { throw new ApiException(400, "Missing the required parameter 'authorization' when calling getCardVersion"); } // verify the required parameter 'cardId' is set if (cardId == null) { throw new ApiException(400, "Missing the required parameter 'cardId' when calling getCardVersion"); } // verify the required parameter 'version' is set if (version == null) { throw new ApiException(400, "Missing the required parameter 'version' when calling getCardVersion"); } // create path and map variables String localVarPath = "/cards/{card_id}/versions/{version}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "card_id" + "\\}", apiInvoker.escapeString(cardId.toString())) .replaceAll("\\{" + "version" + "\\}", apiInvoker.escapeString(version.toString())); // query params List<Pair> localVarQueryParams = new ArrayList<Pair>(); // header params Map<String, String> localVarHeaderParams = new HashMap<String, String>(); // form params Map<String, String> localVarFormParams = new HashMap<String, String>(); localVarQueryParams.addAll(ApiInvoker.parameterToPairs("", "relations", relations)); localVarQueryParams.addAll(ApiInvoker.parameterToPairs("", "image_size", imageSize)); localVarHeaderParams.put("Authorization", ApiInvoker.parameterToString(authorization)); localVarHeaderParams.put("Accept-Language", ApiInvoker.parameterToString(acceptLanguage)); localVarHeaderParams.put("Content-Type", ApiInvoker.parameterToString(contentType)); String[] localVarContentTypes = { "application/json" }; String localVarContentType = localVarContentTypes.length > 0 ? localVarContentTypes[0] : "application/json"; if (localVarContentType.startsWith("multipart/form-data")) { // file uploading MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create(); localVarPostBody = localVarBuilder.build(); } else { // normal form params } try { String localVarResponse = apiInvoker.invokeAPI(basePath, localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarContentType); if (localVarResponse != null) { return (Card) ApiInvoker.deserialize(localVarResponse, "", Card.class); } else { return null; } } catch (ApiException ex) { throw ex; } }
From source file:io.swagger.client.api.DefaultApi.java
/** * One-shot movie scene/*w w w. j a v a 2 s . co m*/ * Retrieves the current list of cards related to the given movie scene * @param authorization Authorization token ('Bearer <token>') * @param clientMovieId Client movie ID being played * @param timestamp Current movie timestamp in seconds * @param acceptLanguage Client locale, as <language>-<country> * @param contentType application/json * @param relations Indicates if the received scene cards should contain the scene hierarchy (true) or be a flat list of the main scene items (false) * @param imageSize Size of the images returned in the response * @return List<Card> */ public List<Card> getStaticMovieScene(String authorization, String clientMovieId, Float timestamp, String acceptLanguage, String contentType, Boolean relations, String imageSize) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'authorization' is set if (authorization == null) { throw new ApiException(400, "Missing the required parameter 'authorization' when calling getStaticMovieScene"); } // verify the required parameter 'clientMovieId' is set if (clientMovieId == null) { throw new ApiException(400, "Missing the required parameter 'clientMovieId' when calling getStaticMovieScene"); } // verify the required parameter 'timestamp' is set if (timestamp == null) { throw new ApiException(400, "Missing the required parameter 'timestamp' when calling getStaticMovieScene"); } // create path and map variables String localVarPath = "/movies/{client_movie_id}/static/{timestamp}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "client_movie_id" + "\\}", apiInvoker.escapeString(clientMovieId.toString())) .replaceAll("\\{" + "timestamp" + "\\}", apiInvoker.escapeString(timestamp.toString())); // query params List<Pair> localVarQueryParams = new ArrayList<Pair>(); // header params Map<String, String> localVarHeaderParams = new HashMap<String, String>(); // form params Map<String, String> localVarFormParams = new HashMap<String, String>(); localVarQueryParams.addAll(ApiInvoker.parameterToPairs("", "relations", relations)); localVarQueryParams.addAll(ApiInvoker.parameterToPairs("", "image_size", imageSize)); localVarHeaderParams.put("Authorization", ApiInvoker.parameterToString(authorization)); localVarHeaderParams.put("Accept-Language", ApiInvoker.parameterToString(acceptLanguage)); localVarHeaderParams.put("Content-Type", ApiInvoker.parameterToString(contentType)); String[] localVarContentTypes = { "application/json" }; String localVarContentType = localVarContentTypes.length > 0 ? localVarContentTypes[0] : "application/json"; if (localVarContentType.startsWith("multipart/form-data")) { // file uploading MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create(); localVarPostBody = localVarBuilder.build(); } else { // normal form params } try { String localVarResponse = apiInvoker.invokeAPI(basePath, localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarContentType); if (localVarResponse != null) { return (List<Card>) ApiInvoker.deserialize(localVarResponse, "array", Card.class); } else { return null; } } catch (ApiException ex) { throw ex; } }
From source file:objective.taskboard.it.TemplateIT.java
private HttpResponse uploadTemplate(File file) throws URISyntaxException, IOException { FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); StringBody templateName = new StringBody(file.getName(), ContentType.MULTIPART_FORM_DATA); StringBody roles = new StringBody("Role", ContentType.MULTIPART_FORM_DATA); builder.addPart("file", fileBody); builder.addPart("name", templateName); builder.addPart("roles", roles); HttpEntity entity = builder.build(); HttpPost post = new HttpPost(); post.setURI(new URI("http://localhost:8900/api/templates")); post.setHeaders(session);//from ww w. ja v a 2 s . com post.setEntity(entity); return client.execute(post); }
From source file:org.apache.sling.scripting.sightly.it.SlingSpecificsSightlyIT.java
private void uploadFile(String fileName, String serverFileName, String url) throws IOException { HttpClient httpClient = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(launchpadURL + url); post.setHeader("Authorization", "Basic YWRtaW46YWRtaW4="); MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); InputStreamBody inputStreamBody = new InputStreamBody( this.getClass().getClassLoader().getResourceAsStream(fileName), ContentType.TEXT_PLAIN, fileName); entityBuilder.addPart(serverFileName, inputStreamBody); post.setEntity(entityBuilder.build()); httpClient.execute(post);/* w w w.ja va 2 s. co m*/ }
From source file:com.nridge.ds.solr.SolrConfigSet.java
/** * Uploads the Solr config set ZIP file into the search cluster. * * @see <a href="http://lucene.apache.org/solr/guide/7_6/configsets-api.html">Solr ConfigSets API</a> * @see <a href="https://www.baeldung.com/httpclient-post-http-request">Upload Binary File with HttpClient 4</a> * * @param aPathFileName Path file name of ZIP containing the configuration set. * @param aConfigSetName Config set name. * * @throws DSException Solr Data Source exception. */// w w w. ja v a2s . co m public void uploadZipFile(String aPathFileName, String aConfigSetName) throws DSException { Logger appLogger = mAppMgr.getLogger(this, "uploadZipFile"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); initialize(); String baseSolrURL = mSolrDS.getBaseURL(false); String solrURI = String.format("%s/admin/configs?action=UPLOAD&name=%s", baseSolrURL, aConfigSetName); File pathFile = new File(aPathFileName); CloseableHttpResponse httpResponse = null; HttpPost httpPost = new HttpPost(solrURI); MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); multipartEntityBuilder.addBinaryBody("file", pathFile, ContentType.APPLICATION_OCTET_STREAM, "file.zip"); HttpEntity httpEntity = multipartEntityBuilder.build(); httpPost.setEntity(httpEntity); CloseableHttpClient httpClient = HttpClients.createDefault(); try { httpResponse = httpClient.execute(httpPost); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); String msgStr = String.format("%s [%d]: %s", solrURI, statusCode, statusLine); appLogger.debug(msgStr); if (statusCode == HttpStatus.SC_OK) { httpEntity = httpResponse.getEntity(); EntityUtils.consume(httpEntity); } else { msgStr = String.format("%s [%d]: %s", solrURI, statusCode, statusLine); appLogger.error(msgStr); throw new DSException(msgStr); } } catch (IOException e) { String msgStr = String.format("%s: %s", solrURI, e.getMessage()); appLogger.error(msgStr, e); throw new DSException(msgStr); } finally { if (httpResponse != null) IO.closeQuietly(httpResponse); } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:ai.susi.server.ClientConnection.java
/** * POST request//from ww w . j av a 2 s .c o m * @param urlstring * @param map * @param useAuthentication * @throws ClientProtocolException * @throws IOException */ public ClientConnection(String urlstring, Map<String, byte[]> map, boolean useAuthentication) throws ClientProtocolException, IOException { this.httpClient = HttpClients.custom().useSystemProperties() .setConnectionManager(getConnctionManager(useAuthentication)) .setDefaultRequestConfig(defaultRequestConfig).build(); this.request = new HttpPost(urlstring); MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); for (Map.Entry<String, byte[]> entry : map.entrySet()) { entityBuilder.addBinaryBody(entry.getKey(), entry.getValue()); } ((HttpPost) this.request).setEntity(entityBuilder.build()); this.request.setHeader("User-Agent", USER_AGENT); this.init(); }