use of nl.nn.adapterframework.util.Dir2Xml in project iaf by ibissource.
the class ShowLogging method executeSub.
public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Initialize action
initAction(request);
// Retrieve logging directory for browsing
String path = request.getParameter("directory");
if (StringUtils.isEmpty(path)) {
path = AppConstants.getInstance().getResolvedProperty("logging.path");
}
boolean sizeFormat = true;
String sizeFormatString = request.getParameter("sizeFormat");
if (StringUtils.isNotEmpty(sizeFormatString)) {
sizeFormat = Boolean.parseBoolean(sizeFormatString);
}
Dir2Xml dx = new Dir2Xml();
dx.setPath(path);
String listresult;
if (!FileUtils.readAllowed(FileViewerServlet.permissionRules, request, path)) {
error("access to path (" + path + ") not allowed", null);
listresult = "<directory/>";
} else {
String wildcard = request.getParameter("wildcard");
if (StringUtils.isEmpty(wildcard)) {
wildcard = AppConstants.getInstance().getProperty("logging.wildcard");
}
if (wildcard != null)
dx.setWildCard(wildcard);
try {
listresult = dx.getDirList(showDirectories, maxItems);
if (listresult != null) {
Element root = XmlUtils.buildDomDocument(listresult).getDocumentElement();
root.setAttribute("sizeFormat", Boolean.toString(sizeFormat));
listresult = XmlUtils.nodeToString(root);
String countStr = root.getAttribute("count");
if (countStr != null) {
int count = Integer.parseInt(countStr);
if (count > maxItems) {
error("total number of items (" + count + ") exceeded maximum number, only showing first " + maxItems + " items", null);
}
}
}
} catch (Exception e) {
error("error occured on getting directory list", e);
log.warn("returning empty result for directory listing");
listresult = "<directory/>";
}
}
request.setAttribute("Dir2Xml", listresult);
// Report any errors we have discovered back to the original form
if (!errors.isEmpty()) {
saveErrors(request, errors);
}
// Forward control to the specified success URI
log.debug("forward to success");
return (mapping.findForward("success"));
}
use of nl.nn.adapterframework.util.Dir2Xml in project iaf by ibissource.
the class FileSender method getMessage.
public String getMessage() throws TimeOutException, SenderException {
Dir2Xml dx = new Dir2Xml();
dx.setPath(filename);
return dx.getRecursiveDirList();
}
use of nl.nn.adapterframework.util.Dir2Xml 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);
}
Aggregations