use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class CompareStringPipe method configure.
@Override
public void configure() throws ConfigurationException {
super.configure();
if (null == findForward(LESSTHANFORWARD))
throw new ConfigurationException(getLogPrefix(null) + "forward [" + LESSTHANFORWARD + "] is not defined");
if (null == findForward(GREATERTHANFORWARD))
throw new ConfigurationException(getLogPrefix(null) + "forward [" + GREATERTHANFORWARD + "] is not defined");
if (null == findForward(EQUALSFORWARD))
throw new ConfigurationException(getLogPrefix(null) + "forward [" + EQUALSFORWARD + "] is not defined");
if (StringUtils.isEmpty(sessionKey1) && StringUtils.isEmpty(sessionKey2)) {
boolean operand1Exists = false;
boolean operand2Exists = false;
ParameterList parameterList = getParameterList();
for (int i = 0; i < parameterList.size(); i++) {
Parameter parameter = parameterList.getParameter(i);
if (parameter.getName().equalsIgnoreCase(OPERAND1)) {
operand1Exists = true;
} else {
if (parameter.getName().equalsIgnoreCase(OPERAND2)) {
operand2Exists = true;
}
}
}
if (!operand1Exists && !operand2Exists) {
throw new ConfigurationException(getLogPrefix(null) + "has neither parameter [" + OPERAND1 + "] nor parameter [" + OPERAND2 + "] specified");
}
}
}
use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class AbstractPipe method configure.
/**
* <code>configure()</code> is called after the {@link nl.nn.adapterframework.core.PipeLine Pipeline} is registered
* at the {@link nl.nn.adapterframework.core.Adapter Adapter}. Purpose of this method is to reduce
* creating connections to databases etc. in the {@link #doPipe(Object) doPipe()} method.
* As much as possible class-instantiating should take place in the
* <code>configure()</code> method, to improve performance.
*/
@Override
public void configure() throws ConfigurationException {
ParameterList params = getParameterList();
if (params != null) {
try {
params.configure();
} catch (ConfigurationException e) {
throw new ConfigurationException(getLogPrefix(null) + "while configuring parameters", e);
}
}
if (!StringUtils.isEmpty(getElementToMove()) && !StringUtils.isEmpty(getElementToMoveChain())) {
throw new ConfigurationException(getLogPrefix(null) + "cannot have both an elementToMove and an elementToMoveChain specified");
}
if (pipeForwards.isEmpty()) {
ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
String msg = getLogPrefix(null) + "has no forwards defined.";
configWarnings.add(log, msg);
} else {
for (Iterator<String> it = pipeForwards.keySet().iterator(); it.hasNext(); ) {
String forwardName = it.next();
PipeForward forward = pipeForwards.get(forwardName);
if (forward != null) {
String path = forward.getPath();
if (path != null) {
PipeLineExit plExit = pipeline.getPipeLineExits().get(path);
if (plExit == null) {
if (pipeline.getPipe(path) == null) {
ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
String msg = getLogPrefix(null) + "has a forward of which the pipe to execute [" + path + "] is not defined.";
configWarnings.add(log, msg);
}
}
}
}
}
}
if (getLocker() != null) {
getLocker().configure();
}
eventHandler = MonitorManager.getEventHandler();
}
use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class Json2XmlValidator method alignJson.
protected PipeRunResult alignJson(String messageToValidate, IPipeLineSession session, boolean responseMode) throws PipeRunException, XmlValidatorException {
ValidationContext context;
ValidatorHandler validatorHandler;
try {
context = validator.createValidationContext(session, getRootValidations(responseMode), getInvalidRootNamespaces());
validatorHandler = validator.getValidatorHandler(session, context);
} catch (ConfigurationException e) {
throw new PipeRunException(this, "Cannot create ValidationContext", e);
}
String resultEvent;
String out = null;
try {
Json2Xml aligner = new Json2Xml(validatorHandler, context.getXsModels(), isCompactJsonArrays(), getMessageRoot(responseMode), isStrictJsonArraySyntax());
if (StringUtils.isNotEmpty(getTargetNamespace())) {
aligner.setTargetNamespace(getTargetNamespace());
}
aligner.setDeepSearch(isDeepSearch());
aligner.setErrorHandler(context.getErrorHandler());
aligner.setFailOnWildcards(isFailOnWildcards());
ParameterList parameterList = getParameterList();
if (parameterList != null) {
ParameterResolutionContext prc = new ParameterResolutionContext(messageToValidate, session, isNamespaceAware(), false);
Map<String, Object> parametervalues = null;
parametervalues = prc.getValueMap(parameterList);
aligner.setOverrideValues(parametervalues);
}
JsonStructure jsonStructure = Json.createReader(new StringReader(messageToValidate)).read();
if (getOutputFormat(session, responseMode).equalsIgnoreCase(FORMAT_JSON)) {
Xml2Json xml2json = new Xml2Json(aligner, isCompactJsonArrays(), !isJsonWithRootElements());
aligner.setContentHandler(xml2json);
aligner.startParse(jsonStructure);
out = xml2json.toString();
} else {
Source source = aligner.asSource(jsonStructure);
out = XmlUtils.source2String(source, isProduceNamespaceLessXml());
}
} catch (Exception e) {
resultEvent = validator.finalizeValidation(context, session, e);
}
resultEvent = validator.finalizeValidation(context, session, null);
PipeForward forward = determineForward(resultEvent, session, responseMode);
PipeRunResult result = new PipeRunResult(forward, out);
return result;
}
use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class EtagHandlerPipe method doPipe.
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if (input == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null input");
}
if (!(input instanceof String)) {
throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
}
String uriPatternSessionKey = null;
ParameterValueList pvl = null;
ParameterList parameterList = getParameterList();
if (parameterList != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
try {
pvl = prc.getValues(getParameterList());
if (pvl != null) {
for (int i = 0; i < parameterList.size(); i++) {
Parameter parameter = parameterList.getParameter(i);
if ("uriPattern".equalsIgnoreCase(parameter.getName()))
uriPatternSessionKey = (String) parameter.getValue(pvl, prc);
}
}
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
}
// hash over data genereren, uit cache lezen en teruggeven, in cache updaten, verwijderen uit cache, cache naar disk wegschrijven, cache legen
String cacheKey = null;
if (uriPatternSessionKey != null && !uriPatternSessionKey.isEmpty())
cacheKey = getRestPath() + "_" + uriPatternSessionKey.toLowerCase();
else
cacheKey = getRestPath() + "_" + getUriPattern();
if (cache != null && cache.containsKey(cacheKey)) {
Object returnCode = false;
if (getAction().equalsIgnoreCase("generate")) {
cache.put(cacheKey, RestListenerUtils.formatEtag(getRestPath(), getUriPattern(), input.hashCode()));
returnCode = true;
} else if (getAction().equalsIgnoreCase("get")) {
returnCode = cache.get(cacheKey);
} else if (getAction().equalsIgnoreCase("set")) {
cache.put(cacheKey, input.toString());
returnCode = true;
} else if (getAction().equalsIgnoreCase("delete")) {
returnCode = cache.remove(cacheKey);
} else if (getAction().equalsIgnoreCase("flush")) {
if (cache instanceof ApiEhcache) {
((ApiEhcache) cache).flush();
returnCode = true;
}
} else if (getAction().equalsIgnoreCase("clear")) {
cache.clear();
returnCode = true;
} else {
throw new PipeRunException(this, getLogPrefix(session) + "action not found [" + getAction() + "]");
}
if (log.isDebugEnabled())
log.debug("found eTag cacheKey [" + cacheKey + "] with action [" + getAction() + "]");
return new PipeRunResult(getForward(), returnCode);
} else {
PipeForward pipeForward = findForward("exception");
String msg;
if (cache == null)
msg = "failed to locate cache";
else
msg = "failed to locate eTag [" + cacheKey + "] in cache";
if (pipeForward == null) {
throw new PipeRunException(this, getLogPrefix(session) + msg);
}
return new PipeRunResult(pipeForward, "");
}
}
use of nl.nn.adapterframework.parameters.ParameterList in project iaf by ibissource.
the class EtagHandlerPipe method configure.
@Override
public void configure() throws ConfigurationException {
super.configure();
String action = getAction();
if (action == null) {
throw new ConfigurationException(getLogPrefix(null) + "action must be set");
}
if (!actions.contains(action)) {
throw new ConfigurationException(getLogPrefix(null) + "illegal value for action [" + action + "], must be one of " + actions.toString());
}
boolean hasUriPatternParameter = false;
ParameterList parameterList = getParameterList();
for (int i = 0; i < parameterList.size(); i++) {
Parameter parameter = parameterList.getParameter(i);
if ("uriPattern".equalsIgnoreCase(parameter.getName()))
hasUriPatternParameter = true;
}
if (getUriPattern() == null && !hasUriPatternParameter) {
throw new ConfigurationException(getLogPrefix(null) + "no uriPattern found!");
}
cache = ApiCacheManager.getInstance();
}
Aggregations