Source Code Cross Referenced for MarkupManagerImpl.java in  » Portal » Open-Portal » com » sun » portal » wsrp » consumer » markup » impl » 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.wsrp.consumer.markup.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Copyright 2003 Sun Microsystems, Inc. All
0003:         * rights reserved. Use of this product is subject
0004:         * to license terms. Federal Acquisitions:
0005:         * Commercial Software -- Government Users
0006:         * Subject to Standard License Terms and
0007:         * Conditions.
0008:         *
0009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010:         * are trademarks or registered trademarks of Sun Microsystems,
0011:         * Inc. in the United States and other countries.
0012:         */package com.sun.portal.wsrp.consumer.markup.impl;
0013:
0014:        import java.util.ArrayList;
0015:        import java.util.List;
0016:        import java.util.HashMap;
0017:        import java.util.logging.Level;
0018:        import java.util.logging.Logger;
0019:        import java.io.UnsupportedEncodingException;
0020:        import java.rmi.RemoteException;
0021:        import java.net.URL;
0022:        import java.net.MalformedURLException;
0023:
0024:        import com.sun.portal.container.ChannelMode;
0025:        import com.sun.portal.container.Container;
0026:        import com.sun.portal.container.GetResourceRequest;
0027:        import com.sun.portal.container.GetResourceResponse;
0028:        import com.sun.portal.container.ExecuteActionRequest;
0029:        import com.sun.portal.container.ExecuteActionResponse;
0030:        import com.sun.portal.container.GetMarkupRequest;
0031:        import com.sun.portal.container.GetMarkupResponse;
0032:        import com.sun.portal.container.ContainerRequest;
0033:        import com.sun.portal.container.ContainerResponse;
0034:        import com.sun.portal.container.ContainerException;
0035:        import com.sun.portal.container.ContentException;
0036:        import com.sun.portal.container.WindowState;
0037:
0038:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerRewriter;
0039:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerRewriterException;
0040:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerErrorCode;
0041:
0042:        import com.sun.portal.wsrp.common.stubs.SessionContext;
0043:        import com.sun.portal.wsrp.common.stubs.UserContext;
0044:        import com.sun.portal.wsrp.common.stubs.CacheControl;
0045:        import com.sun.portal.wsrp.common.stubs.PortletContext;
0046:        import com.sun.portal.wsrp.common.stubs.RegistrationContext;
0047:        import com.sun.portal.wsrp.common.stubs.WSRP_v1_Markup_PortType;
0048:        import com.sun.portal.wsrp.common.stubs.MarkupParams;
0049:        import com.sun.portal.wsrp.common.stubs.RuntimeContext;
0050:        import com.sun.portal.wsrp.common.stubs.MarkupContext;
0051:        import com.sun.portal.wsrp.common.stubs.InteractionParams;
0052:        import com.sun.portal.wsrp.common.stubs.UploadContext;
0053:        import com.sun.portal.wsrp.common.stubs.PerformBlockingInteraction;
0054:        import com.sun.portal.wsrp.common.stubs.BlockingInteractionResponse;
0055:        import com.sun.portal.wsrp.common.stubs.InvalidSessionFault;
0056:        import com.sun.portal.wsrp.common.stubs.InvalidCookieFault;
0057:        import com.sun.portal.wsrp.common.stubs.InvalidRegistrationFault;
0058:        import com.sun.portal.wsrp.common.stubs.Fault;
0059:        import com.sun.portal.wsrp.common.stubs.MarkupResponse;
0060:        import com.sun.portal.wsrp.common.stubs.GetMarkup;
0061:        import com.sun.portal.wsrp.common.stubs.Templates;
0062:        import com.sun.portal.wsrp.common.stubs.ClientData;
0063:        import com.sun.portal.wsrp.common.stubs.NamedString;
0064:        import com.sun.portal.wsrp.common.stubs.StateChange;
0065:        import com.sun.portal.wsrp.common.stubs.UpdateResponse;
0066:        import com.sun.portal.wsrp.common.stubs.PortletDescription;
0067:        import com.sun.portal.wsrp.common.stubs.LocalizedString;
0068:        import com.sun.portal.wsrp.common.stubs.ResourceList;
0069:
0070:        import com.sun.portal.wsrp.common.WSRPToContainerMap;
0071:        import com.sun.portal.wsrp.common.ContainerToString;
0072:        import com.sun.portal.wsrp.common.WSRPUtility;
0073:        import com.sun.portal.wsrp.common.WSRPSpecKeys;
0074:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityStatus;
0075:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerUtil;
0076:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
0077:
0078:        import com.sun.portal.wsrp.consumer.markup.MarkupConfig;
0079:        import com.sun.portal.wsrp.consumer.markup.CacheManager;
0080:        import com.sun.portal.wsrp.consumer.markup.CacheEntry;
0081:        import com.sun.portal.wsrp.consumer.markup.ProducerSessionManager;
0082:        import com.sun.portal.wsrp.consumer.markup.UserContextManager;
0083:        import com.sun.portal.wsrp.consumer.markup.MarkupConfigManager;
0084:        import com.sun.portal.wsrp.consumer.markup.MarkupContent;
0085:        import com.sun.portal.wsrp.consumer.markup.MarkupContentException;
0086:
0087:        import javax.servlet.http.HttpServletRequest;
0088:
0089:        import org.apache.commons.fileupload.FileUpload;
0090:        import org.apache.commons.fileupload.FileItem;
0091:        import org.apache.commons.fileupload.FileUploadException;
0092:        import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
0093:        import org.apache.commons.fileupload.DefaultFileItemFactory;
0094:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerConfig;
0095:        import com.sun.portal.log.common.PortalLogger;
0096:
0097:        import com.iplanet.sso.SSOToken;
0098:        import com.iplanet.sso.SSOException;
0099:        import com.iplanet.sso.SSOTokenID;
0100:        import com.iplanet.sso.SSOTokenManager;
0101:        import com.sun.portal.wsrp.common.IdentityPropagationConstants;
0102:        import javax.xml.soap.SOAPElement;
0103:        import javax.xml.soap.SOAPException;
0104:        import javax.xml.soap.SOAPFactory;
0105:        import com.sun.portal.wsrp.common.stubs.Extension;
0106:
0107:        /**
0108:         * MarkupManagerImpl is the WSRP implementation
0109:         * for Container interface. MarkupManager is responsible
0110:         * for the actual execution of WSRP portlets to get markup
0111:         * and perform interactions on the behalf of clients like
0112:         * WSRPWindowProvider. A request to MarkupManager is
0113:         * made on behalf of one WSRP channel.
0114:         */
0115:        public class MarkupManagerImpl implements  Container {
0116:
0117:            //
0118:            // Constants
0119:            //
0120:
0121:            /**
0122:             * List of parameters that are local
0123:             * (navigational state and interaction state)
0124:             * that must be filtered out from the action
0125:             * parameters(aka form parameters) before calling
0126:             * performBlockingInteraction
0127:             */
0128:            static private List reservedParams = getReservedParams();
0129:
0130:            //
0131:            // Local managers
0132:            //
0133:            private CacheManager _cacheManager;
0134:            private ProducerSessionManager _producerSessionManager;
0135:            private UserContextManager _userContextManager;
0136:            private MarkupConfigManager _markupConfigManager;
0137:
0138:            private static Logger logger = PortalLogger
0139:                    .getLogger(MarkupManagerImpl.class);
0140:
0141:            private static final String SSOTOKEN_STRING = "sso_token";
0142:
0143:            /**
0144:             * Constructor that initializes all the local sub-managers.
0145:             */
0146:            public MarkupManagerImpl() throws WSRPConsumerException {
0147:
0148:                //
0149:                // Initialize MarkupConfigManager that
0150:                // returns the MarkupConfig object that
0151:                // contains all configutation information
0152:                // to process a WSRP request.
0153:                //
0154:
0155:                _markupConfigManager = new MarkupConfigManagerImpl();
0156:
0157:                //
0158:                // Initialize rest of the managers.
0159:                // These managers work off the markupConfig
0160:                // that is sent on each method to
0161:                // find all static kind of information.
0162:                //
0163:                _cacheManager = new CacheManagerImpl();
0164:                _producerSessionManager = new ProducerSessionManagerImpl();
0165:                _userContextManager = new UserContextManagerImpl();
0166:            }
0167:
0168:            /**
0169:             * Implementation for getMarkup() method of the
0170:             * Container interface. This method is called by the
0171:             * clients like WSRPProvider, whenever the Portal calls its
0172:             * Provider.getContent() method. It's goal is to populate
0173:             * the response object with markup obtained either via
0174:             * the cache manager or by making a fresh call to the
0175:             * remote producer. Cache is not blindly used if the provider
0176:             * was the target of the request. A wsrp provider is
0177:             * target, when a user clicks explicity on a url in the contents
0178:             * or in its controls 
0179:             *
0180:             * @param request
0181:             * @param response
0182:             * @exception com.sun.portal.container.ContainerException
0183:             * @exception com.sun.portal.container.ContentException
0184:             */
0185:            public void getMarkup(GetMarkupRequest request,
0186:                    GetMarkupResponse response) throws ContainerException,
0187:                    ContentException {
0188:
0189:                //-------------------------------------------------------------
0190:                // Get the markupConfig instance that gives
0191:                // configuration(reletively static)  information needed to run
0192:                // this call
0193:                //
0194:
0195:                MarkupConfig markupConfig = _markupConfigManager
0196:                        .getMarkupConfig(request);
0197:
0198:                //
0199:                // Create Markup Params
0200:                // and use that to get the cache entry
0201:                //
0202:
0203:                String navigationalState = null;
0204:                String[] navigationalStateTemp = (String[]) request
0205:                        .getRenderParameters().get(
0206:                                WSRPSpecKeys.NAVIGATIONAL_STATE);
0207:                if (navigationalStateTemp != null
0208:                        && navigationalStateTemp.length > 0
0209:                        && navigationalStateTemp[0].length() > 0) {
0210:                    navigationalState = navigationalStateTemp[0];
0211:                }
0212:
0213:                MarkupParams markupParams = getMarkupParams(markupConfig,
0214:                        request, navigationalState);
0215:                // Get the cached entry if there is any
0216:
0217:                CacheEntry cacheEntry = _cacheManager.getCacheEntry(
0218:                        markupConfig, request, markupParams);
0219:
0220:                //
0221:                // Compare the UserContext related data
0222:                // to make sure it didn't change since the 
0223:                // cache was generated (CS044)
0224:                // else cache is invalidated
0225:
0226:                if ((cacheEntry != null)
0227:                        && (WSRPSpecKeys.CACHE_PER_USER.equals(cacheEntry
0228:                                .getUserScope()))
0229:                        && (!_userContextManager.isUserContextCacheValid(
0230:                                markupConfig, request))) {
0231:
0232:                    _cacheManager.invalidateCacheEntry(markupConfig, request);
0233:                    cacheEntry = null;
0234:                }
0235:
0236:                //
0237:                // Now check for the validity of the markup cache
0238:                // itself. If the request is targeted to the provider
0239:                // then we can't use the cache. If these cases, we'll
0240:                // try to send out the validate tag to producer
0241:                // to find out if the - existing expired- cache
0242:                // can still be used.
0243:                //
0244:                if (!request.getIsTarget() && cacheEntry != null
0245:                        && cacheEntry.isValid()) {
0246:                    getCachedMarkup(markupConfig, request, response, cacheEntry);
0247:                } else {
0248:                    if (cacheEntry != null) {
0249:                        String validateTag = cacheEntry.getValidateTag();
0250:                        markupParams.setValidateTag(validateTag);
0251:                    }
0252:                    getFreshMarkup(markupConfig, request, response, cacheEntry,
0253:                            markupParams, false, false);
0254:
0255:                }
0256:            }
0257:
0258:            /**
0259:             * This method is the implementation of executeAction in
0260:             * the Container interface. This method is called by the
0261:             * WSRPWindowProvider when the user clicks on a render or
0262:             * blockingAction url. Check the spec for their description.
0263:             * The goal is to populate the response object using data
0264:             * returned via remote call to performBlockingInteraction.
0265:             * This response object is then processed by the clients like
0266:             * WSRPWindowProvider, to change the windowstate/portletmode
0267:             * and set render paramters for next render calls.
0268:             *
0269:             * @param request
0270:             * @param response
0271:             * @exception com.sun.portal.container.ContainerException
0272:             * @exception com.sun.portal.container.ContentException
0273:             */
0274:            public void executeAction(ExecuteActionRequest request,
0275:                    ExecuteActionResponse response) throws ContainerException,
0276:                    ContentException {
0277:
0278:                executeActionInternal(request, response, false, false);
0279:
0280:            }
0281:
0282:            /**
0283:             * Real internal method implementation of executeAction with 
0284:             * all the logic.
0285:             * Look in the caller method to for all details.
0286:             * Operation is allowed to repeat once if it runs into
0287:             * InvalidSessionFault or InvalidCookieFault
0288:             *
0289:             * @param request
0290:             * @param response
0291:             * @param resetAfterSessionFault
0292:             * @param resetAfterCookieFault
0293:             * @exception com.sun.portal.container.ContainerException
0294:             * @exception com.sun.portal.container.ContentException
0295:             */
0296:            private void executeActionInternal(ExecuteActionRequest request,
0297:                    ExecuteActionResponse response,
0298:                    boolean resetAfterSessionFault,
0299:                    boolean resetAfterCookieFault) throws ContainerException,
0300:                    ContentException {
0301:
0302:                CommonRequestParams commonRequestParams = null;
0303:                MarkupConfig markupConfig = null;
0304:                WSRP_v1_Markup_PortType markupPortType = null;
0305:
0306:                try {
0307:
0308:                    //
0309:                    // debug section
0310:                    //
0311:                    if (logger.isLoggable(Level.FINEST)) {
0312:                        String[] param = {
0313:                                "ExecuteActionRequest",
0314:                                ContainerToString
0315:                                        .toStringExecuteActionRequest(request) };
0316:                        logger.log(Level.FINEST, "PSWS_CSPWCMI0007", param);
0317:                    }
0318:
0319:                    //-------------------------------------------------------------
0320:                    // Get the markupConfig instance that gives
0321:                    // configuration information needed to run
0322:                    // this call
0323:                    //
0324:
0325:                    markupConfig = _markupConfigManager
0326:                            .getMarkupConfig(request);
0327:
0328:                    //--------------------------------------------------------
0329:                    // Check secure flag requirement
0330:
0331:                    boolean onlySecure = Boolean.TRUE.equals(markupConfig
0332:                            .getPortletDescription().getOnlySecure());
0333:
0334:                    if (onlySecure
0335:                            && (!request.getHttpServletRequest().isSecure())) {
0336:                        throw new MarkupContentException(
0337:                                WSRPConsumerErrorCode.RUNTIME_NOT_IN_SECURE_MODE,
0338:                                "Not in secure mode");
0339:                    }
0340:
0341:                    //-------------------------------------------------------
0342:                    // Get the markup port that can be used 
0343:                    // ( initialized with cookies)
0344:                    // 
0345:
0346:                    markupPortType = _producerSessionManager.getMarkupPortType(
0347:                            markupConfig, request);
0348:
0349:                    //
0350:                    // Get the markup Params 
0351:                    //
0352:
0353:                    String navigationalState = null;
0354:                    String[] navigationalStateTemp = (String[]) request
0355:                            .getActionParameters().get(
0356:                                    WSRPSpecKeys.NAVIGATIONAL_STATE);
0357:                    if (navigationalStateTemp != null
0358:                            && navigationalStateTemp.length > 0
0359:                            && navigationalStateTemp[0].length() > 0) {
0360:                        navigationalState = navigationalStateTemp[0];
0361:                    }
0362:
0363:                    MarkupParams markupParams = getMarkupParams(markupConfig,
0364:                            request, navigationalState);
0365:
0366:                    //
0367:                    // Get the cache entry if any for this markupParams
0368:                    // and remove it from the cache. We would though
0369:                    // send the validateTag, just in case, producer thinks
0370:                    // it is still valid and then markup would be 
0371:                    // put back in the CacheManager.
0372:                    // We send the validate tag only after 
0373:                    // comparing the UserContext related data
0374:                    // to make sure it didn't change since the 
0375:                    // markup cache was generated (CS044)
0376:                    //
0377:
0378:                    CacheEntry origCacheEntry = _cacheManager.getCacheEntry(
0379:                            markupConfig, request, markupParams);
0380:
0381:                    if (origCacheEntry != null) {
0382:
0383:                        boolean valid = true;
0384:                        if ((WSRPSpecKeys.CACHE_PER_USER.equals(origCacheEntry
0385:                                .getUserScope()))
0386:                                && (!_userContextManager
0387:                                        .isUserContextCacheValid(markupConfig,
0388:                                                request))) {
0389:                            valid = false;
0390:                        }
0391:                        if (valid) {
0392:                            String validateTag = origCacheEntry
0393:                                    .getValidateTag();
0394:                            markupParams.setValidateTag(validateTag);
0395:                        }
0396:                        _cacheManager.invalidateCacheEntry(markupConfig,
0397:                                request);
0398:                    }
0399:
0400:                    //
0401:                    // Get all the common parameters needed for calling
0402:                    // the markup methods and make a performInteraction call
0403:                    //
0404:
0405:                    commonRequestParams = getCommonRequestParams(markupConfig,
0406:                            request, response);
0407:
0408:                    //
0409:                    // Get interaction params
0410:                    //
0411:
0412:                    InteractionParams interactionParams = getInteractionParams(
0413:                            markupConfig, request);
0414:
0415:                    //
0416:                    // Call the remote service
0417:                    // and execute performBlockingInteraction
0418:                    //
0419:
0420:                    PerformBlockingInteraction blockingInteractionRequest = new PerformBlockingInteraction(
0421:                            commonRequestParams.getRegistrationContext(),
0422:                            commonRequestParams.getPortletContext(),
0423:                            commonRequestParams.getRuntimeContext(),
0424:                            commonRequestParams.getUserContext(), markupParams,
0425:                            interactionParams);
0426:
0427:                    BlockingInteractionResponse blockingInteractionResponse = markupPortType
0428:                            .performBlockingInteraction(blockingInteractionRequest);
0429:
0430:                    //
0431:                    // Process the response
0432:                    //
0433:                    // If a redirect URL is sent back, we don't have to process
0434:                    // anything, else we need to initialize the session and
0435:                    // send back mode/windowstate change back to the provider.
0436:                    // For optimization some prodcuers might send the
0437:                    // markup with performBlockingInteraction. In that case,
0438:                    // save the markup in the cache if the cache control is
0439:                    // returned.
0440:                    // If markup is returned without cache control, it is
0441:                    // right now wasted -- a performance TODO
0442:                    //
0443:
0444:                    String redirectURL = blockingInteractionResponse
0445:                            .getRedirectURL();
0446:
0447:                    if (redirectURL == null || redirectURL.length() == 0) {
0448:
0449:                        UpdateResponse updateResponse = blockingInteractionResponse
0450:                                .getUpdateResponse();
0451:
0452:                        //
0453:                        // process session
0454:                        //
0455:
0456:                        SessionContext sessionContext = updateResponse
0457:                                .getSessionContext();
0458:                        _producerSessionManager.processSessionContext(
0459:                                markupConfig, request, sessionContext);
0460:
0461:                        //
0462:                        // get the MarkupContext and start processing
0463:                        //
0464:
0465:                        MarkupContext markupContext = updateResponse
0466:                                .getMarkupContext();
0467:
0468:                        //
0469:                        // TODO:: Check container interface on null
0470:
0471:                        String wsrpMode = updateResponse.getNewMode();
0472:                        String wsrpWindowState = updateResponse
0473:                                .getNewWindowState();
0474:
0475:                        ChannelMode mode = request.getChannelMode();
0476:                        WindowState windowState = request.getWindowState();
0477:                        if (wsrpMode != null) {
0478:
0479:                            mode = WSRPToContainerMap
0480:                                    .mapChannelModeToContainer(updateResponse
0481:                                            .getNewMode());
0482:                            response.setNewChannelMode(mode);
0483:                        }
0484:
0485:                        if (wsrpWindowState != null) {
0486:                            windowState = WSRPToContainerMap
0487:                                    .mapWindowStateToContainer(updateResponse
0488:                                            .getNewWindowState());
0489:
0490:                            response.setNewWindowState(windowState);
0491:                        }
0492:
0493:                        //
0494:                        // Update MarkupParams with the new mode or windowState
0495:                        // this would be used for specifying the caching criteria 
0496:
0497:                        markupParams.setMode(WSRPToContainerMap
0498:                                .mapChannelModeToWSRP(mode));
0499:                        markupParams.setWindowState(WSRPToContainerMap
0500:                                .mapWindowStateToWSRP(windowState));
0501:                        markupParams.setNavigationalState(updateResponse
0502:                                .getNavigationalState());
0503:
0504:                        //
0505:                        // Process markup obtained 
0506:                        //
0507:                        processMarkupContext(markupConfig, request,
0508:                                markupContext, origCacheEntry, markupParams);
0509:
0510:                        //
0511:                        // process PortletContext
0512:                        //
0513:
0514:                        _markupConfigManager.processPortletContext(request,
0515:                                updateResponse.getPortletContext());
0516:
0517:                        //
0518:                        // process navigational state
0519:                        // and interaction state
0520:                        // and store them in the render parameters
0521:                        // so that they can be used for following requests.
0522:                        //
0523:
0524:                        HashMap map = new HashMap();
0525:                        String navigationState = updateResponse
0526:                                .getNavigationalState();
0527:                        if (navigationState != null) {
0528:                            map.put(WSRPSpecKeys.NAVIGATIONAL_STATE,
0529:                                    new String[] { navigationState });
0530:                        }
0531:                        response.setRenderParameters(map);
0532:
0533:                    } else {
0534:                        response.setRedirectURL(new URL(redirectURL));
0535:
0536:                    }
0537:
0538:                    if (logger.isLoggable(Level.FINEST))
0539:                        logger.log(Level.FINEST, "PSWS_CSPWCMI0008");
0540:
0541:                } catch (InvalidSessionFault fault) {
0542:                    _producerSessionManager.resetSessionId(commonRequestParams
0543:                            .getRuntimeContext().getSessionID(), markupConfig,
0544:                            request);
0545:
0546:                    if (!resetAfterSessionFault) {
0547:                        if (logger.isLoggable(Level.INFO))
0548:                            logger.log(Level.INFO, "PSWS_CSPWCMI0009", fault
0549:                                    .toString());
0550:                        executeActionInternal(request, response, true,
0551:                                resetAfterCookieFault);
0552:                    } else {
0553:                        if (logger.isLoggable(Level.SEVERE))
0554:                            logger.log(Level.SEVERE, "PSWS_CSPWCMI0010", fault);
0555:                        throw new MarkupContentException(MarkupContentException
0556:                                .getFaultErrorCode(fault),
0557:                                "Fault from producer:" + fault.toString(),
0558:                                fault);
0559:
0560:                    }
0561:
0562:                } catch (InvalidCookieFault fault) {
0563:
0564:                    //
0565:                    // reset the markup port
0566:                    //
0567:
0568:                    _producerSessionManager.resetMarkupPortType(markupPortType,
0569:                            markupConfig, request);
0570:                    //
0571:                    // one retry allowed if invalid cookie fault happens
0572:                    //
0573:
0574:                    if (!resetAfterCookieFault) {
0575:                        if (logger.isLoggable(Level.INFO))
0576:                            logger.log(Level.INFO, "PSWS_CSPWCMI0009", fault
0577:                                    .toString());
0578:                        executeActionInternal(request, response,
0579:                                resetAfterSessionFault, true);
0580:                    } else {
0581:                        throw new MarkupContentException(MarkupContentException
0582:                                .getFaultErrorCode(fault),
0583:                                "Fault from producer:" + fault.toString(),
0584:                                fault);
0585:                    }
0586:                } catch (InvalidRegistrationFault fault) {
0587:
0588:                    try {
0589:                        markupConfig.getProducerEntityManager().setStatus(
0590:                                markupConfig.getProducerEntityId(),
0591:                                ProducerEntityStatus.BAD_REGISTRATION);
0592:                    } catch (WSRPConsumerException ex) {
0593:                        throw new ContainerException(
0594:                                "Bad Registration:failed to disable producer:"
0595:                                        + fault.toString(), ex);
0596:                    }
0597:
0598:                    throw new MarkupContentException(MarkupContentException
0599:                            .getFaultErrorCode(fault), "Fault from producer:"
0600:                            + fault.toString(), fault);
0601:                } catch (Fault fault) {
0602:                    throw new MarkupContentException(MarkupContentException
0603:                            .getFaultErrorCode(fault), "Fault from producer:"
0604:                            + fault.toString(), fault);
0605:                } catch (MalformedURLException ex) {
0606:                    throw new MarkupContentException(
0607:                            WSRPConsumerErrorCode.BAD_REDIRECT_URL,
0608:                            "Bad redirect URL:" + ex.toString(), ex);
0609:                } catch (RemoteException ex) {
0610:                    throw new MarkupContentException(
0611:                            WSRPConsumerErrorCode.REMOTE_EXCEPTION, ex
0612:                                    .toString(), ex);
0613:                }
0614:
0615:            }
0616:
0617:            public void getResources(GetResourceRequest request,
0618:                    GetResourceResponse response) throws ContainerException {
0619:
0620:                throw new ContainerException("getResources: Not Supported");
0621:
0622:            }
0623:
0624:            //*******************************************************
0625:            //
0626:            // THESE METHODS ARE SPECIFIC TO getMarkup()
0627:            //
0628:            //*******************************************************
0629:
0630:            /**
0631:             * Gets the fresh markup from the WSRP producer
0632:             * for this request.
0633:             *
0634:             * @param markupConfig object containing static information to process the request.
0635:             * @param request request object that is already populated.
0636:             * @param response response object to be polutated
0637:             * @param origCacheEntry existing cache entry ( might not be valid.)
0638:             * @param markupParams markup params to be used. 
0639:             * @exception com.sun.portal.container.ContainerException
0640:             * @exception com.sun.portal.container.ContentException
0641:             */
0642:            private void getFreshMarkup(MarkupConfig markupConfig,
0643:                    GetMarkupRequest request, GetMarkupResponse response,
0644:                    CacheEntry origCacheEntry, MarkupParams markupParams,
0645:                    boolean resetAfterSessionFault,
0646:                    boolean resetAfterCookieFault) throws ContainerException,
0647:                    ContentException {
0648:
0649:                CommonRequestParams commonRequestParams = null;
0650:                WSRP_v1_Markup_PortType markupPortType = null;
0651:
0652:                try {
0653:                    if (logger.isLoggable(Level.FINEST)) {
0654:                        String[] param = {
0655:                                "MarkupRequest",
0656:                                ContainerToString
0657:                                        .toStringGetMarkupRequest(request) };
0658:                        logger.log(Level.FINEST, "PSWS_CSPWCMI0007");
0659:                    }
0660:
0661:                    //--------------------------------------------------------
0662:                    // Check secure flag requirement
0663:
0664:                    boolean onlySecure = Boolean.TRUE.equals(markupConfig
0665:                            .getPortletDescription().getOnlySecure());
0666:
0667:                    boolean defaultMarkupSecure = Boolean.TRUE
0668:                            .equals(markupConfig.getPortletDescription()
0669:                                    .getDefaultMarkupSecure());
0670:
0671:                    if ((onlySecure || defaultMarkupSecure)
0672:                            && (!request.getHttpServletRequest().isSecure())) {
0673:                        throw new MarkupContentException(
0674:                                WSRPConsumerErrorCode.RUNTIME_NOT_IN_SECURE_MODE,
0675:                                "Not running in secure mode");
0676:                    }
0677:                    //
0678:                    // get the port to be used ( initialized with cookie etc)
0679:                    //
0680:
0681:                    markupPortType = _producerSessionManager.getMarkupPortType(
0682:                            markupConfig, request);
0683:
0684:                    //
0685:                    // Get all the common parameters needed for calling
0686:                    // the markup methods.
0687:                    //
0688:
0689:                    commonRequestParams = getCommonRequestParams(markupConfig,
0690:                            request, response);
0691:
0692:                    UserContext userCtx = commonRequestParams.getUserContext();
0693:
0694:                    if (markupConfig
0695:                            .getProducerEntity()
0696:                            .getIdentityPropagationType()
0697:                            .equals(
0698:                                    IdentityPropagationConstants.SSOTOKEN_IDENTITY_PROPAGATION)) {
0699:                        addExtensions(userCtx, request);
0700:                    }
0701:
0702:                    //-----------------------------------------------------
0703:                    // We are ready to call remote markup call
0704:                    //
0705:
0706:                    MarkupResponse markupResponse = null;
0707:
0708:                    GetMarkup markupRequest = new GetMarkup(commonRequestParams
0709:                            .getRegistrationContext(), commonRequestParams
0710:                            .getPortletContext(), commonRequestParams
0711:                            .getRuntimeContext(), userCtx, markupParams);
0712:
0713:                    markupResponse = markupPortType.getMarkup(markupRequest);
0714:
0715:                    //
0716:                    // Process the sessionContext
0717:                    //
0718:
0719:                    SessionContext sessionContext = markupResponse
0720:                            .getSessionContext();
0721:                    _producerSessionManager.processSessionContext(markupConfig,
0722:                            request, sessionContext);
0723:
0724:                    //
0725:                    // Process the markupContext
0726:                    //
0727:
0728:                    MarkupContext markupContext = markupResponse
0729:                            .getMarkupContext();
0730:                    MarkupContent content = processMarkupContext(markupConfig,
0731:                            request, markupContext, origCacheEntry,
0732:                            markupParams);
0733:
0734:                    String markupString = content.getContent();
0735:                    if (content.needRewrite()) {
0736:
0737:                        WSRPConsumerRewriter rewriter = getWSRPConsumerRewriter(
0738:                                markupConfig, request);
0739:
0740:                        markupString = rewriter.rewrite(markupString, request
0741:                                .getHttpServletRequest());
0742:                    }
0743:
0744:                    response.setMarkup(new StringBuffer(markupString));
0745:                    response.setTitle(content.getTitleResource());
0746:
0747:                    if (logger.isLoggable(Level.FINEST))
0748:                        logger.log(Level.FINEST, "PSWS_CSPWCMI0008");
0749:                    return;
0750:
0751:                } catch (InvalidSessionFault ex) {
0752:                    _producerSessionManager.resetSessionId(commonRequestParams
0753:                            .getRuntimeContext().getSessionID(), markupConfig,
0754:                            request);
0755:                    //
0756:                    // one retry allowed if invalid cookie fault happens
0757:                    //
0758:
0759:                    if (!resetAfterSessionFault) {
0760:                        if (logger.isLoggable(Level.FINEST))
0761:                            logger.log(Level.FINEST, "PSWS_CSPWCMI0009", ex);
0762:
0763:                        getFreshMarkup(markupConfig, request, response,
0764:                                origCacheEntry, markupParams, true,
0765:                                resetAfterCookieFault);
0766:                    } else {
0767:                        throw new MarkupContentException(MarkupContentException
0768:                                .getFaultErrorCode(ex), "Fault from producer:"
0769:                                + ex.toString(), ex);
0770:                    }
0771:                } catch (InvalidCookieFault ex) {
0772:                    _producerSessionManager.resetMarkupPortType(markupPortType,
0773:                            markupConfig, request);
0774:                    //
0775:                    // one retry allowed if invalid cookie fault happens
0776:                    //
0777:
0778:                    if (!resetAfterCookieFault) {
0779:                        if (logger.isLoggable(Level.FINEST))
0780:                            logger.log(Level.FINEST, "PSWS_CSPWCMI0009", ex);
0781:
0782:                        getFreshMarkup(markupConfig, request, response,
0783:                                origCacheEntry, markupParams,
0784:                                resetAfterSessionFault, true);
0785:
0786:                    } else {
0787:                        throw new MarkupContentException(MarkupContentException
0788:                                .getFaultErrorCode(ex), "Fault from producer:"
0789:                                + ex.toString(), ex);
0790:                    }
0791:                } catch (InvalidRegistrationFault fault) {
0792:                    try {
0793:                        markupConfig.getProducerEntityManager().setStatus(
0794:                                markupConfig.getProducerEntityId(),
0795:                                ProducerEntityStatus.BAD_REGISTRATION);
0796:                    } catch (WSRPConsumerException ex) {
0797:                        throw new ContainerException(
0798:                                "Bad Registration:failed to disable producer:",
0799:                                ex);
0800:                    }
0801:                    throw new MarkupContentException(MarkupContentException
0802:                            .getFaultErrorCode(fault), "Fault from producer:"
0803:                            + fault.toString(), fault);
0804:                } catch (Fault fault) {
0805:                    throw new MarkupContentException(MarkupContentException
0806:                            .getFaultErrorCode(fault), "Fault from producer:"
0807:                            + fault.toString(), fault);
0808:                } catch (WSRPConsumerRewriterException ex) {
0809:                    throw new MarkupContentException(
0810:                            WSRPConsumerErrorCode.INVALID_REMOTE_CONTENT,
0811:                            "Rewriter Exception", ex);
0812:                } catch (RemoteException ex) {
0813:                    throw new MarkupContentException(
0814:                            WSRPConsumerErrorCode.REMOTE_EXCEPTION, ex
0815:                                    .toString(), ex);
0816:                }
0817:
0818:            }
0819:
0820:            /**
0821:             * Popluate the response object using cached markup
0822:             * for this request.
0823:             *
0824:             * @param markupConfig object containing static information to process the request.
0825:             * @param request request object that is already populated.
0826:             * @param response response object to be polutated
0827:             * @param cacheEntry existing valid cache entry
0828:             * @exception com.sun.portal.container.ContainerException
0829:             * @exception com.sun.portal.container.ContentException
0830:             */
0831:
0832:            private void getCachedMarkup(MarkupConfig markupConfig,
0833:                    GetMarkupRequest request, GetMarkupResponse response,
0834:                    CacheEntry cacheEntry) throws ContainerException,
0835:                    ContentException {
0836:
0837:                if (logger.isLoggable(Level.FINEST)) {
0838:                    String[] param = { "MarkupRequest",
0839:                            ContainerToString.toStringGetMarkupRequest(request) };
0840:                    logger.log(Level.FINEST, "PSWS_CSPWCMI0007");
0841:                }
0842:
0843:                String markupString = cacheEntry.getMarkupContent()
0844:                        .getContent();
0845:                if (cacheEntry.getMarkupContent().needRewrite()) {
0846:
0847:                    WSRPConsumerRewriter rewriter = getWSRPConsumerRewriter(
0848:                            markupConfig, request);
0849:
0850:                    try {
0851:                        markupString = rewriter.rewrite(markupString, request
0852:                                .getHttpServletRequest());
0853:                    } catch (WSRPConsumerRewriterException ex) {
0854:                        throw new MarkupContentException(
0855:                                WSRPConsumerErrorCode.INVALID_REMOTE_CONTENT,
0856:                                "Rewriter Exception", ex);
0857:                    }
0858:                }
0859:                response.setMarkup(new StringBuffer(markupString));
0860:
0861:                String title = cacheEntry.getMarkupContent().getTitleResource();
0862:                if (title == null) {
0863:                    title = getTitleFromPortletDescription(markupConfig,
0864:                            request);
0865:                }
0866:
0867:                response.setTitle(title);
0868:                if (logger.isLoggable(Level.FINEST))
0869:                    logger.log(Level.FINEST, "PSWS_CSPWCMI0008");
0870:
0871:            }
0872:
0873:            //******************************************************
0874:            //
0875:            // THESE METHODS ARE COMMON FOR BOTH getMarkup() AND
0876:            // performBlockingAction
0877:            //
0878:            //******************************************************
0879:
0880:            /**
0881:             * All the common parameters for markup and
0882:             * performBlockingInteraction are encapsulated in a
0883:             * local class CommonRequestParams. This method uses the
0884:             * information in the markupConfig and in the request object to
0885:             * populate this object. This method is called by both getMarkup and
0886:             * executeAction.
0887:             *
0888:             * @param markupConfig
0889:             * @param request
0890:             * @param response
0891:             * @param navigationalState
0892:             * @param origCacheEntry
0893:             * @exception com.sun.portal.container.ContainerException
0894:             * @exception com.sun.portal.container.ContentException
0895:             */
0896:
0897:            private CommonRequestParams getCommonRequestParams(
0898:                    MarkupConfig markupConfig, ContainerRequest request,
0899:                    ContainerResponse response) throws ContainerException,
0900:                    ContentException {
0901:
0902:                //
0903:                // Get registration context if required
0904:                //
0905:
0906:                RegistrationContext registrationContext = null;
0907:                if (markupConfig.getServiceDescription()
0908:                        .isRequiresRegistration()) {
0909:                    registrationContext = markupConfig.getProducerEntity()
0910:                            .getRegistrationContext();
0911:                    if (registrationContext == null) {
0912:                        throw new ContainerException("Registration required.");
0913:                    }
0914:                }
0915:
0916:                //
0917:                // Get the portletContext
0918:                //
0919:
0920:                PortletContext portletContext = markupConfig
0921:                        .getPortletContext();
0922:
0923:                //
0924:                // RuntimeContext
0925:                //
0926:                RuntimeContext runtimeContext = getRuntimeContext(markupConfig,
0927:                        request);
0928:
0929:                //
0930:                // UserContext
0931:                //
0932:
0933:                UserContext userContext = _userContextManager.getUserContext(
0934:                        markupConfig, request);
0935:
0936:                //
0937:                // Ready to create the object containing
0938:                // common parameters for WSRP markup parameters.
0939:                //
0940:
0941:                return new CommonRequestParams(registrationContext,
0942:                        portletContext, runtimeContext, userContext);
0943:
0944:            }
0945:
0946:            /**
0947:             * Create instance of RuntimeContext using information in
0948:             * markupConfig and request.
0949:             *
0950:             * @param markupConfig
0951:             * @param request
0952:             * @exception com.sun.portal.container.ContainerException
0953:             * @exception com.sun.portal.container.ContentException
0954:             */
0955:            private RuntimeContext getRuntimeContext(MarkupConfig markupConfig,
0956:                    ContainerRequest request) throws ContainerException,
0957:                    ContentException {
0958:
0959:                String userAuthentication = MarkupUtil.getAuthType(request);
0960:
0961:                String portletInstanceKey = markupConfig
0962:                        .getPortletInstanceKey();
0963:
0964:                String namespacePrefix = markupConfig.getNamespacePrefix();
0965:
0966:                Templates templates = null;
0967:                if (Boolean.TRUE.equals(markupConfig.getPortletDescription()
0968:                        .getDoesUrlTemplateProcessing())) {
0969:                    WSRPConsumerRewriter rewriter = getWSRPConsumerRewriter(
0970:                            markupConfig, request);
0971:
0972:                    templates = rewriter.getTemplates(request
0973:                            .getHttpServletRequest());
0974:                    //_debug.debugMessage(templates.getResourceTemplate());
0975:                    //_debug.debugMessage(templates.getRenderTemplate());
0976:                    //_debug.debugMessage(templates.getBlockingActionTemplate());
0977:                }
0978:
0979:                String sessionId = _producerSessionManager
0980:                        .getProducerSessionId(markupConfig, request);
0981:
0982:                // make the RuntimeContext object and return it.
0983:
0984:                return new RuntimeContext(userAuthentication,
0985:                        portletInstanceKey, namespacePrefix, templates,
0986:                        sessionId, (Extension[]) null);
0987:
0988:            }
0989:
0990:            /**
0991:             * Create instance of MakrupParams based on information
0992:             * collected from all the parameters.
0993:             *
0994:             * @param markupConfig
0995:             * @param request
0996:             * @param navigationalState
0997:             * @param cacheEntry
0998:             */
0999:            private MarkupParams getMarkupParams(MarkupConfig markupConfig,
1000:                    ContainerRequest request, String navigationalState) {
1001:
1002:                //
1003:                // Get secureClientCommunitcation from the httpRequest.
1004:                //
1005:                boolean secureClientCommunication = request
1006:                        .getHttpServletRequest().isSecure();
1007:
1008:                //
1009:                // Get client data from the httpRequest
1010:                //
1011:
1012:                ClientData clientData = new ClientData(request
1013:                        .getHttpServletRequest().getHeader("User-Agent"),
1014:                        (Extension[]) null);
1015:
1016:                //
1017:                // Get locale
1018:                // TODO: Check with Elaine
1019:                String locales[] = new String[] { MarkupUtil
1020:                        .getProviderContext(request).getLocaleString() };
1021:
1022:                //
1023:                // Get mimeTypes
1024:                // TODO: Verify:: content is same as mime ?
1025:                // TODO: Container interface need to specify the behavior -
1026:                // if null or empty list would be created.
1027:
1028:                List mimetypes = request.getAllowableContentType();
1029:                String[] mimes = new String[mimetypes.size()];
1030:                mimetypes.toArray(mimes);
1031:
1032:                //
1033:                // Get mode and convert it to the wsrp defined constant
1034:                // Can't be null ( TODO guranteed by the container interface and
1035:                // check by mapChannelModeToWSRP
1036:                //
1037:
1038:                String mode = WSRPToContainerMap.mapChannelModeToWSRP(request
1039:                        .getChannelMode());
1040:
1041:                //
1042:                // Get window state and convert it to the wsrp defined constant
1043:                // Can't be null
1044:                // ( TODO guranteed by the container interface and
1045:                // check by mapWindowStateToWSRP
1046:                //
1047:                String windowState = WSRPToContainerMap
1048:                        .mapWindowStateToWSRP(request.getWindowState());
1049:
1050:                //
1051:                // Get allowed window state and portlet modes
1052:                //
1053:                String[] allowedWindowStates = WSRPToContainerMap
1054:                        .mapWindowStateToWSRP(request.getAllowableWindowState());
1055:                String[] allowedPortletModes = WSRPToContainerMap
1056:                        .mapChannelModeToWSRP(request.getAllowableChannelMode());
1057:
1058:                //
1059:                // Get character encoding
1060:                //
1061:
1062:                String[] markupCharacterSets = new String[] { request
1063:                        .getCharacterEncoding() };
1064:                //
1065:                // We have all the information to create markupParams
1066:                // Let's read it.
1067:                //
1068:                return new MarkupParams(secureClientCommunication, locales,
1069:                        mimes, mode, windowState, clientData,
1070:                        navigationalState, markupCharacterSets,
1071:                        null, // populated later
1072:                        allowedPortletModes, allowedWindowStates,
1073:                        (Extension[]) null);
1074:
1075:            }
1076:
1077:            /**
1078:             * Shared method to process the MarkupContext returned by getMarkup and
1079:             * performBlockingAction. It returns an instance of MarkupContent that is
1080:             * sent. It returns null if makrupContext is null.
1081:             *
1082:             * @param request
1083:             * @param markupContext
1084:             * @param origCacheEntry
1085:             * @param channelMode
1086:             * @param windowState
1087:             * @exception com.sun.portal.container.ContainerException
1088:             */
1089:            private MarkupContent processMarkupContext(
1090:                    MarkupConfig markupConfig, ContainerRequest request,
1091:                    MarkupContext markupContext, CacheEntry origCacheEntry,
1092:                    MarkupParams markupParams) throws ContainerException,
1093:                    ContentException {
1094:
1095:                MarkupContent markupContent = null;
1096:                CacheEntry newCacheEntry = null;
1097:
1098:                //
1099:                // input parameter sanity check
1100:                //
1101:
1102:                if (markupContext == null) {
1103:                    _cacheManager.invalidateCacheEntry(markupConfig, request);
1104:                    return null;
1105:                }
1106:
1107:                boolean needRewrite = Boolean.TRUE.equals(markupContext
1108:                        .getRequiresUrlRewriting());
1109:
1110:                //
1111:                // TODO Ask Elaine about the binary output
1112:                //
1113:
1114:                //
1115:                // Process the markup
1116:                //
1117:
1118:                CacheControl cacheControl = markupContext.getCacheControl();
1119:
1120:                //
1121:                // Process if asked to use the old the cache
1122:                // or if new content with or without cache information
1123:                // is sent back.
1124:
1125:                if (Boolean.TRUE.equals(markupContext.getUseCachedMarkup())) {
1126:                    if (cacheControl != null) {
1127:                        newCacheEntry = new CacheEntry(origCacheEntry
1128:                                .getMarkupContent(), cacheControl, markupParams);
1129:                        _cacheManager.putCacheEntry(markupConfig, request,
1130:                                newCacheEntry);
1131:                    }
1132:                    markupContent = origCacheEntry.getMarkupContent();
1133:                } else {
1134:
1135:                    //
1136:                    // If new cacheControl is sent, create a new cache entry
1137:                    // with the new content that is sent
1138:                    // else delete the cache.
1139:                    // Optimize
1140:
1141:                    String markupString = getMarkupString(markupContext);
1142:                    String title = markupContext.getPreferredTitle();
1143:                    if (title == null) {
1144:                        title = getTitleFromPortletDescription(markupConfig,
1145:                                request);
1146:                    }
1147:
1148:                    if (cacheControl != null) {
1149:
1150:                        if (markupString != null) {
1151:                            if (cacheControl.getUserScope() == "perUser") {
1152:                                if (needRewrite) {
1153:                                    WSRPConsumerRewriter rewriter = getWSRPConsumerRewriter(
1154:                                            markupConfig, request);
1155:
1156:                                    try {
1157:                                        markupString = rewriter
1158:                                                .rewrite(
1159:                                                        markupString,
1160:                                                        request
1161:                                                                .getHttpServletRequest());
1162:                                    } catch (WSRPConsumerRewriterException ex) {
1163:                                        throw new MarkupContentException(
1164:                                                WSRPConsumerErrorCode.INVALID_REMOTE_CONTENT,
1165:                                                "Rewriter Exception", ex);
1166:                                    }
1167:                                    needRewrite = false;
1168:                                }
1169:                            }
1170:                        }
1171:                        markupContent = new MarkupContent(markupString, title,
1172:                                needRewrite);
1173:                        newCacheEntry = new CacheEntry(markupContent,
1174:                                cacheControl, markupParams);
1175:
1176:                        _cacheManager.putCacheEntry(markupConfig, request,
1177:                                newCacheEntry);
1178:                    } else {
1179:                        _cacheManager.invalidateCacheEntry(markupConfig,
1180:                                request);
1181:                        markupContent = new MarkupContent(markupString, title,
1182:                                needRewrite);
1183:                    }
1184:                }
1185:
1186:                return markupContent;
1187:
1188:            }
1189:
1190:            //***************************************************************
1191:            //
1192:            // THESE METHODS ARE SPECIFIC FOR performBlockingInteraction
1193:            //
1194:            //**************************************************************
1195:
1196:            /**
1197:             * Create an instance of InteractionParams to be
1198:             * passed to remote portlet.
1199:             *
1200:             * @param markupConfig
1201:             * @param request
1202:             */
1203:
1204:            private InteractionParams getInteractionParams(
1205:                    MarkupConfig markupConfig, ExecuteActionRequest request)
1206:                    throws ContainerException, ContentException {
1207:
1208:                //
1209:                // Get interaction state
1210:                //
1211:
1212:                String interactionState = null;
1213:                String[] interactionStateTemp = (String[]) request
1214:                        .getActionParameters().get(
1215:                                WSRPSpecKeys.INTERACTION_STATE);
1216:                if (interactionStateTemp != null
1217:                        && interactionStateTemp.length > 0
1218:                        && interactionStateTemp[0].length() > 0) {
1219:                    interactionState = interactionStateTemp[0];
1220:                }
1221:
1222:                //
1223:                // remove interaction state and navigational state
1224:                // to create just the form parameters
1225:                // TODO -- where are reservedParams coming from
1226:
1227:                NamedString[] formParameters = WSRPUtility
1228:                        .convertToNamedStrings(request.getActionParameters(),
1229:                                reservedParams);
1230:
1231:                //
1232:                // Calculate the optimum portletState
1233:                //
1234:                // for now, we are not calling the
1235:                // explicit clone method on the producer
1236:                // as suggested by the defn of
1237:                // "hasUserSpecificState", i.e. from the spec
1238:                //  if this is sent "true" by the producer,
1239:                // the consumer is suggested to do a
1240:                // explicit clone upfront as an optimization
1241:                // when placing the portlet on a users page
1242:                // - this instead of waiting for the implicit clone
1243:                // as we do currently. We may want to
1244:                // revisit this in the future  
1245:                //
1246:                // If according to the portlet handle
1247:                // obtained from the MarkupConfig, we are still
1248:                // dealing with default portlet handle, that means
1249:                // so far no state has been stored for this user on
1250:                // the producer or consumer side for this portlet.
1251:                // In that case, we send StateChange.cloneBeforeWrite.
1252:                //
1253:                // If the portletHandle has been modified, then
1254:                // we send StateChange.readWrite.
1255:                //
1256:
1257:                StateChange portletStateChange = null;
1258:
1259:                /* Commented for now, refer the above comments
1260:                Boolean hasUserSpecificState =
1261:                        markupConfig.getPortletDescription().getHasUserSpecificState();
1262:
1263:                if ( Boolean.TRUE.equals(hasUserSpecificState)) {
1264:                 */
1265:
1266:                //
1267:                // throw exception if user is anonymous
1268:                //
1269:                if (MarkupUtil.isAuthless(request)) {
1270:                    portletStateChange = StateChange.readOnly;
1271:                } else {
1272:                    if (markupConfig.isPortletHandleDefault()) {
1273:                        portletStateChange = StateChange.cloneBeforeWrite;
1274:                    } else {
1275:                        portletStateChange = StateChange.readWrite;
1276:                    }
1277:                }
1278:
1279:                /*
1280:                  Commented for now, refer the above comments
1281:                }
1282:                else {
1283:                    portletStateChange = StateChange.cloneBeforeWrite;
1284:                }*/
1285:
1286:                //
1287:                // UploadContexts
1288:                //
1289:                HttpServletRequest req = request.getHttpServletRequest();
1290:                String contentType = req.getContentType();
1291:                UploadContext[] uploadContexts = null;
1292:                if ((contentType != null)
1293:                        && !contentType
1294:                                .equals("application/x-www-form-urlencoded")
1295:                        && req.getContentLength() > 0) {
1296:
1297:                    ArrayList formParamList = new ArrayList();
1298:                    ArrayList uploadContextList = new ArrayList();
1299:                    int maxSize = WSRPConsumerConfig.getInstance()
1300:                            .getFileUploadMaxSize();
1301:
1302:                    if (logger.isLoggable(Level.FINEST))
1303:                        logger.log(Level.FINEST, "PSWS_CSPWCMI0011", ""
1304:                                + req.getContentLength());
1305:
1306:                    try {
1307:
1308:                        // Create instance of FileUpload
1309:                        //
1310:                        FileUpload fileUpload = new FileUpload(
1311:                                new DefaultFileItemFactory());
1312:                        if (maxSize != -1) {
1313:                            fileUpload.setSizeMax(maxSize);
1314:                        }
1315:
1316:                        //
1317:                        // read in parts
1318:                        //
1319:                        List fileItemList = fileUpload.parseRequest(request
1320:                                .getHttpServletRequest());
1321:
1322:                        if (fileItemList != null) {
1323:                            for (int i = 0; i < fileItemList.size(); i++) {
1324:                                FileItem item = (FileItem) fileItemList.get(i);
1325:                                if (item.isFormField()) {
1326:                                    NamedString formParam = new NamedString();
1327:                                    formParam.setName(item.getFieldName());
1328:                                    formParam.setValue(item.getString());
1329:                                    formParamList.add(formParam);
1330:                                } else {
1331:                                    UploadContext uploadContext = getUploadContext(item);
1332:                                    uploadContextList.add(uploadContext);
1333:                                }
1334:                            }
1335:                        }
1336:                        formParameters = new NamedString[formParamList.size()];
1337:                        formParamList.toArray(formParameters);
1338:                        uploadContexts = new UploadContext[uploadContextList
1339:                                .size()];
1340:                        uploadContextList.toArray(uploadContexts);
1341:                    } catch (SizeLimitExceededException ex) {
1342:                        throw new MarkupContentException(
1343:                                WSRPConsumerErrorCode.READING_UPLOAD_SIZE_LIMIT,
1344:                                "request more than configured upload limit:"
1345:                                        + maxSize, ex);
1346:                    } catch (FileUploadException ex) {
1347:                        throw new MarkupContentException(
1348:                                WSRPConsumerErrorCode.ERROR_IN_READING_UPLOAD,
1349:                                "Error in file upload", ex);
1350:                    }
1351:                }
1352:
1353:                //
1354:                // We are ready to send it out
1355:
1356:                return new InteractionParams(portletStateChange,
1357:                        interactionState, formParameters, uploadContexts,
1358:                        (Extension[]) null);
1359:
1360:            }
1361:
1362:            private UploadContext getUploadContext(FileItem item)
1363:                    throws ContainerException {
1364:
1365:                UploadContext uploadContext = new UploadContext();
1366:
1367:                //
1368:                // set the mime type
1369:                //
1370:                uploadContext.setMimeType(item.getContentType());
1371:
1372:                //
1373:                // Set attributes
1374:
1375:                NamedString[] mimeAttributes = new NamedString[2];
1376:
1377:                mimeAttributes[0] = new NamedString();
1378:                mimeAttributes[0].setName(FileUpload.CONTENT_DISPOSITION);
1379:                mimeAttributes[0].setValue(FileUpload.FORM_DATA + ";"
1380:                        + " name=\"" + item.getFieldName() + "\";"
1381:                        + " filename=\"" + item.getName() + "\"");
1382:                mimeAttributes[1] = new NamedString();
1383:                mimeAttributes[1].setName(FileUpload.CONTENT_TYPE);
1384:                mimeAttributes[1].setValue(item.getContentType());
1385:
1386:                uploadContext.setMimeAttributes(mimeAttributes);
1387:
1388:                //
1389:                // set data
1390:                //
1391:                uploadContext.setUploadData(item.get());
1392:
1393:                return uploadContext;
1394:
1395:            }
1396:
1397:            /**
1398:             * Returns list of parameters that are local
1399:             * (navigational state and interaction state)
1400:             * that must be filtered out from the action
1401:             * parameters(aka form parameters) before calling
1402:             * performBlockingInteraction
1403:             */
1404:            static private List getReservedParams() {
1405:                ArrayList excludeParams = new ArrayList();
1406:                excludeParams.add(WSRPSpecKeys.NAVIGATIONAL_STATE);
1407:                excludeParams.add(WSRPSpecKeys.INTERACTION_STATE);
1408:                return excludeParams;
1409:            }
1410:
1411:            private String getPortalServerURLPrefix(ContainerRequest request) {
1412:
1413:                HttpServletRequest httpRequest = request
1414:                        .getHttpServletRequest();
1415:                return MarkupUtil.getProviderContext(request).getRequestServer(
1416:                        httpRequest)
1417:                        + httpRequest.getContextPath();
1418:            }
1419:
1420:            private WSRPConsumerRewriter getWSRPConsumerRewriter(
1421:                    MarkupConfig markupConfig, ContainerRequest request)
1422:                    throws ContainerException {
1423:
1424:                WSRPConsumerRewriter rewriter = new WSRPConsumerRewriter(
1425:                        request.getChannelURLFactory(),
1426:                        getPortalServerURLPrefix(request),
1427:                        _producerSessionManager.getCookieHandleKey(
1428:                                markupConfig, request), markupConfig
1429:                                .getNamespacePrefix());
1430:
1431:                return rewriter;
1432:            }
1433:
1434:            private String getTitleFromPortletDescription(
1435:                    MarkupConfig markupConfig, ContainerRequest request) {
1436:
1437:                //
1438:                // use the default title from PortletDescription
1439:                //
1440:                String locale = MarkupUtil.getProviderContext(request)
1441:                        .getLocaleString();
1442:                String xmlLocale = WSRPConsumerUtil.getXMLLocale(locale);
1443:
1444:                PortletDescription portletDescription = markupConfig
1445:                        .getPortletDescription();
1446:
1447:                LocalizedString localizedTitle = portletDescription.getTitle();
1448:
1449:                String title = localizedTitle.getValue();
1450:                //
1451:                // look up resource list only if the user's locale does not
1452:                // match the default locale of the title
1453:                //
1454:                if ((localizedTitle.getLang() != null)
1455:                        && !(localizedTitle.getLang().equals(xmlLocale))) {
1456:                    ResourceList resourceList = markupConfig
1457:                            .getServiceDescription().getResourceList();
1458:                    String resourceName = localizedTitle.getResourceName();
1459:
1460:                    String titleResource = WSRPConsumerUtil.getResource(
1461:                            resourceList, resourceName, xmlLocale);
1462:                    if (titleResource != null) {
1463:                        title = titleResource;
1464:                    }
1465:                }
1466:
1467:                return title;
1468:
1469:            }
1470:
1471:            String getMarkupString(MarkupContext markupContext)
1472:                    throws ContentException {
1473:                String markupString = markupContext.getMarkupString();
1474:                if (markupString != null) {
1475:                    return markupString;
1476:                }
1477:                byte[] markupBinary = markupContext.getMarkupBinary();
1478:                String mimeType = markupContext.getMimeType();
1479:                int charsetIndex = mimeType.indexOf("charset=");
1480:                if ((markupBinary != null) && (charsetIndex != -1)) {
1481:                    int valueIndex = mimeType.indexOf("=") + 1;
1482:                    String charset = mimeType.substring(valueIndex);
1483:
1484:                    try {
1485:                        return new String(markupBinary, charset);
1486:                    } catch (UnsupportedEncodingException ex) {
1487:                        throw new MarkupContentException(
1488:                                WSRPConsumerErrorCode.BINARY_CONTENT_NOT_SUPPORTED,
1489:                                "Binary content not supported", ex);
1490:                    }
1491:                }
1492:                return null;
1493:            }
1494:
1495:            private void addExtensions(UserContext ctx, GetMarkupRequest request) {
1496:                try {
1497:                    String userId = request.getUserID();
1498:                    HttpServletRequest req = request.getHttpServletRequest();
1499:                    SSOToken ssoToken = (SSOToken) req
1500:                            .getAttribute(SSOTOKEN_STRING);
1501:                    SSOTokenManager tokenManager = SSOTokenManager
1502:                            .getInstance();
1503:                    tokenManager.validateToken(ssoToken);
1504:                    SSOTokenID id = ssoToken.getTokenID();
1505:                    SOAPFactory sf = SOAPFactory.newInstance();
1506:                    SOAPElement se = sf
1507:                            .createElement(IdentityPropagationConstants.USERCTX_EXTN_SSOTOKEN_ELEMENT);
1508:                    se
1509:                            .setAttribute(
1510:                                    IdentityPropagationConstants.USERCTX_EXTN_SSOTOKEN_VALUE,
1511:                                    id.toString());
1512:                    Extension ssoTokenExtn = new Extension();
1513:                    ssoTokenExtn.set_any(se);
1514:                    Extension ext[] = { ssoTokenExtn };
1515:                    ctx.setExtensions(ext);
1516:                } catch (SSOException se) {
1517:                    // Just logging and ignoring the SSOToken Identity Propagation
1518:                    if (logger.isLoggable(Level.SEVERE)) {
1519:                        logger.log(Level.SEVERE, "PSWS_CSPWCMI0020", se);
1520:                    }
1521:                } catch (SOAPException soe) {
1522:                    // Just logging and ignoring the SSOToken Identity Propagation
1523:                    if (logger.isLoggable(Level.SEVERE)) {
1524:                        logger.log(Level.SEVERE, "PSWS_CSPWCMI0020", soe);
1525:                    }
1526:                }
1527:            }
1528:        }
w__w___w___._j_a___v__a__2__s_.__c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.