001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: ReadExchangeImpl.java 11730 2008-01-30 09:27:25Z rhou $
023: */
024: package com.bostechcorp.cbesb.console.server;
025:
026: import java.sql.Connection;
027: import java.sql.ResultSet;
028: import java.sql.ResultSetMetaData;
029: import java.sql.Statement;
030:
031: import javax.servlet.http.HttpSession;
032:
033: import com.bostechcorp.cbesb.common.i18n.CoreMessageConstants;
034: import com.bostechcorp.cbesb.common.i18n.Messages;
035: import com.bostechcorp.cbesb.console.common.ExceptionUtil;
036: import com.bostechcorp.cbesb.console.common.ServerSideException;
037: import com.bostechcorp.cbesb.console.common.errordb.DatabaseDataInfo;
038: import com.bostechcorp.cbesb.console.rpc.ReadExchange;
039:
040: public class ReadExchangeImpl extends ConsoleRemoteServiceServlet
041: implements
042:
043: ReadExchange {
044: /**
045: *
046: */
047: private static final long serialVersionUID = -4037401796055853775L;
048: private StringBuffer sb;
049: private boolean isConnected;
050: private String baseURL;
051:
052: public DatabaseDataInfo read(int errorId, String baseURL)
053: throws ServerSideException {
054: sb = new StringBuffer();
055: this .baseURL = baseURL;
056: HttpSession session = this .getThreadLocalRequest().getSession();
057: Connection dbc = (Connection) session.getAttribute("DBC");
058: if (dbc == null) {
059: throw new ServerSideException((Messages
060: .get(CoreMessageConstants.NO_DATABASE_CONNECTION)));
061: }
062:
063: readExchange(dbc, errorId);
064: DatabaseDataInfo result = new DatabaseDataInfo();
065: result.setData(new String(sb));
066: String[] a = new String[0];
067: result.setRowList(a);
068: return result;
069: }
070:
071: private void processError(Exception e) {
072: sb
073: .append((Messages
074: .get(CoreMessageConstants.DATABASE_CONNECTION_EXCEPTION))
075: + ":" + e + "\n\n");
076: sb.append(ExceptionUtil.stackTraceString(e));
077: }
078:
079: private void readExchange(Connection dbc, int errorId) {
080: try {
081: Statement stmt = dbc.createStatement();
082: ResultSet rs = stmt
083: .executeQuery("select * from exchange where exchangeid = (select exchangeid from error where errorid = "
084: + errorId + ")");
085: rs.next();
086: int exchangeId = rs.getInt("EXCHANGEID");
087: // wrap the exchange in a table
088: sb.append("<table border='6'>");
089: sb.append("<tr><td><table border='2' align='left'>");
090: sb.append("<tr><th>Exchange ID=" + rs.getInt("EXCHANGEID")
091: + "</th></tr>");
092: sb.append("</table></td></tr>");
093: sb.append("<tr><td><table align='left' border='2'>");
094: sb.append("<tr><th align='left'>Role</th><td>"
095: + rs.getString("ROLE") + "</td></tr>");
096: sb.append("<tr><th align='left'>Endpoint</th><td>"
097: + rs.getString("ENDPOINTSERVICE") + ":"
098: + rs.getString("ENDPOINTNAME") + "</td></tr>");
099: sb.append("<tr><th align='left'>Container ID</th><td>"
100: + rs.getString("EXCHANGECONTAINERID")
101: + "</td></tr>");
102: sb.append("<tr><th align='left'>Interface</th><td>"
103: + rs.getString("INTERFACENAME") + "</td></tr>");
104: sb.append("<tr><th align='left'>Operation</th><td>"
105: + rs.getString("OPERATION") + "</td></tr>");
106: sb.append("<tr><th align='left'>Pattern</th><td>"
107: + rs.getString("PATTERN") + "</td></tr>");
108: sb.append("<tr><th align='left'>Service</th><td>"
109: + rs.getString("SERVICE") + "</td></tr>");
110: sb.append("<tr><th align='left'>Status</th><td>"
111: + rs.getString("EXCHANGESTATUS") + "</td></tr>");
112: sb.append("</table></td></tr>");
113:
114: // Table for messages
115: sb.append("<tr><td><table border='2'>");
116: sb
117: .append("<tr><th>EXCHANGE PROPERTIES</th></tr></table><tr><td>");
118: ResultSet rs2 = stmt
119: .executeQuery("select NAME, VALUE from exchangeproperty where exchangeid = "
120: + exchangeId + "");
121: readExchangeProperty("", rs2);
122: sb.append("</td></tr>");
123:
124: // Table for messages
125: sb.append("<tr><td><table border='2' align='left'>");
126: sb
127: .append("<tr><th>NORMALIZED MESSAGE</th></tr></table><tr><td>");
128: ResultSet rs3 = stmt
129: .executeQuery("select * from normalizedmessage where exchangeid = "
130: + exchangeId + " order by type");
131: readNormalizedMessage("", rs3);
132: sb.append("</td></tr>");
133:
134: // Table for messages
135: sb.append("<tr><td><table border='2' align='left'>");
136: sb.append("<tr><th>Attachment</th></tr></table><tr><td>");
137: ResultSet rs4 = stmt
138: .executeQuery("select * from Attachment where exchangeid = "
139: + exchangeId + " order by type");
140: readAttachment("", rs4);
141: sb.append("</td></tr>");
142:
143: // sb.append("<tr><td><table border='2' align='left'>");
144: // sb.append("<tr><th>ByteContent</th></tr><tr>");
145: // ResultSet rs5 = stmt.executeQuery("select * from ByteContent where exchangeid = "+exchangeId+" order by type");
146: // readByteContent("",rs5);
147: // sb.append("</table></td></tr>");
148: //
149: // sb.append("<tr><td><table border='2' align='left'>");
150: // sb.append("<tr><th>StringContent</th></tr><tr>");
151: // ResultSet rs6 = stmt.executeQuery("select * from StringContent where exchangeid = "+exchangeId+" order by type");
152: // // readStringContent("",rs6);
153: // sb.append("</table></td></tr>");
154:
155: sb.append("</table>");
156:
157: } catch (Exception e) {
158: processError(e);
159: }
160: }
161:
162: private void displyResultSet(String label, ResultSet rs,
163: String hrefColName, String[] styles) throws Exception {
164: ResultSetMetaData rsm = rs.getMetaData();
165: int ncols = rsm.getColumnCount();
166: sb.append("<table border=\"2\" valign=\"top\"><tr>");
167: int idCol = 0;
168: int hrefCol = 0;
169: int contentTypeCol = 0;
170: int typeCol = 0;
171: for (int i = 1; i <= ncols; i++) {
172: if (rsm.getColumnName(i).equalsIgnoreCase("ExchangeID")) {
173: idCol = i;
174: continue;
175: }
176: if (rsm.getColumnName(i).equalsIgnoreCase(hrefColName))
177: hrefCol = i;
178: else if (rsm.getColumnName(i).equalsIgnoreCase(
179: "contentType"))
180: contentTypeCol = i;
181: else if (rsm.getColumnName(i).equalsIgnoreCase("type"))
182: typeCol = i;
183: sb.append("<th>\n");
184: sb.append(rsm.getColumnName(i));
185: sb.append("</th>");
186: }
187: sb.append("</tr>");
188: while (rs.next()) {
189: sb.append("<tr>");
190: for (int c = 1; c <= ncols; c++) {
191: if (c == idCol)
192: continue;
193: if (styles.length >= c && styles[c - 1] != null
194: && styles[c - 1].length() > 0)
195: sb.append("<td valign=\"top\" style=\""
196: + styles[c - 1] + "\">");
197: else
198: sb.append("<td valign=\"top\" >");
199: if (c == hrefCol) {
200: sb.append("<a href=\"" + baseURL
201: + "downloadAttachment?ExchangeID="
202: + rs.getString(idCol) + "&contentType="
203: + rs.getString(contentTypeCol) + "&name="
204: + rs.getString(hrefCol) + "&type="
205: + rs.getString(typeCol) + "\"/a>"
206: + rs.getString(c) + "</td>");
207: } else {
208: sb.append(rs.getString(c) + "</td>");
209:
210: }
211: }
212: sb.append("</tr>");
213: }
214: sb.append("</table>");
215: }
216:
217: private void readExchangeProperty(String label, ResultSet rs)
218: throws Exception {
219: String[] styles = new String[] { "", "width:600;wrap" };
220: displyResultSet(label, rs, null, styles);
221: }
222:
223: private void readNormalizedMessage(String label, ResultSet rs)
224: throws Exception {
225: String[] styles = new String[] { "width:100;wrap",
226: "width:100;wrap", "width:600;wrap" };
227:
228: displyResultSet(label, rs, null, styles);
229: }
230:
231: private void readAttachment(String label, ResultSet rs)
232: throws Exception {
233: String[] styles = new String[] { "width:100;wrap",
234: "width:100;wrap", "width:200;wrap", "width:100;wrap" };
235:
236: displyResultSet(label, rs, "name", styles);
237: }
238:
239: }
|