Skip to content

Commit 4d29f65

Browse files
committed
@Event/ResourceMapping uniquely mapped to through event/resource id, even across controllers (SPR-6062); type-level @RequestMapping header conditions validated in Portlet environments as well
1 parent 76122c9 commit 4d29f65

File tree

7 files changed

+373
-62
lines changed

7 files changed

+373
-62
lines changed

org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/bind/annotation/EventMapping.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,19 @@
3434
@Target({ElementType.METHOD})
3535
@Retention(RetentionPolicy.RUNTIME)
3636
@Documented
37-
@Mapping
37+
@Mapping()
3838
public @interface EventMapping {
3939

4040
/**
4141
* The name of the event to be handled.
42+
* This name uniquely identifies an event within a portlet mode.
4243
* <p>Typically the local name of the event, but fully qualified names
4344
* with a "{...}" namespace part will be mapped correctly as well.
44-
* <p>If not specified, the render method will be invoked for any
45+
* <p>If not specified, the handler method will be invoked for any
4546
* event request within its general mapping.
4647
* @see javax.portlet.EventRequest#getEvent()
4748
* @see javax.portlet.Event#getName()
4849
*/
49-
String value();
50-
51-
/**
52-
* The parameters of the mapped request, narrowing the primary mapping.
53-
* <p>Same format for any environment: a sequence of "myParam=myValue" style
54-
* expressions, with a request only mapped if each such parameter is found
55-
* to have the given value. "myParam" style expressions are also supported,
56-
* with such parameters having to be present in the request (allowed to have
57-
* any value). Finally, "!myParam" style expressions indicate that the
58-
* specified parameter is <i>not</i> supposed to be present in the request.
59-
* @see org.springframework.web.bind.annotation.RequestMapping#params()
60-
*/
61-
String[] params() default {};
50+
String value() default "";
6251

6352
}

org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/bind/annotation/ResourceMapping.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,16 @@
3434
@Target({ElementType.METHOD})
3535
@Retention(RetentionPolicy.RUNTIME)
3636
@Documented
37-
@Mapping
37+
@Mapping()
3838
public @interface ResourceMapping {
3939

4040
/**
4141
* The id of the resource to be handled.
42-
* <p>If not specified, the render method will be invoked for any
42+
* This id uniquely identifies a resource within a portlet mode.
43+
* <p>If not specified, the handler method will be invoked for any
4344
* resource request within its general mapping.
4445
* @see javax.portlet.ResourceRequest#getResourceID()
4546
*/
4647
String value() default "";
4748

48-
/**
49-
* The parameters of the mapped request, narrowing the primary mapping.
50-
* <p>Same format for any environment: a sequence of "myParam=myValue" style
51-
* expressions, with a request only mapped if each such parameter is found
52-
* to have the given value. "myParam" style expressions are also supported,
53-
* with such parameters having to be present in the request (allowed to have
54-
* any value). Finally, "!myParam" style expressions indicate that the
55-
* specified parameter is <i>not</i> supposed to be present in the request.
56-
* @see org.springframework.web.bind.annotation.RequestMapping#params()
57-
*/
58-
String[] params() default {};
59-
6049
}

org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,14 @@ protected boolean isHandlerMethod(Method method) {
385385
mappingInfo.initPhaseMapping(PortletRequest.RENDER_PHASE, renderMapping.value(), renderMapping.params());
386386
}
387387
if (resourceMapping != null) {
388-
mappingInfo.initPhaseMapping(PortletRequest.RESOURCE_PHASE, resourceMapping.value(), resourceMapping.params());
388+
mappingInfo.initPhaseMapping(PortletRequest.RESOURCE_PHASE, resourceMapping.value(), new String[0]);
389389
}
390390
if (eventMapping != null) {
391-
mappingInfo.initPhaseMapping(PortletRequest.EVENT_PHASE, eventMapping.value(), eventMapping.params());
391+
mappingInfo.initPhaseMapping(PortletRequest.EVENT_PHASE, eventMapping.value(), new String[0]);
392392
}
393393
if (requestMapping != null) {
394-
mappingInfo.initStandardMapping(requestMapping.value(), requestMapping.method(), requestMapping.params());
394+
mappingInfo.initStandardMapping(requestMapping.value(), requestMapping.method(),
395+
requestMapping.params(), requestMapping.headers());
395396
if (mappingInfo.phase == null) {
396397
mappingInfo.phase = determineDefaultPhase(method);
397398
}
@@ -466,26 +467,29 @@ else if (EventRequest.class.isAssignableFrom(argType) || EventResponse.class.isA
466467
}
467468

468469

469-
private static class RequestMappingInfo {
470+
private static class RequestMappingInfo {
470471

471-
public Set<PortletMode> modes = new HashSet<PortletMode>();
472+
public final Set<PortletMode> modes = new HashSet<PortletMode>();
472473

473474
public String phase;
474475

475476
public String value;
476477

477-
public Set<String> methods = new HashSet<String>();
478+
public final Set<String> methods = new HashSet<String>();
478479

479480
public String[] params = new String[0];
480481

481-
public void initStandardMapping(String[] modes, RequestMethod[] methods, String[] params) {
482+
public String[] headers = new String[0];
483+
484+
public void initStandardMapping(String[] modes, RequestMethod[] methods, String[] params, String[] headers) {
482485
for (String mode : modes) {
483486
this.modes.add(new PortletMode(mode));
484487
}
485488
for (RequestMethod method : methods) {
486489
this.methods.add(method.name());
487490
}
488491
this.params = StringUtils.mergeStringArrays(this.params, params);
492+
this.headers = StringUtils.mergeStringArrays(this.headers, headers);
489493
}
490494

491495
public void initPhaseMapping(String phase, String value, String[] params) {
@@ -527,7 +531,8 @@ else if (this.phase.equals(PortletRequest.EVENT_PHASE)) {
527531
}
528532
}
529533
return PortletAnnotationMappingUtils.checkRequestMethod(this.methods, request) &&
530-
PortletAnnotationMappingUtils.checkParameters(this.params, request);
534+
PortletAnnotationMappingUtils.checkParameters(this.params, request) &&
535+
PortletAnnotationMappingUtils.checkHeaders(this.headers, request);
531536
}
532537

533538
public boolean isBetterMatchThan(RequestMappingInfo other) {
@@ -545,7 +550,8 @@ public boolean equals(Object obj) {
545550
ObjectUtils.nullSafeEquals(this.phase, other.phase) &&
546551
ObjectUtils.nullSafeEquals(this.value, other.value) &&
547552
this.methods.equals(other.methods) &&
548-
Arrays.equals(this.params, other.params));
553+
Arrays.equals(this.params, other.params) &&
554+
Arrays.equals(this.headers, other.headers));
549555
}
550556

551557
@Override

0 commit comments

Comments
 (0)