Source Code Cross Referenced for XMLRPCDataSource.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » data » 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 » Ajax » Laszlo 4.0.10 » org.openlaszlo.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ****************************************************************************
002:         * XMLRPCDataSource.java
003:         * ****************************************************************************/
004:
005:        /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006:         * Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.              *
007:         * Use is subject to license terms.                                            *
008:         * J_LZ_COPYRIGHT_END *********************************************************/
009:
010:        package org.openlaszlo.data;
011:
012:        import java.io.*;
013:        import java.util.*;
014:        import java.net.MalformedURLException;
015:        import javax.servlet.http.*;
016:        import org.apache.xmlrpc.*;
017:        import org.openlaszlo.server.LPS; // LoadCount belongs in utils
018:        import org.openlaszlo.servlets.LoadCount;
019:        import org.openlaszlo.xml.internal.*;
020:        import org.openlaszlo.media.MimeType;
021:        import org.apache.log4j.*;
022:
023:        /**
024:         *
025:         */
026:        public class XMLRPCDataSource extends DataSource {
027:            private static Logger mLogger = Logger
028:                    .getLogger(XMLRPCDataSource.class);
029:
030:            XmlRpcServer xmlrpc = new XmlRpcServer();
031:
032:            static long mLastCleared = -1;
033:            static LoadCount mXMLRPCLoad = new LoadCount(10);
034:
035:            public XMLRPCDataSource() {
036:                clearLoadInfo();
037:            }
038:
039:            /**
040:             * @return unique name of this data source
041:             */
042:            public String name() {
043:                return "xmlrpc";
044:            }
045:
046:            /**
047:             * Sends system information to client.
048:             * 
049:             * @throws DataSourceException if there was a problem retrieving or sending
050:             * the data.
051:             */
052:            public Data getData(String app, HttpServletRequest req,
053:                    HttpServletResponse res, long lastModifiedTime)
054:                    throws DataSourceException {
055:                mLogger.debug(
056:                /* (non-Javadoc)
057:                 * @i18n.test
058:                 * @org-mes="getData"
059:                 */
060:                org.openlaszlo.i18n.LaszloMessages.getMessage(
061:                        XMLRPCDataSource.class.getName(), "051018-62"));
062:
063:                String runtime = req.getParameter("lzr");
064:
065:                try {
066:                    if (!req.getMethod().equals("POST"))
067:                        return compileFault(
068:                        /* (non-Javadoc)
069:                         * @i18n.test
070:                         * @org-mes="Remote request must be POST"
071:                         */
072:                        org.openlaszlo.i18n.LaszloMessages.getMessage(
073:                                XMLRPCDataSource.class.getName(), "051018-74"),
074:                                runtime);
075:
076:                    String url = getHTTPURL(getURL(req));
077:                    if (url == null) {
078:                        return compileFault(
079:                        /* (non-Javadoc)
080:                         * @i18n.test
081:                         * @org-mes="invalid url specified: " + p[0]
082:                         */
083:                        org.openlaszlo.i18n.LaszloMessages.getMessage(
084:                                XMLRPCDataSource.class.getName(), "051018-85",
085:                                new Object[] { url }), runtime);
086:                    }
087:
088:                    String postbody = req.getParameter("lzpostbody");
089:                    if (postbody != null) {
090:                        url += "?lzpostbody=" + postbody;
091:                    }
092:
093:                    long t0, t1;
094:                    t0 = System.currentTimeMillis();
095:                    mXMLRPCLoad.increment();
096:                    try {
097:                        Data data = HTTPDataSource.getHTTPData(req, res, url,
098:                                -1);
099:                        mLogger.error("xmlrpc data " + data.getAsString());
100:                        return new XMLRPCData(data.getAsString().getBytes(),
101:                                runtime);
102:                    } finally {
103:                        t1 = System.currentTimeMillis();
104:                        mXMLRPCLoad.decrement((int) (t1 - t0));
105:                    }
106:
107:                } catch (Exception e) {
108:                    return compileFault(e, runtime);
109:                }
110:            }
111:
112:            String getHTTPURL(String url) {
113:                if (url != null && url.startsWith("xmlrpc://"))
114:                    return "http" + url.substring(6);
115:                return null;
116:            }
117:
118:            /**
119:             * Compile fault exception message.
120:             */
121:            Data compileFault(Exception e, String runtime) {
122:                mLogger.error("compileFault", e);
123:                return compileFault(e.getMessage(), runtime);
124:            }
125:
126:            /**
127:             * Compile fault response.
128:             */
129:            Data compileFault(String mesg, String runtime) {
130:                mLogger.error("compileFault mesg: " + mesg);
131:                try {
132:
133:                    if ("dhtml".equals(runtime)) {
134:                        byte[] d = XMLRPCJSONCompiler.compileFault(XMLUtils
135:                                .escapeXml(mesg), runtime);
136:                        return new XMLRPCData().setResult(d);
137:                    } else {
138:                        int swfversion = LPS.getSWFVersionNum(runtime);
139:                        byte[] d = XMLRPCCompiler.compileFault(XMLUtils
140:                                .escapeXml(mesg), swfversion);
141:                        return new XMLRPCData().setResult(d);
142:                    }
143:
144:                } catch (Exception e) {
145:                    mLogger.error("Exception", e);
146:                    // this is an error since we can't build a fault response
147:                    throw new Error(e.getMessage());
148:                }
149:            }
150:
151:            public static void clearLoadInfo() {
152:                mXMLRPCLoad.reset();
153:                mLastCleared = System.currentTimeMillis();
154:            }
155:
156:            public static void toXML(StringBuffer sb) {
157:                Date lc = new Date(mLastCleared);
158:                sb.append("<xmlrpcinfo ").append(" last-cleared=\"").append(lc)
159:                        .append("\"").append(">");
160:                sb.append(mXMLRPCLoad.toXML("xmlrpc_load"));
161:                sb.append("</xmlrpcinfo>");
162:            }
163:
164:            /**
165:             * A data object to hold an xmlrpc response.
166:             */
167:            public class XMLRPCData extends Data {
168:                byte[] mResult;
169:
170:                public XMLRPCData() {
171:                }
172:
173:                public XMLRPCData(byte[] result, String runtime)
174:                        throws IOException {
175:                    InputStreamReader reader = new InputStreamReader(
176:                            new ByteArrayInputStream(result));
177:                    mLogger.debug("XMLRPCData runtime=" + runtime);
178:                    if ("dhtml".equals(runtime)) {
179:                        mResult = XMLRPCJSONCompiler.compile(reader, runtime);
180:                    } else {
181:                        int swfversion = LPS.getSWFVersionNum(runtime);
182:                        mResult = XMLRPCCompiler.compile(reader, result.length,
183:                                swfversion);
184:                    }
185:                }
186:
187:                public String getMimeType() {
188:                    return MimeType.SWF;
189:                }
190:
191:                public XMLRPCData setResult(byte[] result) {
192:                    mResult = result;
193:                    return this ;
194:                }
195:
196:                /**
197:                 * @return the encoded XML
198:                 */
199:                public InputStream getInputStream() throws IOException {
200:                    return new ByteArrayInputStream(mResult);
201:                }
202:
203:                public long size() {
204:                    return mResult.length;
205:                }
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.