Source Code Cross Referenced for FaultHandler.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » ccsl » nmhandler » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » cbesb 1.2 » com.bostechcorp.cbesb.runtime.ccsl.nmhandler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         * 		Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2007 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: FaultHandler.java 9472 2007-10-09 15:24:17Z elu $
023:         */
024:
025:        package com.bostechcorp.cbesb.runtime.ccsl.nmhandler;
026:
027:        import java.io.ByteArrayOutputStream;
028:        import java.io.IOException;
029:        import java.io.PrintWriter;
030:        import java.io.StringWriter;
031:        import java.io.UnsupportedEncodingException;
032:
033:        import org.apache.commons.logging.Log;
034:        import org.apache.commons.logging.LogFactory;
035:        import org.jdom.DefaultJDOMFactory;
036:        import org.jdom.Document;
037:        import org.jdom.Element;
038:        import org.jdom.JDOMException;
039:        import org.jdom.JDOMFactory;
040:        import org.jdom.Namespace;
041:        import org.jdom.input.SAXBuilder;
042:        import org.jdom.output.Format;
043:        import org.jdom.output.XMLOutputter;
044:
045:        import com.bostechcorp.cbesb.common.runtime.CbesbException;
046:        import com.bostechcorp.cbesb.common.runtime.ResourcesConnectionException;
047:        import com.bostechcorp.cbesb.common.util.ErrorUtil;
048:        import com.bostechcorp.cbesb.common.util.FileUtil;
049:        import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbEndpoint;
050:
051:        public class FaultHandler {
052:
053:            protected final transient Log logger = LogFactory
054:                    .getLog(getClass());
055:
056:            public static final String FAULT_NS = "http://schemas.xmlsoap.org/soap/envelope/";
057:
058:            public static final String RECOVERABLE_FAULT_NS = "http://cbesb.bostechcorp.com/fault/recoverable/1.0/";
059:
060:            public static final String FAULT_ROOT = "Fault";
061:
062:            public static final String FAULT_CODE = "code";
063:
064:            public static final String FAULT_MESSAGE = "message";
065:
066:            public static final String FAULT_REMEDY = "remedy";
067:
068:            public static final String FAULT_ENDPOINT = "endpoint";
069:
070:            public static final String FAULT_DETAIL = "detail";
071:
072:            private Element rootElement;
073:
074:            private Exception ex;
075:
076:            private CbEndpoint endpoint;
077:
078:            private Namespace faultNS;
079:
080:            JDOMFactory jdomFactory = new DefaultJDOMFactory();
081:
082:            private String code;
083:
084:            private String message;
085:
086:            private String remedy;
087:
088:            private String endpointString;
089:
090:            private String detail;
091:
092:            private boolean isRecoverable;
093:
094:            /**
095:             * @param ex
096:             */
097:            public FaultHandler(String faultString) {
098:                super ();
099:                fromSoap(faultString);
100:            }
101:
102:            protected void fromSoap(String faultString) {
103:
104:                if (logger.isDebugEnabled())
105:                    logger.debug("fault: " + faultString);
106:                SAXBuilder builder = new SAXBuilder();
107:                Document doc = null;
108:                try {
109:                    doc = builder.build(FileUtil
110:                            .String2InputStream(faultString));
111:                } catch (Exception e) {
112:                    logger.error("Exception while getting JDom tree", e);
113:                    ErrorUtil.printWarn("fail to parse the fault string:"
114:                            + faultString, e);
115:                    return;
116:                }
117:
118:                Element root = doc.getRootElement();
119:                if (!root.getName().equals(FAULT_ROOT)) {
120:                    ErrorUtil
121:                            .printWarn("Root Node is not " + FAULT_ROOT,
122:                                    new JDOMException("Root Node is not "
123:                                            + FAULT_ROOT));
124:                    return;
125:                }
126:
127:                isRecoverable = false;
128:                if (root.getNamespaceURI() != null
129:                        && root.getNamespaceURI().equals(RECOVERABLE_FAULT_NS))
130:                    isRecoverable = true;
131:
132:                code = root.getChildText(FAULT_CODE, root.getNamespace());
133:                message = root.getChildText(FAULT_MESSAGE, root.getNamespace());
134:                remedy = root.getChildText(FAULT_REMEDY, root.getNamespace());
135:                endpointString = root.getChildText(FAULT_ENDPOINT, root
136:                        .getNamespace());
137:                detail = root.getChildText(FAULT_DETAIL, root.getNamespace());
138:            }
139:
140:            /**
141:             * @return the code
142:             */
143:            public String getCode() {
144:                return code;
145:            }
146:
147:            /**
148:             * @return the detail
149:             */
150:            public String getDetail() {
151:                return detail;
152:            }
153:
154:            /**
155:             * @return the endpointString
156:             */
157:            public String getEndpointString() {
158:                return endpointString;
159:            }
160:
161:            /**
162:             * @return the isRecoverable
163:             */
164:            public boolean isRecoverable() {
165:                return isRecoverable;
166:            }
167:
168:            /**
169:             * @return the message
170:             */
171:            public String getMessage() {
172:                return message;
173:            }
174:
175:            /**
176:             * @return the remedy
177:             */
178:            public String getRemedy() {
179:                return remedy;
180:            }
181:
182:            /**
183:             * @param ex
184:             */
185:            public FaultHandler(Exception ex, CbEndpoint endpoint) {
186:                super ();
187:                this .endpoint = endpoint;
188:                this .ex = ex;
189:                faultNS = Namespace.getNamespace(FAULT_NS);
190:            }
191:
192:            public String toSoap() {
193:
194:                if (ex instanceof  ResourcesConnectionException)
195:                    faultNS = Namespace.getNamespace(RECOVERABLE_FAULT_NS);
196:                // else
197:                // faultNS = Namespace.getNamespace("fault", FAULT_NS);
198:
199:                rootElement = new Element(FAULT_ROOT, faultNS);
200:
201:                Element partElem = new Element(FAULT_CODE, faultNS);
202:                partElem.setText("");
203:                rootElement.addContent(partElem);
204:
205:                partElem = new Element(FAULT_MESSAGE, faultNS);
206:                partElem.setText(ex.getMessage());
207:                rootElement.addContent(partElem);
208:
209:                if (ex instanceof  CbesbException) {
210:                    partElem = new Element(FAULT_REMEDY, faultNS);
211:                    partElem.setText(((CbesbException) ex).getRemedy());
212:                    rootElement.addContent(partElem);
213:                }
214:
215:                if (endpoint.getEndpoint() != null) {
216:                    partElem = new Element(FAULT_ENDPOINT, faultNS);
217:                    partElem.setText(endpoint.getEndpoint());
218:                    rootElement.addContent(partElem);
219:                }
220:
221:                StringBuffer s = new StringBuffer();
222:                StringWriter sw = new StringWriter();
223:                PrintWriter pw = new PrintWriter(sw);
224:                ex.printStackTrace(pw);
225:                s.append(sw);
226:
227:                partElem = new Element(FAULT_DETAIL, faultNS);
228:                partElem.setText(s.toString());
229:                rootElement.addContent(partElem);
230:
231:                Document jdomDoc = new Document(rootElement);
232:
233:                XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
234:                ByteArrayOutputStream ostream = new ByteArrayOutputStream();
235:
236:                try {
237:                    xmlOut.output(jdomDoc, ostream);
238:                } catch (IOException e) {
239:                    return "";
240:                }
241:
242:                try {
243:                    return ostream.toString("utf-8");
244:                } catch (UnsupportedEncodingException e) {
245:                    return "";
246:                }
247:            }
248:
249:            @Override
250:            public String toString() {
251:                String result = "\tFault Handler:\n";
252:                result += "Recoverable:" + isRecoverable() + "\n";
253:                result += "Message:\t" + getMessage() + "\n";
254:                result += "Code:\t" + getCode() + "\n";
255:                result += "Remedy:\t" + getRemedy() + "\n";
256:                result += "Endpoint:\t" + getEndpointString() + "\n";
257:                result += "Details:\t" + getDetail() + "\n";
258:                return result;
259:            }
260:
261:            //	public static void main(String[] args) 
262:            //	{
263:            //		try {
264:            //			String s =FileUtil.readStringFromFile("c:\\asd\\fault\\oneFaultMessage.xml");
265:            //			FaultHandler fh = new FaultHandler(s);
266:            //			Log loggerr = LogFactory.getLog("Logger");
267:            //			loggerr.error(fh);
268:            //			///
269:            //		} catch (IOException e) {
270:            //			e.printStackTrace();
271:            //		}
272:            //	}
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.