001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.wsrp;
022:
023: import com.liferay.portal.kernel.util.GetterUtil;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.kernel.util.StringMaker;
026: import com.liferay.portal.kernel.util.StringPool;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.model.Company;
029: import com.liferay.portal.util.PortalUtil;
030: import com.liferay.portal.util.WebKeys;
031: import com.liferay.portal.wsrp.util.WSRPUtil;
032: import com.liferay.portlet.StrutsPortlet;
033: import com.liferay.util.servlet.SessionMessages;
034:
035: import java.io.IOException;
036:
037: import java.security.Principal;
038:
039: import java.util.Map;
040:
041: import javax.portlet.ActionRequest;
042: import javax.portlet.ActionResponse;
043: import javax.portlet.PortletConfig;
044: import javax.portlet.PortletException;
045: import javax.portlet.PortletMode;
046: import javax.portlet.PortletModeException;
047: import javax.portlet.PortletPreferences;
048: import javax.portlet.PortletRequest;
049: import javax.portlet.RenderRequest;
050: import javax.portlet.RenderResponse;
051: import javax.portlet.WindowStateException;
052:
053: import oasis.names.tc.wsrp.v1.types.BlockingInteractionResponse;
054: import oasis.names.tc.wsrp.v1.types.MarkupContext;
055: import oasis.names.tc.wsrp.v1.types.MarkupResponse;
056: import oasis.names.tc.wsrp.v1.types.PersonName;
057: import oasis.names.tc.wsrp.v1.types.PortletDescription;
058: import oasis.names.tc.wsrp.v1.types.RegistrationData;
059: import oasis.names.tc.wsrp.v1.types.SessionContext;
060: import oasis.names.tc.wsrp.v1.types.UpdateResponse;
061: import oasis.names.tc.wsrp.v1.types.UserContext;
062: import oasis.names.tc.wsrp.v1.types.UserProfile;
063:
064: import org.apache.wsrp4j.consumer.ConsumerEnvironment;
065: import org.apache.wsrp4j.consumer.GroupSession;
066: import org.apache.wsrp4j.consumer.InteractionRequest;
067: import org.apache.wsrp4j.consumer.MarkupRequest;
068: import org.apache.wsrp4j.consumer.PortletDriver;
069: import org.apache.wsrp4j.consumer.PortletKey;
070: import org.apache.wsrp4j.consumer.PortletSession;
071: import org.apache.wsrp4j.consumer.PortletWindowSession;
072: import org.apache.wsrp4j.consumer.Producer;
073: import org.apache.wsrp4j.consumer.ProducerRegistry;
074: import org.apache.wsrp4j.consumer.URLGenerator;
075: import org.apache.wsrp4j.consumer.URLTemplateComposer;
076: import org.apache.wsrp4j.consumer.User;
077: import org.apache.wsrp4j.consumer.UserSession;
078: import org.apache.wsrp4j.consumer.WSRPPortlet;
079: import org.apache.wsrp4j.consumer.driver.PortletKeyImpl;
080: import org.apache.wsrp4j.consumer.driver.ProducerImpl;
081: import org.apache.wsrp4j.consumer.driver.UserImpl;
082: import org.apache.wsrp4j.consumer.driver.WSRPPortletImpl;
083: import org.apache.wsrp4j.exception.ErrorCodes;
084: import org.apache.wsrp4j.exception.WSRPException;
085: import org.apache.wsrp4j.exception.WSRPXHelper;
086: import org.apache.wsrp4j.log.LogManager;
087: import org.apache.wsrp4j.log.Logger;
088: import org.apache.wsrp4j.util.ParameterChecker;
089:
090: /**
091: * <a href="WSRPProxyPortlet.java.html"><b><i>View Source</i></b></a>
092: *
093: * @author Michael Young
094: *
095: */
096: public class WSRPProxyPortlet extends StrutsPortlet {
097: public void init(PortletConfig config) throws PortletException {
098: _portletConfig = config;
099: super .init(config);
100: }
101:
102: public void processAction(ActionRequest request,
103: ActionResponse response) throws PortletException,
104: IOException {
105: boolean remoteInvocation = ParamUtil.get(request,
106: REMOTE_INVOCATION, false);
107:
108: if (remoteInvocation) {
109: _processActionRemote(request, response);
110: } else {
111: super .processAction(request, response);
112: }
113: }
114:
115: public void render(RenderRequest request, RenderResponse response)
116: throws PortletException, IOException {
117:
118: Exception producerConfigError = null;
119: try {
120: Producer producer = _getProducer(request.getPreferences());
121: request.setAttribute(WebKeys.WSRP_PRODUCER, producer);
122: } catch (WSRPException e) {
123: producerConfigError = e;
124: SessionMessages.add(request, _portletConfig
125: .getPortletName()
126: + ".configError", e);
127: }
128:
129: PortletMode mode = request.getPortletMode();
130: if (mode.equals(PortletMode.VIEW)) {
131: if (producerConfigError == null) {
132: _renderRemote(request, response);
133: } else {
134: super .render(request, response);
135: }
136: } else {
137: boolean remoteInvocation = ParamUtil.get(request,
138: REMOTE_INVOCATION, false);
139:
140: if (remoteInvocation && producerConfigError == null) {
141: _renderRemote(request, response);
142: } else {
143: super .render(request, response);
144: }
145: }
146: }
147:
148: public void _processActionRemote(ActionRequest request,
149: ActionResponse actionResponse) throws PortletException {
150: String MN = "processAction";
151: if (_logger.isLogging(Logger.TRACE_HIGH)) {
152: _logger.entry(Logger.TRACE_HIGH, MN);
153: }
154:
155: try {
156: // get the user on which request this call is being done
157: User user = _getUser(request);
158: String userID = null;
159: if (user != null) {
160: userID = user.getUserID();
161: }
162:
163: // get all information and objects which are needed to perform the
164: // interaction
165:
166: PortletPreferences preferences = request.getPreferences();
167:
168: PortletKey portletKey = _getPortletKey(preferences);
169: WSRPPortlet portlet = _getPortlet(portletKey, preferences);
170: PortletWindowSession windowSession = _getWindowSession(
171: userID, portlet, request);
172: PortletDriver portletDriver = _consumerEnv
173: .getPortletDriverRegistry().getPortletDriver(
174: portlet);
175: InteractionRequest actionRequest = new WSRPRequestImpl(
176: windowSession, request, false);
177:
178: // do the actual call and check the response from the producer
179: BlockingInteractionResponse response = null;
180: try {
181: response = portletDriver.performBlockingInteraction(
182: actionRequest, userID);
183: _checker.check(response);
184:
185: } catch (java.rmi.RemoteException wsrpFault) {
186: WSRPXHelper.handleWSRPFault(_logger, wsrpFault);
187: }
188:
189: // process the reponse
190: if (response != null) {
191: // the producer can either send a update response or a redirect
192: UpdateResponse updateResponse = response
193: .getUpdateResponse();
194: String redirectURL = response.getRedirectURL();
195:
196: if (updateResponse != null) {
197: // process the update response
198: if (windowSession != null) {
199: _updateSessionContext(updateResponse
200: .getSessionContext(), windowSession
201: .getPortletSession());
202: windowSession.updateMarkupCache(updateResponse
203: .getMarkupContext());
204: }
205: _updatePortletContext(request, updateResponse
206: .getPortletContext(), portlet);
207:
208: // pass navState to next getMarkup by using the render
209: // params
210: String navState = updateResponse
211: .getNavigationalState();
212: if (navState != null) {
213: actionResponse.setRenderParameter(
214: NAVIGATIONAL_STATE, navState);
215: }
216:
217: // if the remote portlet requested to change the portlet
218: // mode
219: // we try to solve this request.
220: String newMode = updateResponse.getNewMode();
221: if (newMode != null) {
222: try {
223: actionResponse.setPortletMode(WSRPUtil
224: .fromWsrpMode(newMode));
225: } catch (PortletModeException e) {
226: // means portlet does not support this mode
227: if (_logger.isLogging(Logger.INFO)) {
228: _logger
229: .text(
230: Logger.INFO,
231: MN,
232: "The portlet='"
233: + portlet
234: .getPortletKey()
235: .getPortletHandle()
236: + "' does not support the mode="
237: + e.getMode());
238: }
239: }
240: }
241:
242: // if the remote portlet requested to change the window
243: // state
244: // we try to solve this request. If the window state
245: String newWindowState = updateResponse
246: .getNewWindowState();
247: if (newWindowState != null) {
248: try {
249: actionResponse
250: .setWindowState(WSRPUtil
251: .fromWsrpWindowState(newWindowState));
252: } catch (WindowStateException e) {
253: // means portlet does not support the window state
254: if (_logger.isLogging(Logger.INFO)) {
255: _logger
256: .text(
257: Logger.INFO,
258: MN,
259: "The portlet='"
260: + portlet
261: .getPortletKey()
262: .getPortletHandle()
263: + "' does not support the window state="
264: + e.getState());
265: }
266: }
267: }
268: } else if (redirectURL != null) {
269: // if we got a redirect forward this redirect to the
270: // container
271: try {
272: actionResponse.sendRedirect(redirectURL);
273: } catch (IOException ioEx) {
274: WSRPXHelper.throwX(_logger, Logger.ERROR,
275: "processAction",
276: ErrorCodes.COULD_NOT_FOLLOW_REDIRECT);
277: }
278: }
279: }
280:
281: } catch (WSRPException e) {
282: throw new PortletException(e);
283: } finally {
284: if (_logger.isLogging(Logger.TRACE_HIGH)) {
285: _logger.exit(Logger.TRACE_HIGH, MN);
286: }
287: }
288: }
289:
290: public void _renderRemote(RenderRequest request,
291: RenderResponse renderResponse) throws PortletException,
292: IOException {
293:
294: String MN = "render";
295: if (_logger.isLogging(Logger.TRACE_HIGH)) {
296: _logger.entry(Logger.TRACE_HIGH, MN);
297: }
298:
299: try {
300: // set content type in response
301: renderResponse.setContentType(request
302: .getResponseContentType());
303:
304: // get the user on which request this call is being done
305: User user = _getUser(request);
306: String userID = null;
307: if (user != null) {
308: userID = user.getUserID();
309: }
310:
311: // get all information and objects which are needed to perform the
312: // interaction
313: PortletPreferences preferences = request.getPreferences();
314:
315: PortletKey portletKey = _getPortletKey(preferences);
316: WSRPPortlet portlet = _getPortlet(portletKey, preferences);
317: PortletWindowSession windowSession = _getWindowSession(
318: userID, portlet, request);
319: PortletDriver portletDriver = _consumerEnv
320: .getPortletDriverRegistry().getPortletDriver(
321: portlet);
322: MarkupRequest markupRequest = new WSRPRequestImpl(
323: windowSession, request, true);
324:
325: // feed the url generator with the current response
326: synchronized (_urlGenLock) {
327: // update url generator
328:
329: Company company = null;
330:
331: try {
332: company = PortalUtil.getCompany(request);
333: } catch (Exception e) {
334: throw new PortletException(e);
335: }
336:
337: URLGenerator urlGenerator = new URLGeneratorImpl(
338: renderResponse, company.getKeyObj());
339: URLTemplateComposer templateComposer = _consumerEnv
340: .getTemplateComposer();
341: if (templateComposer != null) {
342: templateComposer.setURLGenerator(urlGenerator);
343: }
344:
345: _consumerEnv.getURLRewriter().setURLGenerator(
346: urlGenerator);
347: }
348:
349: // do a getMarkup call and check the response
350: MarkupResponse response = null;
351: try {
352: response = portletDriver.getMarkup(markupRequest,
353: userID);
354: _checker.check(response);
355:
356: } catch (java.rmi.RemoteException wsrpFault) {
357: WSRPXHelper.handleWSRPFault(_logger, wsrpFault);
358: }
359:
360: // process the markup response
361: if (response != null) {
362: if (windowSession != null) {
363: _updateSessionContext(response.getSessionContext(),
364: windowSession.getPortletSession());
365: }
366: _processMarkupContext(response.getMarkupContext(),
367: request, renderResponse);
368: }
369:
370: // delete any cached markup
371: if (windowSession != null) {
372: windowSession.updateMarkupCache(null);
373: }
374:
375: } catch (WSRPException e) {
376: throw new PortletException(
377: "Error occured while retrieving markup", e);
378: } finally {
379: if (_logger.isLogging(Logger.TRACE_HIGH)) {
380: _logger.exit(Logger.TRACE_HIGH, MN);
381: }
382: }
383: }
384:
385: private String _processMarkupContext(MarkupContext markupContext,
386: RenderRequest renderRequest, RenderResponse renderResponse)
387: throws IOException, WSRPException {
388: final String MN = "processMarkupContext";
389:
390: if (_logger.isLogging(Logger.TRACE_HIGH)) {
391: _logger.entry(Logger.TRACE_HIGH, MN);
392: }
393: String markup = null;
394:
395: if (markupContext != null && renderResponse != null) {
396: // set prefered title if found
397: String title = markupContext.getPreferredTitle();
398: if (title != null) {
399: renderResponse.setTitle(getTitle(renderRequest) + " - "
400: + title);
401: }
402:
403: markup = markupContext.getMarkupString();
404: if (markup != null) {
405: try {
406: renderResponse.getWriter().write(markup);
407: } catch (IOException e) {
408: WSRPXHelper.throwX(0, e);
409: }
410: }
411:
412: // TODO: need to handle markup binary
413: }
414:
415: if (_logger.isLogging(Logger.TRACE_HIGH)) {
416: _logger.exit(Logger.TRACE_HIGH, MN);
417: }
418:
419: return markup;
420: }
421:
422: private PortletWindowSession _getWindowSession(String userID,
423: WSRPPortlet portlet, PortletRequest request)
424: throws WSRPException {
425: PortletKey portletKey = portlet.getPortletKey();
426:
427: javax.portlet.PortletSession jsrPortletSession = request
428: .getPortletSession();
429:
430: // to ensure that producer is added to the producer registry
431: // throws exception which we pass
432: _getProducer(request.getPreferences());
433:
434: // now we can get our sessions
435:
436: UserSession userSession = null;
437:
438: synchronized (_sessionHdlrLock) {
439: SessionHandler sessionHandler = (SessionHandler) _consumerEnv
440: .getSessionHandler();
441: sessionHandler.setPortletSession(jsrPortletSession);
442:
443: // get the user session
444:
445: userSession = sessionHandler.getUserSession(portletKey
446: .getProducerId(), userID);
447: }
448:
449: if (userSession != null) {
450:
451: // get the group session
452:
453: PortletDescription portletDescription = _getPortletDescription(
454: portlet, request.getPreferences());
455:
456: String groupID = portletDescription.getGroupID();
457:
458: if (groupID == null) {
459: groupID = "default";
460: }
461:
462: GroupSession groupSession = userSession
463: .getGroupSession(groupID);
464:
465: if (groupSession != null) {
466:
467: // get the portlet session
468: String handle = _portletConfig.getPortletName();
469:
470: PortletSession portletSession = groupSession
471: .getPortletSession(handle);
472:
473: int sessionScope = javax.portlet.PortletSession.PORTLET_SCOPE;
474: boolean clearSessionCtx = GetterUtil
475: .getBoolean((String) jsrPortletSession
476: .getAttribute(WebKeys.WSRP_NEW_SESSION,
477: sessionScope));
478:
479: if (clearSessionCtx) {
480: portletSession.setSessionContext(null);
481: jsrPortletSession.setAttribute(
482: WebKeys.WSRP_NEW_SESSION, "false");
483: }
484:
485: if (portletSession != null) {
486:
487: // get the window session
488:
489: PortletWindowSession windowSession = portletSession
490: .getPortletWindowSession(handle);
491:
492: return windowSession;
493: } else {
494: WSRPXHelper
495: .throwX(ErrorCodes.PORTLET_SESSION_NOT_FOUND);
496: }
497: } else {
498: WSRPXHelper.throwX(ErrorCodes.GROUP_SESSION_NOT_FOUND);
499: }
500: } else {
501: WSRPXHelper.throwX(ErrorCodes.USER_SESSION_NOT_FOUND);
502: }
503:
504: // we will never reach this
505:
506: return null;
507: }
508:
509: private void _updateSessionContext(SessionContext sessionContext,
510: PortletSession portletSession) {
511:
512: if (portletSession != null && sessionContext != null) {
513: portletSession.setSessionContext(sessionContext);
514: }
515: }
516:
517: private void _updatePortletContext(PortletRequest request,
518: oasis.names.tc.wsrp.v1.types.PortletContext portletContext,
519: WSRPPortlet portlet) throws WSRPException {
520:
521: if (portletContext != null && portlet != null) {
522:
523: String newPortletHandle = portletContext.getPortletHandle();
524: PortletKey portletKey = portlet.getPortletKey();
525:
526: if (newPortletHandle != null
527: && !newPortletHandle.equals(portletKey
528: .getPortletHandle())) {
529:
530: // seems like the producer made a clone
531: String producerID = portletKey.getProducerId();
532: PortletKey newPortletKey = new PortletKeyImpl(
533: newPortletHandle, producerID);
534: portlet = _createPortlet(newPortletKey, portlet
535: .getParent());
536: _consumerEnv.getPortletRegistry().addPortlet(portlet);
537:
538: // set new portlet key in portlet preferences
539: PortletPreferences preferences = request
540: .getPreferences();
541: try {
542: preferences.setValue("portlet-handle",
543: newPortletHandle);
544: preferences.setValue("parent-handle", portlet
545: .getParent());
546: preferences.store();
547: } catch (Exception e) {
548: // ups
549: WSRPXHelper.throwX(0, e);
550: }
551:
552: }
553:
554: portlet.setPortletContext(portletContext);
555: }
556: }
557:
558: private User _getUser(PortletRequest request) {
559:
560: User user = null;
561:
562: Principal userPrincipal = request.getUserPrincipal();
563: if (userPrincipal != null) {
564: String userKey = userPrincipal.getName();
565:
566: user = _consumerEnv.getUserRegistry().getUser(userKey);
567: if (user == null) {
568: user = new UserImpl(userKey);
569: UserContext userContext = new UserContext();
570: userContext.setProfile(_fillUserProfile(request));
571:
572: userContext.setUserContextKey(userKey);
573: user.setUserContext(userContext);
574: _consumerEnv.getUserRegistry().addUser(user);
575: }
576: }
577:
578: return user;
579: }
580:
581: private UserProfile _fillUserProfile(PortletRequest request) {
582:
583: UserProfile userProfile = null;
584:
585: Map userInfo = (Map) request
586: .getAttribute(PortletRequest.USER_INFO);
587: if (userInfo != null) {
588: userProfile = new UserProfile();
589:
590: PersonName personName = new PersonName();
591: personName.setPrefix((String) userInfo
592: .get("user.name.prefix"));
593: personName.setGiven((String) userInfo
594: .get("user.name.given"));
595: personName.setFamily((String) userInfo
596: .get("user.name.family"));
597: personName.setMiddle((String) userInfo
598: .get("user.name.middle"));
599: personName.setSuffix((String) userInfo
600: .get("user.name.suffix"));
601: personName.setNickname((String) userInfo
602: .get("user.name.nickName"));
603:
604: userProfile.setName(personName);
605: }
606:
607: return userProfile;
608: }
609:
610: private PortletKey _getPortletKey(PortletPreferences preferences) {
611: PortletKey portletKey = null;
612:
613: String portletHandle = preferences.getValue("portlet-handle",
614: StringPool.BLANK);
615:
616: if (portletHandle != null) {
617: String producerID = _getProducerID(preferences);
618: if (producerID != null) {
619: portletKey = new PortletKeyImpl(portletHandle,
620: producerID);
621: }
622: }
623:
624: return portletKey;
625: }
626:
627: private WSRPPortlet _getPortlet(PortletKey portletKey,
628: PortletPreferences preferences) throws WSRPException {
629:
630: WSRPPortlet portlet = null;
631:
632: if (portletKey != null) {
633:
634: portlet = _consumerEnv.getPortletRegistry().getPortlet(
635: portletKey);
636:
637: if (portlet == null) {
638:
639: String parentHandle = preferences.getValue(
640: "parent-handle", StringPool.BLANK);
641:
642: // not yet in registry, create new one
643:
644: if (Validator.isNull(parentHandle)) {
645: parentHandle = preferences.getValue(
646: "portlet-handle", StringPool.BLANK);
647: ;
648: }
649:
650: portlet = _createPortlet(portletKey, parentHandle);
651:
652: _consumerEnv.getPortletRegistry().addPortlet(portlet);
653: }
654: }
655:
656: return portlet;
657: }
658:
659: private WSRPPortlet _createPortlet(PortletKey portletKey,
660: String parentHandle) {
661:
662: WSRPPortlet portlet = new WSRPPortletImpl(portletKey);
663:
664: oasis.names.tc.wsrp.v1.types.PortletContext portletContext = new oasis.names.tc.wsrp.v1.types.PortletContext();
665:
666: portletContext.setPortletHandle(portletKey.getPortletHandle());
667: portletContext.setPortletState(null);
668: portletContext.setExtensions(null);
669: portlet.setPortletContext(portletContext);
670:
671: if (parentHandle != null) {
672: portlet.setParent(parentHandle);
673: } else {
674: // assume a POP -> parentHandle = portletHandle
675: portlet.setParent(portletKey.getPortletHandle());
676: }
677:
678: return portlet;
679: }
680:
681: private PortletDescription _getPortletDescription(
682: WSRPPortlet portlet, PortletPreferences preferences)
683: throws WSRPException {
684:
685: Producer producer = _getProducer(preferences);
686:
687: PortletDescription portletDesc = producer
688: .getPortletDescription(portlet.getParent());
689:
690: if (portletDesc == null) {
691: WSRPXHelper.throwX(ErrorCodes.PORTLET_DESC_NOT_FOUND);
692: }
693:
694: return portletDesc;
695: }
696:
697: private Producer _getProducer(PortletPreferences preferences)
698: throws WSRPException {
699:
700: final String MN = "getProducer";
701:
702: if (_logger.isLogging(Logger.TRACE_HIGH)) {
703: _logger.text(Logger.TRACE_HIGH, MN,
704: "Trying to load producer with ID :"
705: + _getProducerID(preferences));
706: }
707:
708: String producerID = _getProducerID(preferences);
709:
710: ProducerRegistry producerReg = _consumerEnv
711: .getProducerRegistry();
712: Producer producer = producerReg.getProducer(producerID);
713:
714: if (producer == null) {
715:
716: String wsrpServiceUrl = preferences.getValue(
717: "wsrp-service-url", StringPool.BLANK);
718: String markupEndpoint = preferences.getValue(
719: "markup-endpoint", StringPool.BLANK);
720: String serviceDescriptionEndpoint = preferences.getValue(
721: "service-description-endpoint", StringPool.BLANK);
722: String registrationEndpoint = preferences.getValue(
723: "registration-endpoint", StringPool.BLANK);
724: String portletManagementEndpoint = preferences.getValue(
725: "portlet-management-endpoint", StringPool.BLANK);
726:
727: markupEndpoint = wsrpServiceUrl + "/" + markupEndpoint;
728: serviceDescriptionEndpoint = wsrpServiceUrl + "/"
729: + serviceDescriptionEndpoint;
730: registrationEndpoint = wsrpServiceUrl + "/"
731: + registrationEndpoint;
732: portletManagementEndpoint = wsrpServiceUrl + "/"
733: + portletManagementEndpoint;
734:
735: RegistrationData regData = new RegistrationData();
736: regData.setConsumerName("Liferay WSRP Agent");
737: regData.setConsumerAgent("Liferay WSRP Agent");
738:
739: producer = new ProducerImpl(producerID, markupEndpoint,
740: serviceDescriptionEndpoint, registrationEndpoint,
741: portletManagementEndpoint, regData);
742:
743: producerReg.addProducer(producer);
744: }
745:
746: if (producer == null) {
747: WSRPXHelper.throwX(_logger, Logger.ERROR, MN,
748: ErrorCodes.PRODUCER_DOES_NOT_EXIST);
749: }
750:
751: return producer;
752: }
753:
754: private String _getProducerID(PortletPreferences preferences) {
755: String wsrpServiceUrl = preferences.getValue(
756: "wsrp-service-url", StringPool.BLANK);
757: String markupEndpoint = preferences.getValue("markup-endpoint",
758: StringPool.BLANK);
759: String serviceDescriptionEndpoint = preferences.getValue(
760: "service-description-endpoint", StringPool.BLANK);
761: String registrationEndpoint = preferences.getValue(
762: "registration-endpoint", StringPool.BLANK);
763: String portletManagementEndpoint = preferences.getValue(
764: "portlet-management-endpoint", StringPool.BLANK);
765:
766: StringMaker sm = new StringMaker();
767:
768: sm.append(wsrpServiceUrl);
769: sm.append(StringPool.UNDERLINE);
770: sm.append(markupEndpoint);
771: sm.append(StringPool.UNDERLINE);
772: sm.append(serviceDescriptionEndpoint);
773: sm.append(StringPool.UNDERLINE);
774: sm.append(registrationEndpoint);
775: sm.append(StringPool.UNDERLINE);
776: sm.append(portletManagementEndpoint);
777: sm.append(StringPool.UNDERLINE);
778:
779: String producerID = sm.toString();
780:
781: return producerID;
782: }
783:
784: // stores consumer specific information
785: private static final ConsumerEnvironment _consumerEnv = new ConsumerEnvironmentImpl();
786:
787: // used to validate producer responses
788: private static final ParameterChecker _checker = new ParameterChecker();
789:
790: // logger
791: private static final Logger _logger = LogManager.getLogManager()
792: .getLogger(WSRPProxyPortlet.class);
793:
794: // lock object for thread synchronization while setting the urlgenerator
795: private static final Object _urlGenLock = new Object();
796:
797: // lock object for thread synchronization while updating session handler
798: private static final Object _sessionHdlrLock = new Object();
799:
800: // used as keys in render params
801: public static final String NAVIGATIONAL_STATE = "proxyportlet-updateResponse-navState";
802:
803: public static final String REMOTE_INVOCATION = "proxyportlet-remoteInvocation";
804:
805: private PortletConfig _portletConfig;
806:
807: }
|