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


Java PutMethod类代码示例

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


PutMethod类属于org.apache.commons.httpclient.methods包,在下文中一共展示了PutMethod类的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: createHttpMethod

import org.apache.commons.httpclient.methods.PutMethod; //导入依赖的package包/类
/**
 * Factory method to create a {@link HttpMethod}-object according to the 
 * given String <code>httpMethod</codde>
 * 
 * @param httpMethodString the name of the {@link HttpMethod} to create
 * @param url
 * 
 * @return an object of type {@link GetMethod}, {@link PutMethod}, 
 * {@link PostMethod} or {@link DeleteMethod}
 * @throws IllegalArgumentException if <code>httpMethod</code> is none of
 * <code>GET</code>, <code>PUT</code>, <code>POST</POST> or <code>DELETE</code>
 */
public static HttpMethod createHttpMethod(String httpMethodString, String url) {
	
	if ("GET".equals(httpMethodString)) {
		return new GetMethod(url);
	}
	else if ("PUT".equals(httpMethodString)) {
        return new PutMethod(url);
	}
	else if ("POST".equals(httpMethodString)) {
        return new PostMethod(url);
	}
	else if ("DELETE".equals(httpMethodString)) {
        return new DeleteMethod(url);
	}
	else {
		throw new IllegalArgumentException("given httpMethod '" + httpMethodString + "' is unknown");
	}
}
 
开发者ID:Neulinet,项目名称:Zoo,代码行数:31,代码来源:HttpUtil.java

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

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

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

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

示例14: testAddAuthor

import org.apache.commons.httpclient.methods.PutMethod; //导入依赖的package包/类
@Test
public void testAddAuthor() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");
    final String uri = "/repo/courses/" + course1.getResourceableId() + "/authors/" + auth0.getKey();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);

    // is auth0 author
    final SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    final boolean isAuthor = securityManager.isIdentityInSecurityGroup(auth0, authorGroup);
    DBFactory.getInstance().intermediateCommit();
    assertTrue(isAuthor);

    // is auth0 owner
    final RepositoryService rm = RepositoryServiceImpl.getInstance();
    final RepositoryEntry repositoryEntry = rm.lookupRepositoryEntry(course1, true);
    final SecurityGroup ownerGroup = repositoryEntry.getOwnerGroup();
    final boolean isOwner = securityManager.isIdentityInSecurityGroup(auth0, ownerGroup);
    DBFactory.getInstance().intermediateCommit();
    assertTrue(isOwner);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:23,代码来源:CourseITCase.java

示例15: testCreateEmptyCourse

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

    final URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").queryParam("shortTitle", "course3").queryParam("title", "course3 long name")
            .build();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);

    final int code = c.executeMethod(method);
    assertEquals(code, 200);
    final String body = method.getResponseBodyAsString();
    final CourseVO course = parse(body, CourseVO.class);
    assertNotNull(course);
    assertEquals("course3", course.getTitle());
    // check repository entry
    final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(course.getRepoEntryKey());
    assertNotNull(re);
    assertNotNull(re.getOlatResource());
    assertNotNull(re.getOwnerGroup());
}
 
开发者ID:huihoo,项目名称:olat,代码行数:21,代码来源:CoursesITCase.java


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