use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.
the class ObjectServiceImpl method getObject.
@Override
public ObjectData getObject(String repositoryId, String objectId, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds, Boolean includeAcl, ExtensionsData extensions) {
boolean bypass = AppConstants.getInstance().getBoolean("cmis.proxy.bypass.getObject", false);
if (!bypass) {
ObjectData objectData = objectService.getObject(repositoryId, objectId, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl, extensions);
return objectData;
} else {
XmlBuilder cmisXml = new XmlBuilder("cmis");
cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
cmisXml.addSubElement(buildXml("objectId", objectId));
cmisXml.addSubElement(buildXml("filter", filter));
cmisXml.addSubElement(buildXml("includeAllowableActions", includeAllowableActions));
cmisXml.addSubElement(buildXml("includePolicies", includePolicyIds));
cmisXml.addSubElement(buildXml("includeAcl", includeAcl));
ObjectDataImpl impl = new ObjectDataImpl();
try {
IPipeLineSession messageContext = new PipeLineSessionBase();
String result = CmisServletDispatcher.getInstance().getCmisListener().processRequest(null, cmisXml.toXML(), messageContext);
Element cmisElement;
if (XmlUtils.isWellFormed(result, "cmis")) {
cmisElement = XmlUtils.buildElement(result);
} else {
cmisElement = XmlUtils.buildElement("<cmis/>");
}
// Handle allowable actions
Element allowableActionsElem = XmlUtils.getFirstChildTag(cmisElement, "allowableActions");
if (allowableActionsElem != null) {
AllowableActionsImpl allowableActions = new AllowableActionsImpl();
Set<Action> actions = EnumSet.noneOf(Action.class);
Iterator<Node> actionIterator = XmlUtils.getChildTags(allowableActionsElem, "action").iterator();
while (actionIterator.hasNext()) {
String property = XmlUtils.getStringValue((Element) actionIterator.next());
actions.add(Action.fromValue(property));
}
allowableActions.setAllowableActions(actions);
impl.setAllowableActions(allowableActions);
}
// Handle isExactAcl
impl.setIsExactAcl(XmlUtils.getChildTagAsBoolean(cmisElement, "isExactAcl"));
// Handle policyIds
Element policyIdsElem = XmlUtils.getFirstChildTag(cmisElement, "policyIds");
if (policyIdsElem != null) {
PolicyIdListImpl policyIdList = new PolicyIdListImpl();
List<String> policies = new ArrayList<String>();
Iterator<Node> policyIterator = XmlUtils.getChildTags(allowableActionsElem, "policyId").iterator();
while (policyIterator.hasNext()) {
String policyId = XmlUtils.getStringValue((Element) policyIterator.next());
policies.add(policyId);
}
policyIdList.setPolicyIds(policies);
impl.setPolicyIds(policyIdList);
}
// Handle properties
impl.setProperties(processProperties(cmisElement));
} catch (Exception e) {
log.error("error creating CMIS objectData: " + e.getMessage(), e.getCause());
}
impl.setRenditions(null);
impl.setExtensions(null);
impl.setChangeEventInfo(null);
impl.setRelationships(null);
return impl;
}
}
use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.
the class ZipWriterSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
ParameterValueList pvl;
try {
pvl = prc.getValues(paramList);
} catch (ParameterException e) {
throw new SenderException("cannot determine filename and/or contents of zip entry", e);
}
IPipeLineSession session = prc.getSession();
ZipWriter sessionData = ZipWriter.getZipWriter(session, getZipWriterHandle());
if (sessionData == null) {
throw new SenderException("zipWriterHandle in session key [" + getZipWriterHandle() + "] is not open");
}
String filename = filenameParameter == null ? message : (String) pvl.getParameterValue(PARAMETER_FILENAME).getValue();
try {
if (contentsParameter == null) {
if (message != null) {
sessionData.writeEntry(filename, message, isCloseInputstreamOnExit(), getCharset());
}
} else {
Object paramValue = pvl.getParameterValue(PARAMETER_CONTENTS).getValue();
sessionData.writeEntry(filename, paramValue, isCloseInputstreamOnExit(), getCharset());
}
return message;
} catch (UnsupportedEncodingException e) {
throw new SenderException(getLogPrefix() + "cannot encode zip entry", e);
} catch (CompressionException e) {
throw new SenderException(getLogPrefix() + "cannot store zip entry", e);
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "cannot store zip entry", e);
}
}
use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.
the class ReceiverBase method processMessageInAdapter.
/*
* Assumes message is read, and when transacted, transaction is still open.
*/
private String processMessageInAdapter(IListener origin, Object rawMessage, String message, String messageId, String technicalCorrelationId, Map threadContext, long waitingDuration, boolean manualRetry) throws ListenerException {
String result = null;
PipeLineResult pipeLineResult = null;
long startProcessingTimestamp = System.currentTimeMillis();
// if (message==null) {
// requestSizeStatistics.addValue(0);
// } else {
// requestSizeStatistics.addValue(message.length());
// }
lastMessageDate = startProcessingTimestamp;
log.debug(getLogPrefix() + "received message with messageId [" + messageId + "] (technical) correlationId [" + technicalCorrelationId + "]");
if (StringUtils.isEmpty(messageId)) {
messageId = Misc.createSimpleUUID();
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "generated messageId [" + messageId + "]");
}
if (getChompCharSize() != null || getElementToMove() != null || getElementToMoveChain() != null) {
log.debug(getLogPrefix() + "compact received message");
try {
InputStream xmlInput = IOUtils.toInputStream(message, "UTF-8");
CompactSaxHandler handler = new CompactSaxHandler();
handler.setChompCharSize(getChompCharSize());
handler.setElementToMove(getElementToMove());
handler.setElementToMoveChain(getElementToMoveChain());
handler.setElementToMoveSessionKey(getElementToMoveSessionKey());
handler.setRemoveCompactMsgNamespaces(isRemoveCompactMsgNamespaces());
if (threadContext != null) {
handler.setContext(threadContext);
}
SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
parserFactory.setNamespaceAware(true);
SAXParser saxParser = parserFactory.newSAXParser();
try {
saxParser.parse(xmlInput, handler);
message = handler.getXmlString();
} catch (Exception e) {
warn("received message could not be compacted: " + e.getMessage());
}
handler = null;
} catch (Exception e) {
throw new ListenerException("error during compacting received message to more compact format: " + e.getMessage());
}
}
String businessCorrelationId = null;
if (correlationIDTp != null) {
try {
businessCorrelationId = correlationIDTp.transform(message, null);
} catch (Exception e) {
// throw new ListenerException(getLogPrefix()+"could not extract businessCorrelationId",e);
log.warn(getLogPrefix() + "could not extract businessCorrelationId");
}
if (StringUtils.isEmpty(businessCorrelationId)) {
String cidText;
if (StringUtils.isNotEmpty(getCorrelationIDXPath())) {
cidText = "xpathExpression [" + getCorrelationIDXPath() + "]";
} else {
cidText = "styleSheet [" + getCorrelationIDStyleSheet() + "]";
}
if (StringUtils.isNotEmpty(technicalCorrelationId)) {
log.info(getLogPrefix() + "did not find correlationId using " + cidText + ", reverting to correlationId of transfer [" + technicalCorrelationId + "]");
businessCorrelationId = technicalCorrelationId;
}
}
} else {
businessCorrelationId = technicalCorrelationId;
}
if (StringUtils.isEmpty(businessCorrelationId)) {
if (StringUtils.isNotEmpty(messageId)) {
log.info(getLogPrefix() + "did not find (technical) correlationId, reverting to messageId [" + messageId + "]");
businessCorrelationId = messageId;
}
}
log.info(getLogPrefix() + "messageId [" + messageId + "] technicalCorrelationId [" + technicalCorrelationId + "] businessCorrelationId [" + businessCorrelationId + "]");
threadContext.put(IPipeLineSession.businessCorrelationIdKey, businessCorrelationId);
String label = null;
if (labelTp != null) {
try {
label = labelTp.transform(message, null);
} catch (Exception e) {
// throw new ListenerException(getLogPrefix()+"could not extract label",e);
log.warn(getLogPrefix() + "could not extract label: (" + ClassUtils.nameOf(e) + ") " + e.getMessage());
}
}
if (hasProblematicHistory(messageId, manualRetry, rawMessage, message, threadContext, businessCorrelationId)) {
if (!isTransacted()) {
log.warn(getLogPrefix() + "received message with messageId [" + messageId + "] which has a problematic history; aborting processing");
}
numRejected.increase();
return result;
}
if (isDuplicateAndSkip(getMessageLog(), messageId, businessCorrelationId)) {
numRejected.increase();
return result;
}
if (getCachedProcessResult(messageId) != null) {
numRetried.increase();
}
int txOption = this.getTransactionAttributeNum();
TransactionDefinition txDef = SpringTxManagerProxy.getTransactionDefinition(txOption, getTransactionTimeout());
// TransactionStatus txStatus = txManager.getTransaction(txDef);
IbisTransaction itx = new IbisTransaction(txManager, txDef, "receiver [" + getName() + "]");
TransactionStatus txStatus = itx.getStatus();
// update processing statistics
// count in processing statistics includes messages that are rolled back to input
startProcessingMessage(waitingDuration);
IPipeLineSession pipelineSession = null;
String errorMessage = "";
boolean messageInError = false;
try {
String pipelineMessage;
if (origin instanceof IBulkDataListener) {
try {
IBulkDataListener bdl = (IBulkDataListener) origin;
pipelineMessage = bdl.retrieveBulkData(rawMessage, message, threadContext);
} catch (Throwable t) {
errorMessage = t.getMessage();
messageInError = true;
ListenerException l = wrapExceptionAsListenerException(t);
throw l;
}
} else {
pipelineMessage = message;
}
numReceived.increase();
// Note: errorMessage is used to pass value from catch-clause to finally-clause!
pipelineSession = createProcessingContext(businessCorrelationId, threadContext, messageId);
// threadContext=pipelineSession; // this is to enable Listeners to use session variables, for instance in afterProcessMessage()
try {
if (getMessageLog() != null) {
getMessageLog().storeMessage(messageId, businessCorrelationId, new Date(), RCV_MESSAGE_LOG_COMMENTS, label, pipelineMessage);
}
log.debug(getLogPrefix() + "preparing TimeoutGuard");
TimeoutGuard tg = new TimeoutGuard("Receiver " + getName());
try {
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "activating TimeoutGuard with transactionTimeout [" + transactionTimeout + "]s");
tg.activateGuard(getTransactionTimeout());
pipeLineResult = adapter.processMessageWithExceptions(businessCorrelationId, pipelineMessage, pipelineSession);
pipelineSession.put("exitcode", "" + pipeLineResult.getExitCode());
result = pipeLineResult.getResult();
errorMessage = "exitState [" + pipeLineResult.getState() + "], result [" + result + "]";
if (pipelineSession.containsKey("exitcode")) {
int status = Integer.parseInt("" + pipelineSession.get("exitcode"));
if (status > 0)
errorMessage += ", exitcode [" + status + "]";
}
if (log.isDebugEnabled()) {
log.debug(getLogPrefix() + "received result: " + errorMessage);
}
messageInError = txStatus.isRollbackOnly();
} finally {
log.debug(getLogPrefix() + "canceling TimeoutGuard, isInterrupted [" + Thread.currentThread().isInterrupted() + "]");
if (tg.cancel()) {
errorMessage = "timeout exceeded";
if (StringUtils.isEmpty(result)) {
result = "<timeout/>";
}
messageInError = true;
}
}
if (!messageInError && !isTransacted()) {
String commitOnState = ((Adapter) adapter).getPipeLine().getCommitOnState();
if (StringUtils.isNotEmpty(commitOnState) && !commitOnState.equalsIgnoreCase(pipeLineResult.getState())) {
messageInError = true;
}
}
} catch (Throwable t) {
if (TransactionSynchronizationManager.isActualTransactionActive()) {
log.debug("<*>" + getLogPrefix() + "TX Update: Received failure, transaction " + (txStatus.isRollbackOnly() ? "already" : "not yet") + " marked for rollback-only");
}
errorMessage = t.getMessage();
messageInError = true;
if (pipeLineResult == null) {
pipeLineResult = new PipeLineResult();
}
if (StringUtils.isEmpty(pipeLineResult.getResult())) {
String formattedErrorMessage = adapter.formatErrorMessage("exception caught", t, message, messageId, this, startProcessingTimestamp);
pipeLineResult.setResult(formattedErrorMessage);
}
ListenerException l = wrapExceptionAsListenerException(t);
throw l;
} finally {
putSessionKeysIntoThreadContext(threadContext, pipelineSession);
}
// }
if (getSender() != null) {
String sendMsg = sendResultToSender(technicalCorrelationId, result);
if (sendMsg != null) {
errorMessage = sendMsg;
}
}
} finally {
cacheProcessResult(messageId, businessCorrelationId, errorMessage, new Date(startProcessingTimestamp));
if (!isTransacted() && messageInError) {
if (!manualRetry) {
moveInProcessToError(messageId, businessCorrelationId, message, new Date(startProcessingTimestamp), errorMessage, rawMessage, TXNEW_CTRL);
}
}
try {
Map afterMessageProcessedMap;
if (threadContext != null) {
afterMessageProcessedMap = threadContext;
if (pipelineSession != null) {
threadContext.putAll(pipelineSession);
}
} else {
afterMessageProcessedMap = pipelineSession;
}
origin.afterMessageProcessed(pipeLineResult, rawMessage, afterMessageProcessedMap);
} finally {
long finishProcessingTimestamp = System.currentTimeMillis();
finishProcessingMessage(finishProcessingTimestamp - startProcessingTimestamp);
if (!txStatus.isCompleted()) {
// NB: Spring will take care of executing a commit or a rollback;
// Spring will also ONLY commit the transaction if it was newly created
// by the above call to txManager.getTransaction().
// txManager.commit(txStatus);
itx.commit();
} else {
throw new ListenerException(getLogPrefix() + "Transaction already completed; we didn't expect this");
}
}
}
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "messageId [" + messageId + "] correlationId [" + businessCorrelationId + "] returning result [" + result + "]");
return result;
}
use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.
the class ReceiverBase method createProcessingContext.
private IPipeLineSession createProcessingContext(String correlationId, Map threadContext, String messageId) {
IPipeLineSession pipelineSession = new PipeLineSessionBase();
if (threadContext != null) {
pipelineSession.putAll(threadContext);
if (log.isDebugEnabled()) {
List hiddenSessionKeys = new ArrayList();
if (getHiddenInputSessionKeys() != null) {
StringTokenizer st = new StringTokenizer(getHiddenInputSessionKeys(), " ,;");
while (st.hasMoreTokens()) {
String key = st.nextToken();
hiddenSessionKeys.add(key);
}
}
String contextDump = "PipeLineSession variables for messageId [" + messageId + "] correlationId [" + correlationId + "]:";
for (Iterator it = pipelineSession.keySet().iterator(); it.hasNext(); ) {
String key = (String) it.next();
Object value = pipelineSession.get(key);
if (key.equals("messageText")) {
value = "(... see elsewhere ...)";
}
String strValue = String.valueOf(value);
contextDump += " " + key + "=[" + (hiddenSessionKeys.contains(key) ? hide(strValue) : strValue) + "]";
}
log.debug(getLogPrefix() + contextDump);
}
}
return pipelineSession;
}
use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.
the class ValidatorTestBase method getSchemasProvider.
public SchemasProvider getSchemasProvider(final String schemaLocation, final boolean addNamespaceToSchema) {
return new SchemasProvider() {
public Set<XSD> getXsds() throws ConfigurationException {
Set<XSD> xsds = new HashSet<XSD>();
// if (StringUtils.isNotEmpty(getNoNamespaceSchemaLocation())) {
// XSD xsd = new XSD();
// xsd.setClassLoader(classLoader);
// xsd.setNoNamespaceSchemaLocation(getNoNamespaceSchemaLocation());
// xsd.setResource(getNoNamespaceSchemaLocation());
// xsd.init();
// xsds.add(xsd);
// } else {
String[] split = schemaLocation.trim().split("\\s+");
if (split.length % 2 != 0)
throw new ConfigurationException("The schema must exist from an even number of strings, but it is " + schemaLocation);
for (int i = 0; i < split.length; i += 2) {
XSD xsd = new XSD();
xsd.setClassLoader(this.getClass().getClassLoader());
xsd.setNamespace(split[i]);
xsd.setResource(split[i + 1]);
xsd.setAddNamespaceToSchema(addNamespaceToSchema);
// xsd.setImportedSchemaLocationsToIgnore(getImportedSchemaLocationsToIgnore());
// xsd.setUseBaseImportedSchemaLocationsToIgnore(isUseBaseImportedSchemaLocationsToIgnore());
// xsd.setImportedNamespacesToIgnore(getImportedNamespacesToIgnore());
xsd.init();
xsds.add(xsd);
}
// }
return xsds;
}
@Override
public List<Schema> getSchemas() throws ConfigurationException {
Set<XSD> xsds = getXsds();
xsds = SchemaUtils.getXsdsRecursive(xsds);
// checkRootValidations(xsds);
try {
Map<String, Set<XSD>> xsdsGroupedByNamespace = SchemaUtils.getXsdsGroupedByNamespace(xsds, false);
xsds = SchemaUtils.mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes(this.getClass().getClassLoader(), xsdsGroupedByNamespace, null);
} catch (Exception e) {
throw new ConfigurationException("could not merge schema's", e);
}
List<Schema> schemas = new ArrayList<Schema>();
SchemaUtils.sortByDependencies(xsds, schemas);
return schemas;
}
@Override
public String getSchemasId() throws ConfigurationException {
return schemaLocation;
}
@Override
public String getSchemasId(IPipeLineSession session) throws PipeRunException {
return null;
}
@Override
public List<Schema> getSchemas(IPipeLineSession session) throws PipeRunException {
return null;
}
};
}
Aggregations