You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Coty Sutherland <cs...@redhat.com> on 2016/03/30 20:09:52 UTC

Re: svn commit: r1731734 - in /tomcat/trunk: java/org/apache/catalina/manager/host/ webapps/docs/

In addition to the object array size restoration made in 1731735, I think
that another erroneous change that I submitted slipped in to your patch. I
noticed it while poking around at tomcat-8.5.0.Beta. Now when you add a
host you get a button that just contains {5} where the persist button that
I proposed would have been. You can revert the change with the following
patch to make it work the way it did before:

+++
Index: java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java
===================================================================
--- java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java (revision
1737136)
+++ java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java (working
copy)
@@ -511,9 +511,6 @@
         "  <form class=\"inline\" method=\"POST\" action=\"{2}\">" +
         "   <small><input type=\"submit\" value=\"{3}\"></small>" +
         "  </form>\n" +
-        "  <form class=\"inline\" method=\"POST\" action=\"{4}\">" +
-        "   <small><input type=\"submit\" value=\"{5}\"></small>" +
-        "  </form>\n" +
         " </td>\n" +
         "</tr>\n";

+++

Cheers

On Mon, Feb 22, 2016 at 3:19 PM, <ma...@apache.org> wrote:

> Author: markt
> Date: Mon Feb 22 20:19:15 2016
> New Revision: 1731734
>
> URL: http://svn.apache.org/viewvc?rev=1731734&view=rev
> Log:
> Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=48674
> Implement an option within the Host Manager web pplication to persist the
> current configuration.
> Based on a patch by Coty Sutherland.
>
> Modified:
>
> tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java
>
> tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java
>
> tomcat/trunk/java/org/apache/catalina/manager/host/LocalStrings.properties
>     tomcat/trunk/webapps/docs/changelog.xml
>
> Modified:
> tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java
> URL:
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java?rev=1731734&r1=1731733&r2=1731734&view=diff
>
> ==============================================================================
> ---
> tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java
> (original)
> +++
> tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java
> Mon Feb 22 20:19:15 2016
> @@ -94,7 +94,8 @@ public final class HTMLHostManagerServle
>          } else if (command.equals("/list")) {
>              // Nothing to do - always generate list
>          } else if (command.equals("/add") || command.equals("/remove") ||
> -                command.equals("/start") || command.equals("/stop")) {
> +                command.equals("/start") || command.equals("/stop") ||
> +                command.equals("/persist")) {
>              message = smClient.getString(
>                      "hostManagerServlet.postCommand", command);
>          } else {
> @@ -143,6 +144,8 @@ public final class HTMLHostManagerServle
>              message = start(name, smClient);
>          } else if (command.equals("/stop")) {
>              message = stop(name, smClient);
> +        } else if (command.equals("/persist")) {
> +            message = persist(smClient);
>          } else {
>              //Try GET
>              doGet(request, response);
> @@ -227,6 +230,22 @@ public final class HTMLHostManagerServle
>
>
>      /**
> +     * Persist the current configuration to server.xml.
> +     *
> +     * @param smClient i18n resources localized for the client
> +     */
> +    protected String persist(StringManager smClient) {
> +
> +        StringWriter stringWriter = new StringWriter();
> +        PrintWriter printWriter = new PrintWriter(stringWriter);
> +
> +        super.persist(printWriter, smClient);
> +
> +        return stringWriter.toString();
> +    }
> +
> +
> +    /**
>       * Render a HTML list of the currently active Contexts in our virtual
> host,
>       * and memory and server status information.
>       *
> @@ -341,7 +360,7 @@ public final class HTMLHostManagerServle
>                  writer.print
>                      (MessageFormat.format(HOSTS_ROW_DETAILS_SECTION,
> args));
>
> -                args = new Object[4];
> +                args = new Object[6];
>                  if (host.getState().isAvailable()) {
>                      args[0] = response.encodeURL
>                      (request.getContextPath() +
> @@ -362,10 +381,10 @@ public final class HTMLHostManagerServle
>                  args[3] = hostsRemove;
>                  if (host == this.installedHost) {
>                      writer.print(MessageFormat.format(
> -                        MANAGER_HOST_ROW_BUTTON_SECTION, args));
> +                            MANAGER_HOST_ROW_BUTTON_SECTION, args));
>                  } else {
>                      writer.print(MessageFormat.format(
> -                        HOSTS_ROW_BUTTON_SECTION, args));
> +                            HOSTS_ROW_BUTTON_SECTION, args));
>                  }
>              }
>          }
> @@ -413,6 +432,14 @@ public final class HTMLHostManagerServle
>          args[0] = smClient.getString("htmlHostManagerServlet.addButton");
>          writer.print(MessageFormat.format(ADD_SECTION_END, args));
>
> +        // Persist Configuration Section
> +        args = new Object[4];
> +        args[0] =
> smClient.getString("htmlHostManagerServlet.persistTitle");
> +        args[1] = response.encodeURL(request.getContextPath() +
> "/html/persist");
> +        args[2] =
> smClient.getString("htmlHostManagerServlet.persistAllButton");
> +        args[3] = smClient.getString("htmlHostManagerServlet.persistAll");
> +        writer.print(MessageFormat.format(PERSIST_SECTION, args));
> +
>          // Server Header Section
>          args = new Object[7];
>          args[0] =
> smClient.getString("htmlHostManagerServlet.serverTitle");
> @@ -483,6 +510,9 @@ public final class HTMLHostManagerServle
>          "  <form class=\"inline\" method=\"POST\" action=\"{2}\">" +
>          "   <small><input type=\"submit\" value=\"{3}\"></small>" +
>          "  </form>\n" +
> +        "  <form class=\"inline\" method=\"POST\" action=\"{4}\">" +
> +        "   <small><input type=\"submit\" value=\"{5}\"></small>" +
> +        "  </form>\n" +
>          " </td>\n" +
>          "</tr>\n";
>
> @@ -552,4 +582,20 @@ public final class HTMLHostManagerServle
>          "<br>\n" +
>          "\n";
>
> +        private static final String PERSIST_SECTION =
> +                "<table border=\"1\" cellspacing=\"0\"
> cellpadding=\"3\">\n" +
> +                "<tr>\n" +
> +                " <td class=\"title\">{0}</td>\n" +
> +                "</tr>\n" +
> +                "<tr>\n" +
> +                " <td class=\"row-left\">\n" +
> +                "  <form class=\"inline\" method=\"POST\"
> action=\"{1}\">" +
> +                "   <small><input type=\"submit\" value=\"{2}\"></small>"
> +
> +                "  </form> {3}\n" +
> +                " </td>\n" +
> +                "</tr>\n" +
> +                "</table>\n" +
> +                "<br>\n" +
> +                "\n";
> +
>  }
>
> Modified:
> tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java
> URL:
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java?rev=1731734&r1=1731733&r2=1731734&view=diff
>
> ==============================================================================
> ---
> tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java
> (original)
> +++
> tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java
> Mon Feb 22 20:19:15 2016
> @@ -20,10 +20,14 @@ import java.io.File;
>  import java.io.IOException;
>  import java.io.InputStream;
>  import java.io.PrintWriter;
> +import java.lang.management.ManagementFactory;
>  import java.nio.file.Files;
>  import java.nio.file.Path;
>  import java.util.StringTokenizer;
>
> +import javax.management.InstanceNotFoundException;
> +import javax.management.MBeanServer;
> +import javax.management.ObjectName;
>  import javax.servlet.ServletException;
>  import javax.servlet.UnavailableException;
>  import javax.servlet.http.HttpServlet;
> @@ -42,7 +46,6 @@ import org.apache.catalina.startup.HostC
>  import org.apache.tomcat.util.ExceptionUtils;
>  import org.apache.tomcat.util.res.StringManager;
>
> -
>  /**
>   * Servlet that enables remote management of the virtual hosts installed
>   * on the server.  Normally, this functionality will be protected by
> @@ -218,6 +221,8 @@ public class HostManagerServlet
>              start(writer, name, smClient);
>          } else if (command.equals("/stop")) {
>              stop(writer, name, smClient);
> +        } else if (command.equals("/persist")) {
> +            persist(writer, smClient);
>          } else {
>
>  writer.println(sm.getString("hostManagerServlet.unknownCommand",
>                                          command));
> @@ -229,7 +234,6 @@ public class HostManagerServlet
>
>      }
>
> -
>      /**
>       * Add host with the given parameters.
>       *
> @@ -652,8 +656,39 @@ public class HostManagerServlet
>      }
>
>
> -    // -------------------------------------------------------- Support
> Methods
> +    /**
> +     * Persist the current configuration to server.xml.
> +     *
> +     * @param writer Writer to render to
> +     * @param smClient i18n resources localized for the client
> +     */
> +    protected void persist(PrintWriter writer, StringManager smClient) {
> +
> +        if (debug >= 1) {
> +            log(sm.getString("hostManagerServlet.persist"));
> +        }
>
> +        try {
> +            MBeanServer platformMBeanServer =
> ManagementFactory.getPlatformMBeanServer();
> +            ObjectName oname = new ObjectName(engine.getDomain() +
> ":type=StoreConfig");
> +            platformMBeanServer.invoke(oname, "storeConfig", null, null);
> +
> writer.println(smClient.getString("hostManagerServlet.persisted"));
> +        } catch (Exception e) {
> +
> getServletContext().log(sm.getString("hostManagerServlet.persistFailed"),
> e);
> +
> writer.println(smClient.getString("hostManagerServlet.persistFailed"));
> +            // catch InstanceNotFoundException when StoreConfig is not
> enabled instead of printing
> +            // the failure message
> +            if (e instanceof InstanceNotFoundException) {
> +                writer.println("Please enable StoreConfig to use this
> feature.");
> +            } else {
> +
> writer.println(smClient.getString("hostManagerServlet.exception",
> e.toString()));
> +            }
> +            return;
> +        }
> +    }
> +
> +
> +    // -------------------------------------------------------- Support
> Methods
>
>      /**
>       * Get config base.
>
> Modified:
> tomcat/trunk/java/org/apache/catalina/manager/host/LocalStrings.properties
> URL:
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/host/LocalStrings.properties?rev=1731734&r1=1731733&r2=1731734&view=diff
>
> ==============================================================================
> ---
> tomcat/trunk/java/org/apache/catalina/manager/host/LocalStrings.properties
> (original)
> +++
> tomcat/trunk/java/org/apache/catalina/manager/host/LocalStrings.properties
> Mon Feb 22 20:19:15 2016
> @@ -44,6 +44,9 @@ hostManagerServlet.remove=remove: Removi
>  hostManagerServlet.list=list: Listing hosts for engine [{0}]
>  hostManagerServlet.start=start: Starting host with name [{0}]
>  hostManagerServlet.stop=stop: Stopping host with name [{0}]
> +hostManagerServlet.persist=persist: Persisting current configuration
> +hostManagerServlet.persisted=OK - Configuration persisted
> +hostManagerServlet.persistFailed=FAIL - Failed to persist configuration
>
>  htmlHostManagerServlet.title=Tomcat Virtual Host Manager
>  htmlHostManagerServlet.messageLabel=Message:
> @@ -59,6 +62,7 @@ htmlHostManagerServlet.hostTasks=Command
>  htmlHostManagerServlet.hostsStart=Start
>  htmlHostManagerServlet.hostsStop=Stop
>  htmlHostManagerServlet.hostsRemove=Remove
> +htmlHostManagerServlet.hostsPersist=Persist
>  htmlHostManagerServlet.hostThis=Host Manager installed - commands disabled
>  htmlHostManagerServlet.addTitle=Add Virtual Host
>  htmlHostManagerServlet.addHost=Host
> @@ -79,6 +83,9 @@ htmlHostManagerServlet.serverJVMVendor=J
>  htmlHostManagerServlet.serverOSName=OS Name
>  htmlHostManagerServlet.serverOSVersion=OS Version
>  htmlHostManagerServlet.serverOSArch=OS Architecture
> +htmlHostManagerServlet.persistTitle=Persist configuration
> +htmlHostManagerServlet.persistAll=Save current configuration (including
> virtual hosts) to server.xml and per web application context.xml files
> +htmlHostManagerServlet.persistAllButton=All
>
>  statusServlet.title=Server Status
>  statusServlet.complete=Complete Server Status
>
> Modified: tomcat/trunk/webapps/docs/changelog.xml
> URL:
> http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1731734&r1=1731733&r2=1731734&view=diff
>
> ==============================================================================
> --- tomcat/trunk/webapps/docs/changelog.xml (original)
> +++ tomcat/trunk/webapps/docs/changelog.xml Mon Feb 22 20:19:15 2016
> @@ -145,6 +145,11 @@
>          the WAR if <code>unpackWARs</code> is <code>true</code>. (markt)
>        </fix>
>        <fix>
> +        <bug>48674</bug>: Implement an option within the Host Manager web
> +        application to persist the current configuration. Based on a
> patch by
> +        Coty Sutherland. (markt)
> +      </fix>
> +      <fix>
>          <bug>58935</bug>: Remove incorrect references in the
> documentation to
>          using <code>jar:file:</code> URLs with the Manager application.
> (markt)
>        </fix>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>


-- 
Coty Sutherland, RHCSA, RHCE, JBCAA
Senior Software Engineer @ Red Hat, Inc.
100 East Davie Street
Raleigh, NC 27606

Email: coty@redhat.com
IRC Nickname: coty
Office: 919-890-8303