Skip to content

Commit

Permalink
@Event/ResourceMapping uniquely mapped to through event/resource id, …
Browse files Browse the repository at this point in the history
…even across controllers (SPR-6062); type-level @RequestMapping header conditions validated in Portlet environments as well
  • Loading branch information
jhoeller committed Sep 25, 2009
1 parent 76122c9 commit 4d29f65
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 62 deletions.
Expand Up @@ -34,30 +34,19 @@
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
@Mapping()
public @interface EventMapping {

/**
* The name of the event to be handled.
* This name uniquely identifies an event within a portlet mode.
* <p>Typically the local name of the event, but fully qualified names
* with a "{...}" namespace part will be mapped correctly as well.
* <p>If not specified, the render method will be invoked for any
* <p>If not specified, the handler method will be invoked for any
* event request within its general mapping.
* @see javax.portlet.EventRequest#getEvent()
* @see javax.portlet.Event#getName()
*/
String value();

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

}
Expand Up @@ -34,27 +34,16 @@
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
@Mapping()
public @interface ResourceMapping {

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

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

}
Expand Up @@ -385,13 +385,14 @@ protected boolean isHandlerMethod(Method method) {
mappingInfo.initPhaseMapping(PortletRequest.RENDER_PHASE, renderMapping.value(), renderMapping.params());
}
if (resourceMapping != null) {
mappingInfo.initPhaseMapping(PortletRequest.RESOURCE_PHASE, resourceMapping.value(), resourceMapping.params());
mappingInfo.initPhaseMapping(PortletRequest.RESOURCE_PHASE, resourceMapping.value(), new String[0]);
}
if (eventMapping != null) {
mappingInfo.initPhaseMapping(PortletRequest.EVENT_PHASE, eventMapping.value(), eventMapping.params());
mappingInfo.initPhaseMapping(PortletRequest.EVENT_PHASE, eventMapping.value(), new String[0]);
}
if (requestMapping != null) {
mappingInfo.initStandardMapping(requestMapping.value(), requestMapping.method(), requestMapping.params());
mappingInfo.initStandardMapping(requestMapping.value(), requestMapping.method(),
requestMapping.params(), requestMapping.headers());
if (mappingInfo.phase == null) {
mappingInfo.phase = determineDefaultPhase(method);
}
Expand Down Expand Up @@ -466,26 +467,29 @@ else if (EventRequest.class.isAssignableFrom(argType) || EventResponse.class.isA
}


private static class RequestMappingInfo {
private static class RequestMappingInfo {

public Set<PortletMode> modes = new HashSet<PortletMode>();
public final Set<PortletMode> modes = new HashSet<PortletMode>();

public String phase;

public String value;

public Set<String> methods = new HashSet<String>();
public final Set<String> methods = new HashSet<String>();

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

public void initStandardMapping(String[] modes, RequestMethod[] methods, String[] params) {
public String[] headers = new String[0];

public void initStandardMapping(String[] modes, RequestMethod[] methods, String[] params, String[] headers) {
for (String mode : modes) {
this.modes.add(new PortletMode(mode));
}
for (RequestMethod method : methods) {
this.methods.add(method.name());
}
this.params = StringUtils.mergeStringArrays(this.params, params);
this.headers = StringUtils.mergeStringArrays(this.headers, headers);
}

public void initPhaseMapping(String phase, String value, String[] params) {
Expand Down Expand Up @@ -527,7 +531,8 @@ else if (this.phase.equals(PortletRequest.EVENT_PHASE)) {
}
}
return PortletAnnotationMappingUtils.checkRequestMethod(this.methods, request) &&
PortletAnnotationMappingUtils.checkParameters(this.params, request);
PortletAnnotationMappingUtils.checkParameters(this.params, request) &&
PortletAnnotationMappingUtils.checkHeaders(this.headers, request);
}

public boolean isBetterMatchThan(RequestMappingInfo other) {
Expand All @@ -545,7 +550,8 @@ public boolean equals(Object obj) {
ObjectUtils.nullSafeEquals(this.phase, other.phase) &&
ObjectUtils.nullSafeEquals(this.value, other.value) &&
this.methods.equals(other.methods) &&
Arrays.equals(this.params, other.params));
Arrays.equals(this.params, other.params) &&
Arrays.equals(this.headers, other.headers));
}

@Override
Expand Down

0 comments on commit 4d29f65

Please sign in to comment.