use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.
the class Parameter method getValue.
/**
* determines the raw value
* @param alreadyResolvedParameters
* @return the raw value as object
* @throws IbisException
*/
public Object getValue(ParameterValueList alreadyResolvedParameters, ParameterResolutionContext prc) throws ParameterException {
Object result = null;
log.debug("Calculating value for Parameter [" + getName() + "]");
if (!configured) {
throw new ParameterException("Parameter [" + getName() + "] not configured");
}
String retrievedSessionKey;
if (transformerPoolSessionKey != null) {
try {
retrievedSessionKey = transformerPoolSessionKey.transform(prc.getInput(), null);
} catch (Exception e) {
throw new ParameterException("SessionKey for parameter [" + getName() + "] exception on transformation to get name", e);
}
} else {
retrievedSessionKey = getSessionKey();
}
TransformerPool pool = getTransformerPool();
if (pool != null) {
try {
Object transformResult = null;
Source source = null;
if (StringUtils.isNotEmpty(getValue())) {
source = XmlUtils.stringToSourceForSingleUse(getValue(), prc.isNamespaceAware());
} else if (StringUtils.isNotEmpty(retrievedSessionKey)) {
String sourceString;
Object sourceObject = prc.getSession().get(retrievedSessionKey);
if (TYPE_LIST.equals(getType()) && sourceObject instanceof List) {
List<String> items = (List<String>) sourceObject;
XmlBuilder itemsXml = new XmlBuilder("items");
for (Iterator<String> it = items.iterator(); it.hasNext(); ) {
String item = it.next();
XmlBuilder itemXml = new XmlBuilder("item");
itemXml.setValue(item);
itemsXml.addSubElement(itemXml);
}
sourceString = itemsXml.toXML();
} else if (TYPE_MAP.equals(getType()) && sourceObject instanceof Map) {
Map<String, String> items = (Map<String, String>) sourceObject;
XmlBuilder itemsXml = new XmlBuilder("items");
for (Iterator<String> it = items.keySet().iterator(); it.hasNext(); ) {
String item = it.next();
XmlBuilder itemXml = new XmlBuilder("item");
itemXml.addAttribute("name", item);
itemXml.setValue(items.get(item));
itemsXml.addSubElement(itemXml);
}
sourceString = itemsXml.toXML();
} else {
sourceString = (String) sourceObject;
}
if (StringUtils.isNotEmpty(sourceString)) {
log.debug("Parameter [" + getName() + "] using sessionvariable [" + retrievedSessionKey + "] as source for transformation");
source = XmlUtils.stringToSourceForSingleUse(sourceString, prc.isNamespaceAware());
} else {
log.debug("Parameter [" + getName() + "] sessionvariable [" + retrievedSessionKey + "] empty, no transformation will be performed");
}
} else if (StringUtils.isNotEmpty(getPattern())) {
String sourceString = format(alreadyResolvedParameters, prc);
if (StringUtils.isNotEmpty(sourceString)) {
log.debug("Parameter [" + getName() + "] using pattern [" + getPattern() + "] as source for transformation");
source = XmlUtils.stringToSourceForSingleUse(sourceString, prc.isNamespaceAware());
} else {
log.debug("Parameter [" + getName() + "] pattern [" + getPattern() + "] empty, no transformation will be performed");
}
} else {
source = prc.getInputSource();
}
if (source != null) {
if (transformerPoolRemoveNamespaces != null) {
String rnResult = transformerPoolRemoveNamespaces.transform(source, null);
source = XmlUtils.stringToSource(rnResult);
}
transformResult = transform(source, prc);
}
if (!(transformResult instanceof String) || StringUtils.isNotEmpty((String) transformResult)) {
result = transformResult;
}
} catch (Exception e) {
throw new ParameterException("Parameter [" + getName() + "] exception on transformation to get parametervalue", e);
}
} else {
if (StringUtils.isNotEmpty(retrievedSessionKey)) {
result = prc.getSession().get(retrievedSessionKey);
} else if (StringUtils.isNotEmpty(getPattern())) {
result = format(alreadyResolvedParameters, prc);
} else if (StringUtils.isNotEmpty(getValue())) {
result = getValue();
} else {
result = prc.getInput();
}
}
if (result != null) {
if (log.isDebugEnabled()) {
log.debug("Parameter [" + getName() + "] resolved to [" + (isHidden() ? hide(result.toString()) : result) + "]");
}
} else {
// if value is null then return specified default value
StringTokenizer stringTokenizer = new StringTokenizer(getDefaultValueMethods(), ",");
while (result == null && stringTokenizer.hasMoreElements()) {
String token = stringTokenizer.nextToken();
if ("defaultValue".equals(token)) {
result = getDefaultValue();
} else if ("sessionKey".equals(token)) {
result = prc.getSession().get(retrievedSessionKey);
} else if ("pattern".equals(token)) {
result = format(alreadyResolvedParameters, prc);
} else if ("value".equals(token)) {
result = getValue();
} else if ("input".equals(token)) {
result = prc.getInput();
}
}
log.debug("Parameter [" + getName() + "] resolved to defaultvalue [" + (isHidden() ? hide(result.toString()) : result) + "]");
}
if (result != null && result instanceof String) {
if (getMinLength() >= 0 && !TYPE_NUMBER.equals(getType())) {
if (result.toString().length() < getMinLength()) {
log.debug("Padding parameter [" + getName() + "] because length [" + result.toString().length() + "] deceeds minLength [" + getMinLength() + "]");
result = StringUtils.rightPad(result.toString(), getMinLength());
}
}
if (getMaxLength() >= 0) {
if (result.toString().length() > getMaxLength()) {
log.debug("Trimming parameter [" + getName() + "] because length [" + result.toString().length() + "] exceeds maxLength [" + getMaxLength() + "]");
result = result.toString().substring(0, getMaxLength());
}
}
if (TYPE_NODE.equals(getType())) {
try {
result = XmlUtils.buildNode((String) result, prc.isNamespaceAware());
if (log.isDebugEnabled())
log.debug("final result [" + result.getClass().getName() + "][" + result + "]");
} catch (DomBuilderException e) {
throw new ParameterException("Parameter [" + getName() + "] could not parse result [" + result + "] to XML nodeset", e);
}
}
if (TYPE_DOMDOC.equals(getType())) {
try {
result = XmlUtils.buildDomDocument((String) result, prc.isNamespaceAware(), prc.isXslt2());
if (log.isDebugEnabled())
log.debug("final result [" + result.getClass().getName() + "][" + result + "]");
} catch (DomBuilderException e) {
throw new ParameterException("Parameter [" + getName() + "] could not parse result [" + result + "] to XML document", e);
}
}
if (TYPE_DATE.equals(getType()) || TYPE_DATETIME.equals(getType()) || TYPE_TIMESTAMP.equals(getType()) || TYPE_TIME.equals(getType())) {
log.debug("Parameter [" + getName() + "] converting result [" + result + "] to date using formatString [" + getFormatString() + "]");
DateFormat df = new SimpleDateFormat(getFormatString());
try {
result = df.parseObject((String) result);
} catch (ParseException e) {
throw new ParameterException("Parameter [" + getName() + "] could not parse result [" + result + "] to Date using formatString [" + getFormatString() + "]", e);
}
}
if (TYPE_XMLDATETIME.equals(getType())) {
log.debug("Parameter [" + getName() + "] converting result [" + result + "] from xml dateTime to date");
result = DateUtils.parseXmlDateTime((String) result);
}
if (TYPE_NUMBER.equals(getType())) {
log.debug("Parameter [" + getName() + "] converting result [" + result + "] to number decimalSeparator [" + decimalFormatSymbols.getDecimalSeparator() + "] groupingSeparator [" + decimalFormatSymbols.getGroupingSeparator() + "]");
DecimalFormat df = new DecimalFormat();
df.setDecimalFormatSymbols(decimalFormatSymbols);
try {
Number n = df.parse((String) result);
result = n;
} catch (ParseException e) {
throw new ParameterException("Parameter [" + getName() + "] could not parse result [" + result + "] to number decimalSeparator [" + decimalFormatSymbols.getDecimalSeparator() + "] groupingSeparator [" + decimalFormatSymbols.getGroupingSeparator() + "]", e);
}
if (getMinLength() >= 0 && result.toString().length() < getMinLength()) {
log.debug("Adding leading zeros to parameter [" + getName() + "]");
result = StringUtils.leftPad(result.toString(), getMinLength(), '0');
}
}
if (TYPE_INTEGER.equals(getType())) {
log.debug("Parameter [" + getName() + "] converting result [" + result + "] to integer");
try {
Integer i = Integer.parseInt((String) result);
result = i;
} catch (NumberFormatException e) {
throw new ParameterException("Parameter [" + getName() + "] could not parse result [" + result + "] to integer", e);
}
}
}
if (result != null) {
if (getMinInclusive() != null || getMaxInclusive() != null) {
if (getMinInclusive() != null) {
if (((Number) result).floatValue() < minInclusive.floatValue()) {
log.debug("Replacing parameter [" + getName() + "] because value [" + result + "] exceeds minInclusive [" + getMinInclusive() + "]");
result = minInclusive;
}
}
if (getMaxInclusive() != null) {
if (((Number) result).floatValue() > maxInclusive.floatValue()) {
log.debug("Replacing parameter [" + getName() + "] because value [" + result + "] exceeds maxInclusive [" + getMaxInclusive() + "]");
result = maxInclusive;
}
}
}
}
return result;
}
use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.
the class CmisSender method sendMessageForActionFind.
private String sendMessageForActionFind(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queryElement = null;
try {
if (XmlUtils.isWellFormed(message, "query")) {
queryElement = XmlUtils.buildElement(message);
} else {
queryElement = XmlUtils.buildElement("<query/>");
}
} catch (DomBuilderException e) {
throw new SenderException(e);
}
String statement = XmlUtils.getChildTagAsString(queryElement, "statement");
String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems");
String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount");
String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions");
String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions");
OperationContext operationContext = session.createOperationContext();
if (StringUtils.isNotEmpty(maxItems)) {
operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems));
}
boolean sav = false;
if (StringUtils.isNotEmpty(searchAllVersions)) {
sav = Boolean.parseBoolean(searchAllVersions);
}
if (StringUtils.isNotEmpty(includeAllowableActions)) {
operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions));
}
ItemIterable<QueryResult> q = session.query(statement, sav, operationContext);
if (StringUtils.isNotEmpty(skipCount)) {
long sc = Long.parseLong(skipCount);
q = q.skipTo(sc);
}
if (StringUtils.isNotEmpty(maxItems)) {
q = q.getPage();
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder rowsetXml = new XmlBuilder("rowset");
for (QueryResult qResult : q) {
XmlBuilder rowXml = new XmlBuilder("row");
for (PropertyData<?> property : qResult.getProperties()) {
rowXml.addSubElement(getPropertyXml(property));
}
rowsetXml.addSubElement(rowXml);
}
cmisXml.addSubElement(rowsetXml);
return cmisXml.toXML();
}
use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.
the class CmisSender method sendMessageForActionFetch.
private String sendMessageForActionFetch(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queryElement = null;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
queryElement = XmlUtils.buildElement(message);
} else {
queryElement = XmlUtils.buildElement("<cmis/>");
}
} catch (DomBuilderException e) {
throw new SenderException(e);
}
String objectIdstr = XmlUtils.getChildTagAsString(queryElement, "objectId");
String filter = XmlUtils.getChildTagAsString(queryElement, "filter");
boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(queryElement, "includeAllowableActions");
boolean includePolicies = XmlUtils.getChildTagAsBoolean(queryElement, "includePolicies");
boolean includeAcl = XmlUtils.getChildTagAsBoolean(queryElement, "includeAcl");
OperationContext operationContext = session.createOperationContext();
if (StringUtils.isNotEmpty(filter))
operationContext.setFilterString(filter);
operationContext.setIncludeAllowableActions(includeAllowableActions);
operationContext.setIncludePolicies(includePolicies);
operationContext.setIncludeAcls(includeAcl);
CmisObject object = null;
try {
object = session.getObject(session.createObjectId(objectIdstr), operationContext);
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return getResultOnNotFound();
} else {
throw new SenderException(e);
}
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder propertiesXml = new XmlBuilder("properties");
for (Iterator it = object.getProperties().iterator(); it.hasNext(); ) {
Property property = (Property) it.next();
propertiesXml.addSubElement(getPropertyXml(property));
}
cmisXml.addSubElement(propertiesXml);
XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
Set<Action> actions = object.getAllowableActions().getAllowableActions();
for (Action action : actions) {
XmlBuilder actionXml = new XmlBuilder("action");
actionXml.setValue(action.value());
allowableActionsXml.addSubElement(actionXml);
}
cmisXml.addSubElement(allowableActionsXml);
XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
if (object.getAcl() != null)
isExactAclXml.setValue(object.getAcl().isExact().toString());
cmisXml.addSubElement(isExactAclXml);
XmlBuilder policiesXml = new XmlBuilder("policyIds");
List<ObjectId> policies = object.getPolicyIds();
if (policies != null) {
for (ObjectId objectId : policies) {
XmlBuilder policyXml = new XmlBuilder("policyId");
policyXml.setValue(objectId.getId());
policiesXml.addSubElement(policyXml);
}
}
cmisXml.addSubElement(policiesXml);
XmlBuilder relationshipsXml = new XmlBuilder("relationships");
List<Relationship> relationships = object.getRelationships();
if (relationships != null) {
for (Relationship relation : relationships) {
XmlBuilder policyXml = new XmlBuilder("relation");
policyXml.setValue(relation.getId());
relationshipsXml.addSubElement(policyXml);
}
}
cmisXml.addSubElement(relationshipsXml);
return cmisXml.toXML();
}
use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.
the class CmisSender method sendMessageForActionUpdate.
private String sendMessageForActionUpdate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String objectId = null;
Map props = new HashMap();
Element cmisElement;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
cmisElement = XmlUtils.buildElement(message);
} else {
cmisElement = XmlUtils.buildElement("<cmis/>");
}
objectId = XmlUtils.getChildTagAsString(cmisElement, "id");
Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
if (propertiesElement != null) {
processProperties(propertiesElement, props);
}
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
}
CmisObject object = null;
try {
object = session.getObject(session.createObjectId(objectId));
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return getResultOnNotFound();
} else {
throw new SenderException(e);
}
}
object.updateProperties(props);
return object.getId();
}
use of nl.nn.adapterframework.util.DomBuilderException in project iaf by ibissource.
the class CoolGenWrapperPipe method doPipe.
/**
* Transform the input (optionally), check the conformance to the schema (optionally),
* call the required proxy, transform the output (optionally)
*/
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
Writer proxyResult;
String proxypreProc = null;
Variant inputVar;
String wrapperResult = "";
CoolGenXMLProxy proxy;
ActionListener actionListener = new ActionListener() {
/**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
public String errorMessage;
public void actionPerformed(ActionEvent e) {
errorMessage = e.toString();
}
public String toString() {
return errorMessage;
}
};
Source in;
try {
log.info(getLogPrefix(session) + "instantiating proxy [" + proxyClassName + "] as a temporary fix for broken comm-bridge connections");
proxy = createProxy(proxyClassName);
} catch (ConfigurationException ce) {
String msg = getLogPrefix(session) + "cannot recreate proxy after exception";
log.error(msg, ce);
throw new PipeRunException(this, msg, ce);
}
proxy.addExceptionListener(actionListener);
try {
inputVar = new Variant(input);
in = inputVar.asXmlSource();
if (preProcTransformer != null) {
proxypreProc = XmlUtils.transformXml(preProcTransformer, in);
log.debug(getLogPrefix(session) + "] preprocessing transformed message into [" + proxypreProc + "]");
} else
proxypreProc = inputVar.asString();
if (proxyInputFixTransformer != null)
proxypreProc = XmlUtils.transformXml(proxyInputFixTransformer, proxypreProc);
proxyResult = new StringWriter(10 * 1024);
try {
proxy.clear();
} catch (PropertyVetoException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot clear CoolGen proxy", e);
}
try {
proxy.executeXML(new StringReader(proxypreProc), proxyResult);
proxy.removeExceptionListener(actionListener);
String err = actionListener.toString();
if (err != null) {
// if an error occurs, recreate the proxy and throw an exception
log.debug(getLogPrefix(session) + "got error, recreating proxy with class [" + proxyClassName + "]");
try {
proxy = createProxy(proxyClassName);
} catch (ConfigurationException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot recreate proxy [" + proxyClassName + "]", e);
}
throw new PipeRunException(this, getLogPrefix(session) + "error excuting proxy [" + proxyClassName + "]:" + err);
}
} catch (XmlProxyException xpe) {
try {
proxy = createProxy(proxyClassName);
} catch (ConfigurationException ce) {
log.error(getLogPrefix(session) + "cannot recreate proxy", xpe);
}
throw new PipeRunException(this, getLogPrefix(session) + "error excecuting proxy", xpe);
}
if (postProcTransformer != null) {
log.debug(getLogPrefix(session) + " CoolGen proxy returned: [" + proxyResult.toString() + "]");
wrapperResult = XmlUtils.transformXml(postProcTransformer, proxyResult.toString());
} else
wrapperResult = proxyResult.toString();
} catch (DomBuilderException e) {
throw new PipeRunException(this, getLogPrefix(session) + "DomBuilderException excecuting proxy", e);
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "IOException excecuting proxy", e);
} catch (TransformerException e) {
throw new PipeRunException(this, getLogPrefix(session) + "TransformerException excecuting proxy", e);
}
return new PipeRunResult(getForward(), wrapperResult);
}
Aggregations