1 17 package org.apache.servicemix.console; 18 19 import org.apache.servicemix.JbiConstants; 20 import org.apache.servicemix.jbi.audit.AuditorMBean; 21 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 22 import org.apache.servicemix.jbi.messaging.MessageExchangeSupport; 23 24 import javax.jbi.messaging.MessageExchange; 25 import javax.jbi.messaging.NormalizedMessage; 26 import javax.portlet.ActionRequest; 27 import javax.portlet.ActionResponse; 28 import javax.portlet.RenderRequest; 29 30 import java.net.URI ; 31 import java.text.DateFormat ; 32 import java.util.Calendar ; 33 import java.util.Date ; 34 35 public class JBIAuditPortlet extends ServiceMixPortlet { 36 37 protected int page = 0; 38 39 public static class ExchangeInfo { 40 private String id; 41 private String date; 42 private String mep; 43 private String status; 44 45 48 public String getDate() { 49 return date; 50 } 51 54 public void setDate(String dateStamp) { 55 this.date = dateStamp; 56 } 57 60 public String getStatus() { 61 return status; 62 } 63 66 public void setStatus(String status) { 67 this.status = status; 68 } 69 72 public String getId() { 73 return id; 74 } 75 78 public void setId(String id) { 79 this.id = id; 80 } 81 84 public String getMep() { 85 return mep; 86 } 87 90 public void setMep(String mep) { 91 this.mep = mep; 92 } 93 } 94 95 protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { 96 System.err.println(actionRequest.getParameterMap()); 97 if (actionRequest.getParameter("view") != null) { 98 page = Integer.parseInt(actionRequest.getParameter("view")); 99 } 100 } 101 102 protected void fillViewRequest(RenderRequest request) throws Exception { 103 AuditorMBean auditor = getJdbcAuditor(); 104 int count = auditor.getExchangeCount(); 105 request.setAttribute("count", new Integer (count)); 106 request.setAttribute("page", new Integer (page)); 107 MessageExchange[] exchanges = auditor.getExchanges(page * 10, Math.min((page + 1) * 10, count)); 108 request.setAttribute("exchanges", prepare(exchanges)); 109 super.fillViewRequest(request); 110 } 111 112 private ExchangeInfo[] prepare(MessageExchange[] exchanges) throws Exception { 113 ExchangeInfo[] infos = new ExchangeInfo[exchanges.length]; 114 for (int i = 0; i < infos.length; i++) { 115 infos[i] = new ExchangeInfo(); 116 infos[i].id = exchanges[i].getExchangeId(); 117 infos[i].mep = getMep(exchanges[i]); 118 infos[i].status = exchanges[i].getStatus().toString(); 119 Object c = exchanges[i].getProperty(JbiConstants.DATESTAMP_PROPERTY_NAME); 120 if (c instanceof Calendar ) { 121 infos[i].date = DateFormat.getDateTimeInstance().format(((Calendar ) c).getTime()); 122 } else if (c instanceof Date ) { 123 infos[i].date = DateFormat.getDateTimeInstance().format((Date ) c); 124 } 125 } 126 return infos; 127 } 128 129 private String getMep(MessageExchange exchange) { 130 URI uri = exchange.getPattern(); 131 if (MessageExchangeSupport.IN_ONLY.equals(uri)) { 132 return "In Only"; 133 } else if (MessageExchangeSupport.IN_OPTIONAL_OUT.equals(uri)) { 134 return "In Opt Out"; 135 } else if (MessageExchangeSupport.IN_OUT.equals(uri)) { 136 return "In Out"; 137 } else if (MessageExchangeSupport.ROBUST_IN_ONLY.equals(uri)) { 138 return "Robust In Only"; 139 } else { 140 return uri.toString(); 141 } 142 } 143 144 private String prepareContent(NormalizedMessage msg) throws Exception { 145 if (msg != null) { 146 SourceTransformer st = new SourceTransformer(); 147 String s = st.contentToString(msg); 148 if (s != null && s.length() > 30) { 149 return s.substring(0, 30) + "..."; 150 } else { 151 return s; 152 } 153 } else { 154 return null; 155 } 156 } 157 158 } 159 | Popular Tags |