On Fri, 2012-05-04 at 11:45 +0200, Robert Naczinski wrote:
> Hello,
> 
> what is the best way to send JAXB entities with Apache Http
> Components? We have on the server side  REST with Jersey.
> 
> I can of course marshals the JAXB objects and send them as strings,
> but this is the best possibility?
> 
> Regards,
> 
> Robert
> 

---
static class JAXBEntity extends AbstractHttpEntity {

    public JAXBEntity() {
        super();
        setContentType("application/xml");
    }
    
    public InputStream getContent() throws IOException {
        // Omitted for brevity
        throw new UnsupportedOperationException();
    }

    public long getContentLength() {
        return -1;
    }

    public boolean isRepeatable() {
        return true;
    }

    public boolean isStreaming() {
        return false;
    }

    public void writeTo(
       final OutputStream outstream) throws IOException {
        XMLOutputFactory xmloutputf = XMLOutputFactory.newInstance();
        try {
            XMLStreamWriter writer = xmloutputf.createXMLStreamWriter(
               outstream, "UTF-8");
            // do the actual writing using an appropriate Marshaller 
            // and do not forget to flush
            writer.flush();
        } catch (XMLStreamException ex) {
            // Re-throw appropriate i/o or runtime exception
            throw new IOException("Oppsie");
        }
    }
    
};
---

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to