On Wed, 2008-09-17 at 17:35 -0400, Zhaohua Meng wrote: > Oleg, > > Thanks for the pointer. I implemented the RequestEntity and the > streaming is working fine if I know the content length. However the > content is generated dynamically from business data. As is specified > in the RequestEntity, my getContentLength() returns -1. However I'm > getting the following exception. Do I need to implement anything else? > > Thanks, >
If the content is repeatable, that is, it can be reliably generated by the entity more than once, the entity should indicate so by returning true from RequestEntity#isRepeatable(). If the content is not repeatable, then the request enclosing such entity cannot be retried for obvious reasons. Hope this helps Oleg > > Sep 17, 2008 5:23:47 PM > org.apache.commons.httpclient.HttpMethodDirector executeWithRetry > INFO: I/O exception > (org.apache.commons.httpclient.NoHttpResponseException) caught when > processing request: The server www.apache.org failed to respond > Sep 17, 2008 5:23:47 PM > org.apache.commons.httpclient.HttpMethodDirector executeWithRetry > INFO: Retrying request > org.apache.commons.httpclient.ProtocolException: Unbuffered entity > enclosing request can not be repeated. > at > org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:487) > at > org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114) > at > org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096) > at > org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398) > at > org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) > at > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) > at > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) > at > com.cgsh.poc.httpclient.ProxyAuthenticationTest.doHttpClient(ProxyAuthenticationTest.java:36) > at > com.cgsh.poc.httpclient.ProxyAuthenticationTest.main(ProxyAuthenticationTest.java:26) > > > On Wed, Sep 17, 2008 at 1:56 PM, Oleg Kalnichevski <[EMAIL PROTECTED]> wrote: > > On Wed, 2008-09-17 at 00:20 -0400, Zhaohua Meng wrote: > >> I have code snippet like the following. After establishing a > >> connection, I need to steam content from database as post body. How do > >> I get a OutputStream from either HttpClient or PostMethod? With > >> java.net.URL I can use openConnection().getOutputStream(). However I > >> want to leverage the nice features of HttpCleint. In the following > >> code, I want to call the writeContent() method which should get huge > >> data from database. > >> > > > > Zhaohua, > > > > You need to implement a custom RequestEntity > > > > http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/RequestEntity.html > > > > You can use the FileRequestEntity class shipped with HttpClient 3.1 as > > an example > > > > http://hc.apache.org/httpclient-3.x/xref/org/apache/commons/httpclient/methods/FileRequestEntity.html > > > > Hope this helps > > > > Oleg > > > > > >> Any help is appreciated. > >> > >> public static void main(String[] args) throws Exception { > >> HttpClient client = new HttpClient(); > >> PostMethod post = new > >> PostMethod("http://myhost/service/consumer"); > >> try { > >> //how to get a OutputStream to write my content? > >> > >> int status = client.executeMethod(post); > >> > >> System.out.println(post.getResponseBodyAsString()); > >> } finally { > >> post.releaseConnection(); > >> } > >> } > >> public static void writeContent(OutputStream out) throws IOException > >> { > >> //data will be generated from database. > >> out.write("<data><value>this</value></data>".getBytes()); > >> } > >> } > >> > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
