Skip to content

RequestAttributes in FrameworkPortlet [SPR-11295] #15919

@spring-projects-issues

Description

@spring-projects-issues

Szczepan Kuzniarz opened SPR-11295 and commented

In Spring 2.5.x the type of RequestAttributes stored in RequestContextHolder while handling portlet request was always PortletRequestAttributes. It was guaranteed by the code in DispatcherPortlet.doRenderService/doActionService methods:

...
// Expose current RequestAttributes to current thread.
RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
PortletRequestAttributes requestAttributes = new PortletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
...

Since Spring 3.2.x the type is indeterminate - sometimes it is PortletRequestAttributes and sometimes ServletRequestAttributes (if there is RequestContextListener present). This is caused by the following code in FrameworkPortlet.processRequest method:

...
// Expose current RequestAttributes to current thread.
RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
PortletRequestAttributes requestAttributes = null;
if (previousRequestAttributes == null || previousRequestAttributes.getClass().equals(PortletRequestAttributes.class)) {
	requestAttributes = new PortletRequestAttributes(request);
	RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
}
...

Is the condition in if statement correct? It seems to me it should be:

if (previousRequestAttributes == null || !previousRequestAttributes.getClass().equals(PortletRequestAttributes.class)) {

Affects: 3.2.6, 4.0 GA

Referenced from: commits 1be3a6c, 7d94b5e, 2d892da

Backported to: 3.2.10

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions