use of nl.nn.adapterframework.util.Variant 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.util.Variant in project iaf by ibissource.
the class BytesOutputPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
Object result = null;
Variant in = new Variant(input);
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
FieldsContentHandler fieldsContentHandler = new FieldsContentHandler();
parser.setContentHandler(fieldsContentHandler);
parser.parse(in.asXmlInputSource());
result = fieldsContentHandler.getResult();
} catch (SAXException e) {
throw new PipeRunException(this, "SAXException", e);
} catch (IOException e) {
throw new PipeRunException(this, "IOException", e);
}
return new PipeRunResult(getForward(), result);
}
use of nl.nn.adapterframework.util.Variant in project iaf by ibissource.
the class LabelFormat method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
try {
String result;
if (getDirection().equalsIgnoreCase(DIRECTION_XML2LABEL)) {
Variant v = new Variant(input);
DocumentBuilder documentBuilder = XmlUtils.getDocumentBuilderFactory().newDocumentBuilder();
Document document = documentBuilder.parse(new InputSource(new StringReader(v.asString())));
result = XmlToLabelFormat.doTransformation(document).toString();
return new PipeRunResult(getForward(), result);
} else {
Variant v = new Variant(input);
XMLReader reader = XMLReaderFactory.createXMLReader("nl.nn.adapterframework.extensions.rekenbox.CalcboxOutputReader");
CalcboxContentHandler handler = new CalcboxContentHandler(v.asString());
reader.setContentHandler(handler);
return new PipeRunResult(getForward(), handler.getStringResult());
}
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot transform", e);
}
}
use of nl.nn.adapterframework.util.Variant in project iaf by ibissource.
the class AbstractXmlValidator method getInputSource.
protected InputSource getInputSource(Object input) throws XmlValidatorException {
Variant in = new Variant(input);
final InputSource is;
if (isValidateFile()) {
try {
is = new InputSource(new InputStreamReader(new FileInputStream(in.asString()), getCharset()));
} catch (FileNotFoundException e) {
throw new XmlValidatorException("could not find file [" + in.asString() + "]", e);
} catch (UnsupportedEncodingException e) {
throw new XmlValidatorException("could not use charset [" + getCharset() + "]", e);
}
} else {
is = in.asXmlInputSource();
}
return is;
}
use of nl.nn.adapterframework.util.Variant in project iaf by ibissource.
the class Adios2XmlPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
Variant v = new Variant(input);
String result;
if (DIRECTION_BACKWARD.equalsIgnoreCase(getDirection())) {
result = makeAdios(v.asXmlInputSource(), session);
} else {
String inputstring = v.asString();
String firstToken = new StringTokenizer(inputstring).nextToken();
if (firstToken.startsWith("<")) {
log.info(getLogPrefix(session) + "input is already XML, no conversion performed");
return new PipeRunResult(noConversionForward, inputstring);
}
result = makeXml(v.asString(), session);
}
return new PipeRunResult(getForward(), result);
}
Aggregations