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);
// }
}
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;
}
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();
}
}
}
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;
}
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;
}
}
Aggregations