use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class ForEachChildElementPipe method iterateOverInput.
@Override
protected StopReason iterateOverInput(Message input, PipeLineSession session, Map<String, Object> threadContext, ItemCallback callback) throws SenderException, TimeoutException {
InputSource src;
if (isProcessFile()) {
try {
String filename;
try {
filename = input.asString();
} catch (IOException e) {
throw new SenderException(getLogPrefix(session) + "cannot find filename", e);
}
src = new InputSource(new FileInputStream(filename));
} catch (FileNotFoundException e) {
throw new SenderException("could not find file [" + input + "]", e);
}
} else {
try {
src = input.asInputSource();
} catch (IOException e) {
throw new SenderException("could not get InputSource", e);
}
}
HandlerRecord handlerRecord = new HandlerRecord();
try (ThreadConnector threadConnector = streamingXslt ? new ThreadConnector(this, threadLifeCycleEventListener, txManager, session) : null) {
try {
createHandler(handlerRecord, threadConnector, session, callback);
} catch (TransformerException e) {
throw new SenderException(handlerRecord.errorMessage, e);
}
try {
XmlUtils.parseXml(src, handlerRecord.inputHandler);
} catch (Exception e) {
try {
if (e instanceof SaxTimeoutException) {
if (e.getCause() != null && e.getCause() instanceof TimeoutException) {
throw (TimeoutException) e.getCause();
}
throw new TimeoutException(e);
}
if (!(e instanceof SaxAbortException)) {
throw new SenderException(e);
}
} finally {
try {
handlerRecord.inputHandler.endDocument();
} catch (Exception e2) {
log.warn("Exception in endDocument()", e2);
}
}
}
} catch (IOException e) {
throw new SenderException(e);
}
return handlerRecord.itemHandler.stopReason;
// 2020-06-12 removing below 'rethrowTransformerException()', as it does not break the tests, and cannot be implemented when providing an OutputStream.
// However, if cases popup of errors not being signaled, this modification could be the cause.
// rethrowTransformerException(handlerRecord.transformerErrorListener, handlerRecord.errorMessage);
}
use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class IbisLocalSender method sendMessage.
@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
String correlationID = session == null ? null : session.getMessageId();
Message result = null;
HashMap<String, Object> context = null;
if (paramList != null) {
try {
context = (HashMap<String, Object>) paramList.getValues(message, session).getValueMap();
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
}
}
if (context == null) {
context = new HashMap<>();
}
String serviceIndication;
if (StringUtils.isNotEmpty(getServiceName())) {
serviceIndication = "service [" + getServiceName() + "]";
try {
if (isIsolated()) {
if (isSynchronous()) {
log.debug(getLogPrefix() + "calling " + serviceIndication + " in separate Thread");
result = isolatedServiceCaller.callServiceIsolated(getServiceName(), correlationID, message, context, false);
} else {
log.debug(getLogPrefix() + "calling " + serviceIndication + " in asynchronously");
isolatedServiceCaller.callServiceAsynchronous(getServiceName(), correlationID, message, context, false);
result = message;
}
} else {
log.debug(getLogPrefix() + "calling " + serviceIndication + " in same Thread");
result = new Message(ServiceDispatcher.getInstance().dispatchRequest(getServiceName(), correlationID, message.asString(), context));
}
} catch (ListenerException | IOException e) {
if (ExceptionUtils.getRootCause(e) instanceof TimeoutException) {
throw new TimeoutException(getLogPrefix() + "timeout calling " + serviceIndication + "", e);
}
throw new SenderException(getLogPrefix() + "exception calling " + serviceIndication + "", e);
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (session != null) {
Misc.copyContext(getReturnedSessionKeys(), context, session, this);
}
}
} else {
String javaListener;
if (StringUtils.isNotEmpty(getJavaListenerSessionKey())) {
try {
javaListener = session.getMessage(getJavaListenerSessionKey()).asString();
} catch (IOException e) {
throw new SenderException("unable to resolve session key [" + getJavaListenerSessionKey() + "]", e);
}
} else {
javaListener = getJavaListener();
}
serviceIndication = "JavaListener [" + javaListener + "]";
try {
JavaListener listener = JavaListener.getListener(javaListener);
if (listener == null) {
String msg = "could not find JavaListener [" + javaListener + "]";
if (isThrowJavaListenerNotFoundException()) {
throw new SenderException(msg);
}
log.info(getLogPrefix() + msg);
return new Message("<error>" + msg + "</error>");
}
if (isIsolated()) {
if (isSynchronous()) {
log.debug(getLogPrefix() + "calling " + serviceIndication + " in separate Thread");
result = isolatedServiceCaller.callServiceIsolated(javaListener, correlationID, message, context, true);
} else {
log.debug(getLogPrefix() + "calling " + serviceIndication + " in asynchronously");
isolatedServiceCaller.callServiceAsynchronous(javaListener, correlationID, message, context, true);
result = message;
}
} else {
log.debug(getLogPrefix() + "calling " + serviceIndication + " in same Thread");
result = new Message(listener.processRequest(correlationID, message.asString(), context));
}
} catch (ListenerException | IOException e) {
if (ExceptionUtils.getRootCause(e) instanceof TimeoutException) {
throw new TimeoutException(getLogPrefix() + "timeout calling " + serviceIndication, e);
}
throw new SenderException(getLogPrefix() + "exception calling " + serviceIndication, e);
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (session != null) {
Misc.copyContext(getReturnedSessionKeys(), context, session, this);
}
}
}
ExitState exitState = (ExitState) context.remove(PipeLineSession.EXIT_STATE_CONTEXT_KEY);
Object exitCode = context.remove(PipeLineSession.EXIT_CODE_CONTEXT_KEY);
if (exitState != null && exitState != ExitState.SUCCESS) {
context.put("originalResult", result);
throw new SenderException(getLogPrefix() + "call to " + serviceIndication + " resulted in exitState [" + exitState + "] exitCode [" + exitCode + "]");
}
return result;
}
use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class IbisJavaSender method sendMessage.
@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
String result = null;
HashMap context = null;
try {
if (paramList != null) {
context = (HashMap) paramList.getValues(message, session).getValueMap();
} else {
context = new HashMap();
}
DispatcherManager dm = null;
Class c = Class.forName("nl.nn.adapterframework.dispatcher.DispatcherManagerFactory");
if (getDispatchType().equalsIgnoreCase("DLL")) {
String version = nl.nn.adapterframework.dispatcher.Version.version;
if (version.contains("IbisServiceDispatcher 1.3"))
throw new SenderException("IBIS-ServiceDispatcher out of date! Please update to version 1.4 or higher");
Method getDispatcherManager = c.getMethod("getDispatcherManager", String.class);
dm = (DispatcherManager) getDispatcherManager.invoke(null, getDispatchType());
} else {
Method getDispatcherManager = c.getMethod("getDispatcherManager");
dm = (DispatcherManager) getDispatcherManager.invoke(null, (Object[]) null);
}
String serviceName;
if (StringUtils.isNotEmpty(getServiceNameSessionKey())) {
serviceName = session.getMessage(getServiceNameSessionKey()).asString();
} else {
serviceName = getServiceName();
}
String correlationID = session == null ? null : session.getMessage(PipeLineSession.businessCorrelationIdKey).asString();
result = dm.processRequest(serviceName, correlationID, message.asString(), context);
if (isMultipartResponse()) {
return HttpSender.handleMultipartResponse(multipartResponseContentType, new ByteArrayInputStream(result.getBytes(multipartResponseCharset)), session);
}
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "exception evaluating parameters", e);
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "exception processing message using request processor [" + serviceName + "]", e);
} finally {
if (log.isDebugEnabled() && StringUtils.isNotEmpty(getReturnedSessionKeys())) {
log.debug("returning values of session keys [" + getReturnedSessionKeys() + "]");
}
if (session != null) {
Misc.copyContext(getReturnedSessionKeys(), context, session, this);
}
}
return new Message(result);
}
use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class MailSenderTest method createSender.
@Override
public MailSender createSender() throws Exception {
MailSender mailSender = new MailSender() {
Session mailSession;
@Override
protected Session createSession() throws SenderException {
try {
mailSession = super.createSession();
Provider provider = new Provider(Type.TRANSPORT, "smtp", TransportMock.class.getCanonicalName(), "IbisSource.org", "1.0");
mailSession.setProvider(provider);
return mailSession;
} catch (Exception e) {
e.printStackTrace();
throw new SenderException(e);
}
}
@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
super.sendMessage(message, session);
session.put("mailSession", mailSession);
String correlationID = session.getMessageId();
return new Message(correlationID);
}
};
mailSender.setSmtpHost("localhost");
mailSender.setSmtpUserid("user123");
mailSender.setSmtpPassword("secret321");
return mailSender;
}
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 javax.jms.Message getRawReplyMessage(QueueSession session, IFSAQueue queue, TextMessage sentMessage) throws SenderException, TimeoutException {
String selector = null;
javax.jms.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);
// }
}
Aggregations