use of nl.nn.adapterframework.receivers.GenericReceiver in project iaf by ibissource.
the class WsdlGeneratorPipe method doPipe.
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
InputStream inputStream = (InputStream) session.get("file");
if (inputStream == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
}
File tempDir;
String fileName;
try {
tempDir = FileUtils.createTempDir(null, "WEB-INF" + File.separator + "classes");
fileName = (String) session.get("fileName");
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 {
DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(tempDir.getPath());
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();
adapter.setConfiguration(new Configuration(null));
String fileBaseName = FileUtils.getBaseName(fileName).replaceAll(" ", "_");
adapter.setName(fileBaseName);
GenericReceiver genericReceiver = new GenericReceiver();
EsbJmsListener esbJmsListener = new EsbJmsListener();
esbJmsListener.setQueueConnectionFactoryName("jms/qcf_" + fileBaseName);
esbJmsListener.setDestinationName("jms/dest_" + fileBaseName);
genericReceiver.setListener(esbJmsListener);
adapter.registerReceiver(genericReceiver);
pipeLine.setAdapter(adapter);
Wsdl wsdl = null;
wsdl = new Wsdl(pipeLine);
wsdl.setIndent(true);
wsdl.setDocumentation(getWsdlDocumentation(wsdl.getFilename()));
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(getForward(), result);
}
use of nl.nn.adapterframework.receivers.GenericReceiver in project iaf by ibissource.
the class AbstractListenerConnectingEJB method retrieveListener.
protected IListener retrieveListener(String receiverName, String adapterName) {
IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
GenericReceiver receiver = (GenericReceiver) adapter.getReceiverByName(receiverName);
return receiver.getListener();
}
use of nl.nn.adapterframework.receivers.GenericReceiver in project iaf by ibissource.
the class ListenerPortPoller method toggleConfiguratorState.
/**
* Toggle the state of the EjbListenerPortConnector instance by starting/stopping
* the receiver it is attached to (via the JmsListener).
* This method changes the state of the Receiver to match the state of the
* WebSphere ListenerPort.
*
* @param elpc ListenerPortConnector for which state is to be changed.
*
* @throws nl.nn.adapterframework.configuration.ConfigurationException
*/
public void toggleConfiguratorState(IListenerConnector elpc) throws ConfigurationException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
GenericReceiver receiver = (GenericReceiver) getListener(elpc).getReceiver();
if (isListenerPortClosed(elpc)) {
if (receiver.isInRunState(RunStateEnum.STARTED)) {
log.info("Stopping Receiver [" + receiver.getName() + "] because the WebSphere Listener-Port is in state 'stopped' but the JmsConnector in state 'open' and the receiver is in state 'started'");
receiver.stopRunning();
} else {
log.info(// elpc.getListenerPortName(getListener(elpc))
"ListenerPort [" + "] is in closed state, Listener is not in closed state, but Receiver is in state [" + receiver.getRunState().getName() + "] so the state of Receiver will not be changed.");
}
} else {
// Only start the receiver for adapters which are running.
if (receiver.getAdapter().getRunState().equals(RunStateEnum.STARTED)) {
if (!receiver.isInRunState(RunStateEnum.STARTING)) {
log.info("Starting Receiver [" + receiver.getName() + "] because the WebSphere Listener-Port is in state 'started' but the JmsConnector in state 'closed'");
receiver.startRunning();
} else {
log.info("Receiver [" + receiver.getName() + "] still starting, so not changing anything now");
}
} else {
try {
log.warn("JmsConnector is closed, Adapter is not in state '" + RunStateEnum.STARTED + "', but WebSphere Jms Listener Port is in state 'started'. Stopping the listener port.");
elpc.stop();
} catch (ListenerException ex) {
log.error(ex, ex);
}
}
}
}
Aggregations