本文整理匯總了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;
}
示例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);
}
示例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();
}
}
示例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"));
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}