use of nl.nn.adapterframework.core.PipeForward in project iaf by ibissource.
the class WsdlGeneratorPipe method createValidator.
private EsbSoapValidator createValidator(File xsdFile, String namespace, String root, int rootPosition, int cmhVersion) throws ConfigurationException {
if (xsdFile != null) {
EsbSoapValidator esbSoapValidator = new EsbSoapValidator();
esbSoapValidator.setWarn(false);
esbSoapValidator.setCmhVersion(cmhVersion);
if (StringUtils.isEmpty(namespace)) {
String xsdTargetNamespace = null;
try {
TransformerPool tp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource("*/@targetNamespace", "text"));
xsdTargetNamespace = tp.transform(Misc.fileToString(xsdFile.getPath()), null);
if (StringUtils.isNotEmpty(xsdTargetNamespace)) {
log.debug("found target namespace [" + xsdTargetNamespace + "] in xsd file [" + xsdFile.getName() + "]");
} else {
// default namespace to prevent
// "(IllegalArgumentException) The schema attribute isn't supported"
xsdTargetNamespace = "urn:wsdlGenerator";
log.warn("could not find target namespace in xsd file [" + xsdFile.getName() + "], assuming namespace [" + xsdTargetNamespace + "]");
}
} catch (Exception e) {
throw new ConfigurationException(e);
}
if (StringUtils.isEmpty(xsdTargetNamespace)) {
esbSoapValidator.setSchema(xsdFile.getName());
} else {
esbSoapValidator.setSchemaLocation(xsdTargetNamespace + "\t" + xsdFile.getName());
esbSoapValidator.setAddNamespaceToSchema(true);
}
} else {
esbSoapValidator.setSchemaLocation(namespace + "\t" + xsdFile.getName());
esbSoapValidator.setAddNamespaceToSchema(true);
}
if (StringUtils.isEmpty(root)) {
String xsdRoot = null;
try {
String rootXPath = "*/*[local-name()='element'][" + rootPosition + "]/@name";
TransformerPool tp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(rootXPath, "text"));
xsdRoot = tp.transform(Misc.fileToString(xsdFile.getPath()), null);
if (StringUtils.isNotEmpty(xsdRoot)) {
log.debug("found root element [" + xsdRoot + "] in xsd file [" + xsdFile.getName() + "]");
esbSoapValidator.setSoapBody(xsdRoot);
}
} catch (Exception e) {
throw new ConfigurationException(e);
}
} else {
esbSoapValidator.setSoapBody(root);
}
esbSoapValidator.setForwardFailureToSuccess(true);
PipeForward pf = new PipeForward();
pf.setName("success");
esbSoapValidator.registerForward(pf);
esbSoapValidator.configure();
return esbSoapValidator;
}
return null;
}
use of nl.nn.adapterframework.core.PipeForward 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.core.PipeForward in project iaf by ibissource.
the class CounterSwitchPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String forward = "";
PipeForward pipeForward = null;
StatisticsKeeper sk = getPipeLine().getPipeStatistics(this);
if (sk != null) {
long count = sk.getCount();
forward = "" + (getDivisor() - (count % getDivisor()));
}
log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
pipeForward = findForward(forward);
if (pipeForward == null) {
throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]");
}
log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]");
return new PipeRunResult(pipeForward, input);
}
use of nl.nn.adapterframework.core.PipeForward in project iaf by ibissource.
the class FilenameSwitch method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String forward = "";
String sInput = (String) input;
PipeForward pipeForward = null;
int slashPos = sInput.lastIndexOf('/');
if (slashPos > 0) {
sInput = sInput.substring(slashPos + 1);
}
slashPos = sInput.lastIndexOf('\\');
if (slashPos > 0) {
sInput = sInput.substring(slashPos + 1);
}
forward = sInput;
if (isToLowercase()) {
forward = forward.toLowerCase();
}
log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
if (findForward(forward) != null)
pipeForward = findForward(forward);
else {
log.info(getLogPrefix(session) + "determined forward [" + forward + "], which is not defined. Will use [" + getNotFoundForwardName() + "] instead");
pipeForward = findForward(getNotFoundForwardName());
}
if (pipeForward == null) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot find forward or pipe named [" + forward + "]");
}
return new PipeRunResult(pipeForward, input);
}
use of nl.nn.adapterframework.core.PipeForward in project iaf by ibissource.
the class FixedResult method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String result = returnString;
if ((StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) || StringUtils.isNotEmpty(getFileNameSessionKey())) {
String fileName = null;
if (StringUtils.isNotEmpty(getFileNameSessionKey())) {
fileName = (String) session.get(fileNameSessionKey);
}
if (fileName == null) {
if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) {
fileName = getFileName();
}
}
URL resource = null;
try {
resource = ClassUtils.getResourceURL(classLoader, fileName);
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + fileName + "]", e);
}
if (resource == null) {
PipeForward fileNotFoundForward = findForward(FILE_NOT_FOUND_FORWARD);
if (fileNotFoundForward != null) {
return new PipeRunResult(fileNotFoundForward, input);
} else {
throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + fileName + "]");
}
}
try {
result = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR);
} catch (Throwable e) {
throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + fileName + "]", e);
}
}
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);
String replaceFrom;
if (isReplaceFixedParams()) {
replaceFrom = pv.getDefinition().getName();
} else {
replaceFrom = "${" + pv.getDefinition().getName() + "}";
}
result = replace(result, replaceFrom, pv.asStringValue(""));
}
}
if (getSubstituteVars()) {
result = StringResolver.substVars(returnString, session, appConstants);
}
if (StringUtils.isNotEmpty(styleSheetName)) {
URL xsltSource = ClassUtils.getResourceURL(classLoader, styleSheetName);
if (xsltSource != null) {
try {
String xsltResult = null;
Transformer transformer = XmlUtils.createTransformer(xsltSource);
xsltResult = XmlUtils.transformXml(transformer, result);
result = xsltResult;
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot retrieve [" + styleSheetName + "], resource [" + xsltSource.toString() + "]", e);
} catch (TransformerConfigurationException te) {
throw new PipeRunException(this, getLogPrefix(session) + "got error creating transformer from file [" + styleSheetName + "]", te);
} catch (TransformerException te) {
throw new PipeRunException(this, getLogPrefix(session) + "got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", te);
} catch (DomBuilderException te) {
throw new PipeRunException(this, getLogPrefix(session) + "caught DomBuilderException", te);
}
}
}
log.debug(getLogPrefix(session) + " returning fixed result [" + result + "]");
return new PipeRunResult(getForward(), result);
}
Aggregations