Package org.springframework.web.bind.annotation

Examples of org.springframework.web.bind.annotation.RequestMapping


    // In the real implementation AbstractHandlerMethodMapping.handleMatch
    // should to expose the mapping info to a request attribute

    if (handler instanceof HandlerMethod) {
      HandlerMethod handlerMethod = (HandlerMethod) handler;
      RequestMapping rm = handlerMethod.getMethodAnnotation(RequestMapping.class);
      return Arrays.asList(rm.value());
    }

    return Collections.emptyList();
  }
View Full Code Here


        return "redirect:" + backURL;
    }

    protected String defaultViewPrefix() {
        String currentViewPrefix = "";
        RequestMapping requestMapping = AnnotationUtils.findAnnotation(getClass(), RequestMapping.class);
        if (requestMapping != null && requestMapping.value().length > 0) {
            currentViewPrefix = requestMapping.value()[0];
        }

        if (StringUtils.isEmpty(currentViewPrefix)) {
            currentViewPrefix = this.entityClass.getSimpleName();
        }
View Full Code Here

  @Test
  public void testResolveArgument() throws Exception {

    MethodParameter mock2 = mock(MethodParameter.class);
    RequestMapping requestMapping = mock(RequestMapping.class);
    when(mock2.getMethodAnnotation(RequestMapping.class)).thenReturn(requestMapping);
    when(requestMapping.value()).thenReturn(new String[] { "/list/**" });
    final RequestMapping requestMappingOnType = mock(RequestMapping.class);
    when(requestMappingOnType.value()).thenReturn(new String[] { "/script" });
    RemainedPathMethodArgumentResolver resolver = new RemainedPathMethodArgumentResolver() {
      @Override
      protected RequestMapping getDeclaringClassRequestMapping(MethodParameter parameter) {
        return requestMappingOnType;
      }
View Full Code Here

   */
  @Override
  public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
          NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    AntPathMatcher pathMatcher = new AntPathMatcher();
    RequestMapping requestMappingOnMethod = parameter.getMethodAnnotation(RequestMapping.class);
    RequestMapping requestMappingOnClass = getDeclaringClassRequestMapping(parameter);
    String combine = pathMatcher.combine(requestMappingOnClass.value()[0], requestMappingOnMethod.value()[0]);
    return PathUtils.removePrependedSlash(pathMatcher.extractPathWithinPattern(combine, (String) webRequest
        .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE,
            NativeWebRequest.SCOPE_REQUEST)));
  }
View Full Code Here

          }
          ActionMapping actionMapping = AnnotationUtils.findAnnotation(method, ActionMapping.class);
          RenderMapping renderMapping = AnnotationUtils.findAnnotation(method, RenderMapping.class);
          ResourceMapping resourceMapping = AnnotationUtils.findAnnotation(method, ResourceMapping.class);
          EventMapping eventMapping = AnnotationUtils.findAnnotation(method, EventMapping.class);
          RequestMapping requestMapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
          if (actionMapping != null) {
            params = StringUtils.mergeStringArrays(params, actionMapping.params());
            predicate = new ActionMappingPredicate(actionMapping.value(), params);
          }
          else if (renderMapping != null) {
            params = StringUtils.mergeStringArrays(params, renderMapping.params());
            predicate = new RenderMappingPredicate(renderMapping.value(), params);
          }
          else if (resourceMapping != null) {
            predicate = new ResourceMappingPredicate(resourceMapping.value());
          }
          else if (eventMapping != null) {
            predicate = new EventMappingPredicate(eventMapping.value());
          }
          if (requestMapping != null) {
            modeKeys = requestMapping.value();
            if (typeMapping != null) {
              if (!PortletAnnotationMappingUtils.validateModeMapping(modeKeys, typeMapping.value())) {
                throw new IllegalStateException("Mode mappings conflict between method and type level: " +
                    Arrays.asList(modeKeys) + " versus " + Arrays.asList(typeMapping.value()));
              }
            }
            params = StringUtils.mergeStringArrays(params, requestMapping.params());
            if (predicate == null) {
              predicate = new MethodLevelMappingPredicate(params);
            }
          }
          if (predicate != null) {
View Full Code Here

   * @see #getCustomTypeCondition(Class)
   */
  @Override
  protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
    RequestMappingInfo info = null;
    RequestMapping methodAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
    if (methodAnnotation != null) {
      RequestCondition<?> methodCondition = getCustomMethodCondition(method);
      info = createRequestMappingInfo(methodAnnotation, methodCondition);
      RequestMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
      if (typeAnnotation != null) {
        RequestCondition<?> typeCondition = getCustomTypeCondition(handlerType);
        info = createRequestMappingInfo(typeAnnotation, typeCondition).combine(info);
      }
    }
View Full Code Here

      RequestMappingInfo mappingInfo = new RequestMappingInfo();
      ActionMapping actionMapping = AnnotationUtils.findAnnotation(method, ActionMapping.class);
      RenderMapping renderMapping = AnnotationUtils.findAnnotation(method, RenderMapping.class);
      ResourceMapping resourceMapping = AnnotationUtils.findAnnotation(method, ResourceMapping.class);
      EventMapping eventMapping = AnnotationUtils.findAnnotation(method, EventMapping.class);
      RequestMapping requestMapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
      if (actionMapping != null) {
        mappingInfo.initPhaseMapping(PortletRequest.ACTION_PHASE, actionMapping.value(), actionMapping.params());
      }
      if (renderMapping != null) {
        mappingInfo.initPhaseMapping(PortletRequest.RENDER_PHASE, renderMapping.value(), renderMapping.params());
      }
      if (resourceMapping != null) {
        mappingInfo.initPhaseMapping(PortletRequest.RESOURCE_PHASE, resourceMapping.value(), new String[0]);
      }
      if (eventMapping != null) {
        mappingInfo.initPhaseMapping(PortletRequest.EVENT_PHASE, eventMapping.value(), new String[0]);
      }
      if (requestMapping != null) {
        mappingInfo.initStandardMapping(requestMapping.value(), requestMapping.method(),
            requestMapping.params(), requestMapping.headers());
        if (mappingInfo.phase == null) {
          mappingInfo.phase = determineDefaultPhase(method);
        }
      }
      if (mappingInfo.phase != null) {
View Full Code Here

    return ServletUriComponentsBuilder.fromCurrentServletMapping().path(mapping);
  }

  private static String getTypeRequestMapping(Class<?> controllerType) {
    Assert.notNull(controllerType, "'controllerType' must not be null");
    RequestMapping annot = AnnotationUtils.findAnnotation(controllerType, RequestMapping.class);
    if (annot == null || ObjectUtils.isEmpty(annot.value()) || StringUtils.isEmpty(annot.value()[0])) {
      return "/";
    }
    if (annot.value().length > 1 && logger.isWarnEnabled()) {
      logger.warn("Multiple paths on controller " + controllerType.getName() + ", using first one");
    }
    return annot.value()[0];
  }
View Full Code Here

    UriComponents uriComponents = applyContributors(builder, method, argumentValues);
    return ServletUriComponentsBuilder.newInstance().uriComponents(uriComponents);
  }

  private static String getMethodRequestMapping(Method method) {
    RequestMapping annot = AnnotationUtils.findAnnotation(method, RequestMapping.class);
    if (annot == null) {
      throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
    }
    if (ObjectUtils.isEmpty(annot.value()) || StringUtils.isEmpty(annot.value()[0])) {
      return "/";
    }
    if (annot.value().length > 1 && logger.isWarnEnabled()) {
      logger.warn("Multiple paths on method " + method.toGenericString() + ", using first one");
    }
    return annot.value()[0];
  }
View Full Code Here

  protected void detectHandlers() throws BeansException {
    ApplicationContext context = getApplicationContext();
    String[] beanNames = context.getBeanNamesForType(Object.class);
    for (String beanName : beanNames) {
      Class<?> handlerType = context.getType(beanName);
      RequestMapping mapping = context.findAnnotationOnBean(beanName, RequestMapping.class);
      if (mapping != null) {
        // @RequestMapping found at type level
        String[] modeKeys = mapping.value();
        String[] params = mapping.params();
        boolean registerHandlerType = true;
        if (modeKeys.length == 0 || params.length == 0) {
          registerHandlerType = !detectHandlerMethods(handlerType, beanName, mapping);
        }
        if (registerHandlerType) {
          AbstractParameterMappingPredicate predicate = new TypeLevelMappingPredicate(
              params, mapping.headers(), mapping.method());
          for (String modeKey : modeKeys) {
            registerHandler(new PortletMode(modeKey), beanName, predicate);
          }
        }
      }
View Full Code Here

TOP

Related Classes of org.springframework.web.bind.annotation.RequestMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.