本文整理匯總了Java中org.apache.commons.httpclient.methods.GetMethod.getResponseBodyAsString方法的典型用法代碼示例。如果您正苦於以下問題:Java GetMethod.getResponseBodyAsString方法的具體用法?Java GetMethod.getResponseBodyAsString怎麽用?Java GetMethod.getResponseBodyAsString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.methods.GetMethod
的用法示例。
在下文中一共展示了GetMethod.getResponseBodyAsString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCreateNodeMultipart
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void testCreateNodeMultipart() throws IOException {
final String url = HTTP_BASE_URL + "/CreateNodeTest_2_" + System.currentTimeMillis();
// add some properties to the node
final Map<String,String> props = new HashMap<String,String>();
props.put("name1","value1B");
props.put("name2","value2B");
// POST and get URL of created node
String urlOfNewNode = null;
try {
urlOfNewNode = testClient.createNode(url, props, null, true);
} catch(IOException ioe) {
fail("createNode failed: " + ioe);
}
// check node contents (not all renderings - those are tested above)
final GetMethod get = new GetMethod(urlOfNewNode + DEFAULT_EXT);
final int status = httpClient.executeMethod(get);
assertEquals(urlOfNewNode + " must be accessible after createNode",200,status);
final String responseBodyStr = get.getResponseBodyAsString();
assertTrue(responseBodyStr.contains("value1B"));
assertTrue(responseBodyStr.contains("value2B"));
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:25,代碼來源:CreateNodeTest.java
示例2: testInfiniteLoopDetection
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
@Test
@Retry
public void testInfiniteLoopDetection() throws IOException {
// Node C has a property that causes an infinite include loop,
// Sling must indicate the problem in its response
final GetMethod get = new GetMethod(nodeUrlC + ".html");
H.getHttpClient().executeMethod(get);
final String content = get.getResponseBodyAsString();
assertTrue(
"Response contains infinite loop error message",
content.contains("org.apache.sling.api.request.RecursionTooDeepException"));
// TODO: SLING-515, status is 500 when running the tests as part of the maven build
// but 200 if running tests against a separate instance started with mvn jetty:run
// final int status = get.getStatusCode();
// assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:18,代碼來源:JspIncludeTest.java
示例3: testMaxCallsDetection
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
@Test
@Retry
public void testMaxCallsDetection() throws IOException {
// Node F has a property that causes over 1000 includes
// Sling must indicate the problem in its response
final GetMethod get = new GetMethod(nodeUrlF + ".html");
H.getHttpClient().executeMethod(get);
final String content = get.getResponseBodyAsString();
assertTrue(
"Response contains infinite loop error message",
content.contains("org.apache.sling.api.request.TooManyCallsException"));
// TODO: SLING-515, status is 500 when running the tests as part of the maven build
// but 200 if running tests against a separate instance started with mvn jetty:run
// final int status = get.getStatusCode();
// assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:18,代碼來源:JspIncludeTest.java
示例4: getAndSaveTranscript
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/**
* Fetches captions/transcript for a given video
* @param videoID to fetch
* @param lang this captions should be in
* @throws IOException
*/
public void getAndSaveTranscript(String videoID, String lang) throws IOException {
lang = LanguageCode.convertIso2toIso1(lang);
String url = captionEndPoint+"lang="+lang+"&v="+videoID;
GetMethod get = new GetMethod(url);
this.client.executeMethod(get);
String xmlData = get.getResponseBodyAsString();
//parse XML
Document doc = Jsoup.parse(xmlData, "", Parser.xmlParser());
String allCaps = "";
for (Element e : doc.select("text")) {
allCaps += e.text();
}
FileSaver file = new FileSaver(allCaps, lang, "youtube_caps", url, videoID);
file.save(logDb);
}
示例5: videoHasCaptionsInLanguage
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/**
* Checks if a given video has captions in our target language. As identified by the user who entered them
* @param videoID to check
* @param lang target
* @return true if there are captions in lang
* @throws IOException
*/
public boolean videoHasCaptionsInLanguage(String videoID, String lang) throws IOException {
//visit captions index
GetMethod get = new GetMethod(captionsIndex+videoID);
this.client.executeMethod(get);
String xmlData = get.getResponseBodyAsString();
//parse XML
Document doc = Jsoup.parse(xmlData, "", Parser.xmlParser());
//iterate over all captions
for (Element e : doc.select("track")) {
String langCode = e.attr("lang_code");
String fixedLangCode = LanguageCode.convertIso1toIso2(langCode);
if(fixedLangCode.equals(lang))
return true;
}
return false;
}
示例6: testOverwriteRequestHeader
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/**
* Test {@link HttpMethod#setRequestHeader}.
*/
public void testOverwriteRequestHeader() throws Exception {
this.server.setHttpService(new HeaderDumpService());
GetMethod method = new GetMethod("/");
method.setRequestHeader(new Header("xxx-a-header","one"));
method.setRequestHeader("XXX-A-HEADER","two");
try {
this.client.executeMethod(method);
String s = method.getResponseBodyAsString();
assertTrue(s.indexOf("name=\"xxx-a-header\";value=\"two\"") >= 0);
} finally {
method.releaseConnection();
}
}
示例7: checkUploadedFileState
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
private void checkUploadedFileState(String urlOfFileNode) throws IOException,
HttpException {
final GetMethod get = new GetMethod(urlOfFileNode);
final int status = httpClient.executeMethod(get);
assertEquals(urlOfFileNode + " must be accessible after createNode",200,status);
/*
We should check the data, but nt:resources are not handled yet
// compare data with local file (just length)
final byte[] data = get.getResponseBody();
assertEquals("size of file must be same", localFile.length(), data.length);
*/
String data = get.getResponseBodyAsString();
assertTrue("checking for content", data.contains("http://www.apache.org/licenses/LICENSE-2.0"));
// download structure
String json = getContent(urlOfFileNode + ".json", CONTENT_TYPE_JSON);
// just check for some strings
assertTrue("checking primary type", json.contains("\"jcr:primaryType\":\"nt:file\""));
String content_json = getContent(urlOfFileNode + "/jcr:content.json", CONTENT_TYPE_JSON);
// just check for some strings
assertTrue("checking primary type", content_json.contains("\"jcr:primaryType\":\"nt:resource\""));
assertTrue("checking mime type", content_json.contains("\"jcr:mimeType\":\"text/plain\""));
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:26,代碼來源:UploadFileTest.java
示例8: testEmptyBodyAsString
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/**
* Tests empty body response
*/
public void testEmptyBodyAsString() throws Exception {
this.server.setHttpService(new EmptyResponseService());
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
String response = httpget.getResponseBodyAsString();
assertNull(response);
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
response = httpget.getResponseBodyAsString(1);
assertNull(response);
} finally {
httpget.releaseConnection();
}
}
示例9: testInfiniteLoopDetection
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
@Test
@Retry
public void testInfiniteLoopDetection() throws IOException {
// Node C has a property that causes an infinite include loop,
// Sling must indicate the problem in its response
final GetMethod get = new GetMethod(nodeUrlC + ".html");
H.getHttpClient().executeMethod(get);
final String content = get.getResponseBodyAsString();
assertTrue(
"Response contains infinite loop error message",
content.contains("org.apache.sling.api.request.RecursionTooDeepException"));
// TODO: SLING-515, status is 500 when running the tests as part of the maven build
// but 200 if running tests against a separate instance started with mvn jetty:run
// final int status = get.getStatusCode();
// assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:18,代碼來源:JspForwardTest.java
示例10: testRedirectJson
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/** test JSON result for .json requests with sling:target */
public void testRedirectJson() throws JsonException, IOException {
// create a sling:redirect node without a target
Map<String, String> props = new HashMap<String, String>();
props.put("sling:resourceType", "sling:redirect");
props.put("sling:target", "/index.html");
String redirNodeUrl = testClient.createNode(postUrl, props);
// get the created node without following redirects
final GetMethod get = new GetMethod(redirNodeUrl + ".json");
get.setFollowRedirects(false);
final int status = httpClient.executeMethod(get);
// expect 200 OK with the JSON data
assertEquals(200, status);
assertTrue(get.getResponseHeader("Content-Type").getValue().startsWith(CONTENT_TYPE_JSON));
// the json data
String jsonString = get.getResponseBodyAsString();
JsonObject json = JsonUtil.parseObject(jsonString);
assertEquals("sling:redirect", json.getString("sling:resourceType"));
assertEquals("/index.html", json.getString("sling:target"));
}
示例11: httpClientPost
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public static final String httpClientPost(String url) {
String result = "";
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod(url);
try {
client.executeMethod(getMethod);
result = getMethod.getResponseBodyAsString();
} catch (Exception e) {
logger.error("", e);
} finally {
getMethod.releaseConnection();
}
return result;
}
示例12: get
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public String get(String url, String cookies) throws
IOException {
// clearCookies();
GetMethod g = new GetMethod(url);
g.setFollowRedirects(false);
if (StringUtils.isNotEmpty(cookies)) {
g.addRequestHeader("cookie", cookies);
}
hc.executeMethod(g);
return g.getResponseBodyAsString();
}
示例13: httpClientPost
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public static final String httpClientPost(String url) {
String result = "";
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod(url);
try {
client.executeMethod(getMethod);
result = getMethod.getResponseBodyAsString();
} catch (Exception e) {
logger.error(e);
} finally {
getMethod.releaseConnection();
}
return result;
}
示例14: testCreateNode
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void testCreateNode() throws IOException {
final String url = HTTP_BASE_URL + "/CreateNodeTest_1_" + System.currentTimeMillis();
// add some properties to the node
final Map<String,String> props = new HashMap<String,String>();
props.put("name1","value1");
props.put("name2","value2");
// POST and get URL of created node
String urlOfNewNode = null;
try {
urlOfNewNode = testClient.createNode(url, props);
} catch(IOException ioe) {
fail("createNode failed: " + ioe);
}
// get and check URL of created node
final GetMethod get = new GetMethod(urlOfNewNode + DEFAULT_EXT);
final int status = httpClient.executeMethod(get);
assertEquals(urlOfNewNode + " must be accessible after createNode",200,status);
final String responseBodyStr = get.getResponseBodyAsString();
assertTrue(responseBodyStr.contains("value1"));
assertTrue(responseBodyStr.contains("value2"));
// test default txt and html renderings
getContent(urlOfNewNode + DEFAULT_EXT, CONTENT_TYPE_PLAIN);
getContent(urlOfNewNode + ".txt", CONTENT_TYPE_PLAIN);
getContent(urlOfNewNode + ".html", CONTENT_TYPE_HTML);
getContent(urlOfNewNode + ".json", CONTENT_TYPE_JSON);
getContent(urlOfNewNode + ".xml", CONTENT_TYPE_XML);
// And extensions for which we have no renderer fail
assertHttpStatus(urlOfNewNode + ".pdf", 404);
assertHttpStatus(urlOfNewNode + ".someWeirdExtension", 404);
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:36,代碼來源:CreateNodeTest.java
示例15: testInfiniteLoopDetection
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void testInfiniteLoopDetection() throws IOException {
// Node C has a property that causes an infinite include loop,
// Sling must indicate the problem in its response
final GetMethod get = new GetMethod(nodeUrlC + ".html");
httpClient.executeMethod(get);
final String content = get.getResponseBodyAsString();
assertTrue(
"Response contains infinite loop error message",
content.contains("org.apache.sling.api.request.RecursionTooDeepException"));
// TODO: SLING-515, status is 500 when running the tests as part of the maven build
// but 200 if running tests against a separate instance started with mvn jetty:run
// final int status = get.getStatusCode();
// assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
}