use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class TimeoutGuardPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
ParameterValueList pvl = null;
if (getParameterList() != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e);
}
}
int timeout_work;
String timeout_work_str = getParameterValue(pvl, "timeout");
if (timeout_work_str == null) {
timeout_work = getTimeout();
} else {
timeout_work = Integer.valueOf(timeout_work_str);
}
DoPipe doPipe = new DoPipe(input, session, Thread.currentThread().getName(), NDC.peek());
ExecutorService service = Executors.newSingleThreadExecutor();
Future future = service.submit(doPipe);
String result = null;
try {
log.debug(getLogPrefix(session) + "setting timeout of [" + timeout_work + "] s");
result = (String) future.get(timeout_work, TimeUnit.SECONDS);
} catch (Exception e) {
String msg;
if (e instanceof TimeoutException) {
String errorMsg = getLogPrefix(session) + "exceeds timeout of [" + timeout_work + "] s, interupting";
future.cancel(true);
msg = e.getClass().getName() + ": " + errorMsg;
} else {
msg = e.getClass().getName();
}
if (isThrowException()) {
throw new PipeRunException(this, msg, e);
} else {
String msgString = msg + ": " + e.getMessage();
log.error(msgString, e);
String msgCdataString = "<![CDATA[" + msgString + "]]>";
result = "<error>" + msgCdataString + "</error>";
}
} finally {
service.shutdown();
}
return new PipeRunResult(getForward(), result);
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext 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.ParameterResolutionContext in project iaf by ibissource.
the class DirectWrapperPipe method doPipeWithTimeoutGuarded.
public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
String result;
ParameterValueList pvl = null;
if (getParameterList() != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
}
String destination = getParameterValue(pvl, DESTINATION);
String cmhVersion = getParameterValue(pvl, CMHVERSION);
String addOutputNamespace = getParameterValue(pvl, ADDOUTPUTNAMESPACE);
EsbSoapWrapperPipe eswPipe = new EsbSoapWrapperPipe();
if (addOutputNamespace != null) {
if ("on".equalsIgnoreCase(addOutputNamespace)) {
eswPipe.setAddOutputNamespace(true);
}
}
if (destination != null) {
Parameter p = new Parameter();
p.setName(DESTINATION);
p.setValue(destination);
eswPipe.addParameter(p);
}
if (cmhVersion != null) {
if (StringUtils.isNumeric(cmhVersion)) {
eswPipe.setCmhVersion(Integer.parseInt(cmhVersion));
}
}
PipeForward pf = new PipeForward();
pf.setName("success");
eswPipe.registerForward(pf);
try {
eswPipe.configure();
PipeRunResult prr = eswPipe.doPipe(input, session);
result = (String) prr.getResult();
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "Exception on wrapping input", e);
}
return result;
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class StreamTransformerPipe method doPipe.
/**
* Open a reader for the file named according the input messsage and transform it.
* Move the input file to a done directory when transformation is finished
* and return the names of the generated files.
*
* @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.IPipeLineSession)
*/
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String streamId = getStreamId(input, session);
BufferedReader reader = getReader(streamId, input, session);
if (reader == null) {
throw new PipeRunException(this, "could not obtain reader for [" + streamId + "]");
}
Object transformationResult = null;
ParameterResolutionContext prc = new ParameterResolutionContext("", session);
try {
transformationResult = transform(streamId, reader, session, prc);
} finally {
if (isCloseInputstreamOnExit()) {
try {
reader.close();
} catch (IOException e) {
log.warn(getLogPrefix(session) + "Exception closing reader", e);
}
}
}
return new PipeRunResult(getForward(), transformationResult);
}
use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.
the class SoapWrapperPipe method doPipe.
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String result;
try {
if ("wrap".equalsIgnoreCase(getDirection())) {
String payload = input.toString();
if (rootTp != null) {
payload = rootTp.transform(payload, null, true);
}
if (outputNamespaceTp != null) {
payload = outputNamespaceTp.transform(payload, null, true);
}
ParameterResolutionContext prc = null;
Map parameterValues = null;
if (getParameterList() != null && (soapHeaderTp != null || soapBodyTp != null)) {
prc = new ParameterResolutionContext(payload, session);
parameterValues = prc.getValueMap(getParameterList());
}
String soapHeader = null;
if (soapHeaderTp != null) {
soapHeader = soapHeaderTp.transform(prc.getInputSource(), parameterValues);
} else {
if (StringUtils.isNotEmpty(getSoapHeaderSessionKey())) {
soapHeader = (String) session.get(getSoapHeaderSessionKey());
}
}
if (soapBodyTp != null) {
payload = soapBodyTp.transform(prc.getInputSource(), parameterValues);
}
result = wrapMessage(payload, soapHeader);
} else {
result = unwrapMessage(input.toString());
if (StringUtils.isEmpty(result)) {
throw new PipeRunException(this, getLogPrefix(session) + "SOAP Body is empty or message is not a SOAP Message");
}
if (!isIgnoreSoapFault() && soapWrapper.getFaultCount(input.toString()) > 0) {
throw new PipeRunException(this, getLogPrefix(session) + "SOAP Body contains SOAP Fault");
}
if (StringUtils.isNotEmpty(getSoapHeaderSessionKey())) {
String soapHeader = soapWrapper.getHeader(input.toString());
session.put(getSoapHeaderSessionKey(), soapHeader);
}
if (removeOutputNamespacesTp != null) {
result = removeOutputNamespacesTp.transform(result, null, true);
}
if (removeUnusedOutputNamespacesTp != null) {
result = removeUnusedOutputNamespacesTp.transform(result, null, true);
}
if (rootTp != null) {
result = rootTp.transform(result, null, true);
}
}
} catch (Exception t) {
throw new PipeRunException(this, getLogPrefix(session) + " Unexpected exception during (un)wrapping ", t);
}
return new PipeRunResult(getForward(), result);
}
Aggregations