Search in sources :

Example 61 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class IdocSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String tid = null;
    try {
        ParameterValueList pvl = null;
        if (prc != null) {
            pvl = prc.getValues(paramList);
        }
        SapSystem sapSystem = getSystem(pvl);
        IDoc.Document idoc = parseIdoc(sapSystem, message);
        try {
            log.debug(getLogPrefix() + "checking syntax");
            idoc.checkSyntax();
        } catch (IDoc.Exception e) {
            throw new SenderException("Syntax error in idoc", e);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + "parsed idoc [" + idoc.toXML() + "]");
        }
        JCO.Client client = getClient(prc.getSession(), sapSystem);
        try {
            tid = getTid(client, sapSystem);
            if (tid == null) {
                throw new SenderException("could not obtain TID to send Idoc");
            }
            client.send(idoc, tid);
        } finally {
            releaseClient(client, sapSystem);
        }
        return tid;
    } catch (Exception e) {
        throw new SenderException(e);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) JCO(com.sap.mw.jco.JCO) SenderException(nl.nn.adapterframework.core.SenderException) IDoc(com.sap.mw.idoc.IDoc) SenderException(nl.nn.adapterframework.core.SenderException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 62 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class JmsSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc, String soapHeader) throws SenderException, TimeOutException {
    Session s = null;
    MessageProducer mp = null;
    ParameterValueList pvl = null;
    if (prc != null && paramList != null) {
        try {
            pvl = prc.getValues(paramList);
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "cannot extract parameters", e);
        }
    }
    if (isSoap()) {
        if (soapHeader == null) {
            if (pvl != null && StringUtils.isNotEmpty(getSoapHeaderParam())) {
                ParameterValue soapHeaderParamValue = pvl.getParameterValue(getSoapHeaderParam());
                if (soapHeaderParamValue == null) {
                    log.warn("no SoapHeader found using parameter [" + getSoapHeaderParam() + "]");
                } else {
                    soapHeader = soapHeaderParamValue.asStringValue("");
                }
            }
        }
        message = soapWrapper.putInEnvelope(message, getEncodingStyleURI(), getServiceNamespaceURI(), soapHeader);
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + "correlationId [" + correlationID + "] soap message [" + message + "]");
    }
    try {
        s = createSession();
        mp = getMessageProducer(s, getDestination(prc));
        Destination replyQueue = null;
        // create message
        Message msg = createTextMessage(s, correlationID, message);
        if (getMessageType() != null) {
            msg.setJMSType(getMessageType());
        }
        if (getDeliveryModeInt() > 0) {
            msg.setJMSDeliveryMode(getDeliveryModeInt());
            mp.setDeliveryMode(getDeliveryModeInt());
        }
        if (getPriority() >= 0) {
            msg.setJMSPriority(getPriority());
            mp.setPriority(getPriority());
        }
        // set properties
        if (pvl != null) {
            setProperties(msg, pvl);
        }
        if (replyToName != null) {
            replyQueue = getDestination(replyToName);
        } else {
            if (isSynchronous()) {
                replyQueue = getMessagingSource().getDynamicReplyQueue(s);
            }
        }
        if (replyQueue != null) {
            msg.setJMSReplyTo(replyQueue);
            if (log.isDebugEnabled())
                log.debug("replyTo set to queue [" + replyQueue.toString() + "]");
        }
        // send message
        send(mp, msg);
        if (log.isDebugEnabled()) {
            log.debug("[" + getName() + "] " + "sent message [" + message + "] " + "to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
        } else {
            if (log.isInfoEnabled()) {
                log.info("[" + getName() + "] " + "sent message to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
            }
        }
        if (isSynchronous()) {
            String replyCorrelationId = null;
            if (replyToName != null) {
                if ("CORRELATIONID".equalsIgnoreCase(getLinkMethod())) {
                    replyCorrelationId = correlationID;
                } else if ("CORRELATIONID_FROM_MESSAGE".equalsIgnoreCase(getLinkMethod())) {
                    replyCorrelationId = msg.getJMSCorrelationID();
                } else {
                    replyCorrelationId = msg.getJMSMessageID();
                }
            }
            if (log.isDebugEnabled())
                log.debug("[" + getName() + "] start waiting for reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] for [" + getReplyTimeout() + "] ms");
            MessageConsumer mc = getMessageConsumerForCorrelationId(s, replyQueue, replyCorrelationId);
            try {
                Message rawReplyMsg = mc.receive(getReplyTimeout());
                if (rawReplyMsg == null) {
                    throw new TimeOutException("did not receive reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] within [" + getReplyTimeout() + "] ms");
                }
                return getStringFromRawMessage(rawReplyMsg, prc != null ? prc.getSession() : null, isSoap(), getReplySoapHeaderSessionKey(), soapWrapper);
            } finally {
                if (mc != null) {
                    try {
                        mc.close();
                    } catch (JMSException e) {
                        log.warn("JmsSender [" + getName() + "] got exception closing message consumer for reply", e);
                    }
                }
            }
        }
        return msg.getJMSMessageID();
    } catch (JMSException e) {
        throw new SenderException(e);
    } catch (IOException e) {
        throw new SenderException(e);
    } catch (NamingException e) {
        throw new SenderException(e);
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    } catch (TransformerException e) {
        throw new SenderException(e);
    } catch (JmsException e) {
        throw new SenderException(e);
    } finally {
        if (mp != null) {
            try {
                mp.close();
            } catch (JMSException e) {
                log.warn("JmsSender [" + getName() + "] got exception closing message producer", e);
            }
        }
        closeSession(s);
    }
}
Also used : Destination(javax.jms.Destination) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) MessageConsumer(javax.jms.MessageConsumer) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) Message(javax.jms.Message) JMSException(javax.jms.JMSException) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ParameterException(nl.nn.adapterframework.core.ParameterException) NamingException(javax.naming.NamingException) MessageProducer(javax.jms.MessageProducer) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) TransformerException(javax.xml.transform.TransformerException) Session(javax.jms.Session)

Example 63 with SenderException

use of nl.nn.adapterframework.core.SenderException 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 64 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class LdapSender method performOperationGetSubContexts.

private String performOperationGetSubContexts(String entryName, ParameterResolutionContext prc, Map paramValueMap) throws SenderException, ParameterException {
    DirContext dirContext = null;
    try {
        dirContext = getDirContext(paramValueMap);
        String[] subs = getSubContextList(dirContext, entryName, prc);
        return subContextsToXml(entryName, subs, dirContext).toXML();
    } catch (NamingException e) {
        storeLdapException(e, prc);
        throw new SenderException(e);
    } finally {
        closeDirContext(dirContext);
    }
}
Also used : NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) SenderException(nl.nn.adapterframework.core.SenderException)

Example 65 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class LdapSender method performOperationChangeUnicodePwd.

private String performOperationChangeUnicodePwd(String entryName, ParameterResolutionContext prc, Map paramValueMap) throws SenderException, ParameterException {
    ModificationItem[] modificationItems = new ModificationItem[2];
    modificationItems[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("unicodePwd", encodeUnicodePwd(paramValueMap.get("oldPassword"))));
    modificationItems[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("unicodePwd", encodeUnicodePwd(paramValueMap.get("newPassword"))));
    DirContext dirContext = null;
    try {
        dirContext = getDirContext(paramValueMap);
        dirContext.modifyAttributes(entryName, modificationItems);
        return DEFAULT_RESULT_CHANGE_UNICODE_PWD_OK;
    } catch (NamingException e) {
        // [LDAP: error code 19 - 0000052D: AtrErr: DSID-03191041, #1...
        if (e.getMessage().startsWith("[LDAP: error code 19 - ")) {
            if (log.isDebugEnabled())
                log.debug("Operation [" + getOperation() + "] old password doesn't match or new password doesn't comply with policy for: " + entryName);
            return DEFAULT_RESULT_CHANGE_UNICODE_PWD_NOK;
        } else {
            storeLdapException(e, prc);
            throw new SenderException("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e);
        }
    } finally {
        closeDirContext(dirContext);
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)130 TimeOutException (nl.nn.adapterframework.core.TimeOutException)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)36 SQLException (java.sql.SQLException)25 HashMap (java.util.HashMap)21 ParameterException (nl.nn.adapterframework.core.ParameterException)21 PreparedStatement (java.sql.PreparedStatement)20 Map (java.util.Map)20 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 Iterator (java.util.Iterator)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 InputStream (java.io.InputStream)15 ResultSet (java.sql.ResultSet)13 Element (org.w3c.dom.Element)13 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)12 Date (java.util.Date)10 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9