Search in sources :

Example 11 with HandlerMatchingMetadata

use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.

the class RequestMappingInfoHandlerMapping method handleMatch.

/**
 * Expose URI template variables, matrix variables, and producible media types in the request.
 */
@Override
protected void handleMatch(Match bestMatch, String lookupPath, RequestContext request) {
    super.handleMatch(bestMatch, lookupPath, request);
    RequestMappingInfo info = bestMatch.mapping;
    PathPatternsRequestCondition pathPatternsCondition = info.getPathPatternsCondition();
    HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(bestMatch.getHandlerMethod(), lookupPath, request.getLookupPath(), CollectionUtils.firstElement(pathPatternsCondition.getPatterns()), getPatternParser());
    request.setMatchingMetadata(matchingMetadata);
    Set<MediaType> mediaTypes = info.getProducesCondition().getProducibleMediaTypes();
    if (!mediaTypes.isEmpty()) {
        matchingMetadata.setProducibleMediaTypes(mediaTypes.toArray(new MediaType[0]));
    }
}
Also used : PathPatternsRequestCondition(cn.taketoday.web.handler.condition.PathPatternsRequestCondition) MediaType(cn.taketoday.http.MediaType) HandlerMatchingMetadata(cn.taketoday.web.HandlerMatchingMetadata)

Example 12 with HandlerMatchingMetadata

use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.

the class AbstractView method createMergedOutputModel.

/**
 * Creates a combined output Map (never {@code null}) that includes dynamic values and static attributes.
 * Dynamic values take precedence over static attributes.
 */
protected Map<String, Object> createMergedOutputModel(@Nullable Map<String, ?> model, RequestContext context) {
    // Consolidate static and dynamic model attributes.
    Map<String, Object> staticAttributes = getStaticAttributes();
    int size = model != null ? model.size() : 0;
    if (staticAttributes != null) {
        size += staticAttributes.size();
    }
    Map<String, String> pathVars = null;
    HandlerMatchingMetadata matchingMetadata = context.getMatchingMetadata();
    if (exposePathVariables && matchingMetadata != null) {
        pathVars = matchingMetadata.getUriVariables();
        size += pathVars.size();
    }
    Map<String, Object> mergedModel = CollectionUtils.newLinkedHashMap(size);
    if (CollectionUtils.isNotEmpty(staticAttributes)) {
        mergedModel.putAll(staticAttributes);
    }
    if (CollectionUtils.isNotEmpty(pathVars)) {
        mergedModel.putAll(pathVars);
    }
    if (CollectionUtils.isNotEmpty(model)) {
        mergedModel.putAll(model);
    }
    // Expose RequestContext?
    if (requestContextAttribute != null) {
        mergedModel.put(requestContextAttribute, context);
    }
    return mergedModel;
}
Also used : HandlerMatchingMetadata(cn.taketoday.web.HandlerMatchingMetadata)

Example 13 with HandlerMatchingMetadata

use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.

the class PathVariableMapMethodArgumentResolverTests method applyTemplateVars.

private void applyTemplateVars() {
    RequestPath requestPath = RequestPath.parse("/mock/value", null);
    PathPattern pathPattern = PathPatternParser.defaultInstance.parse("/mock/{name}");
    HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(new Object(), "/mock", requestPath, pathPattern, PathPatternParser.defaultInstance);
    webRequest.setMatchingMetadata(matchingMetadata);
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath) PathPattern(cn.taketoday.web.util.pattern.PathPattern) HandlerMatchingMetadata(cn.taketoday.web.HandlerMatchingMetadata)

Example 14 with HandlerMatchingMetadata

use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.

the class PathVariableMethodArgumentResolverTests method applyTemplateVars.

private void applyTemplateVars(String name, String value) {
    RequestPath requestPath = RequestPath.parse("/mock/" + value, null);
    PathPattern pathPattern = PathPatternParser.defaultInstance.parse("/mock/{" + name + "}");
    HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(new Object(), "/mock", requestPath, pathPattern, PathPatternParser.defaultInstance);
    webRequest.setMatchingMetadata(matchingMetadata);
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath) PathPattern(cn.taketoday.web.util.pattern.PathPattern) HandlerMatchingMetadata(cn.taketoday.web.HandlerMatchingMetadata)

Example 15 with HandlerMatchingMetadata

use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.

the class PathVariableMethodArgumentResolverTests method applyTemplateVars.

private void applyTemplateVars() {
    RequestPath requestPath = RequestPath.parse("/mock/value", null);
    PathPattern pathPattern = PathPatternParser.defaultInstance.parse("/mock/{name}");
    HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(new Object(), "/mock", requestPath, pathPattern, PathPatternParser.defaultInstance);
    webRequest.setMatchingMetadata(matchingMetadata);
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath) PathPattern(cn.taketoday.web.util.pattern.PathPattern) HandlerMatchingMetadata(cn.taketoday.web.HandlerMatchingMetadata)

Aggregations

HandlerMatchingMetadata (cn.taketoday.web.HandlerMatchingMetadata)19 Test (org.junit.jupiter.api.Test)12 HashMap (java.util.HashMap)7 MediaType (cn.taketoday.http.MediaType)6 RequestPath (cn.taketoday.http.server.RequestPath)4 RequestContext (cn.taketoday.web.RequestContext)4 WebServletApplicationContext (cn.taketoday.web.servlet.WebServletApplicationContext)4 PathPattern (cn.taketoday.web.util.pattern.PathPattern)4 PathPatternsRequestCondition (cn.taketoday.web.handler.condition.PathPatternsRequestCondition)2 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)2 MockServletContext (cn.taketoday.web.mock.MockServletContext)2 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 MockServletContext (cn.taketoday.web.testfixture.servlet.MockServletContext)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)2 Map (java.util.Map)2 Properties (java.util.Properties)2 HttpOutputMessage (cn.taketoday.http.HttpOutputMessage)1