本文整理汇总了Java中org.apache.commons.httpclient.methods.PutMethod.getResponseBodyAsString方法的典型用法代码示例。如果您正苦于以下问题:Java PutMethod.getResponseBodyAsString方法的具体用法?Java PutMethod.getResponseBodyAsString怎么用?Java PutMethod.getResponseBodyAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.PutMethod
的用法示例。
在下文中一共展示了PutMethod.getResponseBodyAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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());
}
示例3: 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);
}
示例4: testPutMethodServletSpecificRT
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
public void testPutMethodServletSpecificRT() throws Exception {
final PutMethod put = new PutMethod(testNodeRT.nodeUrl);
final int status = httpClient.executeMethod(put);
assertEquals("PUT to testNodeRT should return 200", 200, status);
final String content = put.getResponseBodyAsString();
assertServlet(content, PUT_SERVLET_SUFFIX);
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:8,代码来源:PutMethodServletTest.java
示例5: testPutCourseGroup
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testPutCourseGroup() throws IOException {
final HttpClient c = loginWithCookie("administrator", "olat");
final GroupVO vo = new GroupVO();
vo.setName("hello");
vo.setDescription("hello description");
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(200, code);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final GroupVO responseVo = parse(body, GroupVO.class);
assertNotNull(responseVo);
assertEquals(vo.getName(), responseVo.getName());
final BusinessGroup bg = businessGroupService.loadBusinessGroup(responseVo.getKey(), false);
assertNotNull(bg);
assertEquals(bg.getKey(), responseVo.getKey());
assertEquals(bg.getName(), vo.getName());
assertEquals(bg.getDescription(), vo.getDescription());
assertEquals(new Integer(0), bg.getMinParticipants());
assertEquals(new Integer(0), bg.getMaxParticipants());
}
示例6: testNewThread
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testNewThread() throws IOException {
final HttpClient c = loginWithCookie("administrator", "olat");
final URI uri = getForumUriBuilder().path("threads").queryParam("authorKey", id1.getKey()).queryParam("title", "New thread")
.queryParam("body", "A very interesting thread").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 MessageVO thread = parse(body, MessageVO.class);
assertNotNull(thread);
assertNotNull(thread.getKey());
assertEquals(thread.getForumKey(), forum.getKey());
assertEquals(thread.getAuthorKey(), id1.getKey());
// really saved?
boolean saved = false;
final ForumService fm = getForumService();
final List<Message> allMessages = fm.getMessagesByForum(forum);
for (final Message message : allMessages) {
if (message.getKey().equals(thread.getKey())) {
saved = true;
}
}
assertTrue(saved);
}
示例7: testImportTest
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testImportTest() throws HttpException, IOException, URISyntaxException {
final URL cpUrl = RepositoryEntriesITCase.class.getResource("qti-demo.zip");
assertNotNull(cpUrl);
final File cp = new File(cpUrl.toURI());
final HttpClient c = loginWithCookie("administrator", "olat");
final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA);
final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "qti-demo.zip"), new StringPart("resourcename", "QTI demo"),
new StringPart("displayname", "QTI demo") };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
final int code = c.executeMethod(method);
assertTrue(code == 200 || code == 201);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class);
assertNotNull(vo);
final Long key = vo.getKey();
final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key);
assertNotNull(re);
assertNotNull(re.getOwnerGroup());
assertNotNull(re.getOlatResource());
assertEquals("QTI demo", re.getDisplayname());
log.info(re.getOlatResource().getResourceableTypeName());
}
示例8: testImportQuestionnaire
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testImportQuestionnaire() throws HttpException, IOException, URISyntaxException {
final URL cpUrl = RepositoryEntriesITCase.class.getResource("questionnaire-demo.zip");
assertNotNull(cpUrl);
final File cp = new File(cpUrl.toURI());
final HttpClient c = loginWithCookie("administrator", "olat");
final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA);
final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "questionnaire-demo.zip"), new StringPart("resourcename", "Questionnaire demo"),
new StringPart("displayname", "Questionnaire demo") };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
final int code = c.executeMethod(method);
assertTrue(code == 200 || code == 201);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class);
assertNotNull(vo);
final Long key = vo.getKey();
final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key);
assertNotNull(re);
assertNotNull(re.getOwnerGroup());
assertNotNull(re.getOlatResource());
assertEquals("Questionnaire demo", re.getDisplayname());
log.info(re.getOlatResource().getResourceableTypeName());
}
示例9: testImportWiki
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testImportWiki() throws HttpException, IOException, URISyntaxException {
final URL cpUrl = RepositoryEntriesITCase.class.getResource("wiki-demo.zip");
assertNotNull(cpUrl);
final File cp = new File(cpUrl.toURI());
final HttpClient c = loginWithCookie("administrator", "olat");
final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA);
final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "wiki-demo.zip"), new StringPart("resourcename", "Wiki demo"),
new StringPart("displayname", "Wiki demo") };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
final int code = c.executeMethod(method);
assertTrue(code == 200 || code == 201);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class);
assertNotNull(vo);
final Long key = vo.getKey();
final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key);
assertNotNull(re);
assertNotNull(re.getOwnerGroup());
assertNotNull(re.getOlatResource());
assertEquals("Wiki demo", re.getDisplayname());
log.info(re.getOlatResource().getResourceableTypeName());
}
示例10: testPutCatalogEntryJson
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testPutCatalogEntryJson() throws IOException {
final RepositoryEntry re = createRepository("put-cat-entry-json", 6458438l);
final HttpClient c = loginWithCookie("administrator", "olat");
final CatalogEntryVO subEntry = new CatalogEntryVO();
subEntry.setName("Sub-entry-1");
subEntry.setDescription("Sub-entry-description-1");
subEntry.setType(CatalogEntry.TYPE_NODE);
subEntry.setRepositoryEntryKey(re.getKey());
final String entity = stringuified(subEntry);
final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.APPLICATION_JSON);
final RequestEntity requestEntity = new StringRequestEntity(entity, MediaType.APPLICATION_JSON, "UTF-8");
method.setRequestEntity(requestEntity);
final int code = c.executeMethod(method);
assertEquals(200, code);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final CatalogEntryVO vo = parse(body, CatalogEntryVO.class);
assertNotNull(vo);
final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
CatalogEntry ce = null;
for (final CatalogEntry child : children) {
if (vo.getKey().equals(child.getKey())) {
ce = child;
break;
}
}
assertNotNull(ce);
assertNotNull(ce.getRepositoryEntry());
assertEquals(re.getKey(), ce.getRepositoryEntry().getKey());
}
示例11: testCreateUser2
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
/**
* Test machine format for gender and date
*/
@Test
public void testCreateUser2() throws IOException {
final HttpClient c = loginWithCookie("administrator", "olat");
final UserVO vo = new UserVO();
final String username = UUID.randomUUID().toString();
vo.setLogin(username);
vo.setFirstName("John");
vo.setLastName("Smith");
vo.setEmail(username + "@frentix.com");
vo.putProperty("telOffice", "39847592");
vo.putProperty("telPrivate", "39847592");
vo.putProperty("telMobile", "39847592");
vo.putProperty("gender", "female");// male or female
vo.putProperty("birthDay", "20091212");
final String stringuifiedAuth = stringuified(vo);
final PutMethod method = createPut("/users", MediaType.APPLICATION_JSON, true);
final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8");
method.setRequestEntity(entity);
method.addRequestHeader("Accept-Language", "en");
final int code = c.executeMethod(method);
assertTrue(code == 200 || code == 201);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final UserVO savedVo = parse(body, UserVO.class);
final Identity savedIdent = securityManager.findIdentityByName(username);
assertNotNull(savedVo);
assertNotNull(savedIdent);
assertEquals(savedVo.getKey(), savedIdent.getKey());
assertEquals(savedVo.getLogin(), savedIdent.getName());
assertEquals("Female", userService.getUserProperty(savedIdent.getUser(), UserConstants.GENDER, Locale.ENGLISH));
assertEquals("39847592", userService.getUserProperty(savedIdent.getUser(), UserConstants.TELPRIVATE, Locale.ENGLISH));
assertEquals("12/12/09", userService.getUserProperty(savedIdent.getUser(), UserConstants.BIRTHDAY, Locale.ENGLISH));
}
示例12: testCreateUserWithValidationError
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testCreateUserWithValidationError() throws IOException {
final HttpClient c = loginWithCookie("administrator", "olat");
final UserVO vo = new UserVO();
vo.setLogin("rest-809");
vo.setFirstName("John");
vo.setLastName("Smith");
vo.setEmail("");
vo.putProperty("gender", "lu");
final String stringuifiedAuth = stringuified(vo);
final PutMethod method = createPut("/users", MediaType.APPLICATION_JSON, true);
final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8");
method.setRequestEntity(entity);
final int code = c.executeMethod(method);
assertTrue(code == 406);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final List<ErrorVO> errors = parseErrorArray(body);
assertNotNull(errors);
assertFalse(errors.isEmpty());
assertTrue(errors.size() >= 2);
assertNotNull(errors.get(0).getCode());
assertNotNull(errors.get(0).getTranslation());
assertNotNull(errors.get(1).getCode());
assertNotNull(errors.get(1).getTranslation());
final Identity savedIdent = securityManager.findIdentityByName("rest-809");
assertNull(savedIdent);
}
示例13: testPutCategoryJson
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testPutCategoryJson() throws IOException {
final HttpClient c = loginWithCookie("administrator", "olat");
final CatalogEntryVO subEntry = new CatalogEntryVO();
subEntry.setName("Sub-entry-1");
subEntry.setDescription("Sub-entry-description-1");
subEntry.setType(CatalogEntry.TYPE_NODE);
final String entity = stringuified(subEntry);
final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
method.addRequestHeader("Content-Type", MediaType.APPLICATION_JSON);
final RequestEntity requestEntity = new StringRequestEntity(entity, MediaType.APPLICATION_JSON, "UTF-8");
method.setRequestEntity(requestEntity);
final int code = c.executeMethod(method);
assertEquals(200, code);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final CatalogEntryVO vo = parse(body, CatalogEntryVO.class);
assertNotNull(vo);
final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
boolean saved = false;
for (final CatalogEntry child : children) {
if (vo.getKey().equals(child.getKey())) {
saved = true;
break;
}
}
assertTrue(saved);
}
示例14: testPutCategoryQuery
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testPutCategoryQuery() throws IOException {
final HttpClient c = loginWithCookie("administrator", "olat");
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", "Sub-entry-2"), new NameValuePair("description", "Sub-entry-description-2"),
new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)) });
final int code = c.executeMethod(method);
assertEquals(200, code);
final String body = method.getResponseBodyAsString();
method.releaseConnection();
final CatalogEntryVO vo = parse(body, CatalogEntryVO.class);
assertNotNull(vo);
final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
boolean saved = false;
for (final CatalogEntry child : children) {
if (vo.getKey().equals(child.getKey())) {
saved = true;
break;
}
}
assertTrue(saved);
}
示例15: testNewMessage
import org.apache.commons.httpclient.methods.PutMethod; //导入方法依赖的package包/类
@Test
public void testNewMessage() throws IOException {
final HttpClient c = loginWithCookie("administrator", "olat");
final URI uri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).queryParam("authorKey", id1.getKey()).queryParam("title", "New message")
.queryParam("body", "A very interesting response in Thread-1").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 MessageVO message = parse(body, MessageVO.class);
assertNotNull(message);
assertNotNull(message.getKey());
assertEquals(message.getForumKey(), forum.getKey());
assertEquals(message.getAuthorKey(), id1.getKey());
assertEquals(message.getParentKey(), m1.getKey());
// really saved?
boolean saved = false;
final ForumService fm = getForumService();
final List<Message> allMessages = fm.getMessagesByForum(forum);
for (final Message msg : allMessages) {
if (msg.getKey().equals(message.getKey())) {
saved = true;
}
}
assertTrue(saved);
}