use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.
the class ShowConfigurationStatusTest method testSingleConfig.
@Test
public void testSingleConfig() throws ConfigurationException, PipeRunException, DomBuilderException, SAXException, IOException, TransformerException {
ShowConfigurationStatus showConfigurationStatus = new ShowConfigurationStatus();
PipeLine pipeLine = new PipeLine();
Adapter adapter = (Adapter) ibisContext.getIbisManager().getRegisteredAdapter("WebControlShowConfigurationStatus");
pipeLine.setAdapter(adapter);
showConfigurationStatus.registerForward(createPipeSuccessForward());
showConfigurationStatus.configure(pipeLine);
session.put("configuration", "Ibis4Example");
MockHttpServletRequest request = new MockHttpServletRequest();
session.put(IPipeLineSession.HTTP_REQUEST_KEY, request);
PipeRunResult pipeRunResult = showConfigurationStatus.doPipe(null, session);
compareXML("webcontrol/singleConfig.xml", (String) pipeRunResult.getResult());
}
use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.
the class WsdlTest method mockPipeLine.
protected PipeLine mockPipeLine(IPipe inputValidator, IPipe outputValidator, String targetNamespace, String adapterName) {
PipeLine simple = mock(PipeLine.class);
when(simple.getInputValidator()).thenReturn(inputValidator);
when(simple.getOutputValidator()).thenReturn(outputValidator);
Adapter adp = mock(Adapter.class);
when(simple.getAdapter()).thenReturn(adp);
Configuration cfg = mock(Configuration.class);
when(simple.getAdapter().getConfiguration()).thenReturn(cfg);
final ReceiverBase receiverBase = mock(ReceiverBase.class);
WebServiceListener listener = new WebServiceListener();
listener.setServiceNamespaceURI(targetNamespace);
when(receiverBase.getListener()).thenReturn(listener);
when(adp.getReceiverIterator()).thenAnswer(new Answer<Iterator>() {
public Iterator answer(InvocationOnMock invocation) throws Throwable {
return Arrays.asList(receiverBase).iterator();
}
});
when(adp.getName()).thenReturn(adapterName);
return simple;
}
use of nl.nn.adapterframework.core.Adapter 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.core.Adapter in project iaf by ibissource.
the class JobDef method recoverAdapters.
private void recoverAdapters(IbisManager ibisManager) {
int countAdapter = 0;
int countAdapterStateStarted = 0;
int countReceiver = 0;
int countReceiverStateStarted = 0;
for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
countAdapter++;
if (iAdapter instanceof Adapter) {
Adapter adapter = (Adapter) iAdapter;
RunStateEnum adapterRunState = adapter.getRunState();
if (adapterRunState.equals(RunStateEnum.ERROR)) {
log.debug("trying to recover adapter [" + adapter.getName() + "]");
try {
adapter.setRecover(true);
adapter.configure();
} catch (ConfigurationException e) {
// do nothing
log.warn("error during recovering adapter [" + adapter.getName() + "]: " + e.getMessage());
} finally {
adapter.setRecover(false);
}
if (adapter.configurationSucceeded()) {
adapter.stopRunning();
int count = 10;
while (count-- >= 0 && !adapter.getRunState().equals(RunStateEnum.STOPPED)) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// do nothing
}
}
}
// check for start is in method startRunning in Adapter self
if (adapter.isAutoStart()) {
adapter.startRunning();
}
log.debug("finished recovering adapter [" + adapter.getName() + "]");
}
String message = "adapter [" + adapter.getName() + "] has state [" + adapterRunState + "]";
adapterRunState = adapter.getRunState();
if (adapterRunState.equals(RunStateEnum.STARTED)) {
countAdapterStateStarted++;
heartbeatLog.info(message);
} else if (adapterRunState.equals(RunStateEnum.ERROR)) {
heartbeatLog.error(message);
} else {
heartbeatLog.warn(message);
}
for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
countReceiver++;
IReceiver iReceiver = (IReceiver) receiverIt.next();
if (iReceiver instanceof ReceiverBase) {
ReceiverBase receiver = (ReceiverBase) iReceiver;
RunStateEnum receiverRunState = receiver.getRunState();
if (!adapterRunState.equals(RunStateEnum.ERROR) && receiverRunState.equals(RunStateEnum.ERROR)) {
log.debug("trying to recover receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
try {
if (receiver != null) {
receiver.setRecover(true);
}
adapter.configureReceiver(receiver);
} finally {
if (receiver != null) {
receiver.setRecover(false);
}
}
if (receiver != null) {
if (receiver.configurationSucceeded()) {
receiver.stopRunning();
int count = 10;
while (count-- >= 0 && !receiver.getRunState().equals(RunStateEnum.STOPPED)) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.debug("Interrupted waiting for receiver to stop", e);
}
}
}
// check for start is in method startRunning in
// ReceiverBase self
receiver.startRunning();
log.debug("finished recovering receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
}
}
receiverRunState = receiver.getRunState();
message = "receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "] has state [" + receiverRunState + "]";
if (receiverRunState.equals(RunStateEnum.STARTED)) {
countReceiverStateStarted++;
heartbeatLog.info(message);
} else if (receiverRunState.equals(RunStateEnum.ERROR)) {
heartbeatLog.error(message);
} else {
heartbeatLog.warn(message);
}
} else {
log.warn("will not try to recover receiver [" + iReceiver.getName() + "] of adapter [" + adapter.getName() + "], is not of type Receiver but [" + iAdapter.getClass().getName() + "]");
}
}
} else {
log.warn("will not try to recover adapter [" + iAdapter.getName() + "], is not of type Adapter but [" + iAdapter.getClass().getName() + "]");
}
}
heartbeatLog.info("[" + countAdapterStateStarted + "/" + countAdapter + "] adapters and [" + countReceiverStateStarted + "/" + countReceiver + "] receivers have state [" + RunStateEnum.STARTED + "]");
}
use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.
the class IbisSoapServlet method wsdl.
private void wsdl(HttpServletRequest req, HttpServletResponse res) throws ServletException {
String servlet = HttpUtils.getRequestURL(req).toString();
try {
Wsdl wsdl;
Adapter a = getAdapter(ibisManager, req.getPathInfo());
if (a == null) {
res.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
wsdl = new Wsdl(a.getPipeLine());
if (req.getParameter("indent") != null) {
wsdl.setIndent("true".equals(req.getParameter("indent")));
}
if (req.getParameter("useIncludes") != null) {
wsdl.setUseIncludes("true".equals(req.getParameter("useIncludes")));
}
setDocumentation(wsdl, req);
wsdl.init();
res.setHeader("Content-Disposition", "inline;filename=\"" + wsdl.getFilename() + ".wsdl\"");
wsdl.wsdl(res.getOutputStream(), servlet);
} catch (Exception e) {
throw new ServletException(e);
}
}
Aggregations