use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class SapFunctionFacade method message2FunctionCall.
public void message2FunctionCall(JCoFunction function, String request, String correlationId, ParameterValueList pvl) throws SapException {
JCoParameterList input = function.getImportParameterList();
int requestFieldIndex = findFieldIndex(input, getRequestFieldIndex(), getRequestFieldName());
setParameters(input, function.getTableParameterList(), request, requestFieldIndex);
if (pvl != null) {
for (ParameterValue pv : pvl) {
String name = pv.getDefinition().getName();
String value = pv.asStringValue("");
int slashPos = name.indexOf('/');
if (slashPos < 0) {
input.setValue(name, value);
} else {
String structName = name.substring(0, slashPos);
String elemName = name.substring(slashPos + 1);
JCoStructure struct = input.getStructure(structName);
struct.setValue(elemName, value);
}
}
}
int correlationIdFieldIndex = findFieldIndex(input, getCorrelationIdFieldIndex(), getCorrelationIdFieldName());
if (correlationIdFieldIndex > 0 && input != null) {
input.setValue(correlationIdFieldIndex - 1, correlationId);
}
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class EtagHandlerPipe method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
if (message == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null input");
}
String uriPatternSessionKey = null;
ParameterValueList pvl = null;
ParameterList parameterList = getParameterList();
if (parameterList != null) {
try {
pvl = parameterList.getValues(message, session);
if (pvl != null) {
ParameterValue pv = pvl.get("uriPattern");
if (pv != null) {
uriPatternSessionKey = pv.asStringValue();
}
}
} 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 (log.isDebugEnabled())
log.debug("found eTag cacheKey [" + cacheKey + "] with action [" + getAction() + "]");
switch(getAction()) {
case GENERATE:
try {
cache.put(cacheKey, ApiCacheManager.buildEtag(getRestPath() + "/" + getUriPattern(), message.asString().hashCode()));
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot open stream", e);
}
returnCode = true;
break;
case GET:
returnCode = cache.get(cacheKey);
break;
case SET:
try {
cache.put(cacheKey, message.asString());
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot open stream", e);
}
returnCode = true;
break;
case DELETE:
returnCode = cache.remove(cacheKey);
break;
case FLUSH:
if (cache instanceof ApiEhcache) {
((ApiEhcache) cache).flush();
returnCode = true;
}
break;
case CLEAR:
cache.clear();
returnCode = true;
break;
default:
throw new PipeRunException(this, getLogPrefix(session) + "action not found [" + getAction() + "]");
}
return new PipeRunResult(getSuccessForward(), returnCode);
} else {
PipeForward pipeForward = findForward(PipeForward.EXCEPTION_FORWARD_NAME);
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.ParameterValue in project iaf by ibissource.
the class JavascriptSender method sendMessage.
@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException {
Object jsResult = "";
int numberOfParameters = 0;
JavascriptEngine<?> jsInstance = engine.create();
try {
jsInstance.startRuntime();
} catch (JavascriptException e) {
throw new SenderException("unable to start Javascript engine", e);
}
// Create a Parameter Value List
ParameterValueList pvl = null;
try {
if (getParameterList() != null) {
pvl = getParameterList().getValues(message, session);
}
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + " exception extracting parameters", e);
}
if (pvl != null) {
numberOfParameters = pvl.size();
}
// This array will contain the parameters given in the configuration
Object[] jsParameters = new Object[numberOfParameters];
for (int i = 0; i < numberOfParameters; i++) {
ParameterValue pv = pvl.getParameterValue(i);
Object value = pv.getValue();
try {
jsParameters[i] = value instanceof Message ? ((Message) value).asString() : value;
} catch (IOException e) {
throw new SenderException(getLogPrefix(), e);
}
}
for (ISender sender : getSenders()) {
jsInstance.registerCallback(sender, session);
}
try {
// Compile the given Javascript and execute the given Javascript function
jsInstance.executeScript(adaptES6Literals(fileInput));
jsResult = jsInstance.executeFunction(jsFunctionName, jsParameters);
} catch (JavascriptException e) {
throw new SenderException("unable to execute script/function", e);
} finally {
jsInstance.closeRuntime();
}
// Pass jsResult, the result of the Javascript function.
// It is recommended to have the result of the Javascript function be of type String, which will be the output of the sender
String result = String.valueOf(jsResult);
if (StringUtils.isEmpty(result) || "null".equals(result) || "undefined".equals(result)) {
return Message.nullMessage();
}
return new Message(result);
}
Aggregations