Source Code Cross Referenced for PSDesktopAppContext.java in  » Portal » Open-Portal » com » sun » portal » desktop » context » 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 » Portal » Open Portal » com.sun.portal.desktop.context 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
0003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
0004:         */
0005:        package com.sun.portal.desktop.context;
0006:
0007:        import com.sun.portal.desktop.DesktopError;
0008:        import com.sun.portal.desktop.DesktopRequestThreadLocalizer;
0009:        import com.sun.portal.desktop.ROC;
0010:        import com.sun.portal.desktop.template.ParsedTagArray;
0011:        import com.sun.portal.desktop.template.TagSwapper;
0012:        import com.sun.portal.desktop.util.PIParser;
0013:        import com.sun.portal.log.common.PortalLogger;
0014:        import com.sun.portal.providers.context.ContainerProviderContext;
0015:
0016:        import javax.servlet.ServletContext;
0017:        import javax.servlet.http.HttpServletRequest;
0018:        import java.io.File;
0019:        import java.util.Collections;
0020:        import java.util.HashMap;
0021:        import java.util.Hashtable;
0022:        import java.util.Iterator;
0023:        import java.util.List;
0024:        import java.util.Locale;
0025:        import java.util.Map;
0026:        import java.util.Properties;
0027:        import java.util.Set;
0028:        import java.util.logging.Logger;
0029:
0030:        import java.util.regex.Pattern;
0031:        import java.util.regex.Matcher;
0032:
0033:        import java.net.URL;
0034:        import java.net.MalformedURLException;
0035:
0036:        public class PSDesktopAppContext implements  DesktopAppContext,
0037:                PSContextConstants {
0038:            private static final String ROC_SID = "sid";
0039:            private static final String ROC_SUID = "suid";
0040:            private static final String ROC_ISAUTHLESS = "isAuthless";
0041:            private static final String propertiesfile = "message.properties";
0042:
0043:            // used to match host:port in host header
0044:            //
0045:            // this does not strictly match only host:port patterns.
0046:            // for example, it would match: !!!:$$$
0047:            // the pattern is simplified to assume the host header
0048:            // already is of the right form. this is done to avoid
0049:            // the possibly error prone approach of defining a complete
0050:            // regex for the host name and port
0051:            private static final Pattern HOST_HEADER_PATTERN = Pattern
0052:                    .compile("(?:(.+):(.+))|(.+)");
0053:
0054:            protected SessionAppContext session = null;
0055:            protected SessionAppContext authlessSession = null;
0056:            protected SessionAppContext wsrpSession = null;
0057:
0058:            protected ServiceAppContext service = null;
0059:            protected ConfigContext config = null;
0060:            protected TemplateContext template = null;
0061:            protected ServletContext servletContext = null;
0062:            protected ClientContext client = null;
0063:
0064:            protected String configContextClassName = null;
0065:
0066:            static private String scratchDir = null;
0067:            static private Map desktopURLs = Collections
0068:                    .synchronizedMap(new HashMap());
0069:
0070:            private String suidCookieName = null;
0071:
0072:            // Create a logger for this class
0073:            private static Logger debugLogger = PortalLogger
0074:                    .getLogger(PSDesktopAppContext.class);
0075:
0076:            public synchronized void init(ServletContext sc) {
0077:                DesktopAppContextThreadLocalizer.set(this );
0078:                servletContext = sc;
0079:
0080:                configContextClassName = sc
0081:                        .getInitParameter(SC_CONFIG_CONTEXT_CLASSNAME);
0082:
0083:                if (configContextClassName == null) {
0084:                    throw new ContextError(
0085:                            "PSDesktopAppContext.init(): could not get config context class name");
0086:                }
0087:
0088:                //
0089:                // order matters here!
0090:                //
0091:                initConfigContext();
0092:                initServiceAppContext();
0093:                initTemplateContext();
0094:                initClientContext();
0095:                initSessionAppContext();
0096:                initWSRPSessionAppContext();
0097:                initAuthlessSessionAppContext();
0098:            }
0099:
0100:            private static boolean toBoolean(String name) {
0101:                return ((name != null) && name.toLowerCase().equals("true"));
0102:            }
0103:
0104:            protected SessionAppContext getSessionAppContext() {
0105:                if (session == null) {
0106:                    throw new ContextError(
0107:                            "PSDesktopAppContext.getSessionAppContext(): not initialized");
0108:                }
0109:                return session;
0110:            }
0111:
0112:            protected SessionAppContext initSessionAppContext() {
0113:                if (session == null) {
0114:                    String sessionAppContextClassName = getSessionAppContextClassName();
0115:                    if (sessionAppContextClassName == null) {
0116:                        throw new ContextError(
0117:                                "DesktopAppContext.getSessionAppContext(): class name was null");
0118:                    }
0119:
0120:                    try {
0121:                        session = (SessionAppContext) (Class
0122:                                .forName(sessionAppContextClassName)
0123:                                .newInstance());
0124:                    } catch (ClassNotFoundException cnfe) {
0125:                        throw new ContextError(
0126:                                "DesktopContext.getSessionAppContext()", cnfe);
0127:                    } catch (NoClassDefFoundError ncdfe) {
0128:                        throw new ContextError(
0129:                                "DesktopContext.getSessionAppContext()", ncdfe);
0130:                    } catch (IllegalAccessException iae) {
0131:                        throw new ContextError(
0132:                                "DesktopContext.getSessionAppContext()", iae);
0133:                    } catch (ClassCastException cce) {
0134:                        throw new ContextError(
0135:                                "DesktopContext.getSessionAppContext()", cce);
0136:                    } catch (InstantiationException ie) {
0137:                        throw new ContextError(
0138:                                "DesktopContext.getSessionAppContext()", ie);
0139:                    } catch (SecurityException se) {
0140:                        throw new ContextError(
0141:                                "DesktopContext.getSessionAppContext()", se);
0142:                    }
0143:                }
0144:
0145:                return session;
0146:            }
0147:
0148:            protected ServiceAppContext getServiceAppContext() {
0149:                if (service == null) {
0150:                    throw new ContextError(
0151:                            "PSDesktopAppContext.getServiceAppContext(): not initialized");
0152:                }
0153:                return service;
0154:            }
0155:
0156:            protected ServiceAppContext initServiceAppContext() {
0157:                if (service == null) {
0158:                    String serviceAppContextClassName = getServiceAppContextClassName();
0159:                    if (serviceAppContextClassName == null) {
0160:                        throw new ContextError(
0161:                                "DesktopContext.getServiceAppContext(): class name was null");
0162:                    }
0163:
0164:                    try {
0165:                        service = (ServiceAppContext) (Class
0166:                                .forName(serviceAppContextClassName)
0167:                                .newInstance());
0168:                    } catch (ClassNotFoundException cnfe) {
0169:                        throw new ContextError(
0170:                                "DesktopContext.getServiceAppContext()", cnfe);
0171:                    } catch (NoClassDefFoundError ncdfe) {
0172:                        throw new ContextError(
0173:                                "DesktopContext.getServiceAppContext()", ncdfe);
0174:                    } catch (IllegalAccessException iae) {
0175:                        throw new ContextError(
0176:                                "DesktopContext.getServiceAppContext()", iae);
0177:                    } catch (ClassCastException cce) {
0178:                        throw new ContextError(
0179:                                "DesktopContext.getServiceAppContext()", cce);
0180:                    } catch (InstantiationException ie) {
0181:                        throw new ContextError(
0182:                                "DesktopContext.getServiceAppContext()", ie);
0183:                    } catch (SecurityException se) {
0184:                        throw new ContextError(
0185:                                "DesktopContext.getServiceAppContext()", se);
0186:                    }
0187:
0188:                    service.init(getPortalId());
0189:                }
0190:
0191:                return service;
0192:            }
0193:
0194:            protected SessionAppContext getWSRPSessionAppContext() {
0195:                if (wsrpSession == null) {
0196:                    throw new ContextError(
0197:                            "PSDesktopAppContext.getWSRPSessionAppContext(): not initialized");
0198:                }
0199:                return wsrpSession;
0200:            }
0201:
0202:            protected SessionAppContext initWSRPSessionAppContext() {
0203:                if (wsrpSession == null) {
0204:                    String wsrpSessionAppContextClassName = getWSRPSessionAppContextClassName();
0205:                    if (wsrpSessionAppContextClassName == null) {
0206:                        throw new ContextError(
0207:                                "PSDesktopAppContext.initWSRPSessionAppContext(): class name was null");
0208:                    }
0209:
0210:                    try {
0211:                        wsrpSession = (SessionAppContext) (Class
0212:                                .forName(wsrpSessionAppContextClassName)
0213:                                .newInstance());
0214:                    } catch (ClassNotFoundException cnfe) {
0215:                        throw new ContextError(
0216:                                "PSDesktopAppContext.initWSRPSessionAppContext()",
0217:                                cnfe);
0218:                    } catch (NoClassDefFoundError ncdfe) {
0219:                        throw new ContextError(
0220:                                "PSDesktopAppContext.initWSRPSessionAppContext()",
0221:                                ncdfe);
0222:                    } catch (IllegalAccessException iae) {
0223:                        throw new ContextError(
0224:                                "PSDesktopAppContext.initWSRPSessionAppContext()",
0225:                                iae);
0226:                    } catch (ClassCastException cce) {
0227:                        throw new ContextError(
0228:                                "PSDesktopAppContext.initWSRPSessionAppContext()",
0229:                                cce);
0230:                    } catch (InstantiationException ie) {
0231:                        throw new ContextError(
0232:                                "PSDesktopAppContext.initWSRPSessionAppContext()",
0233:                                ie);
0234:                    } catch (SecurityException se) {
0235:                        throw new ContextError(
0236:                                "PSDesktopAppContext.initWSRPSessionAppContext()",
0237:                                se);
0238:                    }
0239:                }
0240:
0241:                return wsrpSession;
0242:            }
0243:
0244:            protected SessionAppContext getAuthlessSessionAppContext() {
0245:                if (authlessSession == null) {
0246:                    throw new ContextError(
0247:                            "PSDesktopAppContext.getAuthlessSessionAppContext(): not initialized");
0248:                }
0249:                return authlessSession;
0250:            }
0251:
0252:            protected SessionAppContext initAuthlessSessionAppContext() {
0253:                if (authlessSession == null) {
0254:                    String authlessSessionAppContextClassName = getAuthlessSessionAppContextClassName();
0255:                    if (authlessSessionAppContextClassName == null) {
0256:                        throw new ContextError(
0257:                                "PSDesktopAppContext.initAuthlessSessionAppContext(): class name was null");
0258:                    }
0259:
0260:                    try {
0261:                        authlessSession = (SessionAppContext) (Class
0262:                                .forName(authlessSessionAppContextClassName)
0263:                                .newInstance());
0264:                    } catch (ClassNotFoundException cnfe) {
0265:                        throw new ContextError(
0266:                                "PSDesktopAppContext.initAuthlessSessionAppContext()",
0267:                                cnfe);
0268:                    } catch (NoClassDefFoundError ncdfe) {
0269:                        throw new ContextError(
0270:                                "PSDesktopAppContext.initAuthlessSessionAppContext()",
0271:                                ncdfe);
0272:                    } catch (IllegalAccessException iae) {
0273:                        throw new ContextError(
0274:                                "PSDesktopAppContext.initAuthlessSessionAppContext()",
0275:                                iae);
0276:                    } catch (ClassCastException cce) {
0277:                        throw new ContextError(
0278:                                "PSDesktopAppContext.initAuthlessSessionAppContext()",
0279:                                cce);
0280:                    } catch (InstantiationException ie) {
0281:                        throw new ContextError(
0282:                                "PSDesktopAppContext.initAuthlessSessionAppContext()",
0283:                                ie);
0284:                    } catch (SecurityException se) {
0285:                        throw new ContextError(
0286:                                "PSDesktopAppContext.initAuthlessSessionAppContext()",
0287:                                se);
0288:                    }
0289:                }
0290:
0291:                return authlessSession;
0292:            }
0293:
0294:            protected ConfigContext getConfigContext() {
0295:                if (config == null) {
0296:                    throw new ContextError(
0297:                            "PSDesktopAppContext.getConfigContext(): not initialized");
0298:                }
0299:                return config;
0300:            }
0301:
0302:            protected ConfigContext initConfigContext() {
0303:                if (config == null) {
0304:                    String configContextClassName = getConfigContextClassName();
0305:                    if (configContextClassName == null) {
0306:                        throw new ContextError(
0307:                                "DesktopContext.getConfigContext(): class name was null");
0308:                    }
0309:
0310:                    try {
0311:                        config = (ConfigContext) (Class
0312:                                .forName(configContextClassName).newInstance());
0313:                    } catch (ClassNotFoundException cnfe) {
0314:                        throw new ContextError(
0315:                                "PSDesktopAppContext.getConfigContext()", cnfe);
0316:                    } catch (NoClassDefFoundError ncdfe) {
0317:                        throw new ContextError(
0318:                                "PSDesktopAppContext.getConfigContext()", ncdfe);
0319:                    } catch (IllegalAccessException iae) {
0320:                        throw new ContextError(
0321:                                "PSDesktopAppContext.getConfigContext()", iae);
0322:                    } catch (ClassCastException cce) {
0323:                        throw new ContextError(
0324:                                "PSDesktopAppContext.getConfigContext()", cce);
0325:                    } catch (InstantiationException ie) {
0326:                        throw new ContextError(
0327:                                "PSDesktopAppContext.getConfigContext()", ie);
0328:                    } catch (SecurityException se) {
0329:                        throw new ContextError(
0330:                                "PSDesktopAppContext.getConfigContext()", se);
0331:                    }
0332:                }
0333:
0334:                config.init(servletContext);
0335:
0336:                return config;
0337:            }
0338:
0339:            protected ClientContext getClientContext() {
0340:                if (client == null) {
0341:                    throw new ContextError(
0342:                            "PSDesktopAppContext.getClientContext(): not initialized");
0343:                }
0344:
0345:                return client;
0346:
0347:            }
0348:
0349:            protected ClientContext initClientContext() {
0350:
0351:                if (client == null) {
0352:                    String clientContextClassName = getClientContextClassName();
0353:                    if (clientContextClassName == null) {
0354:                        throw new ContextError(
0355:                                "PSDesktopAppContext.getClientContext(): class name was null");
0356:                    }
0357:
0358:                    try {
0359:                        client = (ClientContext) (Class
0360:                                .forName(clientContextClassName).newInstance());
0361:                    } catch (ClassNotFoundException cnfe) {
0362:                        throw new ContextError(
0363:                                "PSDesktopAppContext.initClientContext()", cnfe);
0364:                    } catch (NoClassDefFoundError ncdfe) {
0365:                        throw new ContextError(
0366:                                "PSDesktopAppContext.initClientContext()",
0367:                                ncdfe);
0368:                    } catch (IllegalAccessException iae) {
0369:                        throw new ContextError(
0370:                                "PSDesktopAppContext.initClientContext()", iae);
0371:                    } catch (ClassCastException cce) {
0372:                        throw new ContextError(
0373:                                "PSDesktopAppContext.initClientContext()", cce);
0374:                    } catch (InstantiationException ie) {
0375:                        throw new ContextError(
0376:                                "PSDesktopAppContext.initClientContext()", ie);
0377:                    } catch (SecurityException se) {
0378:                        throw new ContextError(
0379:                                "PSDesktopAppContext.initClientContext()", se);
0380:                    }
0381:
0382:                }
0383:                client.init();
0384:
0385:                return client;
0386:            }
0387:
0388:            private TemplateContext getTemplateContext() {
0389:                if (template == null) {
0390:                    throw new ContextError(
0391:                            "PSDesktopAppContext.getTemplateContext(): not initialized");
0392:                }
0393:                return template;
0394:            }
0395:
0396:            private TemplateContext initTemplateContext() {
0397:                if (template == null) {
0398:                    String templateContextClassName = getTemplateContextClassName();
0399:                    if (templateContextClassName == null) {
0400:                        throw new ContextError(
0401:                                "PSDesktopAppContext.getTemplateContext(): class name was null");
0402:                    }
0403:
0404:                    try {
0405:                        template = (TemplateContext) (Class
0406:                                .forName(templateContextClassName)
0407:                                .newInstance());
0408:                    } catch (ClassNotFoundException cnfe) {
0409:                        throw new ContextError(
0410:                                "PSDesktopAppContext.getTemplateContext()",
0411:                                cnfe);
0412:                    } catch (NoClassDefFoundError ncdfe) {
0413:                        throw new ContextError(
0414:                                "PSDesktopAppContext.getTemplateContext()",
0415:                                ncdfe);
0416:                    } catch (IllegalAccessException iae) {
0417:                        throw new ContextError(
0418:                                "PSDesktopAppContext.getTemplateContext()", iae);
0419:                    } catch (ClassCastException cce) {
0420:                        throw new ContextError(
0421:                                "PSDesktopAppContext.getTemplateContext()", cce);
0422:                    } catch (InstantiationException ie) {
0423:                        throw new ContextError(
0424:                                "PSDesktopAppContext.getTemplateContext()", ie);
0425:                    } catch (SecurityException se) {
0426:                        throw new ContextError(
0427:                                "PSDesktopAppContext.getTemplateContext()", se);
0428:                    }
0429:                    if (config != null) {
0430:                        template.init(config.getTemplateScanInterval());
0431:                    } else {
0432:                        template.init(30);
0433:                    }
0434:                }
0435:
0436:                return template;
0437:            }
0438:
0439:            //
0440:            // service methods
0441:            //
0442:
0443:            protected String getDebugContextClassName() {
0444:                return getServiceAppContext().getDebugContextClassName();
0445:            }
0446:
0447:            protected String getConfigContextClassName() {
0448:                return configContextClassName;
0449:            }
0450:
0451:            protected String getSessionAppContextClassName() {
0452:                return getServiceAppContext().getSessionAppContextClassName();
0453:            }
0454:
0455:            protected String getAuthlessSessionAppContextClassName() {
0456:                return getServiceAppContext()
0457:                        .getAuthlessSessionAppContextClassName();
0458:            }
0459:
0460:            protected String getWSRPSessionAppContextClassName() {
0461:                return getServiceAppContext()
0462:                        .getWSRPSessionAppContextClassName();
0463:            }
0464:
0465:            protected String getClientContextClassName() {
0466:                return getServiceAppContext().getClientContextClassName();
0467:            }
0468:
0469:            protected String getServiceAppContextClassName() {
0470:                return getConfigContext().getServiceAppContextClassName();
0471:            }
0472:
0473:            public String getDesktopContextClassName() {
0474:                return getServiceAppContext().getDesktopContextClassName();
0475:            }
0476:
0477:            protected String getTemplateContextClassName() {
0478:                return getServiceAppContext().getTemplateContextClassName();
0479:            }
0480:
0481:            public String getServiceContextClassName() {
0482:                return getServiceAppContext().getServiceContextClassName();
0483:            }
0484:
0485:            protected String getSessionContextClassName() {
0486:                return getServiceAppContext().getSessionContextClassName();
0487:            }
0488:
0489:            public String getNoSessionURL() {
0490:                return getServiceAppContext().getNoSessionURL();
0491:            }
0492:
0493:            public String getLogoutURL() {
0494:                return getServiceAppContext().getLogoutURL();
0495:            }
0496:
0497:            public String getSessionReturnURLParamName() {
0498:                return getServiceAppContext().getSessionReturnURLParamName();
0499:            }
0500:
0501:            public Map getAuthorizedAuthlessUIDs() {
0502:                return getServiceAppContext().getAuthorizedAuthlessUIDs();
0503:            }
0504:
0505:            public String getDefaultAuthlessUID() {
0506:                return getServiceAppContext().getDefaultAuthlessUID();
0507:            }
0508:
0509:            public long getClientSessionReapInterval() {
0510:                return getServiceAppContext().getClientSessionReapInterval();
0511:            }
0512:
0513:            public long getClientSessionInactiveMax() {
0514:                return getServiceAppContext().getClientSessionInactiveMax();
0515:            }
0516:
0517:            public long getClientSessionsMax() {
0518:                return getServiceAppContext().getClientSessionsMax();
0519:            }
0520:
0521:            public boolean isAuthlessEnabled() {
0522:                return getServiceAppContext().isAuthlessEnabled();
0523:            }
0524:
0525:            public boolean isFederationEnabled() {
0526:                return getServiceAppContext().isFederationEnabled();
0527:            }
0528:
0529:            public String getPreLoginURL(String returnURL,
0530:                    String libertySSOFailedParamName) {
0531:                return getServiceAppContext().getPreLoginURL(returnURL,
0532:                        libertySSOFailedParamName);
0533:            }
0534:
0535:            //
0536:            // the creation and starting of the reaper thread
0537:            // is disabled per bug #4720290. see this bug report
0538:            // for details.
0539:            /*
0540:              public long getReapInterval() {
0541:              return getServiceAppContext().getReapInterval();
0542:              }
0543:             
0544:              public long getInactiveMax() {
0545:              return getServiceAppContext().getInactiveMax();
0546:              }
0547:             */
0548:
0549:            public String getStringAttribute(String name) {
0550:                return getServiceAppContext().getStringAttribute(name);
0551:            }
0552:
0553:            public void setStringAttribute(String name, String val) {
0554:                getServiceAppContext().setStringAttribute(name, val);
0555:            }
0556:
0557:            //
0558:            // servlet request
0559:            //
0560:
0561:            /*
0562:             * This is a replacement for HttpUtils.getRequestURL because the version of
0563:             * that method in iWS does not use the
0564:             * Host header field to reconstruct the URL.
0565:             * The difference in this
0566:             * version is that it grabs the servername:port
0567:             * from the Host header if it is
0568:             * there.
0569:             *
0570:             * this method is copied from the one in HTMLFetcher.java. however,
0571:             * it is not concerned with the uri, only the protocol, server, and port.
0572:             */
0573:            public StringBuffer getRequestServer(HttpServletRequest req) {
0574:                String host = null;
0575:                String port = null;
0576:                String scheme = null;
0577:
0578:                //
0579:                // this block does the following:
0580:                // 1. checks the client property ignoreHostHeaders to see if we should
0581:                //    consider the host header when building the request server
0582:                // 2. if yes, gets the host header and parses out the host and port
0583:                // 3. gets the access url, checks if the access URL's host matches
0584:                //    the host header's host.
0585:                // 4. if yes, sets the final host, scheme, and port to those
0586:                //    in the access URL (if the port was specified in the
0587:                //    host header, that value is used in favor of the port in
0588:                //    the access URL
0589:                //
0590:
0591:                String ignoreHostHeaders = getClientTypeProperty(
0592:                        getClientType(req), "ignoreHostHeader");
0593:                if (!toBoolean(ignoreHostHeaders)) {
0594:                    String hostHeader = req.getHeader("host");
0595:                    if (hostHeader != null && hostHeader.length() > 0) {
0596:                        Matcher m = HOST_HEADER_PATTERN.matcher(hostHeader);
0597:                        if (!m.matches()) {
0598:                            throw new ContextError(
0599:                                    "unable to parse host header: "
0600:                                            + hostHeader);
0601:                        }
0602:
0603:                        if (m.group(3) != null) {
0604:                            // hostname only
0605:                            host = m.group(3);
0606:                        } else {
0607:                            // hostname + port
0608:                            host = m.group(1);
0609:                            port = m.group(2);
0610:                        }
0611:
0612:                        String au = getServiceAppContext().getAccessURL();
0613:                        if (au != null && au.length() > 0) {
0614:                            try {
0615:                                URL accessURL = new URL(au);
0616:                                if (host.equals(accessURL.getHost())) {
0617:                                    scheme = accessURL.getProtocol();
0618:                                    // if the port was not in the host header, use the
0619:                                    // value from the access URL
0620:                                    if (port == null) {
0621:                                        port = String.valueOf(accessURL
0622:                                                .getPort());
0623:                                    }
0624:                                }
0625:                            } catch (MalformedURLException mfue) {
0626:                                throw new ContextError(
0627:                                        "could not construct access URL: " + au,
0628:                                        mfue);
0629:                            }
0630:                        }
0631:                    }
0632:                }
0633:
0634:                //
0635:                // get the values from the request, if we were not able to determine
0636:                // them from the host header + access URL
0637:                //
0638:
0639:                if (scheme == null) {
0640:                    scheme = req.getScheme();
0641:                }
0642:                if (host == null) {
0643:                    host = req.getServerName();
0644:                }
0645:                if (port == null) {
0646:                    port = String.valueOf(req.getServerPort());
0647:                }
0648:
0649:                //
0650:                // build the request server
0651:                //
0652:
0653:                StringBuffer url = new StringBuffer(32);
0654:                url.append(scheme).append("://");
0655:                url.append(host);
0656:                if ((scheme.equals("http") && !port.equals("80"))
0657:                        || (scheme.equals("https") && !port.equals("443"))) {
0658:                    url.append(':').append(port);
0659:                }
0660:
0661:                return url;
0662:            }
0663:
0664:            public String getDesktopURL(HttpServletRequest req) {
0665:                String requestServer = getRequestServer(req).toString();
0666:                String dtURL = (String) desktopURLs.get(requestServer);
0667:                if (dtURL == null) {
0668:                    dtURL = new StringBuffer(requestServer).append(
0669:                            req.getContextPath()).append(req.getServletPath())
0670:                            .toString();
0671:                    desktopURLs.put(requestServer, dtURL);
0672:                }
0673:                return dtURL;
0674:            }
0675:
0676:            public String getDesktopURL(HttpServletRequest req, Map query,
0677:                    Map pathInfo) {
0678:                StringBuffer urlBuffer = new StringBuffer(getDesktopURL(req));
0679:                // get path info string
0680:                if (pathInfo != null && !pathInfo.isEmpty()) {
0681:                    Map piMap = new HashMap();
0682:                    piMap.put(PIParser.DESKTOP_ARGS, pathInfo);
0683:                    String pathInfoString = PIParser.getPathInfoString(piMap);
0684:                    urlBuffer.append("/").append(pathInfoString);
0685:                }
0686:
0687:                // append queryString
0688:                if (query != null && !query.isEmpty()) {
0689:                    StringBuffer queryBuffer = new StringBuffer();
0690:                    // build query string
0691:                    for (Iterator i = query.keySet().iterator(); i.hasNext();) {
0692:                        String key = (String) i.next();
0693:                        String value = (String) query.get(key);
0694:                        queryBuffer.append(key).append("=").append(value);
0695:                        if (i.hasNext()) {
0696:                            queryBuffer.append("&");
0697:                        }
0698:                    }
0699:                    urlBuffer.append("?").append(queryBuffer.toString());
0700:                }
0701:                return urlBuffer.toString();
0702:            }
0703:
0704:            public String getDesktopURL(HttpServletRequest req, String query) {
0705:                StringBuffer urlBuffer = new StringBuffer(getDesktopURL(req));
0706:                if (query != null && query.length() != 0) {
0707:                    urlBuffer.append("?").append(query);
0708:                }
0709:                return urlBuffer.toString();
0710:            }
0711:
0712:            //
0713:            // session methods
0714:            //
0715:
0716:            public boolean validateSession(HttpServletRequest req) {
0717:                boolean valid = false;
0718:
0719:                if (getSessionAppContext().validateSession(req)) {
0720:                    valid = true;
0721:                }
0722:
0723:                return valid;
0724:            }
0725:
0726:            public boolean validateAuthlessSession(HttpServletRequest req) {
0727:                boolean valid = false;
0728:                if (getAuthlessSessionAppContext().validateSession(req)) {
0729:                    valid = true;
0730:
0731:                } else {
0732:                    //debugError("PSDesktopAppContext.validateAuthlessSession(): invalid session");
0733:                }
0734:                return valid;
0735:            }
0736:
0737:            public boolean isAuthless(HttpServletRequest req) {
0738:                boolean authless = false;
0739:                Boolean al = (Boolean) ROC.getObject(ROC_ISAUTHLESS);
0740:
0741:                if (al != null) {
0742:                    authless = al.booleanValue();
0743:                } else {
0744:                    boolean isValidAuth = false;
0745:                    try {
0746:                        isValidAuth = getSessionAppContext().validateSession(
0747:                                req);
0748:                    } catch (DesktopError e) {
0749:                        // TODO: ignore with logging at FINEST level
0750:                    }
0751:                    boolean isValidWSRP = isWSRP(req);
0752:
0753:                    if (!isValidAuth && !isValidWSRP) {
0754:                        boolean isValidAuthless = getAuthlessSessionAppContext()
0755:                                .validateSession(req);
0756:                        if (isValidAuthless) {
0757:                            authless = true;
0758:                        }
0759:                    }
0760:
0761:                    if (authless) {
0762:                        ROC.setObject(ROC_ISAUTHLESS, Boolean.TRUE);
0763:                    } else {
0764:                        ROC.setObject(ROC_ISAUTHLESS, Boolean.FALSE);
0765:                    }
0766:                }
0767:
0768:                return authless;
0769:            }
0770:
0771:            public boolean isWSRP(HttpServletRequest req) {
0772:                boolean isValidWSRP = getWSRPSessionAppContext()
0773:                        .validateSession(req);
0774:                return isValidWSRP;
0775:            }
0776:
0777:            public boolean isAuthorizedAuthlessUID(String uid) {
0778:                Map authorized = getAuthorizedAuthlessUIDs();
0779:                if (authorized.containsKey(uid.toLowerCase())) {
0780:                    return true;
0781:                }
0782:                return false;
0783:            }
0784:
0785:            public String getSessionID(HttpServletRequest req) {
0786:                //
0787:                // try to get from ROC, so we don't get the
0788:                // session multiple times per request. it's
0789:                // expensive because we have to get the set
0790:                // of cookies each time to check the SUID
0791:                //
0792:                String sid = (String) ROC.getObject(ROC_SID);
0793:                if (sid == null) {
0794:                    if (isWSRP(req)) {
0795:                        sid = getWSRPSessionAppContext().getSessionID(req);
0796:                    } else if (isAuthless(req)) {
0797:                        sid = getAuthlessSessionAppContext().getSessionID(req);
0798:                    } else {
0799:                        sid = getSessionAppContext().getSessionID(req);
0800:                    }
0801:
0802:                    ROC.setObject(ROC_SID, sid);
0803:                }
0804:
0805:                return sid;
0806:            }
0807:
0808:            //
0809:            // client
0810:            //
0811:            public String getContentType(String clientType) {
0812:                return getClientContext().getContentType(clientType);
0813:            }
0814:
0815:            public String getClientType(HttpServletRequest req) {
0816:                String clientType = getClientContext().getClientType(req);
0817:                return clientType;
0818:            }
0819:
0820:            public String getDefaultClientType() {
0821:                return getClientContext().getDefaultClientType();
0822:            }
0823:
0824:            public String getClientPath(String clientType) {
0825:                return getClientContext().getClientPath(clientType);
0826:            }
0827:
0828:            public String getClientTypeProperty(String clientType, String key) {
0829:                return getClientContext()
0830:                        .getClientTypeProperty(clientType, key);
0831:            }
0832:
0833:            public Set getClientTypeProperties(String clientType, String key) {
0834:                return getClientContext().getClientTypeProperties(clientType,
0835:                        key);
0836:            }
0837:
0838:            public String getCharset(String clientType, Locale locale) {
0839:                return getClientContext().getCharset(clientType, locale);
0840:            }
0841:
0842:            public short getCookieSupport(String clientType) {
0843:                return getClientContext().getCookieSupport(clientType);
0844:            }
0845:
0846:            public short getAuthlessState(String clientType) {
0847:                return getClientContext().getAuthlessState(clientType);
0848:            }
0849:
0850:            public String getEncoderClassName(String clientType) {
0851:                return getClientContext().getEncoderClassName(clientType);
0852:            }
0853:
0854:            //
0855:            // config
0856:            //
0857:            public String getPortalId() {
0858:                return getConfigContext().getPortalId();
0859:            }
0860:
0861:            public String getInstanceId() {
0862:                return getConfigContext().getInstanceId();
0863:            }
0864:
0865:            public String getTemplateBaseDir() {
0866:                return getConfigContext().getTemplateBaseDir();
0867:            }
0868:
0869:            public String getProviderClassBaseDir() {
0870:                return getConfigContext().getProviderClassBaseDir();
0871:            }
0872:
0873:            public String getJSPScratchDir() {
0874:                return getConfigContext().getJSPScratchDir();
0875:            }
0876:
0877:            public String getJSPCompilerWARClassPath() {
0878:                return getConfigContext().getJSPCompilerWARClassPath();
0879:            }
0880:
0881:            public String getDefaultDesktopType() {
0882:                return getConfigContext().getDefaultDesktopType();
0883:            }
0884:
0885:            public int getGetterPoolMinSize() {
0886:                return getConfigContext().getGetterPoolMinSize();
0887:            }
0888:
0889:            public int getGetterPoolMaxSize() {
0890:                return getConfigContext().getGetterPoolMaxSize();
0891:            }
0892:
0893:            public int getGetterPoolPartitionSize() {
0894:                return getConfigContext().getGetterPoolPartitionSize();
0895:            }
0896:
0897:            public int getCallerPoolMinSize() {
0898:                return getConfigContext().getCallerPoolMinSize();
0899:            }
0900:
0901:            public int getCallerPoolMaxSize() {
0902:                return getConfigContext().getCallerPoolMaxSize();
0903:            }
0904:
0905:            public int getCallerPoolPartitionSize() {
0906:                return getConfigContext().getCallerPoolPartitionSize();
0907:            }
0908:
0909:            public int getTemplateScanInterval() {
0910:                return getConfigContext().getTemplateScanInterval();
0911:            }
0912:
0913:            public int getClassLoaderRevalidateInterval() {
0914:                return getConfigContext().getClassLoaderRevalidateInterval();
0915:            }
0916:
0917:            public int getBrowserCacheInterval() {
0918:                return getConfigContext().getBrowserCacheInterval();
0919:            }
0920:
0921:            public int getDPScanInterval() {
0922:                return getConfigContext().getDPScanInterval();
0923:            }
0924:
0925:            public List getCommunityContributorTypes() {
0926:                return getConfigContext().getCommunityContributorTypes();
0927:            }
0928:
0929:            public String getStaticContentPath() {
0930:                return DesktopRequestThreadLocalizer.getRequest()
0931:                        .getContextPath();
0932:            }
0933:
0934:            public String getCookiePrefix() {
0935:                return getConfigContext().getCookiePrefix();
0936:            }
0937:
0938:            public String getLBCookieName() {
0939:                return getConfigContext().getLBCookieName();
0940:            }
0941:
0942:            public String getConfigProperty(String key) {
0943:                return getConfigContext().getConfigProperty(key);
0944:            }
0945:
0946:            public int getMaxEventGenerations() {
0947:                return config.getMaxEventGenerations();
0948:            }
0949:
0950:            public String getPortletRenderModeParallel() {
0951:                return config.getPortletRenderModeParallel();
0952:            }
0953:
0954:            //
0955:            // Template
0956:            //
0957:            public ParsedTagArray getTemplate(String type, String locale,
0958:                    String app, String provider, String clientFilePath,
0959:                    String file, String baseDir) {
0960:
0961:                return getTemplateContext().getTemplate(baseDir, type, locale,
0962:                        app, provider, clientFilePath, file);
0963:
0964:            }
0965:
0966:            public StringBuffer getTemplate(String type, String locale,
0967:                    String app, String provider, String clientFilePath,
0968:                    String file, Hashtable table, String baseDir,
0969:                    ContainerProviderContext pc) {
0970:
0971:                ParsedTagArray pta = getTemplate(type, locale, app, provider,
0972:                        clientFilePath, file, baseDir);
0973:
0974:                Properties p = getTemplateContext().getTemplateProperties(
0975:                        baseDir, type, locale, app, provider, clientFilePath,
0976:                        propertiesfile);
0977:
0978:                return TagSwapper.doSwapFromParsedTagArray(pta, pc, app,
0979:                        getStaticContentPath(), table, p);
0980:
0981:            }
0982:
0983:            public StringBuffer getTemplate(String type, String locale,
0984:                    String app, String provider, String clientFilePath,
0985:                    String file, Hashtable table, String baseDir) {
0986:                return getTemplate(type, locale, app, provider, clientFilePath,
0987:                        file, table, baseDir, null);
0988:            }
0989:
0990:            public File getTemplatePath(String type, String locale, String app,
0991:                    String provider, String clientFilePath, String file,
0992:                    String baseDir) {
0993:
0994:                return getTemplateContext().getTemplatePath(baseDir, type,
0995:                        locale, app, provider, clientFilePath, file);
0996:
0997:            }
0998:
0999:            public File getTemplateMostSpecificPath(String type, String locale,
1000:                    String app, String provider, String clientFilePath,
1001:                    String file, String baseDir) {
1002:
1003:                return getTemplateContext().getTemplateMostSpecificPath(
1004:                        baseDir, type, locale, app, provider, clientFilePath,
1005:                        file);
1006:
1007:            }
1008:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.