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.portal.portlet.PortletInvokerException;
025: import org.jboss.portal.portlet.invocation.response.ErrorResponse;
026: import org.jboss.portal.portlet.invocation.response.FragmentResponse;
027: import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
028: import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
029: import org.jboss.portal.portlet.invocation.response.RenderResponse;
030: import org.jboss.portal.portlet.state.producer.PortletStateChangeRequiredException;
031: import org.jboss.portal.wsrp.WSRPExceptionFactory;
032: import org.jboss.portal.wsrp.core.AccessDeniedFault;
033: import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
034: import org.jboss.portal.wsrp.core.GetMarkup;
035: import org.jboss.portal.wsrp.core.InconsistentParametersFault;
036: import org.jboss.portal.wsrp.core.InitCookie;
037: import org.jboss.portal.wsrp.core.InteractionParams;
038: import org.jboss.portal.wsrp.core.InvalidCookieFault;
039: import org.jboss.portal.wsrp.core.InvalidHandleFault;
040: import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
041: import org.jboss.portal.wsrp.core.InvalidSessionFault;
042: import org.jboss.portal.wsrp.core.InvalidUserCategoryFault;
043: import org.jboss.portal.wsrp.core.MarkupResponse;
044: import org.jboss.portal.wsrp.core.MissingParametersFault;
045: import org.jboss.portal.wsrp.core.OperationFailedFault;
046: import org.jboss.portal.wsrp.core.PerformBlockingInteraction;
047: import org.jboss.portal.wsrp.core.PortletStateChangeRequiredFault;
048: import org.jboss.portal.wsrp.core.ReleaseSessions;
049: import org.jboss.portal.wsrp.core.ReturnAny;
050: import org.jboss.portal.wsrp.core.UnsupportedLocaleFault;
051: import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
052: import org.jboss.portal.wsrp.core.UnsupportedModeFault;
053: import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
054: import org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType;
055: import org.jboss.portal.wsrp.servlet.ServletAccess;
056:
057: import javax.portlet.PortletModeException;
058: import javax.portlet.WindowStateException;
059: import java.rmi.RemoteException;
060:
061: /**
062: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
063: * @version $Revision: 8784 $
064: * @since 2.4
065: */
066: class MarkupHandler extends ServiceHandler implements
067: WSRP_v1_Markup_PortType {
068: static final String PBI = "PerformBlockingInteraction";
069: static final String GET_MARKUP = "GetMarkup";
070:
071: MarkupHandler(WSRPProducerImpl producer) {
072: super (producer);
073: }
074:
075: // Markup implementation ********************************************************************************************
076:
077: public MarkupResponse getMarkup(GetMarkup getMarkup)
078: throws UnsupportedWindowStateFault, InvalidCookieFault,
079: InvalidSessionFault, AccessDeniedFault,
080: InconsistentParametersFault, InvalidHandleFault,
081: UnsupportedLocaleFault, UnsupportedModeFault,
082: OperationFailedFault, MissingParametersFault,
083: InvalidUserCategoryFault, InvalidRegistrationFault,
084: UnsupportedMimeTypeFault, RemoteException {
085: WSRPExceptionFactory.throwOperationFailedFaultIfValueIsMissing(
086: getMarkup, GET_MARKUP);
087:
088: RequestProcessor requestProcessor = new RenderRequestProcessor(
089: producer, getMarkup);
090:
091: String handle = requestProcessor.getPortletContext()
092: .getPortletHandle();
093: PortletInvocationResponse response;
094: try {
095: log.debug("RenderInvocation on portlet '" + handle + "'");
096: response = producer.getInvoker().invoke(
097: requestProcessor.getInvocation());
098: log.debug("RenderInvocation done");
099: } catch (PortletInvokerException e) {
100: throw WSRPExceptionFactory.throwSOAPFaultException(
101: WSRPExceptionFactory.OPERATION_FAILED,
102: "Could not render portlet '" + handle + "'", e);
103: }
104:
105: checkForError(response);
106:
107: return (MarkupResponse) requestProcessor
108: .processResponse(response);
109: }
110:
111: public BlockingInteractionResponse performBlockingInteraction(
112: PerformBlockingInteraction performBlockingInteraction)
113: throws InvalidSessionFault, UnsupportedModeFault,
114: UnsupportedMimeTypeFault, OperationFailedFault,
115: UnsupportedWindowStateFault, UnsupportedLocaleFault,
116: AccessDeniedFault, PortletStateChangeRequiredFault,
117: InvalidRegistrationFault, MissingParametersFault,
118: InvalidUserCategoryFault, InconsistentParametersFault,
119: InvalidHandleFault, InvalidCookieFault, RemoteException {
120: WSRPExceptionFactory.throwOperationFailedFaultIfValueIsMissing(
121: performBlockingInteraction, PBI);
122: final InteractionParams interactionParams = performBlockingInteraction
123: .getInteractionParams();
124: WSRPExceptionFactory
125: .throwMissingParametersFaultIfValueIsMissing(
126: interactionParams, "InteractionParams", PBI);
127:
128: RequestProcessor requestProcessor = new ActionRequestProcessor(
129: producer, performBlockingInteraction, interactionParams);
130:
131: PortletInvocationResponse response;
132: String handle = requestProcessor.getPortletContext()
133: .getPortletHandle();
134: try {
135: log.debug("ActionInvocation on portlet '" + handle + "'");
136: response = producer.getInvoker().invoke(
137: requestProcessor.getInvocation());
138: log.debug("ActionInvocation done");
139: } catch (PortletStateChangeRequiredException e) {
140: throw WSRPExceptionFactory.throwSOAPFaultException(
141: WSRPExceptionFactory.PORTLET_STATE_CHANGE_REQUIRED,
142: e.getLocalizedMessage(), e);
143: } catch (PortletInvokerException e) {
144: throw WSRPExceptionFactory.throwSOAPFaultException(
145: WSRPExceptionFactory.OPERATION_FAILED,
146: "Could not perform action on portlet '" + handle
147: + "'", e);
148: }
149:
150: checkForError(response);
151:
152: return (BlockingInteractionResponse) requestProcessor
153: .processResponse(response);
154: }
155:
156: public ReturnAny releaseSessions(ReleaseSessions releaseSessions)
157: throws InvalidRegistrationFault, OperationFailedFault,
158: MissingParametersFault, AccessDeniedFault, RemoteException {
159: // our producer never sends session ids so a Consumer trying to release sessions is an error condition
160: throwOperationFaultOnSessionOperation();
161: return null;
162: }
163:
164: public ReturnAny initCookie(InitCookie initCookie)
165: throws AccessDeniedFault, OperationFailedFault,
166: InvalidRegistrationFault, RemoteException {
167: WSRPExceptionFactory.throwOperationFailedFaultIfValueIsMissing(
168: initCookie, "InitCookie");
169: producer.getRegistrationOrFailIfInvalid(initCookie
170: .getRegistrationContext());
171:
172: // Force HTTP session creation... this is required for BEA Weblogic version < 9.2.
173: // See http://jira.jboss.com/jira/browse/JBPORTAL-1220
174: String sessionId = ServletAccess.getRequest().getSession()
175: .getId();
176: log
177: .debug("Got init cookie operation, created a session with id "
178: + sessionId);
179:
180: return new ReturnAny();
181: }
182:
183: static void throwOperationFaultOnSessionOperation() {
184: throw WSRPExceptionFactory
185: .throwSOAPFaultException(
186: WSRPExceptionFactory.OPERATION_FAILED,
187: "JBoss Portal's Producer"
188: + " manages sessions completely on the server side, passing or trying to release sessionIDs is therefore an error.",
189: null);
190: }
191:
192: private void checkForError(PortletInvocationResponse response)
193: throws UnsupportedModeFault, OperationFailedFault,
194: UnsupportedWindowStateFault {
195: if (response instanceof ErrorResponse) {
196: ErrorResponse errorResult = (ErrorResponse) response;
197: Throwable cause = errorResult.getCause();
198: if (cause instanceof PortletModeException) {
199: throw WSRPExceptionFactory.throwSOAPFaultException(
200: WSRPExceptionFactory.UNSUPPORTED_MODE,
201: "Unsupported mode: "
202: + ((PortletModeException) cause)
203: .getMode(), null);
204: }
205: if (cause instanceof WindowStateException) {
206: throw WSRPExceptionFactory.throwSOAPFaultException(
207: WSRPExceptionFactory.UNSUPPORTED_WINDOW_STATE,
208: "Unsupported window state: "
209: + ((WindowStateException) cause)
210: .getState(), null);
211: }
212: // todo: deal with other exceptions
213:
214: // we're not sure what happened so throw an OperationFailedFault
215: throw WSRPExceptionFactory.throwSOAPFaultException(
216: WSRPExceptionFactory.OPERATION_FAILED, errorResult
217: .getMessage(), cause);
218:
219: } else if (!(response instanceof HTTPRedirectionResponse
220: || response instanceof FragmentResponse || response instanceof RenderResponse)) {
221: throw WSRPExceptionFactory.throwSOAPFaultException(
222: WSRPExceptionFactory.OPERATION_FAILED,
223: "Unsupported result type: "
224: + response.getClass().getName(), null);
225: }
226: }
227: }
|