Search in sources :

Example 11 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.

the class SapSender 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);
        JCO.Function function = getFunction(sapSystem, pvl);
        if (StringUtils.isEmpty(getSapSystemName())) {
            pvl.removeParameterValue(getSapSystemNameParam());
        }
        if (StringUtils.isEmpty(getFunctionName())) {
            pvl.removeParameterValue(getFunctionNameParam());
        }
        message2FunctionCall(function, message, correlationID, pvl);
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + " function call [" + functionCall2message(function) + "]");
        JCO.Client client = getClient(prc.getSession(), sapSystem);
        try {
            tid = getTid(client, sapSystem);
            if (StringUtils.isEmpty(tid)) {
                client.execute(function);
            } else {
                client.execute(function, tid);
            }
        } finally {
            releaseClient(client, sapSystem);
        }
        if (isSynchronous()) {
            return functionResult2message(function);
        } else {
            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) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 12 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList 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);
        IDocDocument idoc = parseIdoc(sapSystem, message);
        try {
            log.debug(getLogPrefix() + "checking syntax");
            idoc.checkSyntax();
        } catch (IDocException e) {
            throw new SenderException("Syntax error in idoc", e);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + "parsed idoc [" + JCoIDoc.getIDocFactory().getIDocXMLProcessor().render(idoc) + "]");
        }
        JCoDestination destination = getDestination(prc.getSession(), sapSystem);
        tid = getTid(destination, sapSystem);
        if (tid == null) {
            throw new SenderException("could not obtain TID to send Idoc");
        }
        JCoIDoc.send(idoc, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);
        return tid;
    } catch (Exception e) {
        throw new SenderException(e);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) JCoDestination(com.sap.conn.jco.JCoDestination) IDocDocument(com.sap.conn.idoc.IDocDocument) SenderException(nl.nn.adapterframework.core.SenderException) IDocException(com.sap.conn.idoc.IDocException) IDocException(com.sap.conn.idoc.IDocException) SenderException(nl.nn.adapterframework.core.SenderException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 13 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList 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 14 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList 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 15 with ParameterValueList

use of nl.nn.adapterframework.parameters.ParameterValueList in project iaf by ibissource.

the class FixedForwardPipe method doInitialPipe.

public PipeRunResult doInitialPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if ((input == null || StringUtils.isEmpty(input.toString())) && isSkipOnEmptyInput()) {
        return new PipeRunResult(getForward(), input);
    }
    if (getIfParam() != null) {
        boolean skipPipe = true;
        ParameterValueList pvl = null;
        if (getParameterList() != null) {
            ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
            try {
                pvl = prc.getValues(getParameterList());
            } catch (ParameterException e) {
                throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e);
            }
        }
        String ip = getParameterValue(pvl, getIfParam());
        if (ip == null) {
            if (getIfValue() == null) {
                skipPipe = false;
            }
        } else {
            if (getIfValue() != null && getIfValue().equalsIgnoreCase(ip)) {
                skipPipe = false;
            }
        }
        if (skipPipe) {
            return new PipeRunResult(getForward(), input);
        }
    }
    return null;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Aggregations

ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)30 ParameterException (nl.nn.adapterframework.core.ParameterException)23 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)16 SenderException (nl.nn.adapterframework.core.SenderException)15 PipeRunException (nl.nn.adapterframework.core.PipeRunException)13 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)11 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)9 TimeOutException (nl.nn.adapterframework.core.TimeOutException)8 IOException (java.io.IOException)7 ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)6 JMSException (javax.jms.JMSException)5 Parameter (nl.nn.adapterframework.parameters.Parameter)5 URL (java.net.URL)4 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)4 HashMap (java.util.HashMap)3 Session (javax.jms.Session)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 ParameterList (nl.nn.adapterframework.parameters.ParameterList)3 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)3