001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.wsrp.producer;
023:
024: import org.jboss.logging.Logger;
025: import org.jboss.portal.jems.as.system.AbstractJBossService;
026: import org.jboss.portal.portlet.NoSuchPortletException;
027: import org.jboss.portal.portlet.Portlet;
028: import org.jboss.portal.portlet.PortletInvoker;
029: import org.jboss.portal.portlet.PortletInvokerException;
030: import org.jboss.portal.portlet.info.PortletInfo;
031: import org.jboss.portal.registration.Registration;
032: import org.jboss.portal.registration.RegistrationLocal;
033: import org.jboss.portal.registration.RegistrationManager;
034: import org.jboss.portal.wsrp.ResponseDebugFactory;
035: import org.jboss.portal.wsrp.WSRPExceptionFactory;
036: import org.jboss.portal.wsrp.WSRPProducer;
037: import org.jboss.portal.wsrp.core.AccessDeniedFault;
038: import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
039: import org.jboss.portal.wsrp.core.ClonePortlet;
040: import org.jboss.portal.wsrp.core.CookieProtocol;
041: import org.jboss.portal.wsrp.core.DestroyPortlets;
042: import org.jboss.portal.wsrp.core.DestroyPortletsResponse;
043: import org.jboss.portal.wsrp.core.GetMarkup;
044: import org.jboss.portal.wsrp.core.GetPortletDescription;
045: import org.jboss.portal.wsrp.core.GetPortletProperties;
046: import org.jboss.portal.wsrp.core.GetPortletPropertyDescription;
047: import org.jboss.portal.wsrp.core.GetServiceDescription;
048: import org.jboss.portal.wsrp.core.InconsistentParametersFault;
049: import org.jboss.portal.wsrp.core.InitCookie;
050: import org.jboss.portal.wsrp.core.InvalidCookieFault;
051: import org.jboss.portal.wsrp.core.InvalidHandleFault;
052: import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
053: import org.jboss.portal.wsrp.core.InvalidSessionFault;
054: import org.jboss.portal.wsrp.core.InvalidUserCategoryFault;
055: import org.jboss.portal.wsrp.core.MarkupResponse;
056: import org.jboss.portal.wsrp.core.MissingParametersFault;
057: import org.jboss.portal.wsrp.core.ModifyRegistration;
058: import org.jboss.portal.wsrp.core.OperationFailedFault;
059: import org.jboss.portal.wsrp.core.PerformBlockingInteraction;
060: import org.jboss.portal.wsrp.core.PortletContext;
061: import org.jboss.portal.wsrp.core.PortletDescription;
062: import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
063: import org.jboss.portal.wsrp.core.PortletPropertyDescriptionResponse;
064: import org.jboss.portal.wsrp.core.PortletStateChangeRequiredFault;
065: import org.jboss.portal.wsrp.core.PropertyList;
066: import org.jboss.portal.wsrp.core.RegistrationContext;
067: import org.jboss.portal.wsrp.core.RegistrationData;
068: import org.jboss.portal.wsrp.core.RegistrationState;
069: import org.jboss.portal.wsrp.core.ReleaseSessions;
070: import org.jboss.portal.wsrp.core.ReturnAny;
071: import org.jboss.portal.wsrp.core.ServiceDescription;
072: import org.jboss.portal.wsrp.core.SetPortletProperties;
073: import org.jboss.portal.wsrp.core.UnsupportedLocaleFault;
074: import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
075: import org.jboss.portal.wsrp.core.UnsupportedModeFault;
076: import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
077: import org.jboss.portal.wsrp.producer.config.ProducerConfiguration;
078: import org.jboss.portal.wsrp.producer.config.ProducerConfigurationService;
079: import org.jboss.portal.wsrp.producer.config.ProducerRegistrationRequirements;
080:
081: import java.rmi.RemoteException;
082: import java.util.HashSet;
083: import java.util.Set;
084:
085: /**
086: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
087: * @version $Revision: 9360 $
088: * @since 2.4
089: */
090: public class WSRPProducerImpl extends AbstractJBossService implements
091: WSRPProducer {
092: /** logger used for logging ;) */
093: private final Logger log = Logger.getLogger(getClass());
094:
095: /** The invoker used to retrieve portlet information and invoke methods. */
096: private PortletInvoker invoker;
097:
098: /** Handles Markup interface calls. */
099: private MarkupHandler markupHandler;
100:
101: /** Handles ServiceDescription interface calls. */
102: private ServiceDescriptionHandler serviceDescriptionHandler;
103:
104: /** Handles Registration interface calls. */
105: private RegistrationHandler registrationHandler;
106:
107: /** Handles Portlet Management interface calls. */
108: private PortletManagementHandler portletManagementHandler;
109:
110: /** Registration configuration service */
111: private ProducerConfiguration producerConfiguration;
112:
113: /** Registration Manager */
114: private RegistrationManager registrationManager;
115:
116: private int sessionExpirationTime = DEFAULT_SESSION_EXPIRATION_TIME;
117:
118: private CookieProtocol requiresInitCookie = CookieProtocol.none;
119:
120: /** Supported locales. */
121: private String[] supportedLocales = new String[] { "en", "en-US" };
122:
123: private ProducerConfigurationService configurationService;
124:
125: public WSRPProducerImpl() {
126: markupHandler = new MarkupHandler(this );
127: serviceDescriptionHandler = new ServiceDescriptionHandler(this );
128: registrationHandler = new RegistrationHandler(this );
129: portletManagementHandler = new PortletManagementHandler(this );
130: }
131:
132: public ProducerRegistrationRequirements getProducerRegistrationRequirements() {
133: return producerConfiguration.getRegistrationRequirements();
134: }
135:
136: // ServiceDescription implementation ********************************************************************************
137:
138: public ServiceDescription getServiceDescription(
139: GetServiceDescription gs) throws InvalidRegistrationFault,
140: OperationFailedFault, RemoteException {
141: log.debug("getServiceDescription invoked");
142: ServiceDescription sd = serviceDescriptionHandler
143: .getServiceDescription(gs);
144:
145: //to avoid unnesessary processing
146: if (log.isDebugEnabled()) {
147: //catch all exceptions as we don't wan't to blow producer flow
148: try {
149: log.debug("getServiceDescription() response data: ");
150: log.debug(ResponseDebugFactory
151: .extractServiceDescription(sd).toString());
152: } catch (Exception e) {
153: e.printStackTrace();
154: }
155: }
156:
157: log.debug("end getServiceDescription");
158: return sd;
159: }
160:
161: // MarkupService implementation *************************************************************************************
162:
163: public MarkupResponse getMarkup(GetMarkup getMarkup)
164: throws UnsupportedWindowStateFault, InvalidCookieFault,
165: InvalidSessionFault, AccessDeniedFault,
166: InconsistentParametersFault, InvalidHandleFault,
167: UnsupportedLocaleFault, UnsupportedModeFault,
168: OperationFailedFault, MissingParametersFault,
169: InvalidUserCategoryFault, InvalidRegistrationFault,
170: UnsupportedMimeTypeFault, RemoteException {
171: log.debug("getMarkup invoked");
172: MarkupResponse response = markupHandler.getMarkup(getMarkup);
173: log.debug("end getMarkup");
174: return response;
175: }
176:
177: public BlockingInteractionResponse performBlockingInteraction(
178: PerformBlockingInteraction performBlockingInteraction)
179: throws InvalidSessionFault, UnsupportedModeFault,
180: UnsupportedMimeTypeFault, OperationFailedFault,
181: UnsupportedWindowStateFault, UnsupportedLocaleFault,
182: AccessDeniedFault, PortletStateChangeRequiredFault,
183: InvalidRegistrationFault, MissingParametersFault,
184: InvalidUserCategoryFault, InconsistentParametersFault,
185: InvalidHandleFault, InvalidCookieFault, RemoteException {
186: log.debug("performBlockingInteraction invoked");
187: BlockingInteractionResponse interactionResponse = markupHandler
188: .performBlockingInteraction(performBlockingInteraction);
189: log.debug("end performBlockingInteraction");
190: return interactionResponse;
191: }
192:
193: public ReturnAny releaseSessions(ReleaseSessions releaseSessions)
194: throws InvalidRegistrationFault, OperationFailedFault,
195: MissingParametersFault, AccessDeniedFault, RemoteException {
196: log.debug("releaseSessions invoked");
197: ReturnAny returnAny = markupHandler
198: .releaseSessions(releaseSessions);
199: log.debug("end releaseSessions");
200: return returnAny;
201: }
202:
203: public ReturnAny initCookie(InitCookie initCookie)
204: throws AccessDeniedFault, OperationFailedFault,
205: InvalidRegistrationFault, RemoteException {
206: log.debug("initCookie invoked");
207: ReturnAny returnAny = markupHandler.initCookie(initCookie);
208: log.debug("end initCookie");
209: return returnAny;
210: }
211:
212: // Registration implementation **************************************************************************************
213:
214: public RegistrationContext register(RegistrationData register)
215: throws MissingParametersFault, OperationFailedFault,
216: RemoteException {
217: log.debug("register invoked");
218: RegistrationContext registrationContext = registrationHandler
219: .register(register);
220: log.debug("end register");
221: return registrationContext;
222: }
223:
224: public ReturnAny deregister(RegistrationContext deregister)
225: throws OperationFailedFault, InvalidRegistrationFault,
226: RemoteException {
227: log.debug("deregister invoked");
228: ReturnAny returnAny = registrationHandler
229: .deregister(deregister);
230: log.debug("end deregister");
231: return returnAny;
232: }
233:
234: public RegistrationState modifyRegistration(
235: ModifyRegistration modifyRegistration)
236: throws MissingParametersFault, OperationFailedFault,
237: InvalidRegistrationFault, RemoteException {
238: log.debug("modifyRegistration invoked");
239: RegistrationState registrationState = registrationHandler
240: .modifyRegistration(modifyRegistration);
241: log.debug("end modifyRegistration");
242: return registrationState;
243: }
244:
245: public ProducerConfiguration getProducerConfiguration() {
246: return producerConfiguration;
247: }
248:
249: public void setProducerConfiguration(
250: ProducerConfiguration producerConfiguration) {
251: this .producerConfiguration = producerConfiguration;
252: }
253:
254: public RegistrationManager getRegistrationManager() {
255: return registrationManager;
256: }
257:
258: public void setRegistrationManager(
259: RegistrationManager registrationManager) {
260: this .registrationManager = registrationManager;
261: }
262:
263: public void setProducerConfigurationService(
264: ProducerConfigurationService configurationService) {
265: this .configurationService = configurationService;
266: }
267:
268: public ProducerConfigurationService getConfigurationService() {
269: return configurationService;
270: }
271:
272: protected void startService() throws Exception {
273: super .startService();
274:
275: producerConfiguration = configurationService.getConfiguration();
276:
277: ProducerRegistrationRequirements registrationRequirements = getProducerRegistrationRequirements();
278: registrationRequirements
279: .addRegistrationPolicyChangeListener(registrationManager);
280: registrationRequirements
281: .addRegistrationPropertyChangeListener(registrationManager);
282:
283: if (registrationRequirements.isRegistrationRequired()) {
284: registrationManager.setPolicy(registrationRequirements
285: .getPolicy());
286: }
287: }
288:
289: protected void stopService() throws Exception {
290: ProducerRegistrationRequirements registrationRequirements = getProducerRegistrationRequirements();
291: registrationRequirements
292: .removeRegistrationPropertyChangeListener(registrationManager);
293: registrationRequirements
294: .removeRegistrationPolicyChangeListener(registrationManager);
295:
296: super .stopService();
297: }
298:
299: // PortletManagement implementation *********************************************************************************
300:
301: public PortletDescriptionResponse getPortletDescription(
302: GetPortletDescription getPortletDescription)
303: throws AccessDeniedFault, InvalidHandleFault,
304: InvalidUserCategoryFault, InconsistentParametersFault,
305: MissingParametersFault, InvalidRegistrationFault,
306: OperationFailedFault, RemoteException {
307: log.debug("getPortletDescription invoked");
308: PortletDescriptionResponse description = portletManagementHandler
309: .getPortletDescription(getPortletDescription);
310: log.debug("end getPortletDescription");
311: return description;
312: }
313:
314: public PortletContext clonePortlet(ClonePortlet clonePortlet)
315: throws InvalidUserCategoryFault, AccessDeniedFault,
316: OperationFailedFault, InvalidHandleFault,
317: InvalidRegistrationFault, InconsistentParametersFault,
318: MissingParametersFault, RemoteException {
319: log.debug("clonePortlet invoked");
320: PortletContext portletContext = portletManagementHandler
321: .clonePortlet(clonePortlet);
322: log.debug("end clonePortlet");
323: return portletContext;
324: }
325:
326: public DestroyPortletsResponse destroyPortlets(
327: DestroyPortlets destroyPortlets)
328: throws InconsistentParametersFault, MissingParametersFault,
329: InvalidRegistrationFault, OperationFailedFault,
330: RemoteException {
331: log.debug("destroyPortlets invoked");
332: DestroyPortletsResponse destroyPortletsResponse = portletManagementHandler
333: .destroyPortlets(destroyPortlets);
334: log.debug("end destroyPortlets");
335: return destroyPortletsResponse;
336: }
337:
338: public PortletContext setPortletProperties(
339: SetPortletProperties setPortletProperties)
340: throws OperationFailedFault, InvalidHandleFault,
341: MissingParametersFault, InconsistentParametersFault,
342: InvalidUserCategoryFault, AccessDeniedFault,
343: InvalidRegistrationFault, RemoteException {
344: log.debug("setPortletProperties invoked");
345: PortletContext portletContext = portletManagementHandler
346: .setPortletProperties(setPortletProperties);
347: log.debug("end setPortletProperties");
348: return portletContext;
349: }
350:
351: public PropertyList getPortletProperties(
352: GetPortletProperties getPortletProperties)
353: throws InvalidHandleFault, MissingParametersFault,
354: InvalidRegistrationFault, AccessDeniedFault,
355: OperationFailedFault, InconsistentParametersFault,
356: InvalidUserCategoryFault, RemoteException {
357: log.debug("getPortletProperties invoked");
358: PropertyList list = portletManagementHandler
359: .getPortletProperties(getPortletProperties);
360: log.debug("end getPortletProperties");
361: return list;
362: }
363:
364: public PortletPropertyDescriptionResponse getPortletPropertyDescription(
365: GetPortletPropertyDescription getPortletPropertyDescription)
366: throws MissingParametersFault, InconsistentParametersFault,
367: InvalidUserCategoryFault, InvalidRegistrationFault,
368: AccessDeniedFault, InvalidHandleFault,
369: OperationFailedFault, RemoteException {
370: log.debug("getPortletPropertyDescription invoked");
371: PortletPropertyDescriptionResponse descriptionResponse = portletManagementHandler
372: .getPortletPropertyDescription(getPortletPropertyDescription);
373: log.debug("end getPortletPropertyDescription");
374: return descriptionResponse;
375: }
376:
377: // Producer implementation ******************************************************************************************
378:
379: public CookieProtocol getRequiresInitCookie() {
380: return requiresInitCookie;
381: }
382:
383: public void setRequiresInitCookie(CookieProtocol requiresInitCookie) {
384: this .requiresInitCookie = requiresInitCookie;
385: }
386:
387: // Session management ***********************************************************************************************
388: public int getSessionExpirationTime() {
389: return sessionExpirationTime;
390: }
391:
392: public void setSessionExpirationTime(int sessionExpirationTime) {
393: this .sessionExpirationTime = sessionExpirationTime;
394: }
395:
396: public PortletInvoker getInvoker() {
397: return invoker;
398: }
399:
400: public void setInvoker(PortletInvoker invoker) {
401: this .invoker = invoker;
402: }
403:
404: Portlet getPortletWith(
405: org.jboss.portal.portlet.PortletContext portletContext,
406: Registration registration) throws InvalidHandleFault,
407: PortletInvokerException {
408: Portlet portlet;
409: try {
410: RegistrationLocal.setRegistration(registration);
411: portlet = invoker.getPortlet(portletContext);
412: } catch (NoSuchPortletException e) {
413: throw WSRPExceptionFactory.throwSOAPFaultException(
414: WSRPExceptionFactory.INVALID_HANDLE,
415: "Couldn't find portlet with handle '"
416: + portletContext.getId() + "'", null);
417: } finally {
418: RegistrationLocal.setRegistration(null);
419: }
420:
421: if (!isRemotable(portlet)) {
422: throw WSRPExceptionFactory.throwSOAPFaultException(
423: WSRPExceptionFactory.INVALID_HANDLE, "Portlet '"
424: + portletContext.getId()
425: + "' is not remotely available.", null);
426: }
427:
428: return portlet;
429: }
430:
431: Set<Portlet> getRemotablePortlets() throws PortletInvokerException {
432: log.debug("Retrieving remotable portlets");
433: Set<Portlet> allPortlets = invoker.getPortlets();
434: Set<Portlet> remotablePortlets = new HashSet<Portlet>(
435: allPortlets.size());
436: for (Portlet portlet : allPortlets) {
437: log.debug("Found portlet: " + portlet.getContext());
438: if (isRemotable(portlet)) {
439: remotablePortlets.add(portlet);
440: log.debug("Adding remotable portlet to set: "
441: + portlet.getContext());
442: }
443: }
444: return remotablePortlets;
445: }
446:
447: public PortletDescription getPortletDescription(
448: PortletContext portletContext, String[] locales,
449: Registration registration) throws InvalidHandleFault,
450: OperationFailedFault {
451: return serviceDescriptionHandler.getPortletDescription(
452: portletContext, locales, registration);
453: }
454:
455: public PortletDescription getPortletDescription(Portlet portlet,
456: String[] locales) {
457: return serviceDescriptionHandler.getPortletDescription(portlet,
458: locales);
459: }
460:
461: /**
462: * @param registrationContext
463: * @return
464: * @throws InvalidRegistrationFault
465: * @throws OperationFailedFault
466: * @since 2.6.2
467: */
468: Registration getRegistrationOrFailIfInvalid(
469: RegistrationContext registrationContext)
470: throws InvalidRegistrationFault, OperationFailedFault {
471: Registration registration = getRegistrationFrom(registrationContext);
472: if (!isRegistrationValid(registration)) {
473: registrationHandler
474: .throwInvalidRegistrationFault("Invalid registration");
475: }
476:
477: return registration;
478: }
479:
480: /**
481: * @param registration
482: * @return
483: * @since 2.6.2
484: */
485: boolean isRegistrationValid(Registration registration) {
486: return registrationHandler.isRegistrationValid(registration,
487: true);
488: }
489:
490: /**
491: * @param registrationContext
492: * @return
493: * @since 2.6.2
494: */
495: Registration getRegistrationFrom(
496: RegistrationContext registrationContext) {
497: return registrationHandler
498: .getRegistrationFrom(registrationContext);
499: }
500:
501: private Boolean remotableByDefault;
502:
503: public Boolean isRemotableByDefault() {
504: return remotableByDefault;
505: }
506:
507: public void setRemotableByDefault(Boolean remotableByDefault) {
508: this .remotableByDefault = remotableByDefault;
509: }
510:
511: private boolean isRemotable(Portlet portlet) {
512: PortletInfo portletInfo = portlet.getInfo();
513: Boolean remotable = portletInfo.isRemotable();
514: log.debug("Portlet " + portlet.getContext() + " remotable: "
515: + remotable);
516: if (remotable != null) {
517: return remotable.booleanValue();
518: } else if (isRemotableByDefault() != null) {
519: return isRemotableByDefault().booleanValue();
520: }
521: return false;
522: }
523:
524: public String[] getSupportedLocales() {
525: return supportedLocales; // todo: avoid hardcoding this at some point...
526: }
527:
528: }
|