Search in sources :

Example 6 with HttpClientException

use of org.expath.httpclient.HttpClientException in project exist by eXist-db.

the class EXistResult method add.

@Override
public void add(final Reader reader, final Charset charset) throws HttpClientException {
    // START TEMP
    // TODO(AR) - replace with a deferred StringReader when eXist has this soon.
    final StringBuilder builder = new StringBuilder();
    try {
        final char[] cbuf = new char[4096];
        int read = -1;
        while ((read = reader.read(cbuf)) > -1) {
            builder.append(cbuf, 0, read);
        }
    } catch (final IOException ioe) {
        throw new HttpClientException("Unable to add string value to result: " + ioe.getMessage(), ioe);
    } finally {
        try {
            reader.close();
        } catch (final IOException ioe) {
            logger.warn(ioe.getMessage(), ioe);
        }
    }
    // END TEMP
    result.add(new StringValue(builder.toString()));
}
Also used : HttpClientException(org.expath.httpclient.HttpClientException) IOException(java.io.IOException)

Example 7 with HttpClientException

use of org.expath.httpclient.HttpClientException in project exist by eXist-db.

the class EXistResult method add.

@Override
public void add(final Source src) throws HttpClientException {
    try {
        final NodeValue nodeValue = ModuleUtils.sourceToXML(context, src);
        result.add(nodeValue);
    } catch (final SAXException | IOException saxe) {
        throw new HttpClientException("Unable to add Source to result:" + saxe.getMessage(), saxe);
    }
}
Also used : HttpClientException(org.expath.httpclient.HttpClientException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

HttpClientException (org.expath.httpclient.HttpClientException)7 IOException (java.io.IOException)3 XPathException (org.exist.xquery.XPathException)3 DocumentImpl (org.exist.dom.memtree.DocumentImpl)2 NodeTest (org.exist.xquery.NodeTest)2 TypeTest (org.exist.xquery.TypeTest)2 HttpResponse (org.expath.httpclient.HttpResponse)2 EXistResult (org.expath.httpclient.model.exist.EXistResult)2 SAXException (org.xml.sax.SAXException)2 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 Source (javax.xml.transform.Source)1 Header (org.apache.http.Header)1 LogManager (org.apache.logging.log4j.LogManager)1