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


Java PutMethod.releaseConnection方法代码示例

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


在下文中一共展示了PutMethod.releaseConnection方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: testUpdateParagraphConfig

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testUpdateParagraphConfig() throws IOException {
  Note note = ZeppelinServer.notebook.createNote(anonymous);
  String noteId = note.getId();
  Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
  assertNull(p.getConfig().get("colWidth"));
  String paragraphId = p.getId();
  String jsonRequest = "{\"colWidth\": 6.0}";

  PutMethod put = httpPut("/notebook/" + noteId + "/paragraph/" + paragraphId +"/config", jsonRequest);
  assertThat("test testUpdateParagraphConfig:", put, isAllowed());

  Map<String, Object> resp = gson.fromJson(put.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
  }.getType());
  Map<String, Object> respBody = (Map<String, Object>) resp.get("body");
  Map<String, Object> config = (Map<String, Object>) respBody.get("config");
  put.releaseConnection();

  assertEquals(config.get("colWidth"), 6.0);
  note = ZeppelinServer.notebook.getNote(noteId);
  assertEquals(note.getParagraph(paragraphId).getConfig().get("colWidth"), 6.0);

  //cleanup
  ZeppelinServer.notebook.removeNote(noteId, anonymous);
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:26,代码来源:NotebookRestApiTest.java

示例9: testThatOtherUserCannotAccessNoteIfPermissionSet

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testThatOtherUserCannotAccessNoteIfPermissionSet() throws IOException {
  String noteId = createNoteForUser("test", "admin", "password1");
  
  //set permission
  String payload = "{ \"owners\": [\"admin\"], \"readers\": [\"user2\"], \"runners\": [\"user2\"], \"writers\": [\"user2\"] }";
  PutMethod put = httpPut("/notebook/" + noteId + "/permissions", payload , "admin", "password1");
  assertThat("test set note permission method:", put, isAllowed());
  put.releaseConnection();
  
  userTryGetNote(noteId, "user1", "password2", isForbidden());
  
  userTryGetNote(noteId, "user2", "password3", isAllowed());
  
  deleteNoteForUser(noteId, "admin", "password1");
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:17,代码来源:NotebookSecurityRestApiTest.java

示例10: testThatWriterCannotRemoveNote

import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testThatWriterCannotRemoveNote() throws IOException {
  String noteId = createNoteForUser("test", "admin", "password1");
  
  //set permission
  String payload = "{ \"owners\": [\"admin\", \"user1\"], \"readers\": [\"user2\"], \"runners\": [\"user2\"], \"writers\": [\"user2\"] }";
  PutMethod put = httpPut("/notebook/" + noteId + "/permissions", payload , "admin", "password1");
  assertThat("test set note permission method:", put, isAllowed());
  put.releaseConnection();
  
  userTryRemoveNote(noteId, "user2", "password3", isForbidden());
  userTryRemoveNote(noteId, "user1", "password2", isAllowed());
  
  Note deletedNote = ZeppelinServer.notebook.getNote(noteId);
  assertNull("Deleted note should be null", deletedNote);
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:17,代码来源:NotebookSecurityRestApiTest.java

示例11: testBareBoneConfig

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

    // create an contact node
    final URI newContactUri = getElementsUri(course1).path("contact").queryParam("parentNodeId", rootNodeId).queryParam("position", "0")
            .queryParam("shortTitle", "Contact-0").queryParam("longTitle", "Contact-long-0").queryParam("objectives", "Contact-objectives-0").build();
    final PutMethod method = createPut(newContactUri, MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    final String body = method.getResponseBodyAsString();
    method.releaseConnection();

    assertEquals(200, code);
    final CourseNodeVO contactNode = parse(body, CourseNodeVO.class);
    assertNotNull(contactNode);
    assertNotNull(contactNode.getId());
    assertEquals(contactNode.getShortTitle(), "Contact-0");
    assertEquals(contactNode.getLongTitle(), "Contact-long-0");
    assertEquals(contactNode.getLearningObjectives(), "Contact-objectives-0");
    assertEquals(contactNode.getParentId(), rootNodeId);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:22,代码来源:CoursesContactElementITCase.java

示例12: testBasicSecurityPutCall

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

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("name", "Not-sub-entry-3"), new NameValuePair("description", "Not-sub-entry-description-3"),
            new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)) });

    final int code = c.executeMethod(method);
    assertEquals(401, code);
    method.releaseConnection();

    final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
    boolean saved = false;
    for (final CatalogEntry child : children) {
        if ("Not-sub-entry-3".equals(child.getName())) {
            saved = true;
            break;
        }
    }

    assertFalse(saved);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:25,代码来源:CatalogITCase.java

示例13: 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

示例14: 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

示例15: 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


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