Source Code Cross Referenced for HttpResponse.java in  » JMX » jfoxmx » org » huihoo » jfox » jmx » adaptor » http » 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 » JMX » jfoxmx » org.huihoo.jfox.jmx.adaptor.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.com
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package org.huihoo.jfox.jmx.adaptor.http;
009:
010:        import java.util.HashMap;
011:        import java.util.Map;
012:        import java.util.Properties;
013:        import java.util.Date;
014:        import java.io.StringWriter;
015:
016:        import org.apache.velocity.app.Velocity;
017:        import org.apache.velocity.Template;
018:        import org.apache.velocity.VelocityContext;
019:
020:        /**
021:         *
022:         * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
023:         */
024:
025:        public class HttpResponse {
026:
027:            private HttpRequest request = null;
028:            private String contentType = "text/html";
029:            private Map headersMap = new HashMap();
030:            private int status = HttpConstants.HTTP_REPLY_OK_ID;
031:
032:            public HttpResponse(HttpRequest req) {
033:                this .request = req;
034:                String templatePath = request.getThread().getServer()
035:                        .getDocumentRoot();
036:                Properties prop = new Properties();
037:                //    System.out.println(templatePath);
038:                prop.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,
039:                        templatePath);
040:                prop.setProperty(Velocity.RUNTIME_LOG, templatePath
041:                        + "/velocity.log");
042:                try {
043:                    Velocity.init(prop);
044:                } catch (Exception e) {
045:                    e.printStackTrace();
046:                }
047:
048:            }
049:
050:            public void setHeader(String name, String value) {
051:                headersMap.put(name.trim().toUpperCase(), value.trim());
052:            }
053:
054:            public void addHeader(String name, String value) {
055:                setHeader(name, value);
056:            }
057:
058:            public void setStatus(int status) {
059:                this .status = status;
060:            }
061:
062:            /**
063:             * output the web page
064:             */
065:            public String output() throws Exception {
066:                String commandName = request.getCommand();
067:                commandName = commandName.substring(0, 1).toUpperCase()
068:                        + commandName.substring(1); // first letter upper case
069:                return output(commandName);
070:            }
071:
072:            String output(String action) throws Exception {
073:                StringWriter out = new StringWriter();
074:                out.write(generateHeader());
075:
076:                try {
077:                    Command command = CommandLoader.loadCommand(action);
078:                    VelocityContext ctx = command.execute(request, this );
079:                    Template tmpl = Velocity
080:                            .getTemplate(getTemplateName(command
081:                                    .getTemplateName()));
082:                    tmpl.merge(ctx, out);
083:                    out.flush();
084:                    String page = out.getBuffer().toString();
085:                    out.close();
086:                    return page;
087:                } catch (HttpRedirectException e) {
088:                    String url = e.getMessage();
089:                    return redirect(url);
090:                }
091:
092:            }
093:
094:            private String redirect(String url) throws Exception {
095:                request.setURI(url);
096:                return output();
097:            }
098:
099:            public void setContentType(String type) {
100:                contentType = type;
101:            }
102:
103:            private String getTemplateName(String command) {
104:                return command.toLowerCase() + ".tmpl";
105:            }
106:
107:            // in ie, the first three line will done by head
108:            private String generateHeader() {
109:                StringWriter out = new StringWriter();
110:                out.write("HTTP/1.1 200 OK" + HttpConstants.CRLF);
111:                out.write("Content-Type: text/html" + HttpConstants.CRLF);
112:                out.write("Date: " + new Date() + HttpConstants.CRLF);
113:                out.write(HttpConstants.CRLF);
114:                return out.getBuffer().toString();
115:            }
116:
117:            /*
118:             HTTP/1.1 200 OK
119:             Date: Thu, 26 Sep 2002 13:34:08 GMT
120:             Server: Microsoft-IIS/6.0
121:             P3P: CP='ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo C
122:             NT COM INT NAV ONL PHY PRE PUR UNI'
123:             Content-Length: 31136
124:             Content-Type: text/html
125:             Expires: Thu, 26 Sep 2002 13:34:08 GMT
126:             Cache-control: private
127:             */
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.