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


Java PutMethod.setRequestEntity方法代码示例

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


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

示例1: doPut

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public String doPut(String url, String charset, String jsonObj) {
    String resStr = null;
    HttpClient htpClient = new HttpClient();
    PutMethod putMethod = new PutMethod(url);
    putMethod.getParams().setParameter(
            HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
    try {
        putMethod.setRequestEntity(new StringRequestEntity(jsonObj,
                "application/json", charset));
        int statusCode = htpClient.executeMethod(putMethod);
        if (statusCode != HttpStatus.SC_OK) {
            log.error("Method failed: " + putMethod.getStatusLine());
            return null;
        }
        byte[] responseBody = putMethod.getResponseBody();
        resStr = new String(responseBody, charset);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        putMethod.releaseConnection();
    }
    return resStr;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:24,代码来源:HttpRequest.java

示例2: putBinary

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public HttpResponse putBinary(final RequestContext rq, final String scope, final int version, final String entityCollectionName,
            final Object entityId, final String relationCollectionName, final Object relationshipEntityId, final BinaryPayload payload,
            final Map<String, String> params) throws IOException
{
    RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
                relationshipEntityId, params);
    String url = endpoint.getUrl();

    PutMethod req = new PutMethod(url);
    if (payload != null)
    {
        BinaryRequestEntity requestEntity = new BinaryRequestEntity(payload.getFile(), payload.getMimeType(), payload.getCharset());
        req.setRequestEntity(requestEntity);
    }
    return submitRequest(req, rq);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:17,代码来源:PublicApiHttpClient.java

示例3: updateAccount

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateAccount() throws HttpException, IOException {
  System.out.println("Sent HTTP PUT request to update Account");
  File input = new File(testFolder + "Account.xml");
  PutMethod put =
      new PutMethod(cadURL + "/object/User?_type=xml&externalServiceType=FBMC&externalUsername=8x8webservice&externalPassword=E4qtjWZLYKre");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例4: updateCustomer

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateCustomer() throws HttpException, IOException {
  System.out.println("Sent HTTP PUT request to update Customer");
  File input = new File(testFolder + "Customer.xml");
  PutMethod put = new PutMethod(cadURL + "/object/customer?_type=xml");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + put.getURI());
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例5: updateContact

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateContact() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to createContact");
  File input = new File(testFolder + "Contact.xml");
  PutMethod put = new PutMethod(cadURL + "/object/oltp?_type=xml");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + put.getURI());
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例6: updateUser

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateUser() throws HttpException, IOException {

    File input = new File(testFolder + "User.xml");
    PutMethod put = new PutMethod(cadURL + "/object/user?_type=xml");
    put.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    put.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + put.getURI());
      int result = httpclient.executeMethod(put);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + put.getResponseBodyAsString());
    } finally {
      put.releaseConnection();
    }
  }
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例7: updateCase

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateCase() throws HttpException, IOException {

    File input = new File(testFolder + "Case.xml");
    PutMethod post = new PutMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例8: updateFollowup

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
private static void updateFollowup() throws HttpException, IOException {

    File input = new File(testFolder + "Followup.xml");
    PutMethod post = new PutMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
 
开发者ID:inbravo,项目名称:scribe,代码行数:18,代码来源:HTTPClient.java

示例9: doPut

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
/**
 * 处理Put请求
 * @param url
 * @param headers
 * @param object
 * @param property
 * @return
 */
public static JSONObject doPut(String url, Map<String, String> headers,String jsonString) {

	HttpClient httpClient = new HttpClient();
	
	PutMethod putMethod = new PutMethod(url);
	
	//设置header
	setHeaders(putMethod,headers);
	
	//设置put传递的json数据
	if(jsonString!=null&&!"".equals(jsonString)){
		putMethod.setRequestEntity(new ByteArrayRequestEntity(jsonString.getBytes()));
	}
	
	String responseStr = "";
	
	try {
		httpClient.executeMethod(putMethod);
		responseStr = putMethod.getResponseBodyAsString();
	} catch (Exception e) {
		log.error(e);
		responseStr="{status:0}";
	} 
	return JSONObject.parseObject(responseStr);
}
 
开发者ID:apicloudcom,项目名称:Java-sdk,代码行数:34,代码来源:HttpUtils.java

示例10: testBasicSecurityPutCall

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testBasicSecurityPutCall() throws IOException {
    final HttpClient c = loginWithCookie("rest-c-g-3", "A6B7C8");

    final GroupVO vo = new GroupVO();
    vo.setName("hello dont put");
    vo.setDescription("hello description dont put");
    vo.setMinParticipants(new Integer(-1));
    vo.setMaxParticipants(new Integer(-1));

    final String stringuifiedAuth = stringuified(vo);
    final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8");
    final String request = "/repo/courses/" + course.getResourceableId() + "/groups";
    final PutMethod method = createPut(request, MediaType.APPLICATION_JSON, true);
    method.setRequestEntity(entity);
    final int code = c.executeMethod(method);

    assertEquals(401, code);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:20,代码来源:CourseGroupMgmtITCase.java

示例11: testUploadFile

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testUploadFile() throws IOException, URISyntaxException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getNodeURI()).path("files").build();

    // create single page
    final URL fileUrl = RepositoryEntriesITCase.class.getResource("singlepage.html");
    assertNotNull(fileUrl);
    final File file = new File(fileUrl.toURI());

    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA);
    final Part[] parts = { new FilePart("file", file), new StringPart("filename", file.getName()) };
    method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
    final int code = c.executeMethod(method);
    assertEquals(code, 200);

    final OlatNamedContainerImpl folder = BCCourseNode.getNodeFolderContainer((BCCourseNode) bcNode, course1.getCourseEnvironment());
    final VFSItem item = folder.resolve(file.getName());
    assertNotNull(item);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:23,代码来源:CoursesFoldersITCase.java

示例12: executeUpdateObject

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
protected <T> String executeUpdateObject(final T newObject, final String uri,
        final Map<String, String> parameters) throws BigSwitchBcfApiException,
IllegalArgumentException{
    checkInvariants();

    PutMethod pm = (PutMethod)createMethod("put", uri, _port);

    setHttpHeader(pm);

    try {
        pm.setRequestEntity(new StringRequestEntity(gson.toJson(newObject), CONTENT_JSON, null));
    } catch (UnsupportedEncodingException e) {
        throw new BigSwitchBcfApiException("Failed to encode json request body", e);
    }

    executeMethod(pm);

    String hash = checkResponse(pm, "BigSwitch HTTP update failed: ");

    pm.releaseConnection();

    return hash;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:24,代码来源:BigSwitchBcfApi.java

示例13: saveStream

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
/**
 * Saves a stream into a file in the repository.
 * 
 * @param text
 *            Stream to be stored.
 * @param url
 *            URL to the file that will be created.
 */
public void saveStream(InputStream stream, String url) throws IOException {

	PutMethod putMethod = new PutMethod(url);

	putMethod.setRequestEntity(new InputStreamRequestEntity(stream));
	try {
		client.executeMethod(putMethod);
		putMethod.releaseConnection();

	} catch (IOException e) {
		throw new IOException(e);
	}
	finally { 
		stream.close();
		
	}

}
 
开发者ID:impactcentre,项目名称:iif-resultsrepository,代码行数:27,代码来源:DavHandler.java

示例14: testRetrieveTextFile

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testRetrieveTextFile() throws HttpException, IOException {
	DavHandler dav = new DavHandler(folders);

	InputStream stream = new ByteArrayInputStream("some text".getBytes());
	PutMethod putMethod = new PutMethod(
			"http://localhost:9002/parent/child/textToRetrieve.txt");
	putMethod.setRequestEntity(new InputStreamRequestEntity(stream));
	HttpClient client = new HttpClient();
	client.executeMethod(putMethod);
	stream.close();
	putMethod.releaseConnection();

	String retrieved = dav.retrieveTextFile("http://localhost:9002/parent/child/textToRetrieve.txt");
	assertEquals("some text", retrieved);
}
 
开发者ID:impactcentre,项目名称:iif-resultsrepository,代码行数:17,代码来源:DavHandlerTest.java

示例15: put

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public HttpResponse put(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId, final String body)
            throws IOException
{
    RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, null);
    String url = endpoint.getUrl();

    PutMethod req = new PutMethod(url);
    if (body != null)
    {
        StringRequestEntity requestEntity = new StringRequestEntity(body, "application/json", "UTF-8");
        req.setRequestEntity(requestEntity);
    }
    return submitRequest(req, rq);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:15,代码来源:PublicApiHttpClient.java


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