fixed mt issue.
@@ -20,6 +20,7 @@ | ||
20 | 20 | import java.util.Arrays; |
21 | 21 | import java.util.Collection; |
22 | 22 | import java.util.Collections; |
23 | +import java.util.Enumeration; | |
23 | 24 | import java.util.HashMap; |
24 | 25 | import java.util.Iterator; |
25 | 26 | import java.util.Map; |
@@ -100,6 +101,8 @@ | ||
100 | 101 | |
101 | 102 | protected long timeout; |
102 | 103 | |
104 | + protected Map<String, Object> requestAttributes; | |
105 | + | |
103 | 106 | public RenderingJobImpl(PortletContainer container, |
104 | 107 | PortletRenderer renderer, PortletDefinition portletDefinition, |
105 | 108 | PortletContent portletContent, ContentFragment fragment, |
@@ -124,6 +127,17 @@ | ||
124 | 127 | .setFragment(fragment); |
125 | 128 | this.expirationCache = expirationCache; |
126 | 129 | this.contentIsCached = contentIsCached; |
130 | + | |
131 | + this.requestAttributes = new HashMap<String, Object>(); | |
132 | + ServletRequest servletRequest = ((HttpServletRequestWrapper) ((HttpServletRequestWrapper) this.request) | |
133 | + .getRequest()).getRequest(); | |
134 | + Enumeration attrNames = servletRequest.getAttributeNames(); | |
135 | + while (attrNames.hasMoreElements()) | |
136 | + { | |
137 | + String key = (String) attrNames.nextElement(); | |
138 | + requestAttributes.put(key, servletRequest.getAttribute(key)); | |
139 | + } | |
140 | + | |
127 | 141 | } |
128 | 142 | |
129 | 143 | public RenderingJobImpl(PortletContainer container, |
@@ -281,25 +295,29 @@ | ||
281 | 295 | |
282 | 296 | if (isParallelMode) |
283 | 297 | { |
284 | - ServletRequest servletRequest = ((HttpServletRequestWrapper) ((HttpServletRequestWrapper) this.request) | |
285 | - .getRequest()).getRequest(); | |
286 | - | |
287 | - synchronized (servletRequest) | |
298 | + for (Map.Entry<String, Object> entry : requestAttributes | |
299 | + .entrySet()) | |
288 | 300 | { |
289 | - this.request.setAttribute( | |
290 | - PortalReservedParameters.FRAGMENT_ATTRIBUTE, | |
291 | - fragment); | |
292 | - this.request.setAttribute( | |
293 | - PortalReservedParameters.PAGE_ATTRIBUTE, | |
294 | - requestContext.getPage()); | |
295 | - this.request.setAttribute( | |
296 | - PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, | |
297 | - requestContext); | |
298 | - this.request.setAttribute( | |
299 | - PortalReservedParameters.REQUEST_CONTEXT_OBJECTS, | |
300 | - requestContext.getObjects()); | |
301 | - // this.request.setAttribute(PortalReservedParameters.CONTENT_DISPATCHER_ATTRIBUTE,dispatcher); | |
301 | + CurrentWorkerContext.setAttribute(entry.getKey(), entry | |
302 | + .getValue()); | |
302 | 303 | } |
304 | + | |
305 | + CurrentWorkerContext.setAttribute( | |
306 | + PortalReservedParameters.UPDATED_ATTRIBUTES, | |
307 | + new HashMap<String, Object>()); | |
308 | + | |
309 | + this.request.setAttribute( | |
310 | + PortalReservedParameters.FRAGMENT_ATTRIBUTE, fragment); | |
311 | + this.request.setAttribute( | |
312 | + PortalReservedParameters.PAGE_ATTRIBUTE, requestContext | |
313 | + .getPage()); | |
314 | + this.request.setAttribute( | |
315 | + PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, | |
316 | + requestContext); | |
317 | + this.request.setAttribute( | |
318 | + PortalReservedParameters.REQUEST_CONTEXT_OBJECTS, | |
319 | + requestContext.getObjects()); | |
320 | + // this.request.setAttribute(PortalReservedParameters.CONTENT_DISPATCHER_ATTRIBUTE,dispatcher); | |
303 | 321 | } |
304 | 322 | else |
305 | 323 | { |
@@ -319,6 +337,36 @@ | ||
319 | 337 | |
320 | 338 | container.renderPortlet(this.window, this.request, this.response); |
321 | 339 | this.response.flushBuffer(); |
340 | + if (isParallelMode) | |
341 | + { | |
342 | + // flush attributes | |
343 | + ServletRequest servletRequest = ((HttpServletRequestWrapper) ((HttpServletRequestWrapper) this.request) | |
344 | + .getRequest()).getRequest(); | |
345 | + | |
346 | + synchronized (servletRequest) | |
347 | + { | |
348 | + Map<String, Object> attrs = (Map<String, Object>) this.request | |
349 | + .getAttribute(PortalReservedParameters.UPDATED_ATTRIBUTES); | |
350 | + if (attrs != null) | |
351 | + { | |
352 | + for (Map.Entry<String, Object> entry : attrs.entrySet()) | |
353 | + { | |
354 | + if (PortalReservedParameters.NULL_ATTRIBUTE | |
355 | + .equals(entry.getValue())) | |
356 | + { | |
357 | + // remove | |
358 | + servletRequest.removeAttribute(entry.getKey()); | |
359 | + } | |
360 | + else | |
361 | + { | |
362 | + // add | |
363 | + servletRequest.setAttribute(entry.getKey(), | |
364 | + entry.getValue()); | |
365 | + } | |
366 | + } | |
367 | + } | |
368 | + } | |
369 | + } | |
322 | 370 | } |
323 | 371 | catch (Throwable t) |
324 | 372 | { |
@@ -464,8 +464,6 @@ | ||
464 | 464 | */ |
465 | 465 | public Enumeration getAttributeNames() |
466 | 466 | { |
467 | - Enumeration attrNames = super.getAttributeNames(); | |
468 | - | |
469 | 467 | // In parallel mode, adjust attributes by the values of the current |
470 | 468 | // thread |
471 | 469 |
@@ -477,20 +475,8 @@ | ||
477 | 475 | { |
478 | 476 | HashMap adjustedAttrMap = new HashMap(); |
479 | 477 | |
480 | - // first, add all attributes of original request. | |
481 | - | |
482 | - while (attrNames.hasMoreElements()) | |
483 | - { | |
484 | - String key = (String) attrNames.nextElement(); | |
485 | - adjustedAttrMap.put(key, super.getAttribute(key)); | |
486 | - } | |
487 | - | |
488 | - // second, add or override all attributes by the current worker | |
489 | - // context. | |
490 | - | |
491 | 478 | Enumeration cwAttrNames = CurrentWorkerContext |
492 | 479 | .getAttributeNames(); |
493 | - | |
494 | 480 | while (cwAttrNames.hasMoreElements()) |
495 | 481 | { |
496 | 482 | String key = (String) cwAttrNames.nextElement(); |
@@ -501,10 +487,12 @@ | ||
501 | 487 | cachedAttributes = Collections.unmodifiableMap(adjustedAttrMap); |
502 | 488 | } |
503 | 489 | |
504 | - attrNames = Collections.enumeration(cachedAttributes.keySet()); | |
490 | + return Collections.enumeration(cachedAttributes.keySet()); | |
505 | 491 | } |
506 | - | |
507 | - return attrNames; | |
492 | + else | |
493 | + { | |
494 | + return super.getAttributeNames(); | |
495 | + } | |
508 | 496 | } |
509 | 497 | |
510 | 498 | /** |
@@ -715,9 +703,33 @@ | ||
715 | 703 | CurrentWorkerContext.setAttribute(name, value); |
716 | 704 | } |
717 | 705 | |
718 | - if (name.startsWith("org.apache.jetspeed")) | |
706 | + if (name | |
707 | + .startsWith(PortalReservedParameters.ORG_APACHE_JETSPEED_PREFIX)) | |
719 | 708 | { |
720 | - setAttributeInternal(name, value); | |
709 | + Map<String, Object> updatedAttributes = (Map<String, Object>) CurrentWorkerContext | |
710 | + .getAttribute(PortalReservedParameters.UPDATED_ATTRIBUTES); | |
711 | + String encodedKey = nameSpaceMapper.encode(portletWindow | |
712 | + .getId(), name); | |
713 | + | |
714 | + // title | |
715 | + if (name | |
716 | + .startsWith(PortalReservedParameters.OVERRIDE_PORTLET_TITLE_ATTR)) | |
717 | + { | |
718 | + encodedKey = name; | |
719 | + } | |
720 | + | |
721 | + if (value == null) | |
722 | + { | |
723 | + // remove | |
724 | + updatedAttributes.put(encodedKey, | |
725 | + PortalReservedParameters.NULL_ATTRIBUTE); | |
726 | + } | |
727 | + else | |
728 | + { | |
729 | + // add | |
730 | + updatedAttributes.put(encodedKey, value); | |
731 | + } | |
732 | + | |
721 | 733 | } |
722 | 734 | } |
723 | 735 | else |
@@ -731,16 +743,17 @@ | ||
731 | 743 | { |
732 | 744 | // This allows us to make jetpseed objects avaiable to portlets |
733 | 745 | // This makes the portlet non-portable but is a must admin portlets |
734 | - if (name.startsWith("org.apache.jetspeed")) | |
746 | + if (name | |
747 | + .startsWith(PortalReservedParameters.ORG_APACHE_JETSPEED_PREFIX)) | |
735 | 748 | { |
749 | + String encodedKey = nameSpaceMapper.encode(portletWindow.getId(), | |
750 | + name); | |
736 | 751 | if (value == null) |
737 | 752 | { |
738 | - this.removeAttribute(name); | |
753 | + this.removeAttribute(encodedKey); | |
739 | 754 | } |
740 | 755 | else |
741 | 756 | { |
742 | - String encodedKey = nameSpaceMapper.encode(portletWindow | |
743 | - .getId(), name); | |
744 | 757 | this._getHttpServletRequest().setAttribute(encodedKey, value); |
745 | 758 | } |
746 | 759 | } |
@@ -770,13 +783,32 @@ | ||
770 | 783 | |
771 | 784 | CurrentWorkerContext.removeAttribute(name); |
772 | 785 | |
773 | - if (name.startsWith("org.apache.jetspeed")) | |
786 | + if (name | |
787 | + .startsWith(PortalReservedParameters.ORG_APACHE_JETSPEED_PREFIX)) | |
774 | 788 | { |
775 | - super.removeAttribute(name); | |
789 | + Map<String, Object> updatedAttributes = (Map<String, Object>) CurrentWorkerContext | |
790 | + .getAttribute(PortalReservedParameters.UPDATED_ATTRIBUTES); | |
791 | + String encodedKey = nameSpaceMapper.encode(portletWindow | |
792 | + .getId(), name); | |
793 | + // title | |
794 | + if (name | |
795 | + .startsWith(PortalReservedParameters.OVERRIDE_PORTLET_TITLE_ATTR)) | |
796 | + { | |
797 | + encodedKey = name; | |
798 | + } | |
799 | + updatedAttributes.put(encodedKey, | |
800 | + PortalReservedParameters.NULL_ATTRIBUTE); | |
776 | 801 | } |
777 | 802 | } |
778 | 803 | else |
779 | 804 | { |
805 | + if (name | |
806 | + .startsWith(PortalReservedParameters.ORG_APACHE_JETSPEED_PREFIX)) | |
807 | + { | |
808 | + String encodedKey = nameSpaceMapper.encode(portletWindow | |
809 | + .getId(), name); | |
810 | + super.removeAttribute(encodedKey); | |
811 | + } | |
780 | 812 | // remove attribute from request. |
781 | 813 | super.removeAttribute(name); |
782 | 814 | } |
@@ -953,4 +985,5 @@ | ||
953 | 985 | super.setCharacterEncoding(arg0); |
954 | 986 | } |
955 | 987 | } |
988 | + | |
956 | 989 | } |
@@ -206,4 +206,10 @@ | ||
206 | 206 | * directly, similar as an ActionURL but as a direct Portlet Render request. |
207 | 207 | */ |
208 | 208 | public static final String PORTLET_RESOURCE_URL_REQUEST_PARAMETER = "org.apache.jetspeed.portlet.resource.url"; |
209 | + | |
210 | + public static final String UPDATED_ATTRIBUTES = "org.apache.jetspeed.UpdatedAttributes"; | |
211 | + | |
212 | + public static final String NULL_ATTRIBUTE = "org.apache.jetspeed.NULL"; | |
213 | + | |
214 | + public static final String ORG_APACHE_JETSPEED_PREFIX = "org.apache.jetspeed"; | |
209 | 215 | } |