You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Peter Neu <pe...@gmx.net> on 2006/02/16 13:12:51 UTC

How to stream xml document with httpclient

Hello,

I have the use case that I need to stream an xml document after the sax
transformation with httpclient's post.setRequestEntity method. 

The sax tranformstation looks like this: 

PrintWriter out = response.getWriter();
StreamResult streamResult = new StreamResult(out);
SAXTransformerFactory tf = (SAXTransformerFactory)
SAXTransformerFactory.newInstance();
TransformerHandler hd = tf.newTransformerHandler();
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
hd.setResult(streamResult);
AttributesImpl atts = new AttributesImpl();
hd.startDocument();
hd.startElement("", "", "Document", atts);
hd.characters("Hello Document".toCharArray(), 0, "Hello Document".length());
atts.clear();
hd.endElement("", "", "Document");
hd.endDocument();

Then I need to insert it to the post method:

post.setRequestEntity(new InputStreamRequestEntity(
                new FileInputStream(input), input.length()));

How can I do this?

Cheers,
Pete



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: How to stream xml document with httpclient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2006-02-16 at 13:12 +0100, Peter Neu wrote:
> Hello,
> 
> I have the use case that I need to stream an xml document after the sax
> transformation with httpclient's post.setRequestEntity method. 
> 
> The sax tranformstation looks like this: 
> 
> PrintWriter out = response.getWriter();
> StreamResult streamResult = new StreamResult(out);
> SAXTransformerFactory tf = (SAXTransformerFactory)
> SAXTransformerFactory.newInstance();
> TransformerHandler hd = tf.newTransformerHandler();
> Transformer serializer = hd.getTransformer();
> serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
> serializer.setOutputProperty(OutputKeys.INDENT, "yes");
> hd.setResult(streamResult);
> AttributesImpl atts = new AttributesImpl();
> hd.startDocument();
> hd.startElement("", "", "Document", atts);
> hd.characters("Hello Document".toCharArray(), 0, "Hello Document".length());
> atts.clear();
> hd.endElement("", "", "Document");
> hd.endDocument();
> 
> Then I need to insert it to the post method:
> 
> post.setRequestEntity(new InputStreamRequestEntity(
>                 new FileInputStream(input), input.length()));
> 
> How can I do this?
> 

Pete,

Implement a custom request entity

Oleg


> Cheers,
> Pete
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org