001: /**
002: * Copyright 2003 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.wsrp.consumer.markup.impl;
013:
014: import com.sun.portal.container.ContainerRequest;
015: import com.sun.portal.container.ContainerException;
016: import com.sun.portal.container.ContentException;
017:
018: import com.sun.portal.wsrp.common.stubs.SessionContext;
019: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Markup_PortType;
020:
021: import com.sun.portal.wsrp.consumer.markup.ProducerSessionManager;
022: import com.sun.portal.wsrp.consumer.markup.MarkupConfig;
023: import com.sun.portal.wsrp.consumer.common.RemoteServiceStubManager;
024: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
025: import com.sun.portal.log.common.PortalLogger;
026:
027: import java.net.URL;
028: import java.rmi.RemoteException;
029: import java.util.logging.Level;
030: import java.util.logging.Logger;
031:
032: /**
033: * This is the implementation of ProducerSessionManager for anonymous/authless
034: * user that has methods to manage the session with a WSRP Producer.
035: * When ever Anonymous is not allowed to have session, means
036: * anonymous desktop shouldn't be configured with a portlet from
037: * producer that requires initCookie. This implementation is used for
038: * anonymous user when that is the case.Having such portlet means
039: * the markup stub needs to be saved for the session and for
040: * anonymous user, there is no place to store it.
041: * Hence all session information is stored in client properties
042: * for anonymous user
043: *
044: */
045:
046: public class ProducerSessionManagerNoInitCookie implements
047: ProducerSessionManager {
048:
049: public final static String WSRP_SESSION_ID = "wsrp_session_id_";
050:
051: private static Logger logger = PortalLogger
052: .getLogger(ProducerSessionManagerNoInitCookie.class);
053:
054: /**
055: * Check javadoc of interface.
056: *
057: * @param markupConfig
058: * @param request
059: * @param sessionContext
060: * @exception com.sun.portal.container.ContainerException
061: * @exception com.sun.portal.container.ContentException
062: */
063: public void processSessionContext(MarkupConfig markupConfig,
064: ContainerRequest request, SessionContext sessionContext)
065: throws ContainerException, ContentException {
066:
067: String sessionId = null;
068:
069: if (sessionContext != null) {
070:
071: sessionId = sessionContext.getSessionID();
072:
073: MarkupUtil.getProviderContext(request).setClientProperty(
074: WSRP_SESSION_ID + request.getEntityID(), sessionId);
075:
076: }
077:
078: //
079: // debug section
080: //
081: if (logger.isLoggable(Level.FINEST)) {
082: String[] param = { "session id ", sessionId };
083: logger.log(Level.FINEST, "PSWS_CSPWCMI0007", param);
084: }
085: }
086:
087: /**
088: * Check javadoc of interface.
089: *
090: * @param markupConfig
091: * @param request
092: * @exception com.sun.portal.container.ContainerException
093: * @exception com.sun.portal.container.ContentException
094: */
095: public String getProducerSessionId(MarkupConfig markupConfig,
096: ContainerRequest request) throws ContainerException,
097: ContentException {
098:
099: return (String) MarkupUtil.getProviderContext(request)
100: .getClientProperty(
101: WSRP_SESSION_ID + request.getEntityID());
102:
103: }
104:
105: /**
106: * Check javadoc of interface.
107: *
108: * @param markupConfig
109: * @param request
110: * @exception com.sun.portal.container.ContainerException
111: * @exception com.sun.portal.container.ContentException
112: */
113: public void resetSessionId(String invalidSessionId,
114: MarkupConfig markupConfig, ContainerRequest request)
115: throws ContainerException, ContentException {
116:
117: //
118: // debug section
119: //
120:
121: if (logger.isLoggable(Level.FINEST)) {
122: String[] param = { "invalid session", invalidSessionId };
123: logger.log(Level.FINEST, "PSWS_CSPWCMI0007", param);
124: }
125:
126: MarkupUtil.getProviderContext(request).setClientProperty(
127: WSRP_SESSION_ID + request.getEntityID(), (String) null);
128:
129: }
130:
131: /**
132: * This gets a stub that can be shared by all users since
133: * anonymous shouldn't be configured with a portlet
134: * that requires a stub that can't be shared.
135: *
136: * @param markupConfig
137: * @param request
138: */
139: public WSRP_v1_Markup_PortType getMarkupPortType(
140: MarkupConfig markupConfig, ContainerRequest request)
141: throws ContainerException, ContentException {
142:
143: WSRP_v1_Markup_PortType portType = null;
144:
145: URL producerURL = markupConfig.getProducerEntity().getURL();
146:
147: RemoteServiceStubManager rssm = markupConfig
148: .getRemoteServiceStubManager();
149:
150: try {
151:
152: //
153: // retrieve the markup port type endpoint from
154: // the producer entity
155: //
156:
157: String endpoint = markupConfig.getProducerEntity()
158: .getMarkupEndpoint();
159:
160: portType = rssm.getMarkupPortType(endpoint,
161: RemoteServiceStubManager.FOR_ALL);
162: } catch (WSRPConsumerException ex) {
163: throw new ContainerException(ex.getMessage(), ex);
164: }
165:
166: if (logger.isLoggable(Level.FINEST))
167: logger.log(Level.FINEST, "PSWS_CSPWCMI0017");
168:
169: return portType;
170:
171: }
172:
173: /**
174: *
175: * this should never be called for anonymous
176: * since it is called only when InvalidCookieFault is
177: * thrown for a markup stub, which won't be the case for
178: * anonymous as it shouldn't be configured with a portlet
179: * that needs initCookie at the first place.
180: */
181: public void resetMarkupPortType(
182: WSRP_v1_Markup_PortType invalidPortType,
183: MarkupConfig markupConfig, ContainerRequest request)
184: throws ContainerException, ContentException {
185:
186: throw new ContainerException(
187: "Anonymnous user can't be configured "
188: + " with a portlet requiring initCookie.");
189: }
190:
191: /**
192: * Return null, since there is no cookie setting for
193: * anonymous.
194: *
195: * @param markupConfig
196: * @param request
197: */
198: public String getCookieHandleKey(MarkupConfig markupConfig,
199: ContainerRequest request) throws ContainerException {
200:
201: return null;
202:
203: }
204:
205: }
|