本文整理匯總了Java中org.apache.commons.httpclient.methods.GetMethod.getResponseBodyAsStream方法的典型用法代碼示例。如果您正苦於以下問題:Java GetMethod.getResponseBodyAsStream方法的具體用法?Java GetMethod.getResponseBodyAsStream怎麽用?Java GetMethod.getResponseBodyAsStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.methods.GetMethod
的用法示例。
在下文中一共展示了GetMethod.getResponseBodyAsStream方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testConnectionAutoClose
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void testConnectionAutoClose() throws Exception {
this.server.setHttpService(new ManyAService());
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
Reader response = new InputStreamReader(httpget.getResponseBodyAsStream());
int c;
while ((c = response.read()) != -1) {
assertEquals((int) 'A', c);
}
assertTrue(this.client.getHttpConnectionManager() instanceof SimpleHttpConnectionManager);
HttpConnection conn = this.client.getHttpConnectionManager().
getConnection(this.client.getHostConfiguration());
assertNotNull(conn);
conn.assertNotOpen();
} finally {
httpget.releaseConnection();
}
}
示例2: getResponse
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
private MCRContent getResponse(String queryURL) throws IOException {
//prepare http client
HttpClient client = new HttpClient();
//prepare GET-request
connection = new GetMethod(queryURL);
//execute request, get response from API and return as stream
client.executeMethod(connection);
InputStream response = connection.getResponseBodyAsStream();
return new MCRStreamContent(response);
}
示例3: getResponse
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
private MCRContent getResponse(String queryURL) throws HttpException, IOException {
//prepare http client
HttpClient client = new HttpClient();
//prepare GET-request
connection = new GetMethod(queryURL);
//execute request, get response from API and return as stream
client.executeMethod(connection);
InputStream response = connection.getResponseBodyAsStream();
return new MCRStreamContent(response);
}
示例4: getResponse
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
private MCRContent getResponse(String queryURL) throws HttpException, IOException {
//prepare http-client
HttpClient client = new HttpClient();
//prepare http GET-request
connection = new GetMethod(queryURL);
//execute request
client.executeMethod(connection);
//return response as stream
InputStream response = connection.getResponseBodyAsStream();
return new MCRStreamContent(response);
}
示例5: getResponse
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public MCRContent getResponse(String queryURL) throws IOException {
// prepare http client
HttpClient client = new HttpClient();
// prepare GET-request
connection = new GetMethod(queryURL);
connection.setRequestHeader("Accept", "application/xml");
// execute request, get response from API and return as stream
client.executeMethod(connection);
InputStream response = connection.getResponseBodyAsStream();
return new MCRStreamContent(response);
}
示例6: getResponse
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public MCRContent getResponse(String queryURL) throws IOException {
//prepare http client
HttpClient client = new HttpClient();
//prepare GET-request
connection = new GetMethod(queryURL);
//execute request, get response from API and return as stream
client.executeMethod(connection);
InputStream response = connection.getResponseBodyAsStream();
return new MCRStreamContent(response);
}
示例7: getResponse
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
private MCRContent getResponse(String queryURL) throws HttpException, IOException {
//prepare http-client
HttpClient client = new HttpClient();
//prepare http GET request
connection = new GetMethod(queryURL);
//execute request
client.executeMethod(connection);
//return input as stream
InputStream response = connection.getResponseBodyAsStream();
return new MCRStreamContent(response);
}
示例8: getResponse
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public MCRStreamContent getResponse(String queryURL) throws IOException {
//prepare http client
HttpClient client = new HttpClient();
//prepare GET-request
connection = new GetMethod(queryURL);
//execute request, get response from API and return as stream
client.executeMethod(connection);
InputStream response = connection.getResponseBodyAsStream();
return new MCRStreamContent(response);
}
示例9: test_multiple_ranges
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void test_multiple_ranges() throws IOException {
GetMethod get = new GetMethod(rootUrl);
get.setRequestHeader(new Header("Range", "bytes 0-9,-10"));
int status = httpClient.executeMethod(get);
assertEquals("Expect 206/PARTIAL CONTENT", 206, status);
String contentType = get.getResponseHeader("Content-Type").getValue();
assertTrue("Content Type must be multipart/byteranges",
contentType.contains("multipart/byteranges"));
String boundary = contentType.substring(contentType.indexOf("boundary=")
+ "boundary=".length());
BufferedReader reader = new BufferedReader(new InputStreamReader(
get.getResponseBodyAsStream()));
String line = reader.readLine();
while (!("--" + boundary).equals(line)) {
line = reader.readLine();
}
assertEquals("Expected content to start with boundary",
"--" + boundary, line);
assertEntityHeaders(reader, "text/plain", "bytes 0-9/79");
assertEquals("The quick ", reader.readLine());
assertEquals("Expected content to start with boundary",
"--" + boundary, reader.readLine());
assertEntityHeaders(reader, "text/plain", "bytes 69-78/79");
assertEquals("corpus sic", reader.readLine());
char[] buf = new char[boundary.length() + 4];
reader.read(buf);
assertEquals("Expected content to start with boundary", "--" + boundary
+ "--", new String(buf));
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:36,代碼來源:RangeStreamingTest.java
示例10: get
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/**
* Send a GET request
* @param c the cluster definition
* @param path the path or URI
* @param headers the HTTP headers to include in the request
* @return a Response object with response detail
* @throws IOException
*/
public Response get(Cluster c, String path, Header[] headers)
throws IOException {
GetMethod method = new GetMethod();
try {
int code = execute(c, method, headers, path);
headers = method.getResponseHeaders();
byte[] body = method.getResponseBody();
InputStream in = method.getResponseBodyAsStream();
return new Response(code, headers, body, in);
} finally {
method.releaseConnection();
}
}
示例11: getDirectReadableChannelImpl
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
private ReadableByteChannel getDirectReadableChannelImpl() throws ContentIOException
{
String contentUrl = getContentUrl();
try
{
if (!exists())
{
throw new IOException("Content doesn't exist");
}
String ticket = transactionService.getRetryingTransactionHelper().doInTransaction(ticketCallback, false, true);
String url = HttpAlfrescoContentReader.generateURL(baseHttpUrl, contentUrl, ticket, false);
GetMethod method = new GetMethod(url);
int statusCode = httpClient.executeMethod(method);
if (statusCode == HttpServletResponse.SC_OK)
{
// Get the stream from the request
InputStream contentStream = method.getResponseBodyAsStream();
// Attach a listener to the stream to ensure that the HTTP request is cleaned up
this.addListener(new StreamCloseListener(method));
// Done
if (logger.isDebugEnabled())
{
logger.debug("\n" +
"HttpReader retrieve intput stream: \n" +
" Reader: " + this + "\n" +
" Server: " + baseHttpUrl);
}
return Channels.newChannel(contentStream);
}
else
{
// The content exists, but we failed to get it
throw new IOException("Failed to get content remote content that supposedly exists.");
}
}
catch (Throwable e)
{
throw new ContentIOException(
"Failed to open stream: \n" +
" Reader: " + this + "\n" +
" Remote server: " + baseHttpUrl,
e);
}
}
示例12: createInputSource
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
private InputSource createInputSource(String url) throws IOException {
final HttpClient client = new HttpClient();
final String proxyHost = System.getProperty("http.proxyHost");
final String proxyPort = System.getProperty("http.proxyPort", "80");
if (proxyHost != null && proxyHost.trim().length() > 0) {
try {
client.getHostConfiguration().setProxy(proxyHost.trim(),
Integer.parseInt(proxyPort));
} catch (NumberFormatException e) {
logger.logError(Log4jLogger.SYSTEM_LOG, e,
LogMessageIdentifier.ERROR_USE_PROXY_DEFINITION_FAILED);
}
}
// Set credentials if specified:
URL targetURL = new URL(url);
if (userName != null && userName.length() > 0) {
client.getParams().setAuthenticationPreemptive(true);
final Credentials credentials = new UsernamePasswordCredentials(
userName, password);
client.getState().setCredentials(
new AuthScope(targetURL.getHost(), targetURL.getPort(),
AuthScope.ANY_REALM), credentials);
}
// Retrieve content:
// opening a local resource isn't supported by apache
// instead open stream directly
if (targetURL.getProtocol().startsWith("file")) {
in = targetURL.openStream();
return new InputSource(in);
}
final GetMethod method = new GetMethod(url);
final int status = client.executeMethod(method);
if (status != HttpStatus.SC_OK) {
throw new IOException("Error " + status + " while retrieving "
+ url);
}
in = method.getResponseBodyAsStream();
return new InputSource(in);
}
示例13: getAuthenticatedContent
import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/** retrieve the contents of given URL and assert its content type
* @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked
* @throws IOException
* @throws HttpException */
public String getAuthenticatedContent(Credentials creds, String url, String expectedContentType, List<NameValuePair> params, int expectedStatusCode) throws IOException {
final GetMethod get = new GetMethod(url);
URL baseUrl = new URL(HTTP_BASE_URL);
AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
get.setDoAuthentication(true);
Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
try {
httpClient.getState().setCredentials(authScope, creds);
if(params != null) {
final NameValuePair [] nvp = new NameValuePair[0];
get.setQueryString(params.toArray(nvp));
}
final int status = httpClient.executeMethod(get);
final InputStream is = get.getResponseBodyAsStream();
final StringBuffer content = new StringBuffer();
final String charset = get.getResponseCharSet();
final byte [] buffer = new byte[16384];
int n = 0;
while( (n = is.read(buffer, 0, buffer.length)) > 0) {
content.append(new String(buffer, 0, n, charset));
}
assertEquals("Expected status " + expectedStatusCode + " for " + url + " (content=" + content + ")",
expectedStatusCode,status);
final Header h = get.getResponseHeader("Content-Type");
if(expectedContentType == null) {
if(h!=null) {
fail("Expected null Content-Type, got " + h.getValue());
}
} else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
// no check
} else if(h==null) {
fail(
"Expected Content-Type that starts with '" + expectedContentType
+" but got no Content-Type header at " + url
);
} else {
assertTrue(
"Expected Content-Type that starts with '" + expectedContentType
+ "' for " + url + ", got '" + h.getValue() + "'",
h.getValue().startsWith(expectedContentType)
);
}
return content.toString();
} finally {
httpClient.getState().setCredentials(authScope, oldCredentials);
}
}
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:55,代碼來源:AuthenticatedTestUtil.java