use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class SoapWrapperPipe method doPipe.
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String result;
try {
if ("wrap".equalsIgnoreCase(getDirection())) {
String payload = input.toString();
if (rootTp != null) {
payload = rootTp.transform(payload, null, true);
}
if (outputNamespaceTp != null) {
payload = outputNamespaceTp.transform(payload, null, true);
}
ParameterResolutionContext prc = null;
Map parameterValues = null;
if (getParameterList() != null && (soapHeaderTp != null || soapBodyTp != null)) {
prc = new ParameterResolutionContext(payload, session);
parameterValues = prc.getValueMap(getParameterList());
}
String soapHeader = null;
if (soapHeaderTp != null) {
soapHeader = soapHeaderTp.transform(prc.getInputSource(), parameterValues);
} else {
if (StringUtils.isNotEmpty(getSoapHeaderSessionKey())) {
soapHeader = (String) session.get(getSoapHeaderSessionKey());
}
}
if (soapBodyTp != null) {
payload = soapBodyTp.transform(prc.getInputSource(), parameterValues);
}
result = wrapMessage(payload, soapHeader);
} else {
result = unwrapMessage(input.toString());
if (StringUtils.isEmpty(result)) {
throw new PipeRunException(this, getLogPrefix(session) + "SOAP Body is empty or message is not a SOAP Message");
}
if (!isIgnoreSoapFault() && soapWrapper.getFaultCount(input.toString()) > 0) {
throw new PipeRunException(this, getLogPrefix(session) + "SOAP Body contains SOAP Fault");
}
if (StringUtils.isNotEmpty(getSoapHeaderSessionKey())) {
String soapHeader = soapWrapper.getHeader(input.toString());
session.put(getSoapHeaderSessionKey(), soapHeader);
}
if (removeOutputNamespacesTp != null) {
result = removeOutputNamespacesTp.transform(result, null, true);
}
if (removeUnusedOutputNamespacesTp != null) {
result = removeUnusedOutputNamespacesTp.transform(result, null, true);
}
if (rootTp != null) {
result = rootTp.transform(result, null, true);
}
}
} catch (Exception t) {
throw new PipeRunException(this, getLogPrefix(session) + " Unexpected exception during (un)wrapping ", t);
}
return new PipeRunResult(getForward(), result);
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class InputOutputPipeLineProcessor method processPipeLine.
public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, String message, IPipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
if (pipeLineSession == null) {
pipeLineSession = new PipeLineSessionBase();
}
// reset the PipeLineSession and store the message and its id in the session
if (messageId == null) {
messageId = Misc.createSimpleUUID();
log.error("null value for messageId, setting to [" + messageId + "]");
}
if (message == null) {
throw new PipeRunException(null, "Pipeline of adapter [" + pipeLine.getOwner().getName() + "] received null message");
}
// store message and messageId in the pipeLineSession
pipeLineSession.put(IPipeLineSession.originalMessageKey, message);
pipeLineSession.put(IPipeLineSession.messageIdKey, messageId);
return pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class LockerPipeLineProcessor method processPipeLine.
public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, String message, IPipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
PipeLineResult pipeLineResult;
Locker locker = pipeLine.getLocker();
String objectId = null;
if (locker != null) {
try {
objectId = locker.lock();
} catch (Exception e) {
boolean isUniqueConstraintViolation = false;
if (e instanceof SQLException) {
SQLException sqle = (SQLException) e;
isUniqueConstraintViolation = locker.getDbmsSupport().isUniqueConstraintViolation(sqle);
}
if (isUniqueConstraintViolation) {
String msg = "error while setting lock: " + e.getMessage();
log.info(msg);
} else {
throw new PipeRunException(null, "error while setting lock", e);
}
}
if (objectId != null) {
try {
pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
} finally {
try {
locker.unlock(objectId);
} catch (Exception e) {
// throw new PipeRunException(null, "error while removing lock", e);
String msg = "error while removing lock: " + e.getMessage();
log.warn(msg);
}
}
} else {
pipeLineResult = new PipeLineResult();
pipeLineResult.setState("success");
}
} else {
pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
}
return pipeLineResult;
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class MonitoringPipeProcessor method processPipe.
public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
PipeRunResult pipeRunResult = null;
IExtendedPipe pe = null;
if (pipe instanceof IExtendedPipe) {
pe = (IExtendedPipe) pipe;
}
long pipeStartTime = System.currentTimeMillis();
if (log.isDebugEnabled()) {
// for performance reasons
StringBuffer sb = new StringBuffer();
String ownerName = pipeLine.getOwner() == null ? "<null>" : pipeLine.getOwner().getName();
String pipeName = pipe == null ? "<null>" : pipe.getName();
sb.append("Pipeline of adapter [" + ownerName + "] messageId [" + messageId + "] is about to call pipe [" + pipeName + "]");
boolean lir = false;
if (AppConstants.getInstance().getProperty("log.logIntermediaryResults") != null) {
if (AppConstants.getInstance().getProperty("log.logIntermediaryResults").equalsIgnoreCase("true")) {
lir = true;
}
}
if (pipe instanceof AbstractPipe) {
AbstractPipe ap = (AbstractPipe) pipe;
if (StringUtils.isNotEmpty(ap.getLogIntermediaryResults())) {
lir = Boolean.valueOf(ap.getLogIntermediaryResults());
}
}
if (lir) {
sb.append(" current result [" + message + "] ");
}
log.debug(sb.toString());
}
// start it
long pipeDuration = -1;
try {
pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
} catch (PipeRunException pre) {
if (pe != null) {
pe.throwEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
}
throw pre;
} catch (RuntimeException re) {
if (pe != null) {
pe.throwEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
}
throw new PipeRunException(pipe, "Uncaught runtime exception running pipe '" + (pipe == null ? "null" : pipe.getName()) + "'", re);
} finally {
long pipeEndTime = System.currentTimeMillis();
pipeDuration = pipeEndTime - pipeStartTime;
StatisticsKeeper sk = pipeLine.getPipeStatistics(pipe);
if (sk == null) {
log.warn("Could not get statistics for pipe [+" + pipe.getName() + "]");
} else {
sk.addValue(pipeDuration);
}
if (pe != null) {
if (pe.getDurationThreshold() >= 0 && pipeDuration > pe.getDurationThreshold()) {
durationLog.info("Pipe [" + pe.getName() + "] of [" + pipeLine.getOwner().getName() + "] duration [" + pipeDuration + "] ms exceeds max [" + pe.getDurationThreshold() + "], message [" + message + "]");
pe.throwEvent(IExtendedPipe.LONG_DURATION_MONITORING_EVENT);
}
}
}
return pipeRunResult;
}
use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.
the class SendTibcoMessage method doPipeWithTimeoutGuarded.
public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
Connection connection = null;
Session jSession = null;
MessageProducer msgProducer = null;
Destination destination = null;
String url_work;
String authAlias_work;
String userName_work;
String password_work;
String queueName_work;
String messageProtocol_work;
int replyTimeout_work;
String soapAction_work;
String result = null;
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);
}
}
url_work = getParameterValue(pvl, "url");
if (url_work == null) {
url_work = getUrl();
}
authAlias_work = getParameterValue(pvl, "authAlias");
if (authAlias_work == null) {
authAlias_work = getAuthAlias();
}
userName_work = getParameterValue(pvl, "userName");
if (userName_work == null) {
userName_work = getUserName();
}
password_work = getParameterValue(pvl, "password");
if (password_work == null) {
password_work = getPassword();
}
queueName_work = getParameterValue(pvl, "queueName");
if (queueName_work == null) {
queueName_work = getQueueName();
}
messageProtocol_work = getParameterValue(pvl, "messageProtocol");
if (messageProtocol_work == null) {
messageProtocol_work = getMessageProtocol();
}
String replyTimeout_work_str = getParameterValue(pvl, "replyTimeout");
if (replyTimeout_work_str == null) {
replyTimeout_work = getReplyTimeout();
} else {
replyTimeout_work = Integer.parseInt(replyTimeout_work_str);
}
soapAction_work = getParameterValue(pvl, "soapAction");
if (soapAction_work == null)
soapAction_work = getSoapAction();
if (StringUtils.isEmpty(soapAction_work) && !StringUtils.isEmpty(queueName_work)) {
String[] q = queueName_work.split("\\.");
if (q.length > 0) {
if (q[0].equalsIgnoreCase("P2P") && q.length >= 4) {
soapAction_work = q[3];
} else if (q[0].equalsIgnoreCase("ESB") && q.length == 8) {
soapAction_work = q[5] + "_" + q[6];
} else if (q[0].equalsIgnoreCase("ESB") && q.length > 8) {
soapAction_work = q[6] + "_" + q[7];
}
}
}
if (StringUtils.isEmpty(soapAction_work)) {
log.debug(getLogPrefix(session) + "deriving default soapAction");
try {
URL resource = ClassUtils.getResourceURL(this, "/xml/xsl/esb/soapAction.xsl");
TransformerPool tp = TransformerPool.getInstance(resource, true);
soapAction_work = tp.transform(input.toString(), null);
} catch (Exception e) {
log.error(getLogPrefix(session) + "failed to execute soapAction.xsl");
}
}
if (messageProtocol_work == null) {
throw new PipeRunException(this, getLogPrefix(session) + "messageProtocol must be set");
}
if (!messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY) && !messageProtocol_work.equalsIgnoreCase(FIRE_AND_FORGET)) {
throw new PipeRunException(this, getLogPrefix(session) + "illegal value for messageProtocol [" + messageProtocol_work + "], must be '" + REQUEST_REPLY + "' or '" + FIRE_AND_FORGET + "'");
}
CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
try {
TibjmsAdmin admin;
try {
admin = TibcoUtils.getActiveServerAdmin(url_work, cf);
} catch (TibjmsAdminException e) {
log.debug(getLogPrefix(session) + "caught exception", e);
admin = null;
}
if (admin != null) {
QueueInfo queueInfo;
try {
queueInfo = admin.getQueue(queueName_work);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " exception on getting queue info", e);
}
if (queueInfo == null) {
throw new PipeRunException(this, getLogPrefix(session) + " queue [" + queueName_work + "] does not exist");
}
try {
admin.close();
} catch (TibjmsAdminException e) {
log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e);
}
}
ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(url_work);
connection = factory.createConnection(cf.getUsername(), cf.getPassword());
jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
destination = jSession.createQueue(queueName_work);
msgProducer = jSession.createProducer(destination);
TextMessage msg = jSession.createTextMessage();
msg.setText(input.toString());
Destination replyQueue = null;
if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) {
replyQueue = jSession.createTemporaryQueue();
msg.setJMSReplyTo(replyQueue);
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
msgProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
msgProducer.setTimeToLive(replyTimeout_work);
} else {
msg.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
msgProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
}
if (StringUtils.isNotEmpty(soapAction_work)) {
log.debug(getLogPrefix(session) + "setting [SoapAction] property to value [" + soapAction_work + "]");
msg.setStringProperty("SoapAction", soapAction_work);
}
msgProducer.send(msg);
if (log.isDebugEnabled()) {
log.debug(getLogPrefix(session) + "sent message [" + msg.getText() + "] " + "to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]");
} else {
if (log.isInfoEnabled()) {
log.info(getLogPrefix(session) + "sent message to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]");
}
}
if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) {
String replyCorrelationId = msg.getJMSMessageID();
MessageConsumer msgConsumer = jSession.createConsumer(replyQueue, "JMSCorrelationID='" + replyCorrelationId + "'");
log.debug(getLogPrefix(session) + "] start waiting for reply on [" + replyQueue + "] selector [" + replyCorrelationId + "] for [" + replyTimeout_work + "] ms");
try {
connection.start();
Message rawReplyMsg = msgConsumer.receive(replyTimeout_work);
if (rawReplyMsg == null) {
throw new PipeRunException(this, getLogPrefix(session) + "did not receive reply on [" + replyQueue + "] replyCorrelationId [" + replyCorrelationId + "] within [" + replyTimeout_work + "] ms");
}
TextMessage replyMsg = (TextMessage) rawReplyMsg;
result = replyMsg.getText();
} finally {
}
} else {
result = msg.getJMSMessageID();
}
} catch (JMSException e) {
throw new PipeRunException(this, getLogPrefix(session) + " exception on sending message to Tibco queue", e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
log.warn(getLogPrefix(session) + "exception on closing connection", e);
}
}
}
return result;
}
Aggregations