use of nl.nn.adapterframework.core.PipeLine in project iaf by ibissource.
the class JdbcEnabledPipeTestBase method setup.
@Override
@Before
public void setup() throws Exception {
super.setup();
pipe = createPipe();
autowireByType(pipe);
pipe.registerForward(new PipeForward("success", "exit"));
pipe.setName(pipe.getClass().getSimpleName() + " under test");
pipeline = getConfiguration().createBean(PipeLine.class);
pipeline.addPipe(pipe);
PipeLineExit exit = new PipeLineExit();
exit.setPath("exit");
exit.setState(ExitState.SUCCESS);
pipeline.registerPipeLineExit(exit);
adapter = getConfiguration().createBean(Adapter.class);
adapter.setName("TestAdapter-for-".concat(pipe.getClass().getSimpleName()));
adapter.setPipeLine(pipeline);
}
use of nl.nn.adapterframework.core.PipeLine in project iaf by ibissource.
the class ShowConfigurationStatus method mapAdapterPipes.
private ArrayList<Object> mapAdapterPipes(Adapter adapter) {
if (!adapter.configurationSucceeded())
return null;
PipeLine pipeline = adapter.getPipeLine();
int totalPipes = pipeline.getPipes().size();
ArrayList<Object> pipes = new ArrayList<Object>(totalPipes);
for (int i = 0; i < totalPipes; i++) {
Map<String, Object> pipesInfo = new HashMap<String, Object>();
IPipe pipe = pipeline.getPipe(i);
Map<String, PipeForward> pipeForwards = pipe.getForwards();
String pipename = pipe.getName();
Map<String, String> forwards = new HashMap<String, String>();
for (PipeForward fwrd : pipeForwards.values()) {
forwards.put(fwrd.getName(), fwrd.getPath());
}
pipesInfo.put("name", pipename);
pipesInfo.put("forwards", forwards);
if (pipe instanceof HasKeystore) {
HasKeystore s = (HasKeystore) pipe;
Map<String, Object> certInfo = addCertificateInfo(s);
if (certInfo != null)
pipesInfo.put("certificate", certInfo);
}
if (pipe instanceof MessageSendingPipe) {
MessageSendingPipe msp = (MessageSendingPipe) pipe;
ISender sender = msp.getSender();
pipesInfo.put("sender", ClassUtils.nameOf(sender));
if (sender instanceof HasKeystore) {
HasKeystore s = (HasKeystore) sender;
Map<String, Object> certInfo = addCertificateInfo(s);
if (certInfo != null)
pipesInfo.put("certificate", certInfo);
}
if (sender instanceof HasPhysicalDestination) {
pipesInfo.put("destination", ((HasPhysicalDestination) sender).getPhysicalDestinationName());
}
if (sender instanceof JdbcSenderBase) {
pipesInfo.put("isJdbcSender", true);
}
IListener<?> listener = msp.getListener();
if (listener != null) {
pipesInfo.put("listenerName", listener.getName());
pipesInfo.put("listenerClass", ClassUtils.nameOf(listener));
if (listener instanceof HasPhysicalDestination) {
String pd = ((HasPhysicalDestination) listener).getPhysicalDestinationName();
pipesInfo.put("listenerDestination", pd);
}
}
ITransactionalStorage<?> messageLog = msp.getMessageLog();
if (messageLog != null) {
pipesInfo.put("hasMessageLog", true);
String messageLogCount;
try {
if (showCountMessageLog) {
messageLogCount = "" + messageLog.getMessageCount();
} else {
messageLogCount = "?";
}
} catch (Exception e) {
log.warn("Cannot determine number of messages in messageLog [" + messageLog.getName() + "]", e);
messageLogCount = "error";
}
pipesInfo.put("messageLogCount", messageLogCount);
Map<String, Object> message = new HashMap<String, Object>();
message.put("name", messageLog.getName());
message.put("type", "log");
message.put("slotId", messageLog.getSlotId());
message.put("count", messageLogCount);
pipesInfo.put("message", message);
}
}
pipes.add(pipesInfo);
}
return pipes;
}
use of nl.nn.adapterframework.core.PipeLine in project iaf by ibissource.
the class SlotIdRecord method getSlotmap.
private Map<String, SlotIdRecord> getSlotmap() {
Map<String, SlotIdRecord> slotmap = new HashMap<String, SlotIdRecord>();
for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
for (Receiver receiver : adapter.getReceivers()) {
ITransactionalStorage errorStorage = receiver.getErrorStorage();
if (errorStorage != null) {
String slotId = errorStorage.getSlotId();
if (StringUtils.isNotEmpty(slotId)) {
SlotIdRecord sir = new SlotIdRecord(adapter.getName(), receiver.getName(), null);
String type = errorStorage.getType();
slotmap.put(type + "/" + slotId, sir);
}
}
ITransactionalStorage messageLog = receiver.getMessageLog();
if (messageLog != null) {
String slotId = messageLog.getSlotId();
if (StringUtils.isNotEmpty(slotId)) {
SlotIdRecord sir = new SlotIdRecord(adapter.getName(), receiver.getName(), null);
String type = messageLog.getType();
slotmap.put(type + "/" + slotId, sir);
}
}
}
PipeLine pipeline = adapter.getPipeLine();
if (pipeline != null) {
for (int i = 0; i < pipeline.getPipeLineSize(); i++) {
IPipe pipe = pipeline.getPipe(i);
if (pipe instanceof MessageSendingPipe) {
MessageSendingPipe msp = (MessageSendingPipe) pipe;
ITransactionalStorage messageLog = msp.getMessageLog();
if (messageLog != null) {
String slotId = messageLog.getSlotId();
if (StringUtils.isNotEmpty(slotId)) {
SlotIdRecord sir = new SlotIdRecord(adapter.getName(), null, msp.getName());
String type = messageLog.getType();
slotmap.put(type + "/" + slotId, sir);
slotmap.put(slotId, sir);
}
}
}
}
}
}
return slotmap;
}
use of nl.nn.adapterframework.core.PipeLine in project iaf by ibissource.
the class WsdlGeneratorPipe method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
Message fileInSession = session.getMessage(getSessionKey());
if (fileInSession == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
}
File tempDir;
String fileName;
try (InputStream inputStream = fileInSession.asInputStream()) {
tempDir = FileUtils.createTempDir(null, "WEB-INF" + File.separator + "classes");
fileName = session.getMessage(getFilenameSessionKey()).asString();
if (FileUtils.extensionEqualsIgnoreCase(fileName, "zip")) {
FileUtils.unzipStream(inputStream, tempDir);
} else {
File file = new File(tempDir, fileName);
Misc.streamToFile(inputStream, file);
file.deleteOnExit();
}
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on uploading and unzipping/writing file", e);
}
File propertiesFile = new File(tempDir, getPropertiesFileName());
PipeLine pipeLine;
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
// A DirectoryClassloader is used to create a new 'dummy' pipeline, see createPipeLineFromPropertiesFile(String)
// This method reads a properties file and xsd's (when present) to programmatically 'create' a pipeline.
// The pipeline will then be used to generate a new WSDL file.
DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(originalClassLoader);
directoryClassLoader.setDirectory(tempDir.getPath());
directoryClassLoader.setBasePath(".");
directoryClassLoader.configure(getAdapter().getConfiguration().getIbisManager().getIbisContext(), "dummy");
Thread.currentThread().setContextClassLoader(directoryClassLoader);
if (propertiesFile.exists()) {
pipeLine = createPipeLineFromPropertiesFile(propertiesFile);
} else {
File xsdFile = FileUtils.getFirstFile(tempDir);
pipeLine = createPipeLineFromXsdFile(xsdFile);
}
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
} finally {
if (originalClassLoader != null) {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
Object result = null;
OutputStream zipOut = null;
OutputStream fullWsdlOut = null;
try {
Adapter adapter = new Adapter();
Configuration configuration = new Configuration();
configuration.setClassLoader(getConfigurationClassLoader());
adapter.setConfiguration(configuration);
String fileBaseName = FileUtils.getBaseName(fileName).replaceAll(" ", "_");
adapter.setName(fileBaseName);
Receiver receiver = new Receiver();
EsbJmsListener esbJmsListener = new EsbJmsListener();
esbJmsListener.setQueueConnectionFactoryName("jms/qcf_" + fileBaseName);
esbJmsListener.setDestinationName("jms/dest_" + fileBaseName);
receiver.setListener(esbJmsListener);
adapter.registerReceiver(receiver);
adapter.setPipeLine(pipeLine);
WsdlGenerator wsdl = null;
String generationInfo = "at " + RestListenerUtils.retrieveRequestURL(session);
wsdl = new WsdlGenerator(pipeLine, generationInfo);
wsdl.setIndent(true);
wsdl.init();
File wsdlDir = FileUtils.createTempDir(tempDir);
// zip (with includes)
File zipOutFile = new File(wsdlDir, wsdl.getFilename() + ".zip");
zipOutFile.deleteOnExit();
zipOut = new FileOutputStream(zipOutFile);
wsdl.setUseIncludes(true);
wsdl.zip(zipOut, null);
// full wsdl (without includes)
File fullWsdlOutFile = new File(wsdlDir, wsdl.getFilename() + ".wsdl");
fullWsdlOutFile.deleteOnExit();
fullWsdlOut = new FileOutputStream(fullWsdlOutFile);
wsdl.setUseIncludes(false);
wsdl.wsdl(fullWsdlOut, null);
Dir2Xml dx = new Dir2Xml();
dx.setPath(wsdlDir.getPath());
result = dx.getDirList();
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
} finally {
try {
if (zipOut != null) {
zipOut.close();
}
if (fullWsdlOut != null) {
fullWsdlOut.close();
}
} catch (IOException e1) {
log.warn("exception closing outputstream", e1);
}
}
return new PipeRunResult(getSuccessForward(), result);
}
use of nl.nn.adapterframework.core.PipeLine in project iaf by ibissource.
the class WsdlGeneratorPipe method createPipeLineFromPropertiesFile.
private PipeLine createPipeLineFromPropertiesFile(File propertiesFile) throws IOException, ConfigurationException {
Properties props = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(propertiesFile);
props.load(fis);
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
log.warn("exception closing inputstream", e);
}
}
PipeLine pipeLine = new PipeLine();
String inputXsd = null;
if (props.containsKey("input.xsd")) {
inputXsd = props.getProperty("input.xsd");
String inputNamespace = props.getProperty("input.namespace");
String inputRoot = props.getProperty("input.root");
String inputCmhString = props.getProperty("input.cmh", "1");
int inputCmh = Integer.parseInt(inputCmhString);
File inputXsdFile = new File(propertiesFile.getParent(), inputXsd);
EsbSoapValidator inputValidator = createValidator(inputXsdFile, inputNamespace, inputRoot, 1, inputCmh, pipeLine);
pipeLine.setInputValidator(inputValidator);
}
if (props.containsKey("output.xsd")) {
String outputXsd = props.getProperty("output.xsd");
String outputNamespace = props.getProperty("output.namespace");
String outputRoot = props.getProperty("output.root");
String outputCmhString = props.getProperty("output.cmh", "1");
int outputCmh = Integer.parseInt(outputCmhString);
File outputXsdFile = new File(propertiesFile.getParent(), outputXsd);
int rootPosition;
if (inputXsd != null && inputXsd.equalsIgnoreCase(outputXsd)) {
rootPosition = 2;
} else {
rootPosition = 1;
}
EsbSoapValidator outputValidator = createValidator(outputXsdFile, outputNamespace, outputRoot, rootPosition, outputCmh, pipeLine);
pipeLine.setOutputValidator(outputValidator);
}
return pipeLine;
}
Aggregations