use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class LdapFindMemberPipe method doPipeWithException.
public PipeRunResult doPipeWithException(Object input, IPipeLineSession session) throws PipeRunException {
String dnSearchIn_work;
String dnFind_work;
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);
}
}
dnSearchIn_work = getParameterValue(pvl, "dnSearchIn");
if (dnSearchIn_work == null) {
dnSearchIn_work = getDnSearchIn();
}
dnFind_work = getParameterValue(pvl, "dnFind");
if (dnFind_work == null) {
dnFind_work = getDnFind();
}
boolean found = false;
if (StringUtils.isNotEmpty(dnSearchIn_work) && StringUtils.isNotEmpty(dnFind_work)) {
try {
found = findMember(getHost(), getPort(), dnSearchIn_work, isUseSsl(), dnFind_work, isRecursiveSearch());
} catch (NamingException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception on ldap lookup", e);
}
}
if (!found) {
String msg = getLogPrefix(session) + "dn [" + dnFind_work + "] not found as member in url [" + retrieveUrl(getHost(), getPort(), dnSearchIn_work, isUseSsl()) + "]";
if (notFoundForward == null) {
throw new PipeRunException(this, msg);
} else {
log.info(msg);
return new PipeRunResult(notFoundForward, input);
}
}
return new PipeRunResult(getForward(), input);
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class ApiPrincipalPipe method doPipe.
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());
}
if (getAction().equals("get")) {
ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
if (userPrincipal == null)
throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
return new PipeRunResult(getForward(), userPrincipal.getData());
}
if (getAction().equals("set")) {
ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
if (userPrincipal == null)
throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
userPrincipal.setData((String) input);
cache.put(userPrincipal.getToken(), userPrincipal, authTTL);
return new PipeRunResult(getForward(), "");
}
if (getAction().equals("create")) {
// TODO type of token? (jwt, saml)
String uidString = (new UID()).toString();
Random random = new Random();
String token = random.nextInt() + uidString + Integer.toHexString(uidString.hashCode()) + random.nextInt(8);
ApiPrincipal userPrincipal = new ApiPrincipal(authTTL);
userPrincipal.setData((String) input);
userPrincipal.setToken(token);
if (getAuthenticationMethod().equals("cookie")) {
Cookie cookie = new Cookie("authenticationToken", token);
cookie.setPath("/");
cookie.setMaxAge(authTTL);
HttpServletResponse response = (HttpServletResponse) session.get(IPipeLineSession.HTTP_RESPONSE_KEY);
response.addCookie(cookie);
}
cache.put(token, userPrincipal, authTTL);
return new PipeRunResult(getForward(), token);
}
if (getAction().equals("remove")) {
ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
if (userPrincipal == null)
throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
cache.remove(userPrincipal.getToken());
return new PipeRunResult(getForward(), "");
}
return new PipeRunResult(findForward("exception"), "this is not supposed to happen... like ever!");
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class CoolGenWrapperPipe method doPipe.
/**
* Transform the input (optionally), check the conformance to the schema (optionally),
* call the required proxy, transform the output (optionally)
*/
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
Writer proxyResult;
String proxypreProc = null;
Variant inputVar;
String wrapperResult = "";
CoolGenXMLProxy proxy;
ActionListener actionListener = new ActionListener() {
/**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
public String errorMessage;
public void actionPerformed(ActionEvent e) {
errorMessage = e.toString();
}
public String toString() {
return errorMessage;
}
};
Source in;
try {
log.info(getLogPrefix(session) + "instantiating proxy [" + proxyClassName + "] as a temporary fix for broken comm-bridge connections");
proxy = createProxy(proxyClassName);
} catch (ConfigurationException ce) {
String msg = getLogPrefix(session) + "cannot recreate proxy after exception";
log.error(msg, ce);
throw new PipeRunException(this, msg, ce);
}
proxy.addExceptionListener(actionListener);
try {
inputVar = new Variant(input);
in = inputVar.asXmlSource();
if (preProcTransformer != null) {
proxypreProc = XmlUtils.transformXml(preProcTransformer, in);
log.debug(getLogPrefix(session) + "] preprocessing transformed message into [" + proxypreProc + "]");
} else
proxypreProc = inputVar.asString();
if (proxyInputFixTransformer != null)
proxypreProc = XmlUtils.transformXml(proxyInputFixTransformer, proxypreProc);
proxyResult = new StringWriter(10 * 1024);
try {
proxy.clear();
} catch (PropertyVetoException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot clear CoolGen proxy", e);
}
try {
proxy.executeXML(new StringReader(proxypreProc), proxyResult);
proxy.removeExceptionListener(actionListener);
String err = actionListener.toString();
if (err != null) {
// if an error occurs, recreate the proxy and throw an exception
log.debug(getLogPrefix(session) + "got error, recreating proxy with class [" + proxyClassName + "]");
try {
proxy = createProxy(proxyClassName);
} catch (ConfigurationException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot recreate proxy [" + proxyClassName + "]", e);
}
throw new PipeRunException(this, getLogPrefix(session) + "error excuting proxy [" + proxyClassName + "]:" + err);
}
} catch (XmlProxyException xpe) {
try {
proxy = createProxy(proxyClassName);
} catch (ConfigurationException ce) {
log.error(getLogPrefix(session) + "cannot recreate proxy", xpe);
}
throw new PipeRunException(this, getLogPrefix(session) + "error excecuting proxy", xpe);
}
if (postProcTransformer != null) {
log.debug(getLogPrefix(session) + " CoolGen proxy returned: [" + proxyResult.toString() + "]");
wrapperResult = XmlUtils.transformXml(postProcTransformer, proxyResult.toString());
} else
wrapperResult = proxyResult.toString();
} catch (DomBuilderException e) {
throw new PipeRunException(this, getLogPrefix(session) + "DomBuilderException excecuting proxy", e);
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "IOException excecuting proxy", e);
} catch (TransformerException e) {
throw new PipeRunException(this, getLogPrefix(session) + "TransformerException excecuting proxy", e);
}
return new PipeRunResult(getForward(), wrapperResult);
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class WsdlGeneratorPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String result = null;
IAdapter adapter;
if ("input".equals(getFrom())) {
adapter = ((Adapter) getAdapter()).getConfiguration().getIbisManager().getRegisteredAdapter((String) input);
if (adapter == null) {
throw new PipeRunException(this, "Could not find adapter: " + input);
}
} else {
adapter = getPipeLine().getAdapter();
}
try {
Wsdl wsdl = new Wsdl(((Adapter) adapter).getPipeLine());
wsdl.setDocumentation("Generated at " + AppConstants.getInstance().getResolvedProperty("otap.stage") + "-" + AppConstants.getInstance().getResolvedProperty("otap.side") + " on " + DateUtils.getIsoTimeStamp() + ".");
wsdl.init();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
wsdl.wsdl(outputStream, null);
result = outputStream.toString("UTF-8");
} catch (Exception e) {
throw new PipeRunException(this, "Could not generate WSDL for adapter '" + adapter.getName() + "'", e);
}
return new PipeRunResult(getForward(), result);
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class XQueryPipe method doPipe.
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());
}
try {
String stringResult = (String) input;
// We already specifically use Saxon in this pipe, hence set xslt2
// to true to make XmlUtils use the Saxon
// DocumentBuilderFactoryImpl.
ParameterResolutionContext prc = new ParameterResolutionContext(stringResult, session, isNamespaceAware(), true);
Map parametervalues = null;
if (getParameterList() != null) {
parametervalues = prc.getValueMap(getParameterList());
}
preparedExpression.bindDocument(XQConstants.CONTEXT_ITEM, stringResult, null, null);
Iterator iterator = getParameterList().iterator();
while (iterator.hasNext()) {
Parameter parameter = (Parameter) iterator.next();
preparedExpression.bindObject(new QName(parameter.getName()), parametervalues.get(parameter.getName()), null);
}
XQResultSequence resultSequence = preparedExpression.executeQuery();
stringResult = resultSequence.getSequenceAsString(null);
return new PipeRunResult(getForward(), stringResult);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on running xquery", e);
}
}
Aggregations