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


Java MultipartEntityBuilder.create方法代码示例

本文整理汇总了Java中org.apache.http.entity.mime.MultipartEntityBuilder.create方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartEntityBuilder.create方法的具体用法?Java MultipartEntityBuilder.create怎么用?Java MultipartEntityBuilder.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.entity.mime.MultipartEntityBuilder的用法示例。


在下文中一共展示了MultipartEntityBuilder.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHttpEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
public HttpEntity getHttpEntity() {
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();

  if (url != null)
    builder.addTextBody(URL_FIELD, url);

  if (certificate != null)
    builder.addBinaryBody(CERTIFICATE_FIELD, new File(certificate));

  if (maxConnections != null)
    builder.addTextBody(MAX_CONNECTIONS_FIELD, maxConnections.toString());

  if (allowedUpdates != null) {
    if (allowedUpdates.length == 0) {
      builder.addTextBody(ALLOWED_UPDATES_FIELD, "[]");
    } else {
      for (String allowedUpdate : allowedUpdates) {
        builder.addTextBody(ALLOWED_UPDATES_FIELD + "[]", allowedUpdate);
      }
    }
  }

  return builder.build();
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:26,代码来源:SetWebhook.java

示例2: initRequest

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
public HttpPost initRequest(final FileUploadParameter parameter) {
	final FileUploadAddress fileUploadAddress = getDependResult(FileUploadAddress.class);
	final HttpPost request = new HttpPost("http://" + fileUploadAddress.getData().getUp() + CONST.URI_PATH);
	final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
	multipartEntity.setCharset(Consts.UTF_8);
	multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
	multipartEntity.addPart(CONST.QID_NAME, new StringBody(getLoginInfo().getQid(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("ofmt", new StringBody("json", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("method", new StringBody("Upload.web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("token", new StringBody(readCookieStoreValue("token"), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("v", new StringBody("1.0.1", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("tk", new StringBody(fileUploadAddress.getData().getTk(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Upload", new StringBody("Submit Query", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("devtype", new StringBody("web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("pid", new StringBody("ajax", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Filename",
			new StringBody(parameter.getUploadFile().getName(), ContentType.APPLICATION_JSON));
	multipartEntity.addPart("path", new StringBody(parameter.getPath(), ContentType.APPLICATION_JSON));// 解决中文不识别问题
	multipartEntity.addBinaryBody("file", parameter.getUploadFile());
	request.setEntity(multipartEntity.build());
	return request;
}
 
开发者ID:dounine,项目名称:clouddisk,代码行数:23,代码来源:FileUploadParser.java

示例3: deployBPMNPackage

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * This Method is used to deploy BPMN packages to the BPMN Server
 *
 * @param fileName The name of the Package to be deployed
 * @param filePath The location of the BPMN package to be deployed
 * @throws java.io.IOException
 * @throws org.json.JSONException
 * @returns String array with status, deploymentID and Name
 */
public String[] deployBPMNPackage(String filePath, String fileName)
        throws RestClientException, IOException, JSONException {
    String url = serviceURL + "repository/deployments";
    DefaultHttpClient httpClient = getHttpClient();
    HttpPost httpPost = new HttpPost(url);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addBinaryBody("file", new File(filePath),
                          ContentType.MULTIPART_FORM_DATA, fileName);
    HttpEntity multipart = builder.build();
    httpPost.setEntity(multipart);
    HttpResponse response = httpClient.execute(httpPost);
    String status = response.getStatusLine().toString();
    String responseData = EntityUtils.toString(response.getEntity());
    JSONObject jsonResponseObject = new JSONObject(responseData);
    if (status.contains(Integer.toString(HttpStatus.SC_CREATED)) || status.contains(Integer.toString(HttpStatus.SC_OK))) {
        String deploymentID = jsonResponseObject.getString(ID);
        String name = jsonResponseObject.getString(NAME);
        return new String[]{status, deploymentID, name};
    } else if (status.contains(Integer.toString(HttpStatus.SC_INTERNAL_SERVER_ERROR))) {
        String errorMessage = jsonResponseObject.getString("errorMessage");
        throw new RestClientException(errorMessage);
    } else {
        throw new RestClientException("Failed to deploy package " + fileName);
    }
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:35,代码来源:ActivitiRestClient.java

示例4: ClientConnection

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * POST request
 * @param urlstring
 * @param map
 * @param useAuthentication
 * @throws ClientProtocolException 
 * @throws IOException
 */
public ClientConnection(String urlstring, Map<String, byte[]> map, boolean useAuthentication) throws ClientProtocolException, IOException {
    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", ClientIdentification.getAgent(ClientIdentification.yacyInternetCrawlerAgentName).userAgent);
    this.init();
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:20,代码来源:ClientConnection.java

示例5: getHttpEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
public HttpEntity getHttpEntity() {
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();

  if(chatId != null)
      builder.addTextBody(CHAT_ID_FIELD, chatId);

  if(photo != null)
      builder.addBinaryBody(PHOTO_FIELD, photo, ContentType.APPLICATION_OCTET_STREAM, fileName);

  return builder.build();
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:13,代码来源:SetChatPhoto.java

示例6: createFileEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private HttpEntity createFileEntity(Object files) {
	MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	for (Entry<String, Object> entry : ((Map<String, Object>) files).entrySet()) {
		if (new File(entry.getValue().toString()).exists()) {
			builder.addPart(entry.getKey(),
					new FileBody(new File(entry.getValue().toString()), ContentType.DEFAULT_BINARY));
		} else {
			builder.addPart(entry.getKey(), new StringBody(entry.getValue().toString(), ContentType.DEFAULT_TEXT));
		}
	}
	return builder.build();
}
 
开发者ID:Hi-Fi,项目名称:httpclient,代码行数:14,代码来源:RestClient.java

示例7: executeHttpPost

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * Performs HTTP Post request with OAuth authentication for the endpoint
 * with the given path, with the given binary bodies as payload. Uses
 * multipart/mixed content type.
 * 
 * @param path
 *            the path to be called.
 * @param binaryBodies
 *            the payload.
 * @return the CloseableHttpResponse object.
 * @throws ClientProtocolException
 * @throws IOException
 */
CloseableHttpResponse executeHttpPost(String path, List<BinaryBody> binaryBodies)
		throws ClientProtocolException, IOException {
	logger.debug(DEBUG_EXECUTING_HTTP_POST_FOR_WITH_BINARY_BODIES, baseUri, path);

	HttpPost httpPost = createHttpPost(baseUri + path);
	httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MULTIPART_MIXED_BOUNDARY);

	MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();

	for (BinaryBody binaryBody : binaryBodies) {
		multipartEntityBuilder.addBinaryBody(binaryBody.getBinaryBodyName(), binaryBody.getFileStream(),
				ContentType.create(binaryBody.getMediaType()), binaryBody.getFileName());
	}

	HttpEntity httpEntity = multipartEntityBuilder.setBoundary(OpenApisEndpoint.BOUNDARY).build();
	httpPost.setEntity(httpEntity);

	CloseableHttpClient httpClient = HttpClients.createDefault();
	CloseableHttpResponse response = httpClient.execute(httpPost);

	logger.debug(DEBUG_EXECUTED_HTTP_POST_FOR_WITH_BINARY_BODIES, baseUri, path);
	return response;
}
 
开发者ID:SAP,项目名称:cloud-ariba-partner-flow-extension-ext,代码行数:37,代码来源:OpenApisEndpoint.java

示例8: sendFormToDLMS

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * * Send POST request to DLMS back end with the result file
 * @param bluemixToken - the Bluemix token
 * @param contents - the result file
 * @param jobUrl -  the build url of the build job in Jenkins
 * @param timestamp
 * @return - response/error message from DLMS
 */
public String sendFormToDLMS(String bluemixToken, FilePath contents, String lifecycleStage, String jobUrl, String timestamp) throws IOException {

    // create http client and post method
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPost postMethod = new HttpPost(this.dlmsUrl);

    postMethod = addProxyInformation(postMethod);
    // build up multi-part forms
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    if (contents != null) {

        File file = new File(root, contents.getName());
        FileBody fileBody = new FileBody(file);
        builder.addPart("contents", fileBody);


        builder.addTextBody("test_artifact", file.getName());
        if (this.isDeploy) {
            builder.addTextBody("environment_name", environmentName);
        }
        //Todo check the value of lifecycleStage
        builder.addTextBody("lifecycle_stage", lifecycleStage);
        builder.addTextBody("url", jobUrl);
        builder.addTextBody("timestamp", timestamp);

        String fileExt = FilenameUtils.getExtension(contents.getName());
        String contentType;
        switch (fileExt) {
            case "json":
                contentType = CONTENT_TYPE_JSON;
                break;
            case "xml":
                contentType = CONTENT_TYPE_XML;
                break;
            default:
                return "Error: " + contents.getName() + " is an invalid result file type";
        }

        builder.addTextBody("contents_type", contentType);
        HttpEntity entity = builder.build();
        postMethod.setEntity(entity);
        postMethod.setHeader("Authorization", bluemixToken);
    } else {
        return "Error: File is null";
    }


    CloseableHttpResponse response = null;
    try {
        response = httpClient.execute(postMethod);
        // parse the response json body to display detailed info
        String resStr = EntityUtils.toString(response.getEntity());
        JsonParser parser = new JsonParser();
        JsonElement element =  parser.parse(resStr);

        if (!element.isJsonObject()) {
            // 401 Forbidden
            return "Error: Upload is Forbidden, please check your org name. Error message: " + element.toString();
        } else {
            JsonObject resJson = element.getAsJsonObject();
            if (resJson != null && resJson.has("status")) {
                return String.valueOf(response.getStatusLine()) + "\n" + resJson.get("status");
            } else {
                // other cases
                return String.valueOf(response.getStatusLine());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw e;
    }
}
 
开发者ID:IBM,项目名称:ibm-cloud-devops,代码行数:82,代码来源:PublishTest.java

示例9: createMultipartEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * Create the required multipart entity
 * @param uploadId Session ID
 * @return Entity to submit to the upload
 * @throws ClientProtocolException
 * @throws IOException
 */
protected HttpEntity createMultipartEntity(String uploadId) throws ClientProtocolException, IOException {
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addTextBody("upload_id", uploadId);
    builder.addTextBody("_uuid", api.getUuid());
    builder.addTextBody("_csrftoken", api.getOrFetchCsrf());
    builder.addTextBody("media_type", "2");
    builder.setBoundary(api.getUuid());

    HttpEntity entity = builder.build();
    return entity;
}
 
开发者ID:brunocvcunha,项目名称:instagram4j,代码行数:19,代码来源:InstagramUploadVideoRequest.java

示例10: buildMultiPartEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * @param buildMap
 * @param partParam
 * 
 * @return HttpEntity
 */
public static HttpEntity buildMultiPartEntity(Map<String, String> buildMap, Map<String, ContentBody> partParam) {
	if (MapUtils.isEmpty(buildMap)) {
		return null;
	}
	MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	buildMap.forEach((k, v) -> builder.addTextBody(k, v));
	if (MapUtils.isNotEmpty(partParam)) {
		partParam.forEach((k, v) -> builder.addPart(k, v));	
	}
	return builder.build();
}
 
开发者ID:Zymr,项目名称:visitormanagement,代码行数:18,代码来源:HttpConnectorHelper.java

示例11: constructRequestBody

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
private void constructRequestBody() {

        // we have work to do here only when using multipart body
        if (requestBodyParts.size() > 0) {
            try {
                MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
                for (HttpBodyPart part : requestBodyParts) {
                    entityBuilder.addPart(part.getName(), part.constructContentBody());
                }
                requestBody = entityBuilder.build();
            } catch (Exception e) {
                throw new HttpException("Exception trying to create a multipart message.", e);
            }
        }
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:16,代码来源:HttpClient.java

示例12: createMultipartFormEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
public static HttpEntity createMultipartFormEntity(Map<String, String> parameters, InputStream is) {
	MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
	multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));

	multipartEntityBuilder.addBinaryBody("file", is, ContentType.create("application/octet-stream"), "file");
	for (Entry<String, String> entry : parameters.entrySet()) {
		multipartEntityBuilder.addTextBody(entry.getKey(), entry.getValue());
	}
	return multipartEntityBuilder.build();
}
 
开发者ID:Code4SocialGood,项目名称:c4sg-services,代码行数:11,代码来源:SlackUtils.java

示例13: createMultipartEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
 * Creates required multipart entity with the image binary
 * 
 * @return HttpEntity to send on the post
 * @throws ClientProtocolException
 * @throws IOException
 */
protected HttpEntity createMultipartEntity() throws ClientProtocolException, IOException {
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addBinaryBody("file", file);

    HttpEntity entity = builder.build();
    return entity;
}
 
开发者ID:brunocvcunha,项目名称:jiphy,代码行数:15,代码来源:JiphyUploadRequest.java

示例14: sendAndReceive

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
protected void sendAndReceive(final VxmlRequestTask task) {
	Timer timer = new Timer();
	Result result = new Result(parameters.getPrefix() + task.getKey());
	result.append("key", result.getKey());
	MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
	try {
		addBody(entityBuilder, task);
		Map<String, String> response = getResponse(parameters.getUri(), entityBuilder.build());
		record(result, task, response);
	} catch (Throwable t) {
		t.printStackTrace();
		String message = null;
		while (t != null && message == null) {
			message = t.getMessage();
			t = t.getCause();
		}
		
		result.append("exception", message);
		summary.getConditionCount("EXCEPTION").increment();
	} finally {
		result.append("time", String.valueOf(timer.getTime()));
		setRetry(result, task);
		synchronized (System.out) {
			summary.getCounter().increment();
			print(result);
		}
	}
}
 
开发者ID:Auraya,项目名称:armorvox-client,代码行数:29,代码来源:VxmlClient.java

示例15: sendFile

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
private String sendFile(String chat_id, File file, String type, String caption, boolean disable_notification,
		int reply_to_message_id, ReplyMarkup reply_markup, int duration, String performer, String title, int width,
		int height) throws IOException {

	MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
	builder.addPart("chat_id", new StringBody(chat_id, ContentType.DEFAULT_TEXT));
	if (caption != null)
		builder.addPart("caption", new StringBody(caption, ContentType.DEFAULT_TEXT));
	if (disable_notification != false)
		builder.addPart("disable_notification",
				new StringBody(Boolean.toString(disable_notification), ContentType.DEFAULT_TEXT));
	if (reply_to_message_id > 0)
		builder.addPart("reply_to_message_id",
				new StringBody(Integer.toString(reply_to_message_id), ContentType.DEFAULT_TEXT));
	if (reply_markup != null)
		builder.addPart("reply_markup",
				new StringBody(URLEncoder.encode(reply_markup.toJSONString(), "utf-8"), ContentType.DEFAULT_TEXT));
	if (duration > 0)
		builder.addPart("duration", new StringBody(Integer.toString(duration), ContentType.DEFAULT_TEXT));
	if (performer != null)
		builder.addPart("performer", new StringBody(performer, ContentType.DEFAULT_TEXT));
	if (title != null)
		builder.addPart("title", new StringBody(title, ContentType.DEFAULT_TEXT));
	if (width > 0)
		builder.addPart("width", new StringBody(Integer.toString(width), ContentType.DEFAULT_TEXT));
	if (height > 0)
		builder.addPart("height", new StringBody(Integer.toString(height), ContentType.DEFAULT_TEXT));
	builder.addPart(type, new FileBody(file, ContentType.DEFAULT_BINARY));
	HttpEntity entity = builder.build();
	HttpPost post = new HttpPost(url + "/send" + type);

	post.setEntity(entity);

	CloseableHttpClient httpclient = HttpClients.createMinimal();
	HttpResponse response = httpclient.execute(post);

	return response.toString();

}
 
开发者ID:leocus,项目名称:telegramBotUtilities,代码行数:41,代码来源:TelegramBot.java


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