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 2006/10/26 15:49:06 UTC

svn commit: r468003 - in /incubator/servicemix/trunk/servicemix-web-console/src/main: java/org/apache/servicemix/web/Auditor.java java/org/apache/servicemix/web/view/DotView.java webapp/audit.jsp

Author: gnodet
Date: Thu Oct 26 06:49:05 2006
New Revision: 468003

URL: http://svn.apache.org/viewvc?view=rev&rev=468003
Log:
Display normalized messages, clean the DotView

Modified:
    incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/Auditor.java
    incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java
    incubator/servicemix/trunk/servicemix-web-console/src/main/webapp/audit.jsp

Modified: incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/Auditor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/Auditor.java?view=diff&rev=468003&r1=468002&r2=468003
==============================================================================
--- incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/Auditor.java (original)
+++ incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/Auditor.java Thu Oct 26 06:49:05 2006
@@ -1,23 +1,34 @@
 package org.apache.servicemix.web;
 
+import java.io.IOException;
 import java.net.URI;
 import java.text.DateFormat;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
 
 import org.apache.servicemix.JbiConstants;
 import org.apache.servicemix.jbi.audit.AuditorException;
 import org.apache.servicemix.jbi.audit.AuditorMBean;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
+import org.xml.sax.SAXException;
 
 public class Auditor {
 
     private AuditorMBean mbean;
     private int page;
+    private String exchangeId;
 
     public Auditor(AuditorMBean mbean) {
         this.mbean = mbean;
@@ -31,6 +42,14 @@
         this.page = page;
     }
     
+    public String getExchangeId() {
+        return exchangeId;
+    }
+
+    public void setExchangeId(String exchangeId) {
+        this.exchangeId = exchangeId;
+    }
+    
     public int getCount() throws AuditorException {
         int count = mbean.getExchangeCount();
         System.err.println(count);
@@ -42,93 +61,140 @@
         ExchangeInfo[] infos = prepare(exchanges);
         return Arrays.asList(infos);
     }
+    
+    public ExchangeInfo getSelectedExchange() throws AuditorException {
+        if (exchangeId == null) {
+            return null;
+        }
+        MessageExchange exchange = mbean.getExchange(exchangeId);
+        if (exchange != null) {
+            return new ExchangeInfo(exchange);
+        } else {
+            return null;
+        }
+    }
 
     private ExchangeInfo[] prepare(MessageExchange[] exchanges) {
         ExchangeInfo[] infos = new ExchangeInfo[exchanges.length];
         for (int i = 0; i < infos.length; i++) {
-            infos[i] = new ExchangeInfo();
-            infos[i].id = exchanges[i].getExchangeId();
-            infos[i].mep = getMep(exchanges[i]);
-            infos[i].status = exchanges[i].getStatus().toString();
-            Object c = exchanges[i].getProperty(JbiConstants.DATESTAMP_PROPERTY_NAME);
-            if (c instanceof Calendar) {
-                infos[i].date = DateFormat.getDateTimeInstance().format(((Calendar) c).getTime());
-            } else if (c instanceof Date) {
-                infos[i].date = DateFormat.getDateTimeInstance().format((Date) c);
-            }
+            infos[i] = new ExchangeInfo(exchanges[i]);
         }
         return infos;
     }
     
-    private String getMep(MessageExchange exchange) {
-        URI uri = exchange.getPattern();
-        if (MessageExchangeSupport.IN_ONLY.equals(uri)) {
-            return "In Only";
-        } else if (MessageExchangeSupport.IN_OPTIONAL_OUT.equals(uri)) {
-            return "In Opt Out";
-        } else if (MessageExchangeSupport.IN_OUT.equals(uri)) {
-            return "In Out";
-        } else if (MessageExchangeSupport.ROBUST_IN_ONLY.equals(uri)) {
-            return "Robust In Only";
-        } else {
-            return uri.toString();
-        }
-    }
-
     public static class ExchangeInfo {
-        private String id;
-        private String date;
-        private String mep;
-        private String status;
+        private final MessageExchange exchange;
+        
+        public ExchangeInfo(MessageExchange exchange) {
+            this.exchange = exchange;
+        }
         
         /**
          * @return Returns the dateStamp.
          */
         public String getDate() {
-            return date;
-        }
-        /**
-         * @param dateStamp The dateStamp to set.
-         */
-        public void setDate(String dateStamp) {
-            this.date = dateStamp;
+            Object c = exchange.getProperty(JbiConstants.DATESTAMP_PROPERTY_NAME);
+            if (c instanceof Calendar) {
+                return DateFormat.getDateTimeInstance().format(((Calendar) c).getTime());
+            } else if (c instanceof Date) {
+                return DateFormat.getDateTimeInstance().format((Date) c);
+            } else if (c != null) {
+                return c.toString();
+            } else {
+                return null;
+            }
         }
         /**
          * @return Returns the status.
          */
         public String getStatus() {
-            return status;
-        }
-        /**
-         * @param status The status to set.
-         */
-        public void setStatus(String status) {
-            this.status = status;
+            return exchange.getStatus().toString();
         }
         /**
          * @return Returns the id.
          */
         public String getId() {
-            return id;
-        }
-        /**
-         * @param id The id to set.
-         */
-        public void setId(String id) {
-            this.id = id;
+            return exchange.getExchangeId();
         }
         /**
          * @return Returns the mep.
          */
         public String getMep() {
-            return mep;
+            URI uri = exchange.getPattern();
+            if (MessageExchangeSupport.IN_ONLY.equals(uri)) {
+                return "In Only";
+            } else if (MessageExchangeSupport.IN_OPTIONAL_OUT.equals(uri)) {
+                return "In Opt Out";
+            } else if (MessageExchangeSupport.IN_OUT.equals(uri)) {
+                return "In Out";
+            } else if (MessageExchangeSupport.ROBUST_IN_ONLY.equals(uri)) {
+                return "Robust In Only";
+            } else {
+                return uri.toString();
+            }
         }
-        /**
-         * @param mep The mep to set.
-         */
-        public void setMep(String mep) {
-            this.mep = mep;
+        
+        public String getProperties() {
+            StringBuilder sb = new StringBuilder();
+            for (String name : (Set<String>) exchange.getPropertyNames()) {
+                if (sb.length() > 0) {
+                    sb.append("\n");
+                }
+                sb.append(name).append(" = ").append(exchange.getProperty(name));
+            }
+            return sb.toString();
+        }
+        
+        public String getErrorMessage() {
+            return exchange.getError() != null ? exchange.getError().getMessage() : null;
+        }
+        
+        public MessageInfo getIn() {
+            return getMessage("in");
+        }
+        
+        public MessageInfo getOut() {
+            return getMessage("out");
+        }
+        
+        public MessageInfo getFault() {
+            return getMessage("fault");
+        }
+        
+        private MessageInfo getMessage(String name) {
+            NormalizedMessage msg = exchange.getMessage(name);
+            return msg != null ? new MessageInfo(msg) : null;
+        }
+        
+        public String getEndpoint() {
+            return exchange.getEndpoint().getServiceName() + ":" + exchange.getEndpoint().getEndpointName();
+        }
+    }
+
+    public static class MessageInfo {
+        private final NormalizedMessage message;
+        public MessageInfo(NormalizedMessage message) {
+            this.message = message;
+        }
+        public String getProperties() {
+            StringBuilder sb = new StringBuilder();
+            for (String name : (Set<String>) message.getPropertyNames()) {
+                if (sb.length() > 0) {
+                    sb.append("\n");
+                }
+                sb.append(name).append(" = ").append(message.getProperty(name));
+            }
+            return sb.toString();
+        }
+        public String getContent() {
+            try {
+                String str = new SourceTransformer().contentToString(message);
+                if (str != null) {
+                    return str.replace("<", "&lt;");
+                }
+            } catch (Exception e) {
+            }
+            return null;
         }
     }
-    
 }

Modified: incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java?view=diff&rev=468003&r1=468002&r2=468003
==============================================================================
--- incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java (original)
+++ incubator/servicemix/trunk/servicemix-web-console/src/main/java/org/apache/servicemix/web/view/DotView.java Thu Oct 26 06:49:05 2006
@@ -68,11 +68,8 @@
             dotImg = File.createTempFile("smx_", ".dot." + getDotFormat());
             
             String cmd = getDotPath() + " -T" + getDotFormat() + " \"" + dotSrc.getCanonicalPath() + "\" -o\"" + dotImg.getAbsolutePath() + "\"";
-            System.err.println("Executing: " + cmd);
             Process p = Runtime.getRuntime().exec(cmd);
             p.waitFor();
-            FileUtil.copyInputStream(p.getErrorStream(), System.err);
-            FileUtil.copyInputStream(p.getInputStream(), System.out);
             
             InputStream is = new FileInputStream(dotImg);
             if (is.available() == 0) {

Modified: incubator/servicemix/trunk/servicemix-web-console/src/main/webapp/audit.jsp
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-web-console/src/main/webapp/audit.jsp?view=diff&rev=468003&r1=468002&r2=468003
==============================================================================
--- incubator/servicemix/trunk/servicemix-web-console/src/main/webapp/audit.jsp (original)
+++ incubator/servicemix/trunk/servicemix-web-console/src/main/webapp/audit.jsp Thu Oct 26 06:49:05 2006
@@ -22,43 +22,131 @@
 
 <h2>Audit</h2>
 
-<table class="autostripe">
-  <thead>
-    <tr>
-      <th>Id</th>
-      <th>Date</th>
-      <th>Status</th>
-      <th>MEP</th>
-    </tr>
-  </thead>
-  <tbody>
-    <c:forEach var="exchange" items="${requestContext.auditor.exchanges}">
-      <tr>
-        <td>${exchange.id}</td>
-        <td>${exchange.date}</td>
-        <td>${exchange.status}</td>
-        <td>${exchange.mep}</td>
-      </tr>
-    </c:forEach>
-  </tbody>
-  <tfooter>
-    <tr>
-      <td colspan="4">
-        <c:forEach var="i" begin="0" end="${requestContext.auditor.count / 10}">
-          <c:choose>
-            <c:when test="${i == requestContext.auditor.page}">
-              ${i}
-            </c:when>
-            <c:otherwise>
-              <a href="audit.jsp?page=${i}">${i}</a>
-            </c:otherwise>
-          </c:choose>
-          &nbsp;
-        </c:forEach>
-      </td>
-    </tr>
-  </tfooter>
-</table>
+<fieldset>
+  <legend>Exchanges</legend>
+  <table class="autostripe">
+    <thead>
+      <tr>
+        <th>Id</th>
+        <th>Date</th>
+        <th>Status</th>
+        <th>MEP</th>
+      </tr>
+    </thead>
+    <tbody>
+      <c:forEach var="exchange" items="${requestContext.auditor.exchanges}">
+        <tr>
+          <td><a href="audit.jsp?page=${requestContext.auditor.page}&amp;exchangeId=${exchange.id}">${exchange.id}</a></td>
+          <td>${exchange.date}</td>
+          <td>${exchange.status}</td>
+          <td>${exchange.mep}</td>
+        </tr>
+      </c:forEach>
+    </tbody>
+    <tfooter>
+      <tr>
+        <td colspan="4">
+          <c:forEach var="i" begin="0" end="${(requestContext.auditor.count - 1) / 10}">
+            <c:choose>
+              <c:when test="${i == requestContext.auditor.page}">
+                ${i}
+              </c:when>
+              <c:otherwise>
+                <a href="audit.jsp?page=${i}">${i}</a>
+              </c:otherwise>
+            </c:choose>
+            &nbsp;
+          </c:forEach>
+        </td>
+      </tr>
+    </tfooter>
+  </table>
+</fieldset>
+
+<c:if test="${requestContext.auditor.selectedExchange != null}">
+<fieldset>
+  <legend>Exchange details</legend>
+  <table>
+    <tbody>
+      <tr>
+        <th>Id</th>
+        <td>${requestContext.auditor.selectedExchange.id}</td>
+      </tr>
+      <tr>
+        <th>Date</th>
+        <td>${requestContext.auditor.selectedExchange.date}</td>
+      </tr>
+      <tr>
+        <th>Status</th>
+        <td>${requestContext.auditor.selectedExchange.status}</td>
+      </tr>
+      <tr>
+        <th>Mep</th>
+        <td>${requestContext.auditor.selectedExchange.mep}</td>
+      </tr>
+      <tr>
+        <th>Properties</th>
+        <td><pre>${requestContext.auditor.selectedExchange.properties}</pre></td>
+      </tr>
+      <tr>
+        <th>Endpoint</th>
+        <td><pre>${requestContext.auditor.selectedExchange.endpoint}</pre></td>
+      </tr>
+    </tbody>
+  </table>
+  <c:if test="${requestContext.auditor.selectedExchange.in != null}">
+    <fieldset>
+      <legend>In</legend>
+      <table>
+        <tbody>
+        <tr>
+          <th>Properties</th>
+          <td><pre>${requestContext.auditor.selectedExchange.in.properties}</pre></td>
+        </tr>
+        <tr>
+          <th>Content</th>
+          <td><pre>${requestContext.auditor.selectedExchange.in.content}</pre></td>
+        </tr>
+        </tbody>
+      </table>
+    </fieldset>
+  </c:if>
+  <c:if test="${requestContext.auditor.selectedExchange.out != null}">
+    <fieldset>
+      <legend>Out</legend>
+      <table>
+        <tbody>
+        <tr>
+          <th>Properties</th>
+          <td><pre>${requestContext.auditor.selectedExchange.out.properties}</pre></td>
+        </tr>
+        <tr>
+          <th>Content</th>
+          <td><pre>${requestContext.auditor.selectedExchange.out.content}</pre></td>
+        </tr>
+        </tbody>
+      </table>
+    </fieldset>
+  </c:if>
+  <c:if test="${requestContext.auditor.selectedExchange.fault != null}">
+    <fieldset>
+      <legend>Fault</legend>
+      <table>
+        <tbody>
+        <tr>
+          <th>Properties</th>
+          <td><pre>${requestContext.auditor.selectedExchange.fault.properties}</pre></td>
+        </tr>
+        <tr>
+          <th>Content</th>
+          <td><pre>${requestContext.auditor.selectedExchange.fault.content}</pre></td>
+        </tr>
+        </tbody>
+      </table>
+    </fieldset>
+  </c:if>
+</fieldset>
+</c:if>
 
 </body>
 </html>