Title: [816] trunk/servicemix-console: SM-148 : Work In Progress, add audit portlet (only view exchange list, for the moment)

Diff

Property changes: trunk/servicemix-console

Name: svn:ignore
   - 
bin
   + bin
.project
.classpath
target

Modified: trunk/servicemix-console/project.xml (815 => 816)

--- trunk/servicemix-console/project.xml	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/project.xml	2005-11-13 21:21:16 UTC (rev 816)
@@ -40,6 +40,38 @@
                 <war.bundle>true</war.bundle>
         </properties>
       </dependency>
+      <dependency>
+        <groupId>springframework</groupId>
+        <artifactId>spring</artifactId>
+        <version>${spring_version}</version>
+        <properties>
+          <eclipse.dependency>true</eclipse.dependency>
+                <war.bundle>true</war.bundle>
+        </properties>
+      </dependency>
+    <dependency>
+      <id>geronimo-spec+jta</id>
+      <version>${geronimo_spec_jta_version}</version>
+      <properties>
+        <war.bundle>true</war.bundle>
+      </properties>
+    </dependency>
+    <dependency>
+      <groupId>geronimo-spec</groupId>
+      <artifactId>geronimo-spec-activation</artifactId>
+      <version>${geronimo_spec_activation_version}</version>
+      <properties>
+        <war.bundle>true</war.bundle>
+      </properties>
+    </dependency>
+    <dependency>
+      <groupId>backport-util-concurrent</groupId>
+      <artifactId>backport-util-concurrent</artifactId>
+      <version>${backport_util_concurrent_version}</version>
+      <properties>
+        <war.bundle>true</war.bundle>
+      </properties>
+    </dependency>
 
     <dependency>
       <groupId>commons-logging</groupId>

Added: trunk/servicemix-console/src/main/java/org/servicemix/console/JBIAuditPortlet.java (815 => 816)

--- trunk/servicemix-console/src/main/java/org/servicemix/console/JBIAuditPortlet.java	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/src/main/java/org/servicemix/console/JBIAuditPortlet.java	2005-11-13 21:21:16 UTC (rev 816)
@@ -0,0 +1,160 @@
+/** 
+ * <a href="" The open source ESB</a> 
+ * 
+ * Copyright 2005 RAJD Consultancy Ltd
+ * 
+ * Licensed 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.servicemix.console;
+
+import org.servicemix.JbiConstants;
+import org.servicemix.jbi.audit.AuditorMBean;
+import org.servicemix.jbi.jaxp.SourceTransformer;
+import org.servicemix.jbi.messaging.MessageExchangeSupport;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.RenderRequest;
+
+import java.net.URI;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+public class JBIAuditPortlet extends ServiceMixPortlet {
+    
+    protected int page = 0;
+
+    public static class ExchangeInfo {
+        private String id;
+        private String date;
+        private String mep;
+        private String status;
+        
+        /**
+         * @return Returns the dateStamp.
+         */
+        public String getDate() {
+            return date;
+        }
+        /**
+         * @param dateStamp The dateStamp to set.
+         */
+        public void setDate(String dateStamp) {
+            this.date = dateStamp;
+        }
+        /**
+         * @return Returns the status.
+         */
+        public String getStatus() {
+            return status;
+        }
+        /**
+         * @param status The status to set.
+         */
+        public void setStatus(String status) {
+            this.status = status;
+        }
+        /**
+         * @return Returns the id.
+         */
+        public String getId() {
+            return id;
+        }
+        /**
+         * @param id The id to set.
+         */
+        public void setId(String id) {
+            this.id = id;
+        }
+        /**
+         * @return Returns the mep.
+         */
+        public String getMep() {
+            return mep;
+        }
+        /**
+         * @param mep The mep to set.
+         */
+        public void setMep(String mep) {
+            this.mep = mep;
+        }
+    }
+    
+    protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
+        System.err.println(actionRequest.getParameterMap());
+        if (actionRequest.getParameter("view") != null) {
+            page = Integer.parseInt(actionRequest.getParameter("view"));
+        }
+    }
+
+    protected void fillViewRequest(RenderRequest request) throws Exception {
+        AuditorMBean auditor = getJdbcAuditor();
+        int count = auditor.getExchangeCount();
+        request.setAttribute("count", new Integer(count));
+        request.setAttribute("page", new Integer(page));
+        MessageExchange[] exchanges = auditor.getExchanges(page * 10, Math.min((page + 1) * 10, count));
+        request.setAttribute("exchanges", prepare(exchanges));
+        super.fillViewRequest(request);
+    }
+
+    private ExchangeInfo[] prepare(MessageExchange[] exchanges) throws Exception {
+        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);
+            }
+        }
+        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();
+        }
+    }
+
+    private String prepareContent(NormalizedMessage msg) throws Exception {
+        if (msg != null) {
+            SourceTransformer st = new SourceTransformer();
+            String s = st.contentToString(msg);
+            if (s != null && s.length() > 30) {
+                return s.substring(0, 30) + "...";
+            } else {
+                return s;
+            }
+        } else {
+            return null;
+        }
+    }
+
+}

Modified: trunk/servicemix-console/src/main/java/org/servicemix/console/ServiceMixPortlet.java (815 => 816)

--- trunk/servicemix-console/src/main/java/org/servicemix/console/ServiceMixPortlet.java	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/src/main/java/org/servicemix/console/ServiceMixPortlet.java	2005-11-13 21:21:16 UTC (rev 816)
@@ -20,6 +20,8 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.servicemix.jbi.audit.AuditorMBean;
+import org.servicemix.jbi.audit.jdbc.JdbcAuditor;
 import org.servicemix.jbi.container.JBIContainer;
 import org.servicemix.jbi.framework.DeploymentService;
 import org.servicemix.jbi.framework.FrameworkInstallationService;
@@ -223,6 +225,11 @@
         return (ManagementContextMBean) getProxy(objectName, ManagementContextMBean.class);
     }
     
+    public AuditorMBean getJdbcAuditor() throws IOException {
+        ObjectName objectName = getObjectName(JdbcAuditor.class);
+        return (AuditorMBean) getProxy(objectName, AuditorMBean.class);
+    }
+    
     public LifeCycleMBean getJBIContainer() throws IOException {
         ObjectName objectName = ManagementContext.getContainerObjectName(jmxDomainName, containerName);
         return (LifeCycleMBean) getProxy(objectName, LifeCycleMBean.class);

Modified: trunk/servicemix-console/src/webapp/WEB-INF/data/pageregistry.xml (815 => 816)

--- trunk/servicemix-console/src/webapp/WEB-INF/data/pageregistry.xml	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/src/webapp/WEB-INF/data/pageregistry.xml	2005-11-13 21:21:16 UTC (rev 816)
@@ -21,6 +21,9 @@
                     <fragment name="p1" type="portlet">
                         <property name="portlet" value="1.1"/>
                     </fragment>
+                    <fragment name="p2" type="portlet">
+                        <property name="portlet" value="1.2"/>
+                    </fragment>
                 </fragment>
             </fragment>
         </fragment>

Modified: trunk/servicemix-console/src/webapp/WEB-INF/data/portletentityregistry.xml (815 => 816)

--- trunk/servicemix-console/src/webapp/WEB-INF/data/portletentityregistry.xml	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/src/webapp/WEB-INF/data/portletentityregistry.xml	2005-11-13 21:21:16 UTC (rev 816)
@@ -5,5 +5,8 @@
         <portlet id="1">
             <definition-id>servicemix-console.JBIContainer</definition-id>
         </portlet>
+        <portlet id="2">
+            <definition-id>servicemix-console.JBIAudit</definition-id>
+        </portlet>
     </application>
 </portlet-entity-registry>

Modified: trunk/servicemix-console/src/webapp/WEB-INF/portlet.xml (815 => 816)

--- trunk/servicemix-console/src/webapp/WEB-INF/portlet.xml	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/src/webapp/WEB-INF/portlet.xml	2005-11-13 21:21:16 UTC (rev 816)
@@ -28,4 +28,27 @@
             <keywords>JBI, Container</keywords>
         </portlet-info>
     </portlet>
+    <portlet>
+        <description>ServiceMix audit tool.</description>
+        <portlet-name>JBIAudit</portlet-name>
+        <display-name>JBI Audit Portlet</display-name>
+
+        <portlet-class>org.servicemix.console.JBIAuditPortlet</portlet-class>
+
+        <expiration-cache>-1</expiration-cache>
+
+        <supports>
+            <mime-type>text/html</mime-type>
+            <portlet-mode>VIEW</portlet-mode>
+            <portlet-mode>HELP</portlet-mode>
+        </supports>
+
+        <supported-locale>en</supported-locale>
+
+        <portlet-info>
+            <title>JBI Audit</title>
+            <short-title>JBI Audit</short-title>
+            <keywords>JBI, Audit</keywords>
+        </portlet-info>
+    </portlet>
  </portlet-app>

Added: trunk/servicemix-console/src/webapp/WEB-INF/view/JBIAudit/help.jsp (815 => 816)

--- trunk/servicemix-console/src/webapp/WEB-INF/view/JBIAudit/help.jsp	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/src/webapp/WEB-INF/view/JBIAudit/help.jsp	2005-11-13 21:21:16 UTC (rev 816)
@@ -0,0 +1 @@
+<p>This portlet allows the user to view the jbi exchanges historic.
\ No newline at end of file

Added: trunk/servicemix-console/src/webapp/WEB-INF/view/JBIAudit/view.jsp (815 => 816)

--- trunk/servicemix-console/src/webapp/WEB-INF/view/JBIAudit/view.jsp	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/src/webapp/WEB-INF/view/JBIAudit/view.jsp	2005-11-13 21:21:16 UTC (rev 816)
@@ -0,0 +1,42 @@
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
+<portlet:defineObjects/>
+<table width="100%">
+  <tr>
+    <td>
+      <a href="" name="action" value="refresh"/></portlet:renderURL>">Refresh</a> 
+    </td>   
+    <td>
+      <c:forEach var="i" begin="0" end="${count / 10}">
+        <c:choose>
+          <c:when test="${i == page}">
+            ${i}
+          </c:when>
+          <c:otherwise>
+            <a href="" name="view" value="${i}"/></portlet:actionURL>">${i}</a>
+          </c:otherwise>
+        </c:choose>
+        &nbsp;
+      </c:forEach>
+    </td>  
+  </tr>
+  <tr>
+    <td class="DarkBackground" width="100%" colspan="4" align="center">
+       Message exchanges (${count})
+    </td>
+  </tr>
+  <tr>
+    <th>Id</th>
+    <th>Date</th>
+    <th>Status</th>
+    <th>MEP</th>
+  </tr>
+  <c:forEach var="exchange" items="${exchanges}">
+    <tr>
+      <td>${exchange.id}</td>
+      <td>${exchange.date}</td>
+      <td>${exchange.status}</td>
+      <td>${exchange.mep}</td>
+    </tr>
+  </c:forEach>
+</table>

Modified: trunk/servicemix-console/src/webapp/WEB-INF/web.xml (815 => 816)

--- trunk/servicemix-console/src/webapp/WEB-INF/web.xml	2005-11-13 21:18:33 UTC (rev 815)
+++ trunk/servicemix-console/src/webapp/WEB-INF/web.xml	2005-11-13 21:21:16 UTC (rev 816)
@@ -13,9 +13,9 @@
     </servlet>
 
   <servlet>
+    <description>Auto Generated Portlet Invoker Servlet</description>
+    <display-name>JBIContainer Portlet</display-name>
     <servlet-name>JBIContainer</servlet-name>
-    <display-name>JBIContainer Portlet</display-name>
-    <description>Auto Generated Portlet Invoker Servlet</description>
     <servlet-class>org.apache.pluto.core.PortletServlet</servlet-class>
     <init-param>
       <param-name>portlet-class</param-name>
@@ -30,6 +30,24 @@
       <role-link>tomcat</role-link>
     </security-role-ref>
   </servlet>
+  <servlet>
+    <description>Auto Generated Portlet Invoker Servlet</description>
+    <display-name>JBIAudit Portlet</display-name>
+    <servlet-name>JBIAudit</servlet-name>
+    <servlet-class>org.apache.pluto.core.PortletServlet</servlet-class>
+    <init-param>
+      <param-name>portlet-class</param-name>
+      <param-value>org.servicemix.console.JBIAuditPortlet</param-value>
+    </init-param>
+    <init-param>
+      <param-name>portlet-guid</param-name>
+      <param-value>servicemix-console.JBIAudit</param-value>
+    </init-param>
+    <security-role-ref>
+      <role-name>plutoTestRole</role-name>
+      <role-link>tomcat</role-link>
+    </security-role-ref>
+  </servlet>
 
     <servlet-mapping>
         <servlet-name>se-console</servlet-name>
@@ -40,6 +58,10 @@
     <servlet-name>JBIContainer</servlet-name>
     <url-pattern>/JBIContainer/*</url-pattern>
   </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>JBIAudit</servlet-name>
+    <url-pattern>/JBIAudit/*</url-pattern>
+  </servlet-mapping>
     
     <jsp-config>
         <taglib>

Reply via email to