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


Java HttpPut.setEntity方法代码示例

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


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

示例1: updateModule

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
/**
 * Updates the module
 *
 * @param moduleName
 *        the name of the module to add
 * @param objectToUpdate
 *        JSON containing the key/value pais to use for update
 * @return request object to check status codes and return values
 */
public Response updateModule( String moduleName, JSONObject objectToUpdate )
{
	HttpPut request = new HttpPut( this.yambasBase + "modules/" + moduleName );
	setAuthorizationHeader( request );
	request.addHeader( "x-apiomat-system", this.system.toString( ) );
	request.setEntity( new StringEntity( objectToUpdate.toString( ), ContentType.APPLICATION_JSON ) );

	try
	{
		final HttpResponse response = this.client.execute( request );
		return new Response( response );
	}
	catch ( final IOException e )
	{
		e.printStackTrace( );
	}
	return null;
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:28,代码来源:AomHttpClient.java

示例2: doPut

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
/**
 * Put String
 * @param host
 * @param path
 * @param method
 * @param headers
 * @param querys
 * @param body
 * @return
 * @throws Exception
 */
public static HttpResponse doPut(String host, String path, String method,
                                 Map<String, String> headers,
                                 Map<String, String> querys,
                                 String body)
        throws Exception {
    HttpClient httpClient = wrapClient(host);

    HttpPut request = new HttpPut(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
        request.addHeader(e.getKey(), e.getValue());
    }

    if (StringUtils.isNotBlank(body)) {
        request.setEntity(new StringEntity(body, "utf-8"));
    }

    return httpClient.execute(request);
}
 
开发者ID:JiaXiaohei,项目名称:elasticjob-stock-push,代码行数:30,代码来源:HttpUtils.java

示例3: setPathRangeIndexInDatabase

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
public static void setPathRangeIndexInDatabase(String dbName, JsonNode jnode) throws IOException
{
	try {			
		DefaultHttpClient client = new DefaultHttpClient();
		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));
		
			HttpPut put = new HttpPut("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
			put.addHeader("Content-type", "application/json");
			put.setEntity(new StringEntity(jnode.toString()));

			HttpResponse response = client.execute(put);
			HttpEntity respEntity = response.getEntity();
			if(respEntity != null){
				String content =  EntityUtils.toString(respEntity);
				System.out.println(content);
			}
		}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:24,代码来源:ConnectedRESTQA.java

示例4: manageWebhookURL

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
/**
 * Realiza a adição ou edição da URL que deve ser utilizada pelos webhooks da Conta Digital
 * @param url: URL à ser configurada como Webhook
 * @return boolean
 */
public boolean manageWebhookURL(String url) throws IOException, PJBankException {
    PJBankClient client = new PJBankClient(this.endPoint);
    HttpPut httpPut = client.getHttpPutClient();
    httpPut.addHeader("x-chave-conta", this.chave);

    JSONObject params = new JSONObject();
    params.put("webhook", url);

    httpPut.setEntity(new StringEntity(params.toString(), StandardCharsets.UTF_8));

    String response = EntityUtils.toString(client.doRequest(httpPut).getEntity());

    JSONObject responseObject = new JSONObject(response);

    return url.equals(responseObject.getString("webhook"));
}
 
开发者ID:pjbank,项目名称:pjbank-java-sdk,代码行数:22,代码来源:ContaDigitalManager.java

示例5: associateRESTServerWithDefaultUser

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
public static void associateRESTServerWithDefaultUser(String restServerName,String userName,String authType)throws Exception{
	DefaultHttpClient client = new DefaultHttpClient();

	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));
	String  body = "{ \"default-user\":\""+userName+"\",\"authentication\": \""+authType+"\",\"group-name\": \"Default\"}";

	HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http");
	put.addHeader("Content-type", "application/json");
	put.setEntity(new StringEntity(body));

	HttpResponse response2 = client.execute(put);
	HttpEntity respEntity = response2.getEntity();
	if(respEntity != null){
		String content =  EntityUtils.toString(respEntity);
		System.out.println(content);
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:20,代码来源:ConnectedRESTQA.java

示例6: setAuthentication

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
public static void setAuthentication(String level,String restServerName) throws ClientProtocolException, IOException
{
	DefaultHttpClient client = new DefaultHttpClient();

	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));
	String  body = "{\"authentication\": \""+level+"\"}";

	HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http&group-id=Default");
	put.addHeader("Content-type", "application/json");
	put.setEntity(new StringEntity(body));

	HttpResponse response2 = client.execute(put);
	HttpEntity respEntity = response2.getEntity();
	if(respEntity != null){
		String content =  EntityUtils.toString(respEntity);
		System.out.println(content);
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:21,代码来源:ConnectedRESTQA.java

示例7: deployApp

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
/**
 * Sets the app to active state
 *
 * @param customerName
 *        the name of the customer
 * @param appName
 *        the name of the app
 * @return request object to check status codes and return values
 */
public Response deployApp( String customerName, String appName )
{
	HttpPut request = new HttpPut( this.yambasBase + "customers/" + customerName + "/apps/" + appName );
	setAuthorizationHeader( request );
	request.addHeader( "ContentType", "application/json" );
	request.addHeader( "x-apiomat-system", this.system.toString( ) );
	try
	{
		final HttpEntity requestEntity = new StringEntity(
			"{\"applicationStatus\":{\"" + this.system + "\":\"ACTIVE\"}, \"applicationName\":\"" +
				appName + "\"}",
			ContentType.APPLICATION_JSON );
		request.setEntity( requestEntity );

		final HttpResponse response = this.client.execute( request );
		return new Response( response );
	}
	catch ( final IOException e )
	{
		e.printStackTrace( );
	}
	return null;
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:33,代码来源:AomHttpClient.java

示例8: doPut

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
/**
 * Put String
 *
 * @param host
 * @param path
 * @param method
 * @param headers
 * @param querys
 * @param body
 * @return
 * @throws Exception
 */
public static HttpResponse doPut(String host, String path, String method,
                                 Map<String, String> headers,
                                 Map<String, String> querys,
                                 String body)
        throws Exception {
    HttpClient httpClient = wrapClient(host);

    HttpPut request = new HttpPut(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
        request.addHeader(e.getKey(), e.getValue());
    }

    if (StringUtils.isNotBlank(body)) {
        request.setEntity(new StringEntity(body, "utf-8"));
    }

    return httpClient.execute(request);
}
 
开发者ID:JiaXiaohei,项目名称:elasticjob-oray-client,代码行数:31,代码来源:HttpUtils.java

示例9: put

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
/**
 * Send the request to the endpoint using a HTTP PUT.
 *
 * @return The response
 * @throws HttpException
 */
@PublicAtsApi
public HttpResponse put() throws HttpException {

    final URI uri = constructURI();
    HttpPut method = new HttpPut(uri);
    constructRequestBody();

    log.info("We will PUT object to " + uri);
    method.setEntity(requestBody);
    return execute(method);
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:18,代码来源:HttpClient.java

示例10: testUpdate

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
/**
 * update a wine
 * 
 * @param id
 *            wine id
 */
private void testUpdate(final int id) throws IOException {
	final HttpPut httpput = new HttpPut(BASE_URI + RESOURCE);
	httpput.setEntity(new StringEntity("{\"id\":" + id + ",\"name\":\"JU" + id + "\",\"grapes\":\"Grenache / Syrah\"," + "\"country\":\"France\","
			+ "\"region\":\"Southern Rhone / Gigondas\"," + "\"year\":2009,\"picture\":\"saint_cosme.jpg\","
			+ "\"description\":\"The aromas of fruit ...\"}", ContentType.APPLICATION_JSON));
	final HttpResponse response = HTTP_CLIENT.execute(httpput);
	Assert.assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:15,代码来源:CrudRestIT.java

示例11: putEntity

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
protected HttpResponse putEntity(String json, String uri, String token, boolean consume, Object... paramNameValues)
	throws IOException
{
	final HttpPut request = new HttpPut(appendQueryString(uri, queryString(paramNameValues)));
	final StringEntity ent = new StringEntity(json, "UTF-8");
	ent.setContentType("application/json");
	request.setEntity(ent);
	return execute(request, consume, token);
}
 
开发者ID:equella,项目名称:Equella,代码行数:10,代码来源:AbstractRestApiTest.java

示例12: upload

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
public void upload(LocalResource resource, URI destination) throws IOException {
    HttpPut method = new HttpPut(destination);
    final RepeatableInputStreamEntity entity = new RepeatableInputStreamEntity(resource, ContentType.APPLICATION_OCTET_STREAM);
    method.setEntity(entity);
    CloseableHttpResponse response = null;
    try {
        response = http.performHttpRequest(method);
        if (!http.wasSuccessful(response)) {
            throw new IOException(String.format("Could not PUT '%s'. Received status code %s from server: %s",
                destination, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
        }
    } finally {
        HttpClientUtils.closeQuietly(response);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:16,代码来源:HttpResourceUploader.java

示例13: store

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
@Override
public void store(BuildCacheKey key, final BuildCacheEntryWriter output) throws BuildCacheException {
    final URI uri = root.resolve(key.getHashCode());
    HttpPut httpPut = new HttpPut(uri);
    httpPut.setEntity(new AbstractHttpEntity() {
        @Override
        public boolean isRepeatable() {
            return true;
        }

        @Override
        public long getContentLength() {
            return -1;
        }

        @Override
        public InputStream getContent() throws IOException, UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void writeTo(OutputStream outstream) throws IOException {
            output.writeTo(outstream);
        }

        @Override
        public boolean isStreaming() {
            return false;
        }
    });
    CloseableHttpResponse response = null;
    try {
        response = httpClient.execute(httpPut);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Response for PUT {}: {}", safeUri(uri), response.getStatusLine());
        }
        // TODO: We should examine the status to make sure the PUT was successful
    } catch (IOException e) {
        // TODO: We should consider different types of exceptions as fatal/recoverable.
        // Right now, everything is considered recoverable.
        throw new BuildCacheException(String.format("storing key '%s' in %s", key, getDescription()), e);
    } finally {
        HttpClientUtils.closeQuietly(response);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:46,代码来源:HttpBuildCache.java

示例14: updateLesson

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
public static int updateLesson(@NotNull final Project project, @NotNull final Lesson lesson) {
  if(!checkIfAuthorized(project, "update lesson")) return -1;

  final HttpPut request = new HttpPut(EduStepicNames.STEPIC_API_URL + EduStepicNames.LESSONS + String.valueOf(lesson.getId()));

  String requestBody = new Gson().toJson(new StepicWrappers.LessonWrapper(lesson));
  request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

  try {
    final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
    if (client == null) return -1;
    final CloseableHttpResponse response = client.execute(request);
    final HttpEntity responseEntity = response.getEntity();
    final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
    final StatusLine line = response.getStatusLine();
    EntityUtils.consume(responseEntity);
    if (line.getStatusCode() != HttpStatus.SC_OK) {
      final String message = "Failed to update lesson ";
      LOG.error(message + responseString);
      showErrorNotification(project, message, responseString);
      return -1;
    }
    else {
      showNotification(project, "Lesson updated");
    }

    final Lesson postedLesson = new Gson().fromJson(responseString, RemoteCourse.class).getLessons().get(0);
    for (Integer step : postedLesson.steps) {
      deleteTask(step, project);
    }

    for (Task task : lesson.getTaskList()) {
      final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
      if (indicator != null) {
        indicator.checkCanceled();
      }
      postTask(project, task, lesson.getId());
    }
    return lesson.getId();
  }
  catch (IOException e) {
    LOG.error(e.getMessage());
  }
  return -1;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:46,代码来源:CCStepicConnector.java

示例15: put

import org.apache.http.client.methods.HttpPut; //导入方法依赖的package包/类
public <T> T put(URI uri, String body, Function<Reader, T> function) {
    HttpPut request = new HttpPut(uri);
    request.setEntity(new StringEntity(body, ContentType.APPLICATION_JSON));
    return execute(request, function);
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:6,代码来源:HttpClient.java


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