Skip to content

DefaultAnnotationHandlerMapping does not allow for distributing Portlet 2.0 action names across controllers [SPR-7685] #12341

@spring-projects-issues

Description

@spring-projects-issues

Jaroslaw Woloch opened SPR-7685 and commented

In spring portlet MVC class DefaultAnnotationHandlerMapping ignore value parameter for @ActionMapping. This parameter contains portlet 2 javax.portlet.ActionRequest#ACTION_NAME value, but 'detectHandlerMethods' ignore it uses only @ActionMappings.params value to match requst params.

Example class:

@Controller
@RequestMapping("VIEV")
class TestController1 {

 @ActionMapping(value = "action1", params = "param1=value1")
    public void testAction(@ModelAttribute(COMMAND_NAME) TestCommand command, ActionResponse response) {
     ...
    }
...
}
@Controller
@RequestMapping("VIEV")
class TestController2 {

 @ActionMapping(value = "action2", params = "param1=value1")
    public void testAction2(@ModelAttribute(COMMAND_NAME) TestCommand command, ActionResponse response) {
     ...
    }
...
}

both action will be mapped as:

param1=value1=TestController1
param1=value1=TestController2

but always first class is used as handler for both url-s:
http://...?...&_testportlet_javax.portlet.action=test1&_testportlet_param1=value1
http://..?...&_testportlet_javax.portlet.action=test2&_testportlet_param1=value1

Example solution for resolve this error:

append @ActionMapping.value as parameter named javax.porlet.ActionRequest.ACTION_NAME to params mapping in method DefaultAnnotationHandlerMapping.detectHandlerMethods(...)

replace this code:

...
else if (ann instanceof EventMapping) {
    EventMapping em = (EventMapping) ann;
    eventName = em.value();
}
else {
    String[] specificParams = (String[]) AnnotationUtils.getValue(ann, "params");
    params = StringUtils.mergeStringArrays(params, specificParams);
							}
...
{/code}

with this:

...
else if (ann instanceof EventMapping) {
EventMapping em = (EventMapping) ann;
eventName = em.value();
}
//this code willbe added to map value as prameter ActionRequest.ACTION_NAME for @ActionMpping
else if (ann instanceof ActionMapping) {
ActionMapping em = (ActionMapping) ann;
String[] action = new String[] {ActionRequest.ACTION_NAME + "=" + em.value()};
params = StringUtils.mergeStringArrays(params, action);
params = StringUtils.mergeStringArrays(params, em.params());
}
else {
String[] specificParams = (String[]) AnnotationUtils.getValue(ann, "params");
params = StringUtils.mergeStringArrays(params, specificParams);
}


Affects: 3.0.4, 3.0.5

Referenced from: commits 66b4eb1

4 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions