You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/04/06 13:36:40 UTC

svn commit: r526124 - in /incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main: java/org/apache/servicemix/web/view/Dot.java java/org/apache/servicemix/web/view/DotView.java webapp/view.jsp

Author: gnodet
Date: Fri Apr  6 04:36:39 2007
New Revision: 526124

URL: http://svn.apache.org/viewvc?view=rev&rev=526124
Log:
SM-914: Display a nice page when the dot process can not be launched

Added:
    incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/Dot.java   (with props)
Modified:
    incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java
    incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/webapp/view.jsp

Added: incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/Dot.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/Dot.java?view=auto&rev=526124
==============================================================================
--- incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/Dot.java (added)
+++ incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/Dot.java Fri Apr  6 04:36:39 2007
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.web.view;
+
+public class Dot {
+
+    public static final String DEFAULT_DOT_PATH = "dot";
+
+    private static boolean initialized = false;
+    private static Exception initException;
+    private static String dotPath = DEFAULT_DOT_PATH;
+
+    public static String getDotPath() {
+        return dotPath;
+    }
+
+    public static void setDotPath(String dotPath) {
+        Dot.dotPath = dotPath;
+    }
+
+
+    public static void initialize() throws Exception {
+        if (!initialized) {
+            try {
+                initException = null;
+                run("-V");
+            } catch (Exception e) {
+                initException = e;
+            } finally {
+                initialized = true;
+            }
+        }
+        if (initException != null) {
+            throw initException;
+        }
+    }
+
+    public static void run(String args) throws Exception {
+        String cmdLine = getDotPath() + " " + args;
+        Process p = Runtime.getRuntime().exec(cmdLine);
+        p.waitFor();
+    }
+
+}

Propchange: incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/Dot.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/Dot.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/Dot.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java?view=diff&rev=526124&r1=526123&r2=526124
==============================================================================
--- incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java (original)
+++ incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java Fri Apr  6 04:36:39 2007
@@ -31,12 +31,10 @@
 
 public class DotView extends AbstractView {
 
-    public static final String DEFAULT_DOT_PATH = "dot";
     public static final String DEFAULT_DOT_FORMAT = "svg";
     public static final String MODEL_SOURCE = "dotSource";
     public static final String MODEL_FORMAT = "dotFormat";
     
-    private String dotPath = DEFAULT_DOT_PATH;
     private String dotModelSource = MODEL_SOURCE;
     private String dotFormat = DEFAULT_DOT_FORMAT;
     
@@ -67,9 +65,8 @@
             w.close();
             dotImg = File.createTempFile("smx_", ".dot." + getDotFormat());
             
-            String cmd = getDotPath() + " -T" + getDotFormat() + " \"" + dotSrc.getCanonicalPath() + "\" -o\"" + dotImg.getAbsolutePath() + "\"";
-            Process p = Runtime.getRuntime().exec(cmd);
-            p.waitFor();
+            String cmd = "-T" + getDotFormat() + " \"" + dotSrc.getCanonicalPath() + "\" -o\"" + dotImg.getAbsolutePath() + "\"";
+            Dot.run(cmd);
             
             InputStream is = new FileInputStream(dotImg);
             if (is.available() == 0) {
@@ -80,7 +77,7 @@
             FileUtil.copyInputStream(is, response.getOutputStream());
         } finally {
             if (dotSrc != null) {
-                dotSrc.delete();
+                //dotSrc.delete();
             }
             if (dotImg != null) {
                 dotImg.delete();
@@ -90,14 +87,6 @@
     
     public String getContentType() {
         return FORMATS.get(getDotFormat());
-    }
-
-    public String getDotPath() {
-        return dotPath;
-    }
-
-    public void setDotPath(String dotPath) {
-        this.dotPath = dotPath;
     }
 
     public String getDotFormat() {

Modified: incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/webapp/view.jsp
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/webapp/view.jsp?view=diff&rev=526124&r1=526123&r2=526124
==============================================================================
--- incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/webapp/view.jsp (original)
+++ incubator/servicemix/branches/servicemix-3.1/web/servicemix-web-console/src/main/webapp/view.jsp Fri Apr  6 04:36:39 2007
@@ -20,6 +20,23 @@
 </head>
 <body>
 
+<%
+Throwable dotException = null;
+try {
+    org.apache.servicemix.web.view.Dot.initialize();
+} catch (Throwable t) {
+    dotException = t;
+}
+if (dotException != null) {
+%>
+<br></br>
+Unable to run dot: <%=dotException.getMessage()%>
+<br></br>
+Check that the dot executable is available in the path or install it from <a href="http://www.graphviz.org/">http://www.graphviz.org/</a>.
+<%
+} else {
+%>
+
 <h2>View</h2>
 
 <fieldset style="height:25em">
@@ -48,6 +65,9 @@
   </object>
 </fieldset>
 
+<%
+}
+%>
 </body>
 </html>