use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class CmisSender method createCmisSession.
/**
* Creates a session during JMV runtime, tries to retrieve parameters and falls back on the defaults when they can't be found
*/
public Session createCmisSession(ParameterValueList pvl) throws SenderException {
String authAlias_work = null;
String username_work = null;
String password_work = null;
if (pvl != null) {
ParameterValue pv = pvl.get("authAlias");
if (pv != null) {
authAlias_work = pv.asStringValue();
}
pv = pvl.get("username");
if (pv == null) {
pv = pvl.get("userName");
}
if (pv != null) {
username_work = pv.asStringValue();
}
pv = pvl.get("password");
if (pv != null) {
password_work = pv.asStringValue();
}
}
if (authAlias_work == null) {
authAlias_work = getAuthAlias();
}
if (username_work == null) {
username_work = getUsername();
}
if (password_work == null) {
password_work = getPassword();
}
CredentialFactory cf = new CredentialFactory(authAlias_work, username_work, password_work);
try {
return getSessionBuilder().build(cf.getUsername(), cf.getPassword());
} catch (CmisSessionException e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class HttpSender method getMultipartPostMethodWithParamsInBody.
/**
* Returns a multi-parted message, either as X-WWW-FORM-URLENCODED, FORM-DATA or MTOM
* @throws IOException
*/
protected HttpPost getMultipartPostMethodWithParamsInBody(URI uri, String message, ParameterValueList parameters, PipeLineSession session) throws SenderException, IOException {
HttpPost hmethod = new HttpPost(uri);
if (postType.equals(PostType.URLENCODED) && StringUtils.isEmpty(getMultipartXmlSessionKey())) {
// x-www-form-urlencoded
List<NameValuePair> requestFormElements = new ArrayList<NameValuePair>();
if (StringUtils.isNotEmpty(getFirstBodyPartName())) {
requestFormElements.add(new BasicNameValuePair(getFirstBodyPartName(), message));
log.debug(getLogPrefix() + "appended parameter [" + getFirstBodyPartName() + "] with value [" + message + "]");
}
if (parameters != null) {
for (ParameterValue pv : parameters) {
String name = pv.getDefinition().getName();
String value = pv.asStringValue("");
// Skip parameters that are configured as ignored
if (skipParameter(name))
continue;
requestFormElements.add(new BasicNameValuePair(name, value));
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "appended parameter [" + name + "] with value [" + value + "]");
}
}
try {
hmethod.setEntity(new UrlEncodedFormEntity(requestFormElements, getCharSet()));
} catch (UnsupportedEncodingException e) {
throw new SenderException(getLogPrefix() + "unsupported encoding for one or more post parameters");
}
} else {
// formdata and mtom
HttpEntity requestEntity = createMultiPartEntity(message, parameters, session);
hmethod.setEntity(requestEntity);
}
return hmethod;
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class JmsSender method setProperties.
/**
* Sets the JMS message properties as described in the msgProperties arraylist
*/
private void setProperties(javax.jms.Message msg, ParameterValueList pvl) throws JMSException {
for (ParameterValue property : pvl) {
ParameterType type = property.getDefinition().getType();
String name = property.getDefinition().getName();
if ((!isSoap() || !name.equals(getSoapHeaderParam()) && (StringUtils.isEmpty(getDestinationParam()) || !name.equals(getDestinationParam())))) {
if (log.isDebugEnabled()) {
log.debug(getLogPrefix() + "setting [" + type + "] property from param [" + name + "] to value [" + property.getValue() + "]");
}
switch(type) {
case BOOLEAN:
msg.setBooleanProperty(name, property.asBooleanValue(false));
break;
case INTEGER:
msg.setIntProperty(name, property.asIntegerValue(0));
break;
case STRING:
msg.setStringProperty(name, property.asStringValue(""));
break;
default:
msg.setObjectProperty(name, property.getValue());
break;
}
}
}
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class PutParametersInSession method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
ParameterList parameterList = getParameterList();
if (!parameterList.isEmpty()) {
try {
ParameterValueList pvl = parameterList.getValues(message, session, isNamespaceAware());
if (pvl != null) {
for (ParameterValue pv : pvl) {
String name = pv.getName();
Object value = pv.getValue();
session.put(name, value);
if (log.isDebugEnabled())
log.debug(getLogPrefix(session) + "stored [" + value + "] in pipeLineSession under key [" + name + "]");
}
}
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
}
return new PipeRunResult(getSuccessForward(), message);
}
use of nl.nn.adapterframework.parameters.ParameterValue in project iaf by ibissource.
the class RhinoPipe method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
// INIT
String eol = System.getProperty("line.separator");
if (message == null || message.isEmpty()) {
// 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");
}
}
// Get the input from the file at Run Time
if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
URL resource = null;
try {
resource = ClassUtils.getResourceURL(this, 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, Misc.LINE_SEPARATOR);
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + getFileName() + "]", e);
}
}
// Get all params as input
if (getParameterList() != null) {
ParameterValueList pvl;
try {
pvl = getParameterList().getValues(message, session);
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
for (ParameterValue pv : pvl) {
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()) {
log.debug("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[] { message.asObject() });
jsResult = (String) Context.jsToJava(result, String.class);
if (isDebug() && log.isDebugEnabled()) {
log.debug(getLogPrefix(session) + "jsResult [" + jsResult + "]");
}
} catch (EcmaError ex) {
throw new PipeRunException(this, "org.mozilla.javascript.EcmaError -> ", ex);
} finally {
Context.exit();
}
// Use the result
if (jsResult != null) {
stringResult = jsResult;
}
if (StringUtils.isEmpty(getSessionKey())) {
return new PipeRunResult(getSuccessForward(), stringResult);
} else {
session.put(getSessionKey(), stringResult);
return new PipeRunResult(getSuccessForward(), message);
}
}
Aggregations