use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class HttpSender method createMultiPartEntity.
protected HttpEntity createMultiPartEntity(String message, ParameterValueList parameters, IPipeLineSession session) throws SenderException {
MultipartEntityBuilder entity = MultipartEntityBuilder.create();
entity.setCharset(Charset.forName(getCharSet()));
if (isMtomEnabled())
entity.setMtomMultipart();
if (StringUtils.isNotEmpty(getInputMessageParam())) {
entity.addPart(createMultipartBodypart(getInputMessageParam(), message));
log.debug(getLogPrefix() + "appended stringpart [" + getInputMessageParam() + "] with value [" + message + "]");
}
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
ParameterValue pv = parameters.getParameterValue(i);
String paramType = pv.getDefinition().getType();
String name = pv.getDefinition().getName();
if (Parameter.TYPE_INPUTSTREAM.equals(paramType)) {
Object value = pv.getValue();
if (value instanceof InputStream) {
InputStream fis = (InputStream) value;
String fileName = null;
String sessionKey = pv.getDefinition().getSessionKey();
if (sessionKey != null) {
fileName = (String) session.get(sessionKey + "Name");
}
entity.addPart(createMultipartBodypart(name, fis, fileName));
log.debug(getLogPrefix() + "appended filepart [" + name + "] with value [" + value + "] and name [" + fileName + "]");
} else {
throw new SenderException(getLogPrefix() + "unknown inputstream [" + value.getClass() + "] for parameter [" + name + "]");
}
} else {
String value = pv.asStringValue("");
entity.addPart(createMultipartBodypart(name, value));
log.debug(getLogPrefix() + "appended stringpart [" + name + "] with value [" + value + "]");
}
}
}
if (StringUtils.isNotEmpty(getMultipartXmlSessionKey())) {
String multipartXml = (String) session.get(getMultipartXmlSessionKey());
if (StringUtils.isEmpty(multipartXml)) {
log.warn(getLogPrefix() + "sessionKey [" + getMultipartXmlSessionKey() + "] is empty");
} else {
Element partsElement;
try {
partsElement = XmlUtils.buildElement(multipartXml);
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "error building multipart xml", e);
}
Collection<Node> parts = XmlUtils.getChildTags(partsElement, "part");
if (parts == null || parts.size() == 0) {
log.warn(getLogPrefix() + "no part(s) in multipart xml [" + multipartXml + "]");
} else {
Iterator<Node> iter = parts.iterator();
while (iter.hasNext()) {
Element partElement = (Element) iter.next();
// String partType = partElement.getAttribute("type");
String partName = partElement.getAttribute("name");
String partSessionKey = partElement.getAttribute("sessionKey");
String partMimeType = partElement.getAttribute("mimeType");
Object partObject = session.get(partSessionKey);
if (partObject instanceof InputStream) {
InputStream fis = (InputStream) partObject;
entity.addPart(createMultipartBodypart(partSessionKey, fis, partName, partMimeType));
log.debug(getLogPrefix() + "appended filepart [" + partSessionKey + "] with value [" + partObject + "] and name [" + partName + "]");
} else {
String partValue = (String) session.get(partSessionKey);
entity.addPart(createMultipartBodypart(partName, partValue, partMimeType));
log.debug(getLogPrefix() + "appended stringpart [" + partSessionKey + "] with value [" + partValue + "]");
}
}
}
}
}
// entity.seContentType(contentTypeMtom);
return entity.build();
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class RhinoPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
// INIT
String eol = System.getProperty("line.separator");
if (input == null) {
// No input from previous pipes. We will use filename and or string input.
if ((StringUtils.isEmpty(fileInput)) && inputString == null && isLookupAtRuntime()) {
// No input from file or input string. Nowhere to GO!
throw new PipeRunException(this, getLogPrefix(session) + "No input specified anywhere. No string input, no file input and no previous pipe input");
}
}
if (!(input instanceof String)) {
throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
}
inputString = (String) input;
// Get the input from the file at Run Time
if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
URL resource = null;
try {
resource = ClassUtils.getResourceURL(classLoader, getFileName());
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + getFileName() + "]", e);
}
if (resource == null) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + getFileName() + "]");
}
try {
fileInput = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR);
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + getFileName() + "]", e);
}
}
// Get all params as input
if (getParameterList() != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
ParameterValueList pvl;
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
for (int i = 0; i < pvl.size(); i++) {
ParameterValue pv = pvl.getParameterValue(i);
paramsInput = pv.asStringValue("") + eol + paramsInput;
}
}
String javascriptcode = "Packages.java;" + eol;
if (fileInput != null) {
javascriptcode = javascriptcode + fileInput;
}
if (paramsInput != null) {
javascriptcode = paramsInput + eol + javascriptcode;
}
String stringResult = (String) javascriptcode;
stringResult = "INPUTSTREAM used in case of ERROR" + eol + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + eol + stringResult;
// Start your engines
// Rhino engine Ok.
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
if (isDebug()) {
System.out.println("debug active");
cx.setLanguageVersion(Context.VERSION_1_2);
cx.setGeneratingDebug(true);
}
// Load javascript factory with javascript functions from file, stringinput and paraminput
String jsResult = "";
try {
cx.evaluateString(scope, javascriptcode, "jsScript", 1, null);
Function fct = (Function) scope.get(jsfunctionName, scope);
// Object result = fct.call(cx, scope, scope, new Object[]{jsfunctionArguments});
Object result = fct.call(cx, scope, scope, new Object[] { input });
if (isDebug()) {
System.out.println(cx.jsToJava(result, String.class));
}
;
jsResult = (String) cx.jsToJava(result, String.class);
} catch (org.mozilla.javascript.EcmaError ex) {
throw new PipeRunException(this, "org.mozilla.javascript.EcmaError -> ", ex);
// System.out.println(ex.getMessage());
} finally {
Context.exit();
}
// Use the result
if (!(jsResult instanceof String)) {
} else {
if ((String) jsResult != null) {
stringResult = (String) jsResult;
}
}
if (StringUtils.isEmpty(getSessionKey())) {
return new PipeRunResult(getForward(), stringResult);
} else {
session.put(getSessionKey(), stringResult);
return new PipeRunResult(getForward(), input);
}
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class FileHandler method createFile.
private File createFile(byte[] in, IPipeLineSession session, ParameterList paramList) throws IOException, ParameterException {
File tmpFile;
String writeSuffix_work = null;
if (paramList != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) null, session);
ParameterValueList pvl = prc.getValues(paramList);
if (pvl != null) {
ParameterValue writeSuffixParamValue = pvl.getParameterValue("writeSuffix");
if (writeSuffixParamValue != null) {
writeSuffix_work = (String) writeSuffixParamValue.getValue();
}
}
}
if (writeSuffix_work == null) {
writeSuffix_work = getWriteSuffix();
}
String name = getEffectiveFileName(null, session);
if (StringUtils.isEmpty(getDirectory())) {
if (StringUtils.isEmpty(name)) {
tmpFile = File.createTempFile("ibis", writeSuffix_work);
} else {
tmpFile = new File(name);
}
} else {
if (StringUtils.isEmpty(name)) {
tmpFile = File.createTempFile("ibis", writeSuffix_work, new File(getDirectory()));
} else {
tmpFile = new File(getDirectory() + File.separator + name);
}
}
return tmpFile;
}
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 (int i = 0; i < pvl.size(); i++) {
ParameterValue pv = pvl.getParameterValue(i);
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 SapSender method getFunction.
public JCO.Function getFunction(SapSystem sapSystem, ParameterValueList pvl) throws SapException {
if (StringUtils.isNotEmpty(getSapSystemName()) && StringUtils.isNotEmpty(getFunctionName())) {
return getFunctionTemplate().getFunction();
}
String functionName = getFunctionName();
if (StringUtils.isEmpty(functionName)) {
if (pvl == null) {
throw new SapException("no parameters to determine functionName from");
}
ParameterValue pv = pvl.getParameterValue(getFunctionNameParam());
if (pv == null) {
throw new SapException("could not get ParameterValue for parameter [" + getFunctionNameParam() + "]");
}
functionName = pv.asStringValue(null);
}
if (StringUtils.isEmpty(functionName)) {
throw new SapException("could not determine functionName using parameter [" + getFunctionNameParam() + "]");
}
return getFunctionTemplate(sapSystem, functionName).getFunction();
}
Aggregations