Source Code Cross Referenced for ProxyPropertiesHandler.java in  » Web-Server » Brazil » sunlabs » brazil » handler » 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 » Web Server » Brazil » sunlabs.brazil.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ProxyPropertiesHandler.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1998-2000 Sun Microsystems, Inc.
007:         *
008:         * Sun Public License Notice
009:         *
010:         * The contents of this file are subject to the Sun Public License Version 
011:         * 1.0 (the "License"). You may not use this file except in compliance with 
012:         * the License. A copy of the License is included as the file "license.terms",
013:         * and also available at http://www.sun.com/
014:         * 
015:         * The Original Code is from:
016:         *    Brazil project web application Framework release 1.1.
017:         * The Initial Developer of the Original Code is: suhler.
018:         * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
019:         * All Rights Reserved.
020:         * 
021:         * Contributor(s): cstevens, suhler.
022:         *
023:         * Version:  1.17
024:         * Created by suhler on 98/09/18
025:         * Last modified by suhler on 00/12/11 13:28:37
026:         */
027:
028:        package sunlabs.brazil.handler;
029:
030:        import java.io.ByteArrayInputStream;
031:        import java.io.IOException;
032:        import sunlabs.brazil.server.Handler;
033:        import sunlabs.brazil.server.Request;
034:        import sunlabs.brazil.server.Server;
035:        import sunlabs.brazil.util.http.MimeHeaders;
036:        import java.util.Enumeration;
037:        import java.util.Properties;
038:
039:        /**
040:         * Obtain properties format content from remote websites, and
041:         * add it to the current request properties.
042:         * Many of the handlers 
043:         * are designed to produce side effects, by inserting values into the
044:         * request properties (see {@link PropertiesHandler}).
045:         * If they are instead configured to produce the properties
046:         * in java properties format, then this handler
047:         * will read their output, and place the result in the request object on
048:         * their behalf.  This capability allows certain handlers to be run on
049:         * other web sites, yet behave as if they are in the handler chain.
050:         *
051:         * The following request properties are used:
052:         * <dl class=props>
053:         * <dt>type	<dd> The document type for files to process as
054:         *		     java properties (defaults to text/plain)
055:         * <dt>prepend	<dd> The prefix that should be prepended to each property
056:         *		     before it is inserted into the request properties
057:         * <dt>url	<dd> The url that should be used to fetch the remote content.
058:         *		     If not specified, the curent url is used instead. 
059:         *		     <br>NOTE: This capability should be generalized
060:         * </dl>
061:         *
062:         * @author      Stephen Uhler
063:         * @version	1.17, 00/12/11
064:         */
065:
066:        public class ProxyPropertiesHandler extends GenericProxyHandler
067:                implements  Handler {
068:
069:            String type; // document type for filtering
070:            String prepend = null; // prepend all properties with this
071:            String mapUrl;
072:
073:            public boolean init(Server server, String prefix) {
074:                type = server.props.getProperty(prefix + "type", "text/plain");
075:                server.log(Server.LOG_DIAGNOSTIC, prefix, "processing type: "
076:                        + type);
077:                return super .init(server, prefix);
078:            }
079:
080:            public boolean respond(Request request) throws IOException {
081:                request.log(Server.LOG_DIAGNOSTIC, prefix,
082:                        "Calling ProxyProps handler respond");
083:                prepend = request.props.getProperty(prefix + "prepend");
084:                mapUrl = request.props.getProperty(prefix + "url");
085:                boolean result;
086:                if (mapUrl != null) {
087:                    String save = request.url;
088:                    request.url = mapUrl;
089:                    request.log(Server.LOG_DIAGNOSTIC, prefix + "Mapping "
090:                            + save + " -> " + mapUrl);
091:                    result = super .respond(request);
092:                    request.url = save;
093:                } else {
094:                    result = super .respond(request);
095:                }
096:                request.log(Server.LOG_DIAGNOSTIC, prefix, "PRoxy done: "
097:                        + result);
098:                return result;
099:            }
100:
101:            /**
102:             * See if the content needs to be filtered
103:             * Return "true" if "modifyContent" should be called
104:             * @param headers	mime headers for data to proxy
105:             */
106:
107:            protected boolean shouldFilter(MimeHeaders headers) {
108:                String header = headers.get("Content-Type");
109:                return (header != null && header.equals(type));
110:            }
111:
112:            public byte[] modifyContent(Request request, byte[] content) {
113:
114:	/*
115: 	 * Get snarf into byte input array, then do a url.props.load on it.
116:	 * If its not a properties object, just return it.  
117:	 * How do we know??
118:	 */
119:
120:	ByteArrayInputStream in = new ByteArrayInputStream(content);
121:	Properties p;
122:	if (prepend != null) {
123:	    p = new Properties();
124:	} else {
125:	    p = request.props;
126:	}
127:	try {
128:	    p.load(in);
129:	    request.log(Server.LOG_INFORMATIONAL, prefix + 
130:		    "..  Got remote properties");
131:	} catch (java.io.IOException e) {
132:	    request.props.put("Error",e.toString());
133:	}
134:
135:	/* add the prefix, if any (yuk!) */
136:
137:	if (prepend != null) {
138:	    Properties to = request.props;
139:	    request.log(Server.LOG_INFORMATIONAL, prefix + 
140:		    "..  prepending: " + prepend);
141:	    Enumeration enum = p.propertyNames();
142:	    while(enum.hasMoreElements()) {
143:		String key = (String) enum.nextElement();
144:		to.put(prepend + key, p.getProperty(key));
145:	    }
146:	    p = null;
147:	}
148:	try {
149:	    in.close();
150:	} catch (java.io.IOException e) {
151:	    request.log(Server.LOG_WARNING, prefix + 
152:		    "..  Close failed!! reading props: " + e);
153:	}
154:	return null;
155:    }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.