Source Code Cross Referenced for PageRedirect.java in  » J2EE » Enhydra-Application-Framework » com » lutris » appserver » server » httpPresentation » 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 » J2EE » Enhydra Application Framework » com.lutris.appserver.server.httpPresentation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-----------------------------------------------------------------------------
002:         * Enhydra Java Application Server
003:         * Copyright 1997-2000 Lutris Technologies, Inc.
004:         * All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         * 1. Redistributions of source code must retain the above copyright
010:         *    notice, this list of conditions and the following disclaimer.
011:         * 2. Redistributions in binary form must reproduce the above copyright
012:         *    notice, this list of conditions and the following disclaimer in
013:         *    the documentation and/or other materials provided with the distribution.
014:         * 3. All advertising materials mentioning features or use of this software
015:         *    must display the following acknowledgement:
016:         *      This product includes Enhydra software developed by Lutris
017:         *      Technologies, Inc. and its contributors.
018:         * 4. Neither the name of Lutris Technologies nor the names of its contributors
019:         *    may be used to endorse or promote products derived from this software
020:         *    without specific prior written permission.
021:         *
022:         * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
023:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
024:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
025:         * ARE DISCLAIMED.  IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
026:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
027:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
028:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
029:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
030:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
031:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
032:         * POSSIBILITY OF SUCH DAMAGE.
033:         *-----------------------------------------------------------------------------
034:         * $Id: PageRedirect.java,v 1.5 2007-05-17 12:52:55 sinisa Exp $
035:         *-----------------------------------------------------------------------------
036:         */
037:
038:        package com.lutris.appserver.server.httpPresentation;
039:
040:        import java.io.IOException;
041:        import java.net.MalformedURLException;
042:        import java.net.URL;
043:
044:        import javax.servlet.RequestDispatcher;
045:        import javax.servlet.http.HttpServletRequest;
046:        import javax.servlet.http.HttpServletResponse;
047:
048:        import com.lutris.appserver.server.StandardAppUtil;
049:        import com.lutris.logging.LogChannel;
050:        import com.lutris.logging.Logger;
051:        import com.lutris.util.ConfigException;
052:
053:        /**
054:         * Static methods for processing a page redirect.
055:         * 
056:         * @version $Revision: 1.5 $
057:         * @author Mark Diekhans, Slobodan Vujasinovic
058:         * @since Jolt1.3
059:         */
060:        class PageRedirect {
061:            /**
062:             * Process a page redirection.
063:             * 
064:             * @return Path of the presentation object to invoke for a server-side
065:             *         redirect or null if a redirect response has been sent to the
066:             *         client. NOTE: Currently always returns null.
067:             */
068:            protected static String handler(HttpPresentationComms comms,
069:                    String presObjPath, PageRedirectException redirectExcept,
070:                    LogChannel logChannel, long requestId)
071:                    throws MalformedURLException, HttpPresentationException,
072:                    IOException {
073:
074:                boolean debug = logChannel.isEnabled(Logger.DEBUG);
075:
076:                // FIX: Break into two functions; one for client., one for server.
077:                if (debug)
078:                    logChannel.write(Logger.DEBUG, "RID:" + requestId + ": "
079:                            + redirectExcept.getClass().getName() + ": "
080:                            + presObjPath + " => " + redirectExcept.getUrl());
081:                String url = redirectExcept.getUrl();
082:                if (redirectExcept instanceof  ClientPageRedirectException) {
083:                    return clientSideRedirect(url, comms, logChannel,
084:                            requestId, redirectExcept.getEncoding());
085:                } else {
086:                    try {
087:                        HttpServletRequest hsreq = comms.request
088:                                .getHttpServletRequest();
089:                        HttpServletResponse hsres = comms.response
090:                                .getHttpServletResponse();
091:
092:                        if (((ServerPageRedirectException) redirectExcept)
093:                                .getHttpServletRequest() != null)
094:                            hsreq = ((ServerPageRedirectException) redirectExcept)
095:                                    .getHttpServletRequest();
096:                        if (((ServerPageRedirectException) redirectExcept)
097:                                .getHttpServletResponse() != null)
098:                            hsres = ((ServerPageRedirectException) redirectExcept)
099:                                    .getHttpServletResponse();
100:
101:                        RequestDispatcher rd = hsreq.getRequestDispatcher(url);
102:
103:                        rd.forward(hsreq, hsres);
104:
105:                    } catch (Exception ex) {
106:                        logChannel.write(Logger.WARNING,
107:                                "Server redirect to \"" + url
108:                                        + "\" failed. Reason: \""
109:                                        + ex.getLocalizedMessage()
110:                                        + "\" reattempt as client redirect.");
111:                        try {
112:                            clientSideRedirect(url, comms, logChannel,
113:                                    requestId, redirectExcept.getEncoding());
114:                        } catch (Exception e) {
115:                            throw new HttpPresentationException(e);
116:                        }
117:                    }
118:                    return null;
119:
120:                }
121:            }
122:
123:            private static String clientSideRedirect(String url,
124:                    HttpPresentationComms comms, LogChannel logChannel,
125:                    long requestId, String encoding)
126:                    throws HttpPresentationException {
127:
128:                boolean debug = logChannel.isEnabled(Logger.DEBUG);
129:                url = makeAbsolute(url, comms.request.getHttpServletRequest());
130:                if (comms.request.isRequestedSessionIdFromUrl()
131:                        && StandardAppUtil.pointsToPO(url)) {
132:                    url = StandardAppUtil.encodeUrl(url, comms.session
133:                            .getSessionKey());
134:
135:                    if (debug)
136:                        logChannel
137:                                .write(Logger.DEBUG, "RID:" + requestId + ": "
138:                                        + "Adding session ID to new URL: "
139:                                        + url);
140:                } else {
141:                    logChannel.write(Logger.DEBUG, "RID:" + requestId + ": "
142:                            + "No session ID for URL: " + url);
143:                }
144:
145:                boolean metaRedirect = false;
146:                try {
147:                    metaRedirect = comms.application.getConfig().getBoolean(
148:                            "Application.ForceHtmlMetaRedirect", false);
149:                } catch (ConfigException ex) {
150:                    metaRedirect = false;
151:                }
152:
153:                if (metaRedirect) {
154:                    String response = "<html><head><meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"0; URL="
155:                            + url
156:                            + "\">"
157:                            + "<title>Redirected to new location</title></head>"
158:                            + "<body><p>&nbsp;</p></body></html>";
159:                    try {
160:                        comms.response.getOutputStream().write(
161:                                response.getBytes());
162:                    } catch (IOException e) {
163:                        logChannel.write(Logger.WARNING, "RID:" + requestId
164:                                + ": "
165:                                + "Not able to write redirect HTML content: "
166:                                + url);
167:                    }
168:                } else {
169:                    comms.response.setHeader("Location", url);
170:                    comms.response.setStatus(
171:                            HttpPresentationResponse.SC_MOVED_TEMPORARILY,
172:                            "Redirected to new location.");
173:                }
174:
175:                comms.response.setContentType("text/html");
176:                comms.response.setEncoding(encoding);
177:                comms.response.flush();
178:                return null;
179:            }
180:
181:            private static String makeAbsolute(String location,
182:                    HttpServletRequest request) {
183:                URL url = null;
184:                try {
185:                    // Try making a URL out of the location
186:                    // Throws an exception if the location is relative
187:                    url = new URL(location);
188:                } catch (MalformedURLException e) {
189:                    // Slobodan Vujasinovic - old implementation deprecated (Servlet API
190:                    // 2.3)
191:                    // String requrl = HttpUtils.getRequestURL(request).toString();
192:                    String requrl = request.getRequestURL().toString();
193:                    try {
194:                        url = new URL(new URL(requrl), location);
195:                    } catch (MalformedURLException ignored) {
196:                        // Give up
197:                        return location;
198:                    }
199:                }
200:                return url.toString();
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.