[jboss-svn-commits] JBL Code SVN: r10402 - in labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor: WEB-INF and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Mar 21 15:17:50 EDT 2007
Author: rex.sheridan
Date: 2007-03-21 15:17:50 -0400 (Wed, 21 Mar 2007)
New Revision: 10402
Added:
labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/dist/jbossesb-config-editor.war
labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/ConfigListServlet.java
labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/JBossESBConfigLocator.java
Removed:
labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/dist/configapp.war
Modified:
labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/WEB-INF/web.xml
labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/build.xml
labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/DownloadServlet.java
labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/UploadServlet.java
Log:
Modified: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/WEB-INF/web.xml
===================================================================
--- labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/WEB-INF/web.xml 2007-03-21 19:03:28 UTC (rev 10401)
+++ labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/WEB-INF/web.xml 2007-03-21 19:17:50 UTC (rev 10402)
@@ -14,7 +14,7 @@
makes updates in the interface.
</description>
- <!-- Servlet for downloading the JBossESB configuration file. -->
+ <!-- Servlet for downloading a JBossESB configuration file. -->
<servlet>
<servlet-name>DownloadConfig</servlet-name>
<servlet-class>
@@ -22,12 +22,18 @@
</servlet-class>
</servlet>
- <!-- Servlet for uploading the JBossESB configuration file. -->
+ <!-- Servlet for uploading a JBossESB configuration file. -->
<servlet>
<servlet-name>UploadConfig</servlet-name>
<servlet-class>org.jboss.configapp.UploadServlet</servlet-class>
</servlet>
+ <!-- Servlet for listing the JBossESB configuration files. -->
+ <servlet>
+ <servlet-name>ConfigList</servlet-name>
+ <servlet-class>org.jboss.configapp.ConfigListServlet</servlet-class>
+ </servlet>
+
<servlet-mapping>
<servlet-name>DownloadConfig</servlet-name>
<url-pattern>/download</url-pattern>
@@ -38,4 +44,9 @@
<url-pattern>/upload</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ConfigList</servlet-name>
+ <url-pattern>/list</url-pattern>
+ </servlet-mapping>
+
</web-app>
\ No newline at end of file
Modified: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/build.xml
===================================================================
--- labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/build.xml 2007-03-21 19:03:28 UTC (rev 10401)
+++ labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/build.xml 2007-03-21 19:17:50 UTC (rev 10402)
@@ -5,24 +5,30 @@
<property name="webinf.dir" value="${basedir}/WEB-INF" />
<property name="classes.dir" value="${webinf.dir}/classes" />
<property name="lib.dir" value="${webinf.dir}/lib" />
-
+
<path id="project.class.path">
<fileset dir="${basedir}">
- <include name="*.jar"/>
+ <include name="*.jar" />
</fileset>
</path>
<target name="prepare">
+ <mkdir dir="${classes.dir}" />
<mkdir dir="${dist.dir}" />
</target>
+ <target name="clean">
+ <delete dir="${classes.dir}}" />
+ </target>
+
<target name="compile">
- <javac srcdir="${src.dir}" destdir="${classes.dir}" source="1.5" classpathref="project.class.path" />
+ <javac srcdir="${src.dir}" destdir="${classes.dir}" source="1.5"
+ classpathref="project.class.path" debug="true" />
</target>
- <target name="build-war" depends="prepare, compile">
+ <target name="build-war" depends="clean, prepare, compile">
- <war destfile="${dist.dir}/configapp.war" webxml="${webinf.dir}/web.xml">
+ <war destfile="${dist.dir}/jbossesb-config-editor.war" webxml="${webinf.dir}/web.xml">
<fileset dir="${basedir}" includes="**/jboss-web.xml" />
<fileset dir="${basedir}" includes="**/*.swf" />
<lib dir="${lib.dir}" />
Deleted: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/dist/configapp.war
===================================================================
(Binary files differ)
Added: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/dist/jbossesb-config-editor.war
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/dist/jbossesb-config-editor.war
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/ConfigListServlet.java
===================================================================
--- labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/ConfigListServlet.java (rev 0)
+++ labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/ConfigListServlet.java 2007-03-21 19:17:50 UTC (rev 10402)
@@ -0,0 +1,57 @@
+package org.jboss.configapp;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Provides a list of all JBossESB configurations on the server. This includes
+ * all *-esb.xml files as well as any *.esb archives and exploded archives.
+ *
+ * @author Derek Adams
+ */
+public class ConfigListServlet extends HttpServlet {
+
+ /** Serial version UID */
+ private static final long serialVersionUID = 1L;
+
+ /** Date formatter for XSD date */
+ private static SimpleDateFormat FORMATTER = new SimpleDateFormat(
+ "yyyy-MM-dd'T'HH:mm:ss");
+
+ @Override
+ protected void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+
+ List<File> configs = JBossESBConfigLocator.locateConfigFiles();
+ StringBuilder builder = new StringBuilder();
+ builder.append("<jbossesb-config-list>\n");
+ for (File file : configs) {
+ Date lastMod = new Date(file.lastModified());
+ builder.append(" <config name=\"" + file.getName()
+ + "\" modified=\"" + FORMATTER.format(lastMod) + "\">\n");
+ }
+ builder.append("</jbossesb-config-list>");
+ String xml = builder.toString();
+
+ response.setContentType("application/octet-stream");
+ response.setContentLength((int) xml.length());
+ response.setHeader("Content-Disposition",
+ "attachement; filename=\"config-list.xml\"");
+
+ ServletOutputStream out = response.getOutputStream();
+ try {
+ out.write(xml.getBytes());
+ } finally {
+ out.close();
+ }
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/DownloadServlet.java
===================================================================
--- labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/DownloadServlet.java 2007-03-21 19:03:28 UTC (rev 10401)
+++ labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/DownloadServlet.java 2007-03-21 19:17:50 UTC (rev 10402)
@@ -1,11 +1,12 @@
package org.jboss.configapp;
-import java.io.DataInputStream;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
@@ -31,50 +32,58 @@
/** Parameter name for choosing file to download */
private static final String ACTIONS_INDICATOR = "actions";
- /** Filename for JBossESB config */
- private static final String CONFIG_FILENAME = "jbossesb.xml";
-
/** Filename for JBossESB action templates */
private static final String ACTIONS_FILENAME = "action-templates.xml";
- /** Size of read buffer in bytes */
- private static final int BUFFER_SIZE = 1024;
-
@Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
- IOException {
+ protected void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
// Locate the config file.
ServerConfig config = ServerConfigLocator.locate();
File confDir = new File(config.getServerConfigURL().getFile());
+ File deployDir = new File(config.getServerHomeDir(), "deploy");
File sourceFile;
-
+
// Use parameter to choose file to load.
String fileParam = request.getParameter(FILE_PARAM);
- if ((fileParam != null) && (fileParam.equals(ACTIONS_INDICATOR))) {
+ boolean loadingActions = (fileParam != null)
+ && (fileParam.equals(ACTIONS_INDICATOR));
+ if (loadingActions) {
sourceFile = new File(confDir, ACTIONS_FILENAME);
} else {
- sourceFile = new File(confDir, CONFIG_FILENAME);
+ sourceFile = new File(deployDir, fileParam);
}
// Get the output stream and mime type.
ServletOutputStream out = response.getOutputStream();
- ServletContext context = getServletConfig().getServletContext();
- String mimetype = context.getMimeType(CONFIG_FILENAME);
- // Set the headers.
- response.setContentType((mimetype != null) ? mimetype : "application/octet-stream");
- response.setContentLength((int) sourceFile.length());
- response.setHeader("Content-Disposition", "attachement; filename=\"" + CONFIG_FILENAME + "\"");
-
- DataInputStream in = null;
+ BufferedReader in = null;
try {
- byte[] bbuf = new byte[BUFFER_SIZE];
- in = new DataInputStream(new FileInputStream(sourceFile));
+ if (loadingActions) {
+ in = new BufferedReader(new InputStreamReader(
+ new FileInputStream(sourceFile)));
+ } else {
+ InputStream configInput = JBossESBConfigLocator
+ .getConfigXmlInputStream(sourceFile);
+ if (configInput != null) {
+ in = new BufferedReader(new InputStreamReader(configInput));
+ } else {
+ throw new ServletException(
+ "Unable to locate JBossESB config file: "
+ + sourceFile.getName());
+ }
+ }
+ String current;
+ StringBuilder buffer = new StringBuilder();
+ while ((in != null) && ((current = in.readLine()) != null)) {
+ buffer.append(current);
+ }
+ byte[] fileBytes = buffer.toString().getBytes();
- int length = 0;
- while ((in != null) && ((length = in.read(bbuf)) != -1)) {
- out.write(bbuf, 0, length);
- }
+ // Set the headers.
+ response.setContentType("text/xml");
+ response.setContentLength(fileBytes.length);
+ out.write(fileBytes, 0, fileBytes.length);
} finally {
try {
if (in != null) {
Added: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/JBossESBConfigLocator.java
===================================================================
--- labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/JBossESBConfigLocator.java (rev 0)
+++ labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/JBossESBConfigLocator.java 2007-03-21 19:17:50 UTC (rev 10402)
@@ -0,0 +1,165 @@
+package org.jboss.configapp;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.jboss.system.server.ServerConfig;
+import org.jboss.system.server.ServerConfigLocator;
+
+/**
+ * Used for locating JBossESB server config files.
+ *
+ * @author Derek Adams
+ */
+public class JBossESBConfigLocator {
+
+ /** Suffix for a standalone JBossESB config file */
+ private static final String STANDALONE_CONFIG_SUFFIX = "-esb.xml";
+
+ /** Suffix for a standalone JBossESB config file */
+ private static final String PACKAGED_CONFIG_SUFFIX = ".esb";
+
+ /** Suffix for a standalone JBossESB config file */
+ private static final String NESTED_CONFIG_PATH = "META-INF/jboss-esb.xml";
+
+ /**
+ * Gets the list of JBossESB files in the deploy directory.
+ *
+ * @return
+ */
+ public static List<File> locateConfigFiles() {
+ // List all files in the config directory.
+ ServerConfig config = ServerConfigLocator.locate();
+ File deployDir = new File(config.getServerHomeDir(), "deploy");
+ File[] files = deployDir.listFiles();
+ List<File> matches = new ArrayList<File>();
+ for (File file : files) {
+ if (JBossESBConfigLocator.isConfigFile(file)) {
+ matches.add(file);
+ }
+ }
+ return matches;
+ }
+
+ /**
+ * Indicates if the given file is a JBossESB config file.
+ *
+ * @param file
+ * @return
+ */
+ public static boolean isConfigFile(File file) {
+ return ((file.getName().endsWith(PACKAGED_CONFIG_SUFFIX)) || (file
+ .getName().endsWith(STANDALONE_CONFIG_SUFFIX)));
+ }
+
+ /**
+ * Indicates if the given file is a *-esb.xml file.
+ *
+ * @param file
+ * @return
+ */
+ public static boolean isStandaloneDeployment(File file) {
+ return file.getName().endsWith(STANDALONE_CONFIG_SUFFIX);
+ }
+
+ /**
+ * Indicates if the given file is a folder containing an exploded
+ * deployment.
+ *
+ * @param file
+ * @return
+ */
+ public static boolean isExplodedDeployment(File file) {
+ return (file.getName().endsWith(PACKAGED_CONFIG_SUFFIX))
+ && (file.isDirectory());
+ }
+
+ /**
+ * Indicates if the given file is a zipped archive containing a JBossESB
+ * deployment.
+ *
+ * @param file
+ * @return
+ */
+ public static boolean isZippedDeployment(File file) {
+ return (file.getName().endsWith(PACKAGED_CONFIG_SUFFIX))
+ && (file.isDirectory());
+ }
+
+ /**
+ * Get an input stream for the JBossESB config taking into account the
+ * different deployment types.
+ *
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ public static InputStream getConfigXmlInputStream(File file)
+ throws IOException {
+ if (isStandaloneDeployment(file)) {
+ if (file.exists()) {
+ return new FileInputStream(file);
+ }
+ } else if (isExplodedDeployment(file)) {
+ File configFile = new File(file, NESTED_CONFIG_PATH);
+ if (configFile.exists()) {
+ return new FileInputStream(configFile);
+ }
+ } else if (isZippedDeployment(file)) {
+ ZipFile zip = new ZipFile(file, ZipFile.OPEN_READ);
+ ZipEntry entry = zip.getEntry(NESTED_CONFIG_PATH);
+ if (entry != null) {
+ return zip.getInputStream(entry);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get an input stream for the JBossESB config taking into account the
+ * different deployment types.
+ *
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ public static OutputStream getConfigXmlOutputStream(File file)
+ throws IOException {
+ if (isStandaloneDeployment(file)) {
+ if (file.exists()) {
+ return new FileOutputStream(file);
+ }
+ } else if (isExplodedDeployment(file)) {
+ File configFile = new File(file, NESTED_CONFIG_PATH);
+ if (configFile.exists()) {
+ return new FileOutputStream(configFile);
+ }
+ }
+ // NOTE: Writing to zipped archives not supported.
+ return null;
+ }
+
+ /**
+ * Gets a JBossESB config file by its unique name.
+ *
+ * @param name
+ * @return
+ */
+ public static File getConfigFileByName(String name) {
+ List<File> configs = JBossESBConfigLocator.locateConfigFiles();
+ for (File file : configs) {
+ if (file.getName().equals(name)) {
+ return file;
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/UploadServlet.java
===================================================================
--- labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/UploadServlet.java 2007-03-21 19:03:28 UTC (rev 10401)
+++ labs/jbossesb/workspace/rsheridan/s360/tools/configeditor/editor/src/org/jboss/configapp/UploadServlet.java 2007-03-21 19:17:50 UTC (rev 10402)
@@ -2,40 +2,49 @@
import java.io.DataInputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.jboss.system.server.ServerConfig;
-import org.jboss.system.server.ServerConfigLocator;
-
public class UploadServlet extends HttpServlet {
/** Serial version UID */
private static final long serialVersionUID = 1L;
- /** Filename for JBossESB config */
- private static final String CONFIG_FILENAME = "jbossesb.xml";
+ /** Parameter name for choosing file to download */
+ private static final String FILE_PARAM = "file";
/** Size of read buffer in bytes */
private static final int BUFFER_SIZE = 1024;
+ /** Default configuration file */
+ private static final String DEFAULT_CONFIG = "jboss-esb.xml";
+
@SuppressWarnings("unchecked")
@Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
- IOException {
+ protected void doPost(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
- // Locate the config file.
- ServerConfig config = ServerConfigLocator.locate();
- File confDir = new File(config.getServerConfigURL().getFile());
- File esbconfig = new File(confDir, CONFIG_FILENAME);
+ // Use parameter to choose file to load.
+ String fileParam = request.getParameter(FILE_PARAM);
+ if ((fileParam == null) || (fileParam.length() == 0)) {
+ fileParam = DEFAULT_CONFIG;
+ }
+ File esbConfig = JBossESBConfigLocator.getConfigFileByName(fileParam);
+ OutputStream output = JBossESBConfigLocator
+ .getConfigXmlOutputStream(esbConfig);
+ if (output == null) {
+ throw new ServletException(
+ "Unable to find config XML to overwrite: "
+ + esbConfig.getName());
+ }
+
DataInputStream input = null;
- FileOutputStream output = new FileOutputStream(esbconfig);
try {
byte[] bbuf = new byte[BUFFER_SIZE];
input = new DataInputStream(request.getInputStream());
More information about the jboss-svn-commits
mailing list