Search in sources :

Example 6 with StreamingException

use of nl.nn.adapterframework.stream.StreamingException in project iaf by ibissource.

the class MongoDbSender method renderResult.

protected void renderResult(Document findResult, MessageOutputStream target) throws StreamingException {
    try (IDocumentBuilder builder = DocumentBuilderFactory.startDocument(getOutputFormat(), "FindOneResult", target)) {
        JsonWriterSettings writerSettings = JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build();
        Encoder<Document> encoder = new DocumentCodec();
        JsonDocumentWriter jsonWriter = new JsonDocumentWriter(builder, writerSettings);
        encoder.encode(jsonWriter, findResult, EncoderContext.builder().build());
    } catch (Exception e) {
        throw new StreamingException("Could not render collection", e);
    }
}
Also used : StreamingException(nl.nn.adapterframework.stream.StreamingException) DocumentCodec(org.bson.codecs.DocumentCodec) JsonWriterSettings(org.bson.json.JsonWriterSettings) IDocumentBuilder(nl.nn.adapterframework.stream.document.IDocumentBuilder) Document(org.bson.Document) NamingException(javax.naming.NamingException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) StreamingException(nl.nn.adapterframework.stream.StreamingException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 7 with StreamingException

use of nl.nn.adapterframework.stream.StreamingException in project iaf by ibissource.

the class ForEachChildElementPipe method provideOutputStream.

@Override
protected MessageOutputStream provideOutputStream(PipeLineSession session) throws StreamingException {
    HandlerRecord handlerRecord = new HandlerRecord();
    try {
        ThreadConnector threadConnector = streamingXslt ? new ThreadConnector(this, threadLifeCycleEventListener, txManager, session) : null;
        MessageOutputStream target = getTargetStream(session);
        Writer resultWriter = target.asWriter();
        ItemCallback callback = createItemCallBack(session, getSender(), resultWriter);
        createHandler(handlerRecord, threadConnector, session, callback);
        return new MessageOutputStream(this, handlerRecord.inputHandler, target, threadLifeCycleEventListener, txManager, session, threadConnector);
    } catch (TransformerException e) {
        throw new StreamingException(handlerRecord.errorMessage, e);
    }
}
Also used : StreamingException(nl.nn.adapterframework.stream.StreamingException) MessageOutputStream(nl.nn.adapterframework.stream.MessageOutputStream) ThreadConnector(nl.nn.adapterframework.stream.ThreadConnector) Writer(java.io.Writer) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) TransformerException(javax.xml.transform.TransformerException)

Example 8 with StreamingException

use of nl.nn.adapterframework.stream.StreamingException in project iaf by ibissource.

the class Base64Pipe method provideOutputStream.

@SuppressWarnings("resource")
@Override
protected MessageOutputStream provideOutputStream(PipeLineSession session) throws StreamingException {
    MessageOutputStream target = getTargetStream(session);
    // TRUE encode - FALSE decode
    boolean directionEncode = getDirection() == Direction.ENCODE;
    OutputStream targetStream;
    String outputCharset = directionEncode ? StandardCharsets.US_ASCII.name() : getCharset();
    if (getOutputTypeEnum() == OutputTypes.STRING) {
        targetStream = new WriterOutputStream(target.asWriter(), outputCharset != null ? outputCharset : StreamUtil.DEFAULT_INPUT_STREAM_ENCODING);
    } else {
        targetStream = target.asStream(outputCharset);
    }
    OutputStream base64 = new Base64OutputStream(targetStream, directionEncode, getLineLength(), lineSeparatorArray);
    if (directionEncode && StringUtils.isNotEmpty(getCharset())) {
        try {
            return new MessageOutputStream(this, new OutputStreamWriter(base64, getCharset()), target);
        } catch (UnsupportedEncodingException e) {
            throw new StreamingException("cannot open OutputStreamWriter", e);
        }
    }
    return new MessageOutputStream(this, base64, target);
}
Also used : StreamingException(nl.nn.adapterframework.stream.StreamingException) MessageOutputStream(nl.nn.adapterframework.stream.MessageOutputStream) OutputStream(java.io.OutputStream) MessageOutputStream(nl.nn.adapterframework.stream.MessageOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream)

Aggregations

StreamingException (nl.nn.adapterframework.stream.StreamingException)8 MessageOutputStream (nl.nn.adapterframework.stream.MessageOutputStream)5 IOException (java.io.IOException)4 ParameterException (nl.nn.adapterframework.core.ParameterException)4 SenderException (nl.nn.adapterframework.core.SenderException)4 Message (nl.nn.adapterframework.stream.Message)4 OutputStream (java.io.OutputStream)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 TimeoutException (nl.nn.adapterframework.core.TimeoutException)3 SAXException (org.xml.sax.SAXException)3 Writer (java.io.Writer)2 NamingException (javax.naming.NamingException)2 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)2 XmlWriter (nl.nn.adapterframework.xml.XmlWriter)2 Base64OutputStream (org.apache.commons.codec.binary.Base64OutputStream)2 Document (org.bson.Document)2 DocumentCodec (org.bson.codecs.DocumentCodec)2 JsonWriterSettings (org.bson.json.JsonWriterSettings)2 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1