use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class CmisDeleteAction method objectNotFound.
@Test
public void objectNotFound() throws Exception {
sender.setBindingType("browser");
sender.setAction("delete");
sender.setResultOnNotFound("document-not-found");
sender.configure();
Message result = sendMessage(NOT_FOUND_SELECTOR);
assertThat(result.asString(), Matchers.startsWith("document-not-found"));
}
use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class Adapter method processMessageWithExceptions.
@Override
public PipeLineResult processMessageWithExceptions(String messageId, Message message, PipeLineSession pipeLineSession) throws ListenerException {
PipeLineResult result = new PipeLineResult();
long startTime = System.currentTimeMillis();
boolean processingSuccess = true;
// prevent executing a stopped adapter
// the receivers should implement this, but you never now....
RunState currentRunState = getRunState();
if (currentRunState != RunState.STARTED && currentRunState != RunState.STOPPING) {
String msgAdapterNotOpen = "Adapter [" + getName() + "] in state [" + currentRunState + "], cannot process message";
throw new ListenerException(new ManagedStateException(msgAdapterNotOpen));
}
incNumOfMessagesInProcess(startTime);
String lastNDC = ThreadContext.peek();
String newNDC = "mid [" + messageId + "]";
boolean ndcChanged = !newNDC.equals(lastNDC);
try {
if (ndcChanged) {
ThreadContext.push(newNDC);
}
if (StringUtils.isNotEmpty(composedHideRegex)) {
IbisMaskingLayout.addToThreadLocalReplace(composedHideRegex);
}
StringBuilder additionalLogging = new StringBuilder();
String xPathLogKeys = (String) pipeLineSession.get("xPathLogKeys");
if (StringUtils.isNotEmpty(xPathLogKeys)) {
StringTokenizer tokenizer = new StringTokenizer(xPathLogKeys, ",");
while (tokenizer.hasMoreTokens()) {
String logName = tokenizer.nextToken();
String xPathResult = (String) pipeLineSession.get(logName);
additionalLogging.append(" and ");
additionalLogging.append(logName);
additionalLogging.append(" [" + xPathResult + "]");
}
}
String format = "Adapter [%s] received message [%s] with messageId [%s]";
if (msgLog.isEnabled(MSGLOG_LEVEL_TERSE)) {
String messageOrSize = (isMsgLogHidden()) ? "SIZE=" + getFileSizeAsBytes(message) : message.toString();
msgLog.log(MSGLOG_LEVEL_TERSE, String.format(format, getName(), messageOrSize, messageId) + additionalLogging);
}
if (log.isDebugEnabled()) {
log.debug(String.format(format, getName(), message, messageId) + additionalLogging);
} else if (log.isInfoEnabled()) {
log.info(String.format("Adapter [%s] received message with messageId [%s]" + additionalLogging, getName(), messageId));
}
if (Message.isEmpty(message) && isReplaceNullMessage()) {
log.debug("Adapter [" + getName() + "] replaces null message with messageId [" + messageId + "] by empty message");
message = new Message("");
}
result = pipeline.process(messageId, message, pipeLineSession);
String duration;
if (msgLogHumanReadable) {
duration = Misc.getAge(startTime);
} else {
duration = Misc.getDurationInMs(startTime);
}
String exitCode = ", exit-code [" + result.getExitCode() + "]";
String format2 = "Adapter [%s] messageId [%s] duration [%s] got exit-state [%s]" + (result.getExitCode() != 0 ? exitCode : "") + " and result [%s] from PipeLine";
if (msgLog.isEnabled(MSGLOG_LEVEL_TERSE)) {
String resultOrSize = (isMsgLogHidden()) ? "SIZE=" + getFileSizeAsBytes(result.getResult()) : result.toString();
msgLog.log(MSGLOG_LEVEL_TERSE, String.format(format2, getName(), messageId, duration, result.getState(), resultOrSize));
}
if (log.isDebugEnabled()) {
log.debug(String.format(format2, getName(), messageId, duration, result.getState(), result.getResult()));
}
return result;
} catch (Throwable t) {
ListenerException e;
if (t instanceof ListenerException) {
e = (ListenerException) t;
} else {
e = new ListenerException(t);
}
processingSuccess = false;
incNumOfMessagesInError();
addErrorMessageToMessageKeeper("error processing message with messageId [" + messageId + "]: ", e);
throw e;
} finally {
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
// reset the InProcess fields, and increase processedMessagesCount
decNumOfMessagesInProcess(duration, processingSuccess);
if (log.isDebugEnabled()) {
// for performance reasons
log.debug("Adapter: [" + getName() + "] STAT: Finished processing message with messageId [" + messageId + "] exit-state [" + result.getState() + "] started " + DateUtils.format(new Date(startTime), DateUtils.FORMAT_FULL_GENERIC) + " finished " + DateUtils.format(new Date(endTime), DateUtils.FORMAT_FULL_GENERIC) + " total duration: " + duration + " msecs");
} else {
log.info("Adapter [" + getName() + "] completed message with messageId [" + messageId + "] with exit-state [" + result.getState() + "]");
}
IbisMaskingLayout.removeThreadLocalReplace();
if (ndcChanged) {
ThreadContext.pop();
}
if (ThreadContext.getDepth() == 0) {
ThreadContext.removeStack();
}
}
}
use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class RecordXmlTransformer method handleRecord.
@Override
public String handleRecord(PipeLineSession session, List<String> parsedRecord) throws Exception {
String xml = getXml(parsedRecord);
if (transformerPool != null) {
if (log.isDebugEnabled()) {
log.debug("Transformer [" + getName() + "] record before XSL transformation [" + xml + "]");
}
Message message = new Message(xml);
ParameterValueList pvl = paramList == null ? null : paramList.getValues(message, session);
return transformerPool.transform(message.asSource(), pvl);
}
return xml;
}
use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class EsbJmsTransactionalStorage method storeMessage.
@Override
public String storeMessage(String messageId, String correlationId, Date receivedDate, String comments, String label, S message) throws SenderException {
Session session = null;
try {
Map<String, Object> parameterValues = createParameterValues(messageId, correlationId, receivedDate, comments, message);
String logRequest;
if (getType().equalsIgnoreCase("E")) {
log.debug(getLogPrefix() + "creating exceptionLog request");
logRequest = exceptionLogTp.transform("<dummy/>", parameterValues, true);
} else {
log.debug(getLogPrefix() + "creating auditLog request");
logRequest = auditLogTp.transform("<dummy/>", parameterValues, true);
}
session = createSession();
javax.jms.Message msg = createMessage(session, null, new Message(logRequest));
String returnMessage = send(session, getDestination(), msg);
log.debug(getLogPrefix() + "sent message [" + logRequest + "] " + "to [" + getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "]");
return returnMessage;
} catch (Exception e) {
throw new SenderException(e);
} finally {
closeSession(session);
}
}
use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class WsdlGeneratorPipe method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
Message fileInSession = session.getMessage(getSessionKey());
if (fileInSession == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
}
File tempDir;
String fileName;
try (InputStream inputStream = fileInSession.asInputStream()) {
tempDir = FileUtils.createTempDir(null, "WEB-INF" + File.separator + "classes");
fileName = session.getMessage(getFilenameSessionKey()).asString();
if (FileUtils.extensionEqualsIgnoreCase(fileName, "zip")) {
FileUtils.unzipStream(inputStream, tempDir);
} else {
File file = new File(tempDir, fileName);
Misc.streamToFile(inputStream, file);
file.deleteOnExit();
}
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on uploading and unzipping/writing file", e);
}
File propertiesFile = new File(tempDir, getPropertiesFileName());
PipeLine pipeLine;
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
// A DirectoryClassloader is used to create a new 'dummy' pipeline, see createPipeLineFromPropertiesFile(String)
// This method reads a properties file and xsd's (when present) to programmatically 'create' a pipeline.
// The pipeline will then be used to generate a new WSDL file.
DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(originalClassLoader);
directoryClassLoader.setDirectory(tempDir.getPath());
directoryClassLoader.setBasePath(".");
directoryClassLoader.configure(getAdapter().getConfiguration().getIbisManager().getIbisContext(), "dummy");
Thread.currentThread().setContextClassLoader(directoryClassLoader);
if (propertiesFile.exists()) {
pipeLine = createPipeLineFromPropertiesFile(propertiesFile);
} else {
File xsdFile = FileUtils.getFirstFile(tempDir);
pipeLine = createPipeLineFromXsdFile(xsdFile);
}
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
} finally {
if (originalClassLoader != null) {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
Object result = null;
OutputStream zipOut = null;
OutputStream fullWsdlOut = null;
try {
Adapter adapter = new Adapter();
Configuration configuration = new Configuration();
configuration.setClassLoader(getConfigurationClassLoader());
adapter.setConfiguration(configuration);
String fileBaseName = FileUtils.getBaseName(fileName).replaceAll(" ", "_");
adapter.setName(fileBaseName);
Receiver receiver = new Receiver();
EsbJmsListener esbJmsListener = new EsbJmsListener();
esbJmsListener.setQueueConnectionFactoryName("jms/qcf_" + fileBaseName);
esbJmsListener.setDestinationName("jms/dest_" + fileBaseName);
receiver.setListener(esbJmsListener);
adapter.registerReceiver(receiver);
adapter.setPipeLine(pipeLine);
WsdlGenerator wsdl = null;
String generationInfo = "at " + RestListenerUtils.retrieveRequestURL(session);
wsdl = new WsdlGenerator(pipeLine, generationInfo);
wsdl.setIndent(true);
wsdl.init();
File wsdlDir = FileUtils.createTempDir(tempDir);
// zip (with includes)
File zipOutFile = new File(wsdlDir, wsdl.getFilename() + ".zip");
zipOutFile.deleteOnExit();
zipOut = new FileOutputStream(zipOutFile);
wsdl.setUseIncludes(true);
wsdl.zip(zipOut, null);
// full wsdl (without includes)
File fullWsdlOutFile = new File(wsdlDir, wsdl.getFilename() + ".wsdl");
fullWsdlOutFile.deleteOnExit();
fullWsdlOut = new FileOutputStream(fullWsdlOutFile);
wsdl.setUseIncludes(false);
wsdl.wsdl(fullWsdlOut, null);
Dir2Xml dx = new Dir2Xml();
dx.setPath(wsdlDir.getPath());
result = dx.getDirList();
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
} finally {
try {
if (zipOut != null) {
zipOut.close();
}
if (fullWsdlOut != null) {
fullWsdlOut.close();
}
} catch (IOException e1) {
log.warn("exception closing outputstream", e1);
}
}
return new PipeRunResult(getSuccessForward(), result);
}
Aggregations