Search in sources :

Example 6 with TimeOutException

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

the class IfsaRequesterSender method getRawReplyMessage.

/**
 * Retrieves a message with the specified correlationId from queue or other channel, but does no processing on it.
 */
private Message getRawReplyMessage(QueueSession session, IFSAQueue queue, TextMessage sentMessage) throws SenderException, TimeOutException {
    String selector = null;
    Message msg = null;
    QueueReceiver replyReceiver = null;
    try {
        replyReceiver = getReplyReceiver(session, sentMessage);
        selector = replyReceiver.getMessageSelector();
        long timeout = getExpiry(queue);
        log.debug(getLogPrefix() + "start waiting at most [" + timeout + "] ms for reply on message using selector [" + selector + "]");
        msg = replyReceiver.receive(timeout);
        if (msg == null) {
            log.info(getLogPrefix() + "received null reply");
        } else {
            log.info(getLogPrefix() + "received reply");
        }
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "got exception retrieving reply", e);
    } finally {
        try {
            closeReplyReceiver(replyReceiver);
        } catch (IfsaException e) {
            log.error(getLogPrefix() + "error closing replyreceiver", e);
        }
    }
    if (msg == null) {
        throw new TimeOutException(getLogPrefix() + " timed out waiting for reply using selector [" + selector + "]");
    }
    if (msg instanceof IFSATimeOutMessage) {
        throw new TimeOutException(getLogPrefix() + "received IFSATimeOutMessage waiting for reply using selector [" + selector + "]");
    }
    return msg;
// try {
// TextMessage result = (TextMessage)msg;
// return result;
// } catch (Exception e) {
// throw new SenderException(getLogPrefix()+"reply received for message using selector ["+selector+"] cannot be cast to TextMessage ["+msg.getClass().getName()+"]",e);
// }
}
Also used : IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) IFSAReportMessage(com.ing.ifsa.IFSAReportMessage) IFSATimeOutMessage(com.ing.ifsa.IFSATimeOutMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueReceiver(javax.jms.QueueReceiver) IFSATimeOutMessage(com.ing.ifsa.IFSATimeOutMessage) SenderException(nl.nn.adapterframework.core.SenderException) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 7 with TimeOutException

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

the class FileListener method getMessage.

/**
 * Read the message from the specified file. If the file doesn't exist,
 * this methods waits a specified time before it attempts to read the file.
 *
 * @return
 * @throws TimeOutException
 * @throws ListenerException
 */
public String getMessage() throws TimeOutException, ListenerException {
    String result = null;
    if (waitBeforeRead != -1) {
        try {
            Thread.sleep(waitBeforeRead);
        } catch (InterruptedException e) {
            throw new ListenerException("Exception waiting before reading the file: " + e.getMessage(), e);
        }
    }
    File file = null;
    if (filename == null) {
        File[] files = FileUtils.getFiles(directory, wildcard, null, 0);
        if (files.length > 0) {
            file = files[0];
        }
    } else {
        file = new File(filename);
    }
    if (filename2 != null) {
        try {
            File file2 = new File(filename2);
            boolean equal = FileUtils.isFileBinaryEqual(file, file2);
            result = Boolean.toString(equal);
        } catch (IOException e) {
            throw new ListenerException("Exception comparing files '" + filename + "' and '" + filename2 + "': " + e.getMessage(), e);
        }
    } else {
        long startTime = System.currentTimeMillis();
        while ((file == null || !file.exists()) && System.currentTimeMillis() < startTime + timeOut) {
            try {
                Thread.sleep(interval);
            } catch (InterruptedException e) {
                throw new ListenerException("Exception waiting for file: " + e.getMessage(), e);
            }
            if (filename == null) {
                File[] files = FileUtils.getFiles(directory, wildcard, null, 0);
                if (files.length > 0) {
                    file = files[0];
                }
            }
        }
        if (file != null && file.exists()) {
            StringBuffer stringBuffer = new StringBuffer();
            FileInputStream fileInputStream = null;
            try {
                fileInputStream = new FileInputStream(file);
            } catch (IOException e) {
                throw new ListenerException("Exception opening file '" + file.getAbsolutePath() + "': " + e.getMessage(), e);
            }
            byte[] buffer = new byte[1024];
            try {
                int length = fileInputStream.read(buffer);
                while (length != -1) {
                    stringBuffer.append(new String(buffer, 0, length, "UTF-8"));
                    length = fileInputStream.read(buffer);
                }
            } catch (IOException e) {
                try {
                    fileInputStream.close();
                } catch (Exception e2) {
                }
                throw new ListenerException("Exception reading file '" + file.getAbsolutePath() + "': " + e.getMessage(), e);
            }
            try {
                fileInputStream.close();
            } catch (IOException e) {
                throw new ListenerException("Exception closing file '" + file.getAbsolutePath() + "': " + e.getMessage(), e);
            }
            result = stringBuffer.toString();
            if (!file.delete()) {
                throw new ListenerException("Could not delete file '" + file.getAbsolutePath() + "'.");
            }
        } else {
            throw new TimeOutException("Time out waiting for file.");
        }
    }
    return result;
}
Also used : IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ListenerException(nl.nn.adapterframework.core.ListenerException) ListenerException(nl.nn.adapterframework.core.ListenerException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) File(java.io.File)

Example 8 with TimeOutException

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

the class IfsaRequesterSender method sendMessage.

/**
 * Execute a request to the IFSA service.
 * @return in Request/Reply, the retrieved message or TIMEOUT, otherwise null
 */
public String sendMessage(String dummyCorrelationId, String message, Map params) throws SenderException, TimeOutException {
    Connection conn = null;
    Map udzMap = null;
    try {
        String realServiceId;
        // Extract parameters
        if (params != null && params.size() > 0) {
            // Use first param as serviceId
            realServiceId = (String) params.get("serviceId");
            if (realServiceId == null) {
                realServiceId = getServiceId();
            }
            String occurrence = (String) params.get("occurrence");
            if (occurrence != null) {
                int i = realServiceId.indexOf('/', realServiceId.indexOf('/', realServiceId.indexOf('/', realServiceId.indexOf('/') + 1) + 1) + 1);
                int j = realServiceId.indexOf('/', i + 1);
                realServiceId = realServiceId.substring(0, i + 1) + occurrence + realServiceId.substring(j);
            }
            // Use remaining params as outgoing UDZs
            udzMap = new HashMap(params);
            udzMap.remove("serviceId");
            udzMap.remove("occurrence");
        } else {
            realServiceId = getServiceId();
        }
        // Open connection to the Application ID
        conn = ConnectionManager.getConnection(getApplicationId());
        // Create the request, and set the Service URI to the Service ID
        ServiceRequest request = new ServiceRequest(new BusinessMessage(message));
        request.setServiceURI(new ServiceURI(realServiceId));
        addUdzMapToRequest(udzMap, request);
        if (isSynchronous()) {
            // RR handling
            if (timeOut > 0) {
                request.setTimeout(timeOut);
            }
            RequestReplyAccessBean rrBean = RequestReplyAccessBean.getInstance();
            ServiceReply reply = rrBean.sendReceive(conn, request);
            return reply.getBusinessMessage().getText();
        } else {
            // FF handling
            FireForgetAccessBean ffBean = FireForgetAccessBean.getInstance();
            ffBean.send(conn, request);
            return null;
        }
    } catch (com.ing.ifsa.exceptions.TimeoutException toe) {
        throw new TimeOutException(toe);
    } catch (IFSAException e) {
        throw new SenderException(e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : RequestReplyAccessBean(com.ing.ifsa.api.RequestReplyAccessBean) HashMap(java.util.HashMap) Connection(com.ing.ifsa.api.Connection) BusinessMessage(com.ing.ifsa.api.BusinessMessage) ServiceRequest(com.ing.ifsa.api.ServiceRequest) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ServiceURI(com.ing.ifsa.api.ServiceURI) ServiceReply(com.ing.ifsa.api.ServiceReply) FireForgetAccessBean(com.ing.ifsa.api.FireForgetAccessBean) IFSAException(com.ing.ifsa.exceptions.IFSAException) SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with TimeOutException

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

the class WebServiceNtlmSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String result = null;
    HttpPost httpPost = new HttpPost(getUrl());
    try {
        StringEntity se = new StringEntity(message);
        httpPost.setEntity(se);
        if (StringUtils.isNotEmpty(getContentType())) {
            log.debug(getLogPrefix() + "setting Content-Type header [" + getContentType() + "]");
            httpPost.addHeader("Content-Type", getContentType());
        }
        if (StringUtils.isNotEmpty(getSoapAction())) {
            log.debug(getLogPrefix() + "setting SOAPAction header [" + getSoapAction() + "]");
            httpPost.addHeader("SOAPAction", getSoapAction());
        }
        log.debug(getLogPrefix() + "executing method");
        HttpResponse httpresponse = httpClient.execute(httpPost);
        log.debug(getLogPrefix() + "executed method");
        StatusLine statusLine = httpresponse.getStatusLine();
        if (statusLine == null) {
            throw new SenderException(getLogPrefix() + "no statusline found");
        } else {
            int statusCode = statusLine.getStatusCode();
            String statusMessage = statusLine.getReasonPhrase();
            if (statusCode == HttpServletResponse.SC_OK) {
                log.debug(getLogPrefix() + "status code [" + statusCode + "] message [" + statusMessage + "]");
            } else {
                throw new SenderException(getLogPrefix() + "status code [" + statusCode + "] message [" + statusMessage + "]");
            }
        }
        HttpEntity httpEntity = httpresponse.getEntity();
        if (httpEntity == null) {
            log.warn(getLogPrefix() + "no response found");
        } else {
            log.debug(getLogPrefix() + "response content length [" + httpEntity.getContentLength() + "]");
            result = EntityUtils.toString(httpEntity);
            log.debug(getLogPrefix() + "retrieved result [" + result + "]");
        }
    } catch (Exception e) {
        if (e instanceof SocketTimeoutException) {
            throw new TimeOutException(e);
        }
        if (e instanceof ConnectTimeoutException) {
            throw new TimeOutException(e);
        }
        throw new SenderException(e);
    } finally {
        httpPost.releaseConnection();
    }
    return result;
}
Also used : StatusLine(org.apache.http.StatusLine) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SocketTimeoutException(java.net.SocketTimeoutException) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) SenderException(nl.nn.adapterframework.core.SenderException) NTLMEngineException(org.apache.http.impl.auth.NTLMEngineException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 10 with TimeOutException

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

the class BisJmsSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String messageHeader;
    try {
        messageHeader = bisUtils.prepareMessageHeader(null, isMessageHeaderInSoapBody(), (String) prc.getSession().get(getConversationIdSessionKey()), (String) prc.getSession().get(getExternalRefToMessageIdSessionKey()));
    } catch (Exception e) {
        throw new SenderException(e);
    }
    String payload;
    try {
        payload = bisUtils.prepareReply(message, isMessageHeaderInSoapBody() ? messageHeader : null, null, false);
        if (StringUtils.isNotEmpty(getRequestNamespace())) {
            payload = XmlUtils.addRootNamespace(payload, getRequestNamespace());
        }
    } catch (Exception e) {
        throw new SenderException(e);
    }
    String replyMessage = super.sendMessage(correlationID, payload, prc, isMessageHeaderInSoapBody() ? null : messageHeader);
    if (isSynchronous()) {
        String bisError;
        String bisErrorList;
        try {
            bisError = bisErrorTp.transform(replyMessage, null, true);
            bisErrorList = bisErrorListTp.transform(replyMessage, null, true);
        } catch (Exception e) {
            throw new SenderException(e);
        }
        if (Boolean.valueOf(bisError).booleanValue()) {
            log.debug("put in session [" + getErrorListSessionKey() + "] [" + bisErrorList + "]");
            prc.getSession().put(getErrorListSessionKey(), bisErrorList);
            throw new SenderException("bisErrorXPath [" + (isResultInPayload() ? bisUtils.getBisErrorXPath() : bisUtils.getOldBisErrorXPath()) + "] returns true");
        }
        try {
            replyMessage = responseTp.transform(replyMessage, null, true);
            if (isRemoveResponseNamespaces()) {
                replyMessage = XmlUtils.removeNamespaces(replyMessage);
            }
            if (isResultInPayload()) {
                Element soapBodyElement = XmlUtils.buildElement(replyMessage, true);
                Element resultElement = XmlUtils.getFirstChildTag(soapBodyElement, "Result");
                if (resultElement != null) {
                    soapBodyElement.removeChild(resultElement);
                }
                replyMessage = XmlUtils.nodeToString(soapBodyElement);
            }
            return replyMessage;
        } catch (Exception e) {
            throw new SenderException(e);
        }
    } else {
        return replyMessage;
    }
}
Also used : Element(org.w3c.dom.Element) SenderException(nl.nn.adapterframework.core.SenderException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

TimeOutException (nl.nn.adapterframework.core.TimeOutException)31 SenderException (nl.nn.adapterframework.core.SenderException)30 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)15 IOException (java.io.IOException)12 HashMap (java.util.HashMap)11 Map (java.util.Map)9 ParameterException (nl.nn.adapterframework.core.ParameterException)9 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)8 LinkedHashMap (java.util.LinkedHashMap)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 Iterator (java.util.Iterator)3 JMSException (javax.jms.JMSException)3 ListenerException (nl.nn.adapterframework.core.ListenerException)3 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)3 JavaListener (nl.nn.adapterframework.receivers.JavaListener)3 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)3 JCoDestination (com.sap.conn.jco.JCoDestination)2