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


Java EntityBuilder.create方法代码示例

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


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

示例1: testCreateSuspect

import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
public void testCreateSuspect() throws IOException {
       CloseableHttpClient httpclient = HttpClients.createDefault();
       StringBuilder url = new StringBuilder(BASE_URL);
	url.append("suspect/");
	HttpPost httpPost = new HttpPost(url.toString());
	
       EntityBuilder entityBuilder = EntityBuilder.create();
       entityBuilder.setContentType(ContentType.APPLICATION_JSON);

	Suspect aaron = createMockSuspect("982c4a67-bb39-41f9-9872-88356822b7ad", "Aaron");
	JsonHelper jsonHelper = new JsonHelper();
	String jsonRequest = jsonHelper.convertToJson(aaron);
	
       entityBuilder.setText(jsonRequest);
       httpPost.setEntity(entityBuilder.build());
       CloseableHttpResponse response = httpclient.execute(httpPost);
	Assert.assertTrue(true);
}
 
开发者ID:CDCA-C5ISR-Summit-Code-a-Thon-2013,项目名称:Works-on-My-Box,代码行数:19,代码来源:SuspectTest.java

示例2: sendFilePostRequest

import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
/**
     * Executes FILE (binary) HTTP POST request based on configuration
     * 
     * @param config
     *            DPU configuration
     * @param client
     *            HTTP client used to execute request
     * @return HTTP response
     * @throws Exception
     *             if request execution fails
     */
    public CloseableHttpResponse sendFilePostRequest(HttpRequestConfig_V1 config, File file, CloseableHttpClient client) throws Exception {
        CloseableHttpResponse response = null;
        try {
            URIBuilder uriBuilder = new URIBuilder(config.getRequestURL());
            uriBuilder.setPath(uriBuilder.getPath());

            HttpPost request = new HttpPost(uriBuilder.build().normalize());
//            if (rdfConfig.isUseAuthentication()) {
//                addBasiAuthenticationForHttpRequest(request, rdfConfig.getUserName(), rdfConfig.getPassword());
//            }

            EntityBuilder builder = EntityBuilder.create();
            builder.setContentEncoding(config.getCharset());

            //ContentType contentType = ContentType.DEFAULT_BINARY;
            ContentType contentType = ContentType.create(config.getContentType().getDescription()).withCharset(config.getCharset());
            builder.setFile(file);
            builder.setContentType(contentType);

            HttpEntity entity = builder.build();
            request.setEntity(entity);
            request.addHeader("Content-Type", contentType.toString());

            LOG.info("Request: {}", request.toString());

            response = this.httpWrapper.getClient().execute(this.httpWrapper.getHost(), request, this.httpWrapper.getContext());
            //response = client.execute(request);
            checkHttpResponseStatus(response);

        } catch (URISyntaxException | IllegalStateException | IOException ex) {
            String errorMsg = String.format("Failed to execute HTTP file POST request to URL %s", config.getRequestURL());
            LOG.error(errorMsg, ex);
            throw new Exception(errorMsg, ex);
        }
        return response;

    }
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:49,代码来源:HttpRequestExecutor.java

示例3: sendFilePutRequest

import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
/**
     * Executes FILE (binary) HTTP PUT request based on configuration
     *
     * @param config
     *            DPU configuration
     * @param client
     *            HTTP client used to execute request
     * @return HTTP response
     * @throws Exception
     *             if request execution fails
     */
    public CloseableHttpResponse sendFilePutRequest(HttpRequestConfig_V1 config, File file, CloseableHttpClient client) throws Exception {
        CloseableHttpResponse response = null;
        try {
            URIBuilder uriBuilder = new URIBuilder(config.getRequestURL());
            uriBuilder.setPath(uriBuilder.getPath());

            HttpPut request = new HttpPut(uriBuilder.build().normalize());
//            if (rdfConfig.isUseAuthentication()) {
//                addBasiAuthenticationForHttpRequest(request, rdfConfig.getUserName(), rdfConfig.getPassword());
//            }

            EntityBuilder builder = EntityBuilder.create();
            builder.setContentEncoding(config.getCharset());

            //ContentType contentType = ContentType.DEFAULT_BINARY;
            ContentType contentType = ContentType.create(config.getContentType().getDescription()).withCharset(config.getCharset());
            builder.setFile(file);
            builder.setContentType(contentType);

            HttpEntity entity = builder.build();
            request.setEntity(entity);
            request.addHeader("Content-Type", contentType.toString());

            LOG.info("Request: {}", request.toString());

            response = this.httpWrapper.getClient().execute(this.httpWrapper.getHost(), request, this.httpWrapper.getContext());
            //response = client.execute(request);
            checkHttpResponseStatus(response);

        } catch (URISyntaxException | IllegalStateException | IOException ex) {
            String errorMsg = String.format("Failed to execute HTTP file PUT request to URL %s", config.getRequestURL());
            LOG.error(errorMsg, ex);
            throw new Exception(errorMsg, ex);
        }
        return response;

    }
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:49,代码来源:HttpRequestExecutor.java

示例4: sendRawDataPostRequest

import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
/**
     * Executes RAW data (text data) HTTP POST request based on configuration
     * 
     * @param config
     *            DPU configuration
     * @param client
     *            HTTP client used to execute request
     * @return HTTP response
     * @throws Exception
     *             if request execution fails
     */
    public CloseableHttpResponse sendRawDataPostRequest(HttpRequestConfig_V1 config, CloseableHttpClient client) throws Exception {
        CloseableHttpResponse response = null;
        try {
            URIBuilder uriBuilder = new URIBuilder(config.getRequestURL());
            uriBuilder.setPath(uriBuilder.getPath());

            HttpPost request = new HttpPost(uriBuilder.build().normalize());
//            if (rdfConfig.isUseAuthentication()) {
//                addBasiAuthenticationForHttpRequest(request, rdfConfig.getUserName(), rdfConfig.getPassword());
//            }

            EntityBuilder builder = EntityBuilder.create();
            builder.setContentEncoding(config.getCharset());

            ContentType contentType = ContentType.create(config.getContentType().getDescription()).withCharset(config.getCharset());
            builder.setText(config.getRawRequestBody());
            builder.setContentType(contentType);

            HttpEntity entity = builder.build();
            request.setEntity(entity);
            request.addHeader("Content-Type", contentType.toString());

            response = this.httpWrapper.getClient().execute(this.httpWrapper.getHost(), request, this.httpWrapper.getContext());
//            response = client.execute(request);
            checkHttpResponseStatus(response);

        } catch (URISyntaxException | IllegalStateException | IOException ex) {
            String errorMsg = String.format("Failed to execute HTTP raw POST request to URL %s", config.getRequestURL());
            LOG.error(errorMsg);
            throw new Exception(errorMsg, ex);
        }
        return response;
    }
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:45,代码来源:HttpRequestExecutor.java

示例5: sendRawDataPutRequest

import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
/**
     * Executes RAW data (text data) HTTP PUT request based on configuration
     *
     * @param config
     *            DPU configuration
     * @param client
     *            HTTP client used to execute request
     * @return HTTP response
     * @throws Exception
     *             if request execution fails
     */
    public CloseableHttpResponse sendRawDataPutRequest(HttpRequestConfig_V1 config, CloseableHttpClient client) throws Exception {
        CloseableHttpResponse response = null;
        try {
            URIBuilder uriBuilder = new URIBuilder(config.getRequestURL());
            uriBuilder.setPath(uriBuilder.getPath());

            HttpPut request = new HttpPut(uriBuilder.build().normalize());
//            if (rdfConfig.isUseAuthentication()) {
//                addBasiAuthenticationForHttpRequest(request, rdfConfig.getUserName(), rdfConfig.getPassword());
//            }

            EntityBuilder builder = EntityBuilder.create();
            builder.setContentEncoding(config.getCharset());

            ContentType contentType = ContentType.create(config.getContentType().getDescription()).withCharset(config.getCharset());
            builder.setText(config.getRawRequestBody());
            builder.setContentType(contentType);

            HttpEntity entity = builder.build();
            request.setEntity(entity);
            request.addHeader("Content-Type", contentType.toString());

            response = this.httpWrapper.getClient().execute(this.httpWrapper.getHost(), request, this.httpWrapper.getContext());
//            response = client.execute(request);
            checkHttpResponseStatus(response);

        } catch (URISyntaxException | IllegalStateException | IOException ex) {
            String errorMsg = String.format("Failed to execute HTTP raw PUT request to URL %s", config.getRequestURL());
            LOG.error(errorMsg);
            throw new Exception(errorMsg, ex);
        }
        return response;
    }
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:45,代码来源:HttpRequestExecutor.java

示例6: communicate

import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
@Override
public void communicate() {
	final String url = "https://www.googleapis.com/urlshortener/v1/url?key=%s";

	InputStream resstream = null;
	JsonReader jsonReader1 = null;
	try {
		setCurrent();
		// create the get request.
		final HttpPost httppost = new HttpPost(String.format(url, this.key));
		final EntityBuilder builder = EntityBuilder.create();

		final String reqjson = Client.gson.toJson(new GooglRequest(this.shortreq.getLongURL()));
		builder.setContentType(ContentType.APPLICATION_JSON);
		builder.setText(reqjson);
		httppost.setEntity(builder.build());

		// execute request
		final HttpResponse response = Downloader.downloader.client.execute(httppost);

		if (response.getStatusLine().getStatusCode()==HttpStatus.SC_OK) {
			final HttpEntity resEntity = response.getEntity();
			if (resEntity!=null) {
				resstream = resEntity.getContent();
				this.result = Client.gson.<GooglResult> fromJson(jsonReader1 = new JsonReader(new InputStreamReader(resstream, Charsets.UTF_8)), GooglResult.class);
				onDone(new CommunicateResponse(true, null));
				return;
			}
		} else {
			onDone(new CommunicateResponse(false, new IOException("Bad Response")));
			return;
		}
	} catch (final Exception e) {
		onDone(new CommunicateResponse(false, e));
		return;
	} finally {
		unsetCurrent();
		IOUtils.closeQuietly(resstream);
		IOUtils.closeQuietly(jsonReader1);
	}
	onDone(new CommunicateResponse(false, null));
	return;
}
 
开发者ID:Team-Fruit,项目名称:SignPicture,代码行数:44,代码来源:GooglShortener.java

示例7: postDocument

import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
public static String postDocument(String baseUrl, String receiverAddress, String externalId, UrkundSubmission submission, String urkundUsername, String urkundPassword, int timeout){
		String ret = null;
		
		RequestConfig.Builder requestBuilder = RequestConfig.custom();
		requestBuilder = requestBuilder.setConnectTimeout(timeout);
		requestBuilder = requestBuilder.setConnectionRequestTimeout(timeout);
		
		HttpClientBuilder builder = HttpClientBuilder.create();     
		builder.setDefaultRequestConfig(requestBuilder.build());
		try (CloseableHttpClient httpClient = builder.build()) {
			
			
			HttpPost httppost = new HttpPost(baseUrl+"submissions/"+receiverAddress+"/"+externalId);
			//------------------------------------------------------------
			EntityBuilder eBuilder = EntityBuilder.create();
			eBuilder.setBinary(submission.getContent());

			httppost.setEntity(eBuilder.build());
			//------------------------------------------------------------
			if(StringUtils.isNotBlank(urkundUsername) && StringUtils.isNotBlank(urkundPassword)) {
				addAuthorization(httppost, urkundUsername, urkundPassword);
			}
			//------------------------------------------------------------
			httppost.addHeader("Accept", "application/json");
			httppost.addHeader("Content-Type", submission.getMimeType());
			httppost.addHeader("Accept-Language", submission.getLanguage());
			httppost.addHeader("x-urkund-filename", submission.getFilenameEncoded());
			httppost.addHeader("x-urkund-submitter", submission.getSubmitterEmail());
			httppost.addHeader("x-urkund-anonymous", Boolean.toString(submission.isAnon()));
			httppost.addHeader("x-urkund-subject", submission.getSubject());
			httppost.addHeader("x-urkund-message", submission.getMessage());
			//------------------------------------------------------------

			HttpResponse response = httpClient.execute(httppost);
			HttpEntity resEntity = response.getEntity();

			if (resEntity != null) {
				ret = EntityUtils.toString(resEntity);
				EntityUtils.consume(resEntity);
			}

		} catch (IOException e) {
			log.error("ERROR uploading File : ", e);
		}
		
		
		return ret;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:49,代码来源:UrkundAPIUtil.java


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