KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > wsrp > WSRPConsumerPortlet


1 /*
2 * Copyright 2001-2004 The eXo platform SARL All rights reserved.
3 * Please look at license.txt in info directory for more license detail.
4 */

5
6 package org.exoplatform.portlets.wsrp;
7
8 import java.io.*;
9 import java.util.*;
10 import javax.portlet.*;
11 import javax.portlet.PortletSession;
12 import org.apache.commons.logging.Log;
13 import org.exoplatform.Constants;
14 import org.exoplatform.container.PortalContainer;
15 import org.exoplatform.container.SessionContainer;
16 import org.exoplatform.portal.session.RequestInfo;
17 import org.exoplatform.services.log.LogService;
18 import org.exoplatform.services.portletcontainer.PortletContainerService;
19 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.ActionRequestImp;
20 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.RenderRequestImp;
21 import org.exoplatform.services.portletcontainer.pci.WindowID;
22 import org.exoplatform.services.wsrp.WSRPConstants;
23 import org.exoplatform.services.wsrp.consumer.*;
24 import org.exoplatform.services.wsrp.consumer.adapters.*;
25 import org.exoplatform.services.wsrp.exceptions.Faults;
26 import org.exoplatform.services.wsrp.exceptions.WSRPException;
27 import org.exoplatform.services.wsrp.type.*;
28 import org.exoplatform.services.wsrp.utils.Modes;
29 import org.exoplatform.services.wsrp.utils.Utils;
30 import org.exoplatform.services.wsrp.utils.WindowStates;
31 /*
32  * A part of the business logic of this portlet was taken from the WSRP4J
33  * project
34  * @author Mestrallet Benjamin
35  * benjmestrallet@users.sourceforge.net
36  * Date: 7 févr. 2004
37  * Time: 18:38:56
38  */

39 public class WSRPConsumerPortlet extends GenericPortlet {
40   public static final String USER_SESSIONS_KEY = "user_session_key";
41   private static final String[] characterEncodings = {"UTF-8"};
42   private static final String[] mimeTypes = {"text/html", "text/wml"};
43   private static final String userAgent = "userAgent";
44   private static final String basePath = "/portal/faces/public/portal.jsp";
45   public static final String[] CONSUMER_SCOPES = {"chunk_data"};
46   public static final String[] CONSUMER_CUSTOM_PROFILES = {"what_more"};
47   public static final String[] SUPPORTED_LOCALES = {"en", "fr"};
48
49   private static PortletMode wsrpMode_ = new PortletMode("wsrp");
50
51   private WSRPConfigModeHandler wsrpConfigModeHandler_ ;
52   private ConsumerEnvironment consumerEnvironment;
53   private PortletContainerService portletContainerService;
54   private Log log;
55   private URLTemplateComposer templateComposer;
56   private static boolean _init;
57
58   public WSRPConsumerPortlet() {
59     this.consumerEnvironment = (ConsumerEnvironment) PortalContainer.getInstance().
60         getComponentInstanceOfType(ConsumerEnvironment.class);
61     this.portletContainerService = (PortletContainerService) PortalContainer.getInstance().
62         getComponentInstanceOfType(PortletContainerService.class);
63     this.log = ((LogService) PortalContainer.getInstance().
64         getComponentInstanceOfType(LogService.class)).getLog(getClass());
65     this.templateComposer = (URLTemplateComposer) PortalContainer.getInstance().
66         getComponentInstanceOfType(URLTemplateComposer.class);
67   }
68
69   public void init(PortletConfig portletConfig) throws PortletException {
70     super.init(portletConfig);
71     wsrpConfigModeHandler_ =
72       new WSRPConfigModeHandler(portletConfig, consumerEnvironment, log) ;
73     initConsumer(portletConfig);
74   }
75
76   public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
77     PortletMode mode = request.getPortletMode();
78     if (mode.equals(wsrpMode_)) {
79       wsrpConfigModeHandler_.processAction(request, response) ;
80     } else {
81       wsrpProcessAction(request, response) ;
82     }
83   }
84
85   public void wsrpProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
86       throws PortletException, IOException {
87     try {
88       ActionRequestImp request = (ActionRequestImp) actionRequest;
89       String key = request.getInput().getWindowID().generateKey();
90       log.debug("use windowID : " + key);
91
92       User user = getUser(actionRequest);
93       String userID = null;
94       if (user != null) {
95         userID = user.getUserID();
96         log.debug("use userID : " + userID);
97       }
98       Map preferences = getPreferences(actionRequest);
99       PortletKey portletKey = getPortletKey(preferences);
100       WSRPPortlet portlet = getPortlet(portletKey, preferences);
101       UserSessionMgr userSession = getUserSession(actionRequest.getPortletSession(),
102           portletKey.getProducerId());
103       PortletWindowSession windowSession = getWindowSession(portletKey, portlet,
104           userSession, key);
105       PortletDriver portletDriver = consumerEnvironment.
106           getPortletDriverRegistry().getPortletDriver(portlet);
107       InteractionRequest interactionRequest = getInteractionRequest(windowSession, actionRequest);
108
109       BlockingInteractionResponse response = portletDriver.
110           performBlockingInteraction(interactionRequest, userSession, userID);
111       if (response != null) {
112         log.debug("manage BlockingInteractionResponse object content");
113         UpdateResponse updateResponse = response.getUpdateResponse();
114         String redirectURL = response.getRedirectURL();
115         if (updateResponse != null) {
116           if (windowSession != null) {
117             updateSessionContext(updateResponse.getSessionContext(), windowSession.getPortletSession());
118             windowSession.updateMarkupCache(updateResponse.getMarkupContext());
119           }
120           updatePortletContext(actionRequest, updateResponse.getPortletContext(), portlet);
121           String navState = updateResponse.getNavigationalState();
122           if (navState != null) {
123             log.debug("set new navigational state : " + navState);
124             actionResponse.setRenderParameter(WSRPConstants.WSRP_NAVIGATIONAL_STATE, navState);
125           }
126           String newMode = updateResponse.getNewMode();
127           if (newMode != null) {
128             log.debug("set Mode required : " + newMode);
129             try {
130               if (newMode.equalsIgnoreCase(Modes._view)) {
131                 actionResponse.setPortletMode(PortletMode.VIEW);
132               } else if (newMode.equalsIgnoreCase(Modes._edit)) {
133                 actionResponse.setPortletMode(PortletMode.EDIT);
134               } else if (newMode.equalsIgnoreCase(Modes._help)) {
135                 actionResponse.setPortletMode(PortletMode.HELP);
136               }
137             } catch (PortletModeException e) {
138               log.error("Unable to set new mode", e);
139             }
140           }
141           String newWindowState = updateResponse.getNewWindowState();
142           if (newWindowState != null) {
143             log.debug("set new required window state : " + newWindowState);
144             try {
145               if (newWindowState.equalsIgnoreCase(WindowStates._maximized)) {
146                 actionResponse.setWindowState(WindowState.MAXIMIZED);
147               } else if (newWindowState.equalsIgnoreCase(WindowStates._minimized)) {
148                 actionResponse.setWindowState(WindowState.MINIMIZED);
149               } else if (newWindowState.equalsIgnoreCase(WindowStates._normal)) {
150                 actionResponse.setWindowState(WindowState.NORMAL);
151               }
152             } catch (WindowStateException e) {
153               log.error("uncable to set new window state");
154             }
155           }
156         } else if (redirectURL != null) {
157           try {
158             log.debug("Redirect action to URL : " + redirectURL);
159             actionResponse.sendRedirect(redirectURL);
160           } catch (IOException ioEx) {
161             log.error("Can not redirect action", ioEx);
162           }
163         }
164       }
165     } catch (WSRPException e) {
166       throw new PortletException("exception in processAction method", e);
167     }
168   }
169
170   private void updatePortletContext(PortletRequest request,
171                                     org.exoplatform.services.wsrp.type.PortletContext portletContext,
172                                     WSRPPortlet portlet)
173       throws WSRPException {
174     if (portletContext != null && portlet != null) {
175       log.debug("update portlet context");
176       String newPortletHandle = portletContext.getPortletHandle();
177       PortletKey portletKey = portlet.getPortletKey();
178       if (newPortletHandle != null && !newPortletHandle.equals(portletKey.getPortletHandle())) {
179         log.debug("portlet was cloned, new handle : " + newPortletHandle);
180         String producerID = portletKey.getProducerId();
181         PortletKey newPortletKey = new PortletKeyAdapter();
182         portletKey.setPortletHandle(newPortletHandle);
183         portletKey.setPortletHandle(producerID);
184         portlet = createPortlet(newPortletKey, portlet.getParent());
185         consumerEnvironment.getPortletRegistry().addPortlet(portlet);
186         PortletPreferences preferences = request.getPreferences();
187         try {
188           preferences.setValue(WSRPConstants.WSRP_PORTLET_HANDLE, newPortletHandle);
189           preferences.setValue(WSRPConstants.WSRP_PARENT_HANDLE, portlet.getParent());
190           preferences.store();
191         } catch (Exception e) {
192           log.error("unable to store the new portlet info in the preferences", e);
193           throw new WSRPException(Faults.PREFERENCES_STORING_IMPOSSIBLE, e);
194         }
195       }
196       portlet.setPortletContext(portletContext);
197     }
198   }
199
200   public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException {
201     if(!_init){
202       templateComposer.setHost(request.getServerName());
203       templateComposer.setPort(request.getServerPort());
204     }
205     response.setTitle(getTitle(request));
206     WindowState state = request.getWindowState();
207     if (!state.equals(WindowState.MINIMIZED)) {
208       PortletMode mode = request.getPortletMode();
209       if (mode.equals(wsrpMode_)) {
210         wsrpConfigModeHandler_.render(request, response) ;
211       } else {
212         Map preferences = getPreferences(request);
213         PortletKey portletKey = getPortletKey(preferences);
214         if(getProducer(portletKey.getProducerId()) == null){
215           Writer w = response.getWriter() ;
216           w.write("Configure a producer first");
217         } else {
218           wsrpRender(request, response) ;
219         }
220       }
221     }
222   }
223
224   public void wsrpRender(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
225     log.debug("WSRPConsumerPortlet render entered");
226     RenderRequestImp request = (RenderRequestImp) renderRequest;
227     WindowID windowID = request.getInput().getWindowID();
228     String key = windowID.generateKey();
229     log.debug("key generated by windowID : " + key);
230     renderResponse.setContentType(renderRequest.getResponseContentType());
231     User user = getUser(renderRequest);
232     String userID = null;
233     if (user != null) {
234       log.debug("use userID : " + userID);
235       userID = user.getUserID();
236     }
237     Map preferences = getPreferences(renderRequest);
238     PortletKey portletKey = getPortletKey(preferences);
239     WSRPPortlet portlet = null;
240     PortletDriver portletDriver = null;
241     PortletWindowSession portletWindowSession = null;
242     MarkupResponse response = null;
243     UserSessionMgr userSession = null;
244     try {
245       userSession = getUserSession(renderRequest.getPortletSession(), portletKey.getProducerId());
246       portlet = getPortlet(portletKey, preferences);
247       portletDriver = consumerEnvironment.getPortletDriverRegistry().getPortletDriver(portlet);
248       portletWindowSession = getWindowSession(portletKey, portlet, userSession, key);
249       WSRPMarkupRequest markupRequest = getMarkupRequest(renderRequest, portletWindowSession);
250       RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class);
251       String path = rinfo.getPageURI();
252       log.debug("User path info : " + path);
253       if (path == null) {
254         path = basePath;
255       }
256       path += "?" + Constants.PORTAL_CONTEXT + "=" +
257           rinfo.getPortalOwner() + "&" +
258           Constants.COMPONENT_PARAMETER + "=";
259       log.debug("use base path : " + path + windowID.getUniqueID());
260       response = portletDriver.getMarkup(markupRequest, userSession, path + windowID.getUniqueID());
261       if (response != null) {
262         if (portletWindowSession != null) {
263           updateSessionContext(response.getSessionContext(), portletWindowSession.getPortletSession());
264         }
265         processMarkupContext(response.getMarkupContext(), renderResponse);
266       }
267       if (portletWindowSession != null) {
268         log.debug("Update cache");
269         portletWindowSession.updateMarkupCache(null);
270       }
271     } catch (Throwable t) {
272       log.error("WS Fault occured", t);
273       Writer w = renderResponse.getWriter() ;
274       w.write("a WSRP Fault occured") ;
275     }
276   }
277
278   private PortletKey getPortletKey(Map preferences) throws PortletException {
279     PortletKey portletKey = null;
280     String portletHandle = (String) preferences.get(WSRPConstants.WSRP_PORTLET_HANDLE);
281     if (portletHandle != null) {
282       String producerID = (String) preferences.get(WSRPConstants.WSRP_PRODUCER_ID);
283       if (producerID != null) {
284         portletKey = new PortletKeyAdapter();
285         portletKey.setProducerId(producerID);
286         log.debug("user portlet key, producerID : ");
287         portletKey.setPortletHandle(portletHandle);
288       } else {
289         throw new PortletException("no producer id specified");
290       }
291     } else {
292       throw new PortletException("no portlet handle specified for portlet");
293     }
294     return portletKey;
295   }
296
297   private WSRPPortlet getPortlet(PortletKey portletKey, Map preferences) throws WSRPException {
298     WSRPPortlet portlet = null;
299     if (portletKey != null) {
300       portlet = consumerEnvironment.getPortletRegistry().getPortlet(portletKey);
301       if (portlet == null) {
302         String parentHandle = (String) preferences.get(WSRPConstants.WSRP_PARENT_HANDLE);
303         portlet = createPortlet(portletKey, parentHandle);
304         consumerEnvironment.getPortletRegistry().addPortlet(portlet);
305       }
306     }
307     return portlet;
308   }
309
310   private WSRPPortlet createPortlet(PortletKey portletKey, String parentHandle) {
311     WSRPPortlet portlet = new WSRPPortletAdapter(portletKey);
312     org.exoplatform.services.wsrp.type.PortletContext portletContext =
313         new org.exoplatform.services.wsrp.type.PortletContext();
314     portletContext.setPortletHandle(portletKey.getPortletHandle());
315     portlet.setPortletContext(portletContext);
316     if (parentHandle != null) {
317       portlet.setParent(parentHandle);
318     } else {
319       portlet.setParent(portletKey.getPortletHandle());
320     }
321     return portlet;
322   }
323
324   private Map getPreferences(PortletRequest portletRequest) {
325     Map preferences = new HashMap();
326     log.debug("getPreferences entered");
327     Enumeration keys = portletRequest.getPreferences().getNames();
328     while (keys.hasMoreElements()) {
329       String key = (String) keys.nextElement();
330       String value = portletRequest.getPreferences().getValue(key, null);
331       log.debug("use of preference, key : " + key + " & value : " + value);
332       preferences.put(key, value);
333     }
334     return preferences;
335   }
336
337   protected void initConsumer(PortletConfig portletConfig) {
338     consumerEnvironment.setCharacterEncodingSet(characterEncodings);
339     consumerEnvironment.setConsumerAgent(portletConfig.getInitParameter("consumerAgent"));
340     consumerEnvironment.setMimeTypes(mimeTypes);
341     consumerEnvironment.setPortletStateChange(StateChange.readWrite);
342     consumerEnvironment.setSupportedModes(getModes(portletContainerService.getSupportedPortletModes()));
343     consumerEnvironment.setSupportedWindowStates(getWindowStates(portletContainerService.getSupportedWindowStates()));
344     consumerEnvironment.setUserAuthentication(WSRPConstants.NO_USER_AUTHENTIFICATION);
345     consumerEnvironment.setSupportedLocales(SUPPORTED_LOCALES);
346   }
347
348   private String[] getWindowStates(Collection supportedWindowStates) {
349     String[] array = new String[supportedWindowStates.size()];
350     int i = 0;
351     for (Iterator iterator = supportedWindowStates.iterator(); iterator.hasNext(); i++) {
352       WindowState windowState = (WindowState) iterator.next();
353       array[i] = WSRPConstants.WSRP_PREFIX + windowState.toString();
354     }
355     return array;
356   }
357
358   private String[] getModes(Collection supportedPortletModes) {
359     String[] array = new String[supportedPortletModes.size()];
360     int i = 0;
361     for (Iterator iterator = supportedPortletModes.iterator(); iterator.hasNext(); i++) {
362       PortletMode portletMode = (PortletMode) iterator.next();
363       array[i] = WSRPConstants.WSRP_PREFIX + portletMode.toString();
364     }
365     return array;
366   }
367
368   private User getUser(PortletRequest request) {
369     User user = null;
370     SessionContainer scontainer = SessionContainer.getInstance() ;
371     if (scontainer != null) {
372       String userKey = scontainer.getOwner() ;
373       log.debug("getUser method with user key : " + userKey);
374       user = consumerEnvironment.getUserRegistry().getUser(userKey);
375       if (user == null) {
376         user = new UserAdapter();
377         UserContext userContext = new UserContext();
378         userContext.setProfile(fillUserProfile(request));
379         userContext.setUserContextKey(userKey);
380         user.setUserID(userKey);
381         user.setUserContext(userContext);
382         consumerEnvironment.getUserRegistry().addUser(user);
383       }
384     }
385     return user;
386   }
387
388   private UserProfile fillUserProfile(PortletRequest request) {
389     UserProfile userProfile = null;
390     Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
391     if (userInfo != null) {
392       userProfile = new UserProfile();
393       PersonName personName = new PersonName();
394       Object nameObject = userInfo.get("name.given");
395       if(nameObject == null)
396         personName.setGiven("unknow name");
397       else
398         personName.setGiven(nameObject.toString());
399       userProfile.setName(personName);
400     }
401     return userProfile;
402   }
403
404   private WSRPMarkupRequest getMarkupRequest(RenderRequest renderRequest,
405                                          PortletWindowSession portletWindowSession) {
406     WSRPMarkupRequestAdapter markupRequest = new WSRPMarkupRequestAdapter();
407     fillMarkupRequest(markupRequest, renderRequest, portletWindowSession);
408     markupRequest.setNavigationalState(getNavigationalState(renderRequest, portletWindowSession));
409     markupRequest.setCachedMarkup(portletWindowSession.getCachedMarkup());
410     return markupRequest;
411   }
412
413   private InteractionRequest getInteractionRequest(PortletWindowSession portletWindowSession,
414                                                    ActionRequest actionRequest) {
415     log.debug("getInteractionRequest entered");
416     InteractionRequestAdapter interactionRequest = new InteractionRequestAdapter();
417     fillMarkupRequest(interactionRequest, actionRequest, portletWindowSession);
418     interactionRequest.setNavigationalState(getNavigationalState(actionRequest, portletWindowSession));
419     Map map = actionRequest.getParameterMap();
420     log.debug("Parameter map empty : " + map.isEmpty());
421     Set keys = map.keySet();
422     NamedString[] array = new NamedString[keys.size()];
423     int i = 0;
424     for (Iterator iterator = keys.iterator(); iterator.hasNext(); i++) {
425       String key = (String) iterator.next();
426       String value = ((String[]) map.get(key))[0];
427       array[i] = Utils.getNamesString(key, value);
428     }
429     interactionRequest.setFormParameters(array);
430     //interactionRequest.setInteractionState();
431
return interactionRequest;
432   }
433
434
435   private void fillMarkupRequest(WSRPBaseRequestAdapter markupRequest,
436                                  PortletRequest portletRequest,
437                                  PortletWindowSession portletWindowSession) {
438     markupRequest.setCharacterEncodingSet(characterEncodings);
439     markupRequest.setClientData(getClientData());
440     markupRequest.setLocales(manageEnumeration(portletRequest.getLocales()));
441     markupRequest.setMimeTypes(manageEnumeration(portletRequest.getResponseContentTypes()));
442     markupRequest.setMode(WSRPConstants.WSRP_PREFIX + portletRequest.getPortletMode().toString());
443     markupRequest.setModes(null);//TODO
444
markupRequest.setUserAuthentication("none");
445     markupRequest.setWindowState(WSRPConstants.WSRP_PREFIX + portletRequest.getWindowState().toString());
446     markupRequest.setWindowStates(null);//TODO
447

448     //specific to WSRP
449
if (portletWindowSession.getPortletSession().getSessionContext() != null) {
450       markupRequest.setSessionID(portletWindowSession.
451           getPortletSession().getSessionContext().getSessionID());
452     }
453
454     markupRequest.setPortletInstanceKey(null);
455   }
456
457   private String getNavigationalState(PortletRequest portletRequest,
458                                       PortletWindowSession portletWindowSession) {
459     String ns = portletRequest.getParameter(WSRPConstants.WSRP_NAVIGATIONAL_STATE);
460     if (ns != null) {
461       log.debug("user navigational state : " + ns);
462       portletWindowSession.setNavigationalState(ns);
463     } else {
464       log.debug("Navigational state null");
465     }
466     return portletWindowSession.getNavigationalState();
467   }
468
469   private ClientData getClientData() {
470     ClientData clientData = new ClientData();
471     clientData.setUserAgent(userAgent);
472     return clientData;
473   }
474
475   private PortletWindowSession getWindowSession(PortletKey portletKey,
476                                                 WSRPPortlet portlet,
477                                                 UserSessionMgr userSession,
478                                                 String windowID)
479       throws WSRPException {
480     if (userSession != null) {
481       log.debug("get group session form user session");
482       String groupID = getPortletDescription(portlet).getGroupID();
483       groupID = groupID == null ? "default" : groupID;
484       log.debug("group ID : " + groupID);
485       GroupSession groupSession = userSession.getGroupSession(groupID);
486       if (groupSession != null) {
487         log.debug("get portlet session from group session");
488         org.exoplatform.services.wsrp.consumer.PortletSession portletSession = groupSession.
489             getPortletSession(portletKey.getPortletHandle());
490         log.debug("portlet handle : " + portletKey.getPortletHandle());
491         if (portletSession != null) {
492           PortletWindowSession windowSession = portletSession.getPortletWindowSession(windowID);
493           log.debug("success in extraction of the window session");
494           return windowSession;
495         } else {
496           log.error("portlet session was null");
497           throw new WSRPException(Faults.INVALID_SESSION_FAULT);
498         }
499       } else {
500         log.error("group session was null");
501         throw new WSRPException(Faults.INVALID_SESSION_FAULT);
502       }
503     } else {
504       log.error("user session was null");
505       throw new WSRPException(Faults.INVALID_SESSION_FAULT);
506     }
507   }
508
509   private UserSessionMgr getUserSession(PortletSession jsr168PortletSession,
510                                         String producerID) throws WSRPException {
511
512     UserSessionMgr userSession = (UserSessionMgr) jsr168PortletSession.
513         getAttribute(USER_SESSIONS_KEY + producerID, PortletSession.PORTLET_SCOPE);
514     if (userSession == null) {
515       log.debug("Create new UserSession");
516       userSession = new UserSessionImpl(getProducer(producerID).
517           getMarkupInterfaceEndpoint());
518       jsr168PortletSession.setAttribute(USER_SESSIONS_KEY + producerID,
519           userSession, PortletSession.PORTLET_SCOPE);
520     } else {
521       log.debug("use existing UserSession");
522     }
523     return userSession;
524   }
525
526   private PortletDescription getPortletDescription(WSRPPortlet portlet)
527       throws WSRPException {
528     log.debug("getPortletDescription entered");
529     String producerID = portlet.getPortletKey().getProducerId();
530     Producer producer = getProducer(producerID);
531     PortletDescription portletDesc = producer.getPortletDescription(portlet.getParent());
532     if (portletDesc == null) {
533       throw new WSRPException(Faults.UNKNOWN_PORTLET_DESCRIPTION);
534     }
535     return portletDesc;
536   }
537
538   private String[] manageEnumeration(Enumeration enum) {
539     List l = Collections.list(enum);
540     String[] array = new String[l.size()];
541     int i = 0;
542     for (Iterator iterator = l.iterator(); iterator.hasNext();) {
543       Object o = (Object) iterator.next();
544       array[i] = o.toString();
545     }
546     return array;
547   }
548
549   private Producer getProducer(String producerID) {
550     log.debug("getProducer : " + producerID);
551     Producer producer = consumerEnvironment.getProducerRegistry().getProducer(producerID);
552     return producer;
553   }
554
555   private void updateSessionContext(SessionContext sessionContext,
556                                     org.exoplatform.services.wsrp.consumer.PortletSession portletSession) {
557     if (sessionContext != null) {
558       log.debug("update session context");
559       if (portletSession != null) {
560         portletSession.setSessionContext(sessionContext);
561       }
562     }
563   }
564
565   private String processMarkupContext(MarkupContext markupContext,
566                                       RenderResponse renderResponse)
567       throws WSRPException {
568     log.debug("process returned markup");
569     String markup = null;
570     byte[] binaryMarkup = null;
571     if (markupContext != null && renderResponse != null) {
572       String title = markupContext.getPreferredTitle();
573       if (title != null) {
574         log.debug("user title : " + title);
575         renderResponse.setTitle(title);
576       }
577       markup = markupContext.getMarkupString();
578       binaryMarkup = markupContext.getMarkupBinary();
579       if (markup != null) {
580         log.debug("markup non null");
581         try {
582           renderResponse.getWriter().write(markup);
583         } catch (IOException e) {
584           log.error("can not write content to writer output", e);
585           throw new WSRPException(Faults.OPERATION_FAILED_FAULT, e);
586         }
587       }
588       if(binaryMarkup != null){
589         log.debug("binary markup non null");
590         Reader reader = new InputStreamReader(new ByteArrayInputStream(binaryMarkup));
591         char[] stringArray = new char[binaryMarkup.length];
592         try {
593           reader.read(stringArray);
594           renderResponse.getWriter().write(stringArray);
595         } catch (IOException e) {
596           log.error("can not write content to writer output", e);
597           throw new WSRPException(Faults.OPERATION_FAILED_FAULT, e);
598         }
599       }
600     }
601     return markup;
602   }
603 }
604
Popular Tags