Search in sources :

Example 11 with DomBuilderException

use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.

the class XmlJmsBrowserSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queueBrowserElement;
    String root = null;
    String jmsRealm = null;
    String queueConnectionFactoryName = null;
    String destinationName = null;
    String destinationType = null;
    try {
        queueBrowserElement = XmlUtils.buildElement(message);
        root = queueBrowserElement.getTagName();
        jmsRealm = XmlUtils.getChildTagAsString(queueBrowserElement, "jmsRealm");
        queueConnectionFactoryName = XmlUtils.getChildTagAsString(queueBrowserElement, "queueConnectionFactoryName");
        destinationName = XmlUtils.getChildTagAsString(queueBrowserElement, "destinationName");
        destinationType = XmlUtils.getChildTagAsString(queueBrowserElement, "destinationType");
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "got exception parsing [" + message + "]", e);
    }
    JmsMessageBrowser jmsBrowser = new JmsMessageBrowser();
    jmsBrowser.setName("XmlQueueBrowserSender");
    if (jmsRealm != null) {
        jmsBrowser.setJmsRealm(jmsRealm);
    }
    if (queueConnectionFactoryName != null) {
        jmsBrowser.setQueueConnectionFactoryName(queueConnectionFactoryName);
    }
    jmsBrowser.setDestinationName(destinationName);
    jmsBrowser.setDestinationType(destinationType);
    IMessageBrowser browser = jmsBrowser;
    IMessageBrowsingIterator it = null;
    boolean remove = false;
    if (root.equalsIgnoreCase("browse")) {
    // OK
    } else {
        if (root.equalsIgnoreCase("remove")) {
            remove = true;
        } else {
            throw new SenderException(getLogPrefix() + "unknown root element [" + root + "]");
        }
    }
    XmlBuilder result = new XmlBuilder("result");
    XmlBuilder items;
    if (remove) {
        items = new XmlBuilder("itemsRemoved");
    } else {
        items = new XmlBuilder("items");
    }
    try {
        int count = 0;
        it = browser.getIterator();
        while (it.hasNext()) {
            count++;
            JmsMessageBrowserIteratorItem jmsMessageBrowserIteratorItem = (JmsMessageBrowserIteratorItem) it.next();
            if (remove) {
                jmsBrowser.deleteMessage(jmsMessageBrowserIteratorItem.getJMSMessageID());
            } else {
                // browse
                XmlBuilder item = new XmlBuilder("item");
                XmlBuilder timestamp = new XmlBuilder("timestamp");
                timestamp.setValue(new java.util.Date(jmsMessageBrowserIteratorItem.getJMSTimestamp()).toString());
                item.addSubElement(timestamp);
                XmlBuilder messageId = new XmlBuilder("messageId");
                messageId.setValue(jmsMessageBrowserIteratorItem.getJMSMessageID());
                item.addSubElement(messageId);
                XmlBuilder correlationId = new XmlBuilder("correlationId");
                correlationId.setValue(jmsMessageBrowserIteratorItem.getCorrelationId());
                item.addSubElement(correlationId);
                XmlBuilder msg = new XmlBuilder("message");
                msg.setCdataValue(jmsMessageBrowserIteratorItem.getText());
                item.addSubElement(msg);
                items.addSubElement(item);
            }
        }
        if (remove) {
            items.setValue(Integer.toString(count));
        } else {
            items.addAttribute("count", count);
        }
        result.addSubElement(items);
    } catch (ListenerException e) {
        throw new SenderException(getLogPrefix() + "got exception browsing messages", e);
    } finally {
        try {
            if (it != null) {
                it.close();
            }
        } catch (ListenerException e) {
            log.warn(getLogPrefix() + "exception on closing message browser iterator", e);
        }
    }
    return result.toXML();
}
Also used : Element(org.w3c.dom.Element) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) IMessageBrowsingIterator(nl.nn.adapterframework.core.IMessageBrowsingIterator) ListenerException(nl.nn.adapterframework.core.ListenerException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 12 with DomBuilderException

use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.

the class FixedResult method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String result = returnString;
    if ((StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) || StringUtils.isNotEmpty(getFileNameSessionKey())) {
        String fileName = null;
        if (StringUtils.isNotEmpty(getFileNameSessionKey())) {
            fileName = (String) session.get(fileNameSessionKey);
        }
        if (fileName == null) {
            if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
                fileName = getFileName();
            }
        }
        URL resource = null;
        try {
            resource = ClassUtils.getResourceURL(classLoader, fileName);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + fileName + "]", e);
        }
        if (resource == null) {
            PipeForward fileNotFoundForward = findForward(FILE_NOT_FOUND_FORWARD);
            if (fileNotFoundForward != null) {
                return new PipeRunResult(fileNotFoundForward, input);
            } else {
                throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + fileName + "]");
            }
        }
        try {
            result = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + fileName + "]", e);
        }
    }
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        ParameterValueList pvl;
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
        for (int i = 0; i < pvl.size(); i++) {
            ParameterValue pv = pvl.getParameterValue(i);
            String replaceFrom;
            if (isReplaceFixedParams()) {
                replaceFrom = pv.getDefinition().getName();
            } else {
                replaceFrom = "${" + pv.getDefinition().getName() + "}";
            }
            result = replace(result, replaceFrom, pv.asStringValue(""));
        }
    }
    if (getSubstituteVars()) {
        result = StringResolver.substVars(returnString, session, appConstants);
    }
    if (StringUtils.isNotEmpty(styleSheetName)) {
        URL xsltSource = ClassUtils.getResourceURL(classLoader, styleSheetName);
        if (xsltSource != null) {
            try {
                String xsltResult = null;
                Transformer transformer = XmlUtils.createTransformer(xsltSource);
                xsltResult = XmlUtils.transformXml(transformer, result);
                result = xsltResult;
            } catch (IOException e) {
                throw new PipeRunException(this, getLogPrefix(session) + "cannot retrieve [" + styleSheetName + "], resource [" + xsltSource.toString() + "]", e);
            } catch (TransformerConfigurationException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "got error creating transformer from file [" + styleSheetName + "]", te);
            } catch (TransformerException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", te);
            } catch (DomBuilderException te) {
                throw new PipeRunException(this, getLogPrefix(session) + "caught DomBuilderException", te);
            }
        }
    }
    log.debug(getLogPrefix(session) + " returning fixed result [" + result + "]");
    return new PipeRunResult(getForward(), result);
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Transformer(javax.xml.transform.Transformer) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) PipeForward(nl.nn.adapterframework.core.PipeForward) URL(java.net.URL) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) TransformerException(javax.xml.transform.TransformerException)

Example 13 with DomBuilderException

use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.

the class CmisSender method sendMessageForActionCreate.

private String sendMessageForActionCreate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String fileName = (String) prc.getSession().get(getFileNameSessionKey());
    InputStream inputStream = null;
    if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
        inputStream = (FileInputStream) prc.getSession().get(getFileInputStreamSessionKey());
    } else {
        String fileContent = (String) prc.getSession().get(getFileContentSessionKey());
        byte[] bytes = Base64.decodeBase64((String) fileContent);
        inputStream = new ByteArrayInputStream(bytes);
    }
    long fileLength = 0;
    try {
        fileLength = inputStream.available();
    } catch (IOException e) {
        log.warn(getLogPrefix() + "could not determine file size", e);
    }
    String mediaType;
    Map props = new HashMap();
    Element cmisElement;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            cmisElement = XmlUtils.buildElement(message);
        } else {
            cmisElement = XmlUtils.buildElement("<cmis/>");
        }
        String objectTypeId = XmlUtils.getChildTagAsString(cmisElement, "objectTypeId");
        if (StringUtils.isNotEmpty(objectTypeId)) {
            props.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        } else {
            props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        }
        String name = XmlUtils.getChildTagAsString(cmisElement, "name");
        if (StringUtils.isEmpty(fileName)) {
            fileName = XmlUtils.getChildTagAsString(cmisElement, "fileName");
        }
        mediaType = XmlUtils.getChildTagAsString(cmisElement, "mediaType");
        if (StringUtils.isNotEmpty(name)) {
            props.put(PropertyIds.NAME, name);
        } else if (StringUtils.isNotEmpty(fileName)) {
            props.put(PropertyIds.NAME, fileName);
        } else {
            props.put(PropertyIds.NAME, "[unknown]");
        }
        Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
        if (propertiesElement != null) {
            processProperties(propertiesElement, props);
        }
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
    }
    if (StringUtils.isEmpty(mediaType)) {
        mediaType = getDefaultMediaType();
    }
    if (isUseRootFolder()) {
        Folder folder = session.getRootFolder();
        ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
        Document document = folder.createDocument(props, contentStream, null);
        log.debug(getLogPrefix() + "created new document [ " + document.getId() + "]");
        return document.getId();
    } else {
        ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
        ObjectId objectId = session.createDocument(props, null, contentStream, null);
        log.debug(getLogPrefix() + "created new document [ " + objectId.getId() + "]");
        return objectId.getId();
    }
}
Also used : HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with DomBuilderException

use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.

the class ScanTibcoSolutionPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlStreamWriter;
    try {
        xmlStreamWriter = XmlUtils.OUTPUT_FACTORY.createXMLStreamWriter(stringWriter);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement("root");
        xmlStreamWriter.writeAttribute("url", getUrl());
        // xmlStreamWriter.writeAttribute("level",
        // String.valueOf(getLevel()));
        process(xmlStreamWriter, getUrl(), getLevel());
        xmlStreamWriter.writeEndDocument();
        xmlStreamWriter.flush();
        xmlStreamWriter.close();
    } catch (XMLStreamException e) {
        throw new PipeRunException(this, "XMLStreamException", e);
    } catch (DomBuilderException e) {
        throw new PipeRunException(this, "DomBuilderException", e);
    } catch (XPathExpressionException e) {
        throw new PipeRunException(this, "XPathExpressionException", e);
    }
    return new PipeRunResult(getForward(), stringWriter.getBuffer().toString());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XPathExpressionException(javax.xml.xpath.XPathExpressionException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException)

Example 15 with DomBuilderException

use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.

the class HttpSender method createMultiPartEntity.

protected HttpEntity createMultiPartEntity(String message, ParameterValueList parameters, IPipeLineSession session) throws SenderException {
    MultipartEntityBuilder entity = MultipartEntityBuilder.create();
    entity.setCharset(Charset.forName(getCharSet()));
    if (isMtomEnabled())
        entity.setMtomMultipart();
    if (StringUtils.isNotEmpty(getInputMessageParam())) {
        entity.addPart(createMultipartBodypart(getInputMessageParam(), message));
        log.debug(getLogPrefix() + "appended stringpart [" + getInputMessageParam() + "] with value [" + message + "]");
    }
    if (parameters != null) {
        for (int i = 0; i < parameters.size(); i++) {
            ParameterValue pv = parameters.getParameterValue(i);
            String paramType = pv.getDefinition().getType();
            String name = pv.getDefinition().getName();
            if (Parameter.TYPE_INPUTSTREAM.equals(paramType)) {
                Object value = pv.getValue();
                if (value instanceof InputStream) {
                    InputStream fis = (InputStream) value;
                    String fileName = null;
                    String sessionKey = pv.getDefinition().getSessionKey();
                    if (sessionKey != null) {
                        fileName = (String) session.get(sessionKey + "Name");
                    }
                    entity.addPart(createMultipartBodypart(name, fis, fileName));
                    log.debug(getLogPrefix() + "appended filepart [" + name + "] with value [" + value + "] and name [" + fileName + "]");
                } else {
                    throw new SenderException(getLogPrefix() + "unknown inputstream [" + value.getClass() + "] for parameter [" + name + "]");
                }
            } else {
                String value = pv.asStringValue("");
                entity.addPart(createMultipartBodypart(name, value));
                log.debug(getLogPrefix() + "appended stringpart [" + name + "] with value [" + value + "]");
            }
        }
    }
    if (StringUtils.isNotEmpty(getMultipartXmlSessionKey())) {
        String multipartXml = (String) session.get(getMultipartXmlSessionKey());
        if (StringUtils.isEmpty(multipartXml)) {
            log.warn(getLogPrefix() + "sessionKey [" + getMultipartXmlSessionKey() + "] is empty");
        } else {
            Element partsElement;
            try {
                partsElement = XmlUtils.buildElement(multipartXml);
            } catch (DomBuilderException e) {
                throw new SenderException(getLogPrefix() + "error building multipart xml", e);
            }
            Collection<Node> parts = XmlUtils.getChildTags(partsElement, "part");
            if (parts == null || parts.size() == 0) {
                log.warn(getLogPrefix() + "no part(s) in multipart xml [" + multipartXml + "]");
            } else {
                Iterator<Node> iter = parts.iterator();
                while (iter.hasNext()) {
                    Element partElement = (Element) iter.next();
                    // String partType = partElement.getAttribute("type");
                    String partName = partElement.getAttribute("name");
                    String partSessionKey = partElement.getAttribute("sessionKey");
                    String partMimeType = partElement.getAttribute("mimeType");
                    Object partObject = session.get(partSessionKey);
                    if (partObject instanceof InputStream) {
                        InputStream fis = (InputStream) partObject;
                        entity.addPart(createMultipartBodypart(partSessionKey, fis, partName, partMimeType));
                        log.debug(getLogPrefix() + "appended filepart [" + partSessionKey + "] with value [" + partObject + "] and name [" + partName + "]");
                    } else {
                        String partValue = (String) session.get(partSessionKey);
                        entity.addPart(createMultipartBodypart(partName, partValue, partMimeType));
                        log.debug(getLogPrefix() + "appended stringpart [" + partSessionKey + "]  with value [" + partValue + "]");
                    }
                }
            }
        }
    }
    // entity.seContentType(contentTypeMtom);
    return entity.build();
}
Also used : MultipartEntityBuilder(nl.nn.adapterframework.http.mime.MultipartEntityBuilder) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 SenderException (nl.nn.adapterframework.core.SenderException)10 IOException (java.io.IOException)9 Element (org.w3c.dom.Element)9 TransformerException (javax.xml.transform.TransformerException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 ParameterException (nl.nn.adapterframework.core.ParameterException)5 Map (java.util.Map)4 Transformer (javax.xml.transform.Transformer)4 PipeRunException (nl.nn.adapterframework.core.PipeRunException)4 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)4 ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)4 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)4 URL (java.net.URL)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2