Source Code Cross Referenced for ItsNatHttpServletResponseImpl.java in  » Ajax » ItsNat » org » itsnat » impl » core » 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 » Ajax » ItsNat » org.itsnat.impl.core.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          ItsNat Java Web Application Framework
003:          Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004:          Author: Jose Maria Arranz Santamaria
005:
006:          This program is free software: you can redistribute it and/or modify
007:          it under the terms of the GNU Affero General Public License as published by
008:          the Free Software Foundation, either version 3 of the License, or
009:          (at your option) any later version. See the GNU Affero General Public 
010:          License for more details. See the copy of the GNU Affero General Public License
011:          included in this program. If not, see <http://www.gnu.org/licenses/>.
012:         */
013:
014:        package org.itsnat.impl.core.http;
015:
016:        import java.io.BufferedWriter;
017:        import java.io.IOException;
018:        import java.io.OutputStream;
019:        import java.io.OutputStreamWriter;
020:        import java.io.Writer;
021:        import java.util.zip.GZIPOutputStream;
022:        import javax.servlet.http.HttpServletRequest;
023:        import org.itsnat.core.http.ItsNatHttpServletResponse;
024:        import org.itsnat.core.http.ItsNatHttpServlet;
025:        import org.itsnat.impl.core.ItsNatServletResponseImpl;
026:        import javax.servlet.http.HttpServletResponse;
027:        import org.itsnat.core.http.ItsNatHttpSession;
028:
029:        /**
030:         *
031:         * @author jmarranz
032:         */
033:        public class ItsNatHttpServletResponseImpl extends
034:                ItsNatServletResponseImpl implements  ItsNatHttpServletResponse {
035:            /**
036:             * Creates a new instance of ItsNatHttpServletResponseImpl
037:             */
038:            public ItsNatHttpServletResponseImpl(
039:                    ItsNatHttpServletRequestImpl request,
040:                    HttpServletResponse response) {
041:                super (request, response);
042:            }
043:
044:            public ItsNatHttpServletImpl getItsNatHttpServletImpl() {
045:                return (ItsNatHttpServletImpl) getItsNatServletImpl();
046:            }
047:
048:            public ItsNatHttpServletRequestImpl getItsNatHttpServletRequestImpl() {
049:                return (ItsNatHttpServletRequestImpl) request;
050:            }
051:
052:            public HttpServletResponse getHttpServletResponse() {
053:                return (HttpServletResponse) response;
054:            }
055:
056:            public ItsNatHttpServlet getItsNatHttpServlet() {
057:                return getItsNatHttpServletRequestImpl()
058:                        .getItsNatHttpServletImpl();
059:            }
060:
061:            public ItsNatHttpSession getItsNatHttpSession() {
062:                return getItsNatHttpServletRequestImpl()
063:                        .getItsNatHttpSessionImpl();
064:            }
065:
066:            public void preProcess() {
067:                HttpServletResponse response = getHttpServletResponse();
068:                response.setHeader("Cache-Control",
069:                        "no-store,no-cache,must-revalidate"); //HTTP 1.1  
070:                response.setHeader("Pragma", "no-cache"); //HTTP 1.0
071:                response.setDateHeader("Expires", 0); // Quizás también -1
072:                // response.setHeader("Expires", "Thu, 01 Jan 1970 01:00:00 GMT");  // En el pasado
073:                // response.addHeader("Expires", "Thu, 01 Jan 1970 01:00:00 GMT");        
074:                // response.setHeader("Last-Modified", "FRI, JUN 26 3020 23:59:59 GMT"); // En el futuro       
075:
076:                // Es absolutamente vital no cachear, sobre todo en FireFox porque soluciona el problema del back/forward
077:                // que al volver ejecuta el evento load pero sin recargar la página en el servidor 
078:                // y el problema de que el evento unload no 
079:                // se ejecuta (por lo menos con listener asociado via addEventListener) y por tanto 
080:                // no podemos detectar cuando se deja la página.
081:                // http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching
082:                // http://www.jguru.com/faq/view.jsp?EID=377&page=2
083:                // http://support.microsoft.com/kb/234067/EN-US/
084:                // http://www.mnot.net/cache_docs/
085:                // Problemas:
086:                // http://support.microsoft.com/kb/q222064/
087:            }
088:
089:            public Writer getWriterGZip() throws IOException {
090:                // http://www.javaworld.com/javaworld/jw-06-2004/jw-0628-performance.html?page=2
091:
092:                // Si el navegador no soporta gzip se devuelve el Writer normal    
093:
094:                OutputStream out = null;
095:
096:                ItsNatHttpServletRequestImpl itsNatRequest = getItsNatHttpServletRequestImpl();
097:
098:                // MSIE 6 tiene problemas con gzip aunque en teoría lo soporta
099:                // http://support.microsoft.com/kb/321722/EN-US/
100:                // http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312496
101:                // http://support.microsoft.com/default.aspx?scid=kb;en-us;823386&Product=ie600
102:                // http://blog.joshuaeichorn.com/archives/2007/01/10/compressing-javascript-and-css/#comment-125483 
103:                // Aunque parece que están solucionados por lo menos enviando JavaScript
104:                // como respuesta AJAX. FireFox no ha dado ningún problema
105:
106:                HttpServletRequest request = itsNatRequest
107:                        .getHttpServletRequest();
108:                HttpServletResponse response = getHttpServletResponse();
109:
110:                String acceptEncoding = request.getHeader("Accept-Encoding");
111:
112:                if (acceptEncoding != null) {
113:                    if (acceptEncoding.indexOf("gzip") != -1) {
114:                        response.setHeader("Content-Encoding", "gzip");
115:                        out = new GZIPOutputStream(response.getOutputStream());
116:                    }
117:                    /* // Ni FireFox ni MSIE por defecto aceptan "compress"
118:                    else if (acceptEncoding.indexOf("compress") != -1)
119:                    {
120:                       response.setHeader("Content-Encoding","compress");
121:                       out = new ZipOutputStream(response.getOutputStream());
122:                    } 
123:                     */
124:                }
125:
126:                if (out != null) {
127:                    // Se supone que ya se definió antes en el response el acceptEncoding
128:                    String encoding = response.getCharacterEncoding();
129:                    return new BufferedWriter(new OutputStreamWriter(out,
130:                            encoding));
131:                } else
132:                    return super.getWriter();
133:            }
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.