Java Code Examples for org.springframework.web.bind.annotation.RequestMapping#path()

The following examples show how to use org.springframework.web.bind.annotation.RequestMapping#path() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static String getClassMapping(Class<?> controllerType) {
	Assert.notNull(controllerType, "'controllerType' must not be null");
	RequestMapping mapping = AnnotatedElementUtils.findMergedAnnotation(controllerType, RequestMapping.class);
	if (mapping == null) {
		return "/";
	}
	String[] paths = mapping.path();
	if (ObjectUtils.isEmpty(paths) || !StringUtils.hasLength(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isTraceEnabled()) {
		logger.trace("Using first of multiple paths on " + controllerType.getName());
	}
	return paths[0];
}
 
Example 2
private static String getMethodMapping(Method method) {
	Assert.notNull(method, "'method' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (requestMapping == null) {
		throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || !StringUtils.hasLength(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isTraceEnabled()) {
		logger.trace("Using first of multiple paths on " + method.toGenericString());
	}
	return paths[0];
}
 
Example 3
private static String getClassMapping(Class<?> controllerType) {
	Assert.notNull(controllerType, "'controllerType' must not be null");
	RequestMapping mapping = AnnotatedElementUtils.findMergedAnnotation(controllerType, RequestMapping.class);
	if (mapping == null) {
		return "/";
	}
	String[] paths = mapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isTraceEnabled()) {
		logger.trace("Using first of multiple paths on " + controllerType.getName());
	}
	return paths[0];
}
 
Example 4
private static String getMethodMapping(Method method) {
	Assert.notNull(method, "'method' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (requestMapping == null) {
		throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isTraceEnabled()) {
		logger.trace("Using first of multiple paths on " + method.toGenericString());
	}
	return paths[0];
}
 
Example 5
private static String getTypeRequestMapping(Class<?> controllerType) {
	Assert.notNull(controllerType, "'controllerType' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(controllerType, RequestMapping.class);
	if (requestMapping == null) {
		return "/";
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isWarnEnabled()) {
		logger.warn("Multiple paths on controller " + controllerType.getName() + ", using first one");
	}
	return paths[0];
}
 
Example 6
private static String getMethodRequestMapping(Method method) {
	Assert.notNull(method, "'method' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (requestMapping == null) {
		throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isWarnEnabled()) {
		logger.warn("Multiple paths on method " + method.toGenericString() + ", using first one");
	}
	return paths[0];
}
 
Example 7
@VisibleForTesting
String[] paths(Class<?> controller)
{
    RequestMapping annotation = AnnotationUtils.findAnnotation(controller, RequestMapping.class);
    if (annotation != null)
    {
        return annotation.path();
    }
    return new String[] {};
}
 
Example 8
private static String getTypeRequestMapping(Class<?> controllerType) {
	Assert.notNull(controllerType, "'controllerType' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(controllerType, RequestMapping.class);
	if (requestMapping == null) {
		return "/";
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isWarnEnabled()) {
		logger.warn("Multiple paths on controller " + controllerType.getName() + ", using first one");
	}
	return paths[0];
}
 
Example 9
private static String getMethodRequestMapping(Method method) {
	Assert.notNull(method, "'method' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (requestMapping == null) {
		throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isWarnEnabled()) {
		logger.warn("Multiple paths on method " + method.toGenericString() + ", using first one");
	}
	return paths[0];
}
 
Example 10
private static String getTypeRequestMapping(Class<?> controllerType) {
	Assert.notNull(controllerType, "'controllerType' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(controllerType, RequestMapping.class);
	if (requestMapping == null) {
		return "/";
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isWarnEnabled()) {
		logger.warn("Multiple paths on controller {}, using first one", controllerType.getName());
	}
	return paths[0];
}
 
Example 11
private static String getMethodRequestMapping(Method method) {
	Assert.notNull(method, "'method' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (requestMapping == null) {
		throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isWarnEnabled()) {
		logger.warn("Multiple paths on method {}, using first one", method.toGenericString());
	}
	return paths[0];
}
 
Example 12
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    String basePath = "";
    RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class);
    if (basePathRequestMapping != null) {
        if (basePathRequestMapping.value().length > 0) {
            basePath = basePathRequestMapping.value()[0];
        } else if (basePathRequestMapping.path().length > 0) {
            basePath = basePathRequestMapping.path()[0];
        }
    }
    EnhanceRequireObjectCache enhanceRequireObjectCache = new EnhanceRequireObjectCache();
    enhanceRequireObjectCache.setPathMappingCache(new PathMappingCache(basePath));
    objInst.setSkyWalkingDynamicField(enhanceRequireObjectCache);
}
 
Example 13
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    String basePath = "";
    RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class);
    if (basePathRequestMapping != null) {
        if (basePathRequestMapping.value().length > 0) {
            basePath = basePathRequestMapping.value()[0];
        } else if (basePathRequestMapping.path().length > 0) {
            basePath = basePathRequestMapping.path()[0];
        }
    }
    EnhanceRequireObjectCache enhanceRequireObjectCache = new EnhanceRequireObjectCache();
    enhanceRequireObjectCache.setPathMappingCache(new PathMappingCache(basePath));
    objInst.setSkyWalkingDynamicField(enhanceRequireObjectCache);
}
 
Example 14
@Override
public JaxrsApplicationParser.Result tryParse(SourceType<?> sourceType) {
    if (!(sourceType.type instanceof Class<?>)) {
        return null;
    }
    final Class<?> cls = (Class<?>) sourceType.type;

    // application
    final SpringBootApplication app = AnnotationUtils.findAnnotation(cls, SpringBootApplication.class);
    if (app != null) {
        if (settings.scanSpringApplication) {
            TypeScriptGenerator.getLogger().verbose("Scanning Spring application: " + cls.getName());
            final ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(settings.classLoader);
                final SpringApplicationHelper springApplicationHelper = new SpringApplicationHelper(settings.classLoader, cls);
                final List<Class<?>> restControllers = springApplicationHelper.findRestControllers();
                return new JaxrsApplicationParser.Result(restControllers.stream()
                    .map(controller -> new SourceType<Type>(controller, cls, "<scanned>"))
                    .collect(Collectors.toList())
                );
            } finally {
                Thread.currentThread().setContextClassLoader(originalContextClassLoader);
            }
        } else {
            return null;
        }
    }

    // controller
    final Component component = AnnotationUtils.findAnnotation(cls, Component.class);
    if (component != null) {
        TypeScriptGenerator.getLogger().verbose("Parsing Spring component: " + cls.getName());
        final JaxrsApplicationParser.Result result = new JaxrsApplicationParser.Result();
        final RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(cls, RequestMapping.class);
        final String path = requestMapping != null && requestMapping.path() != null && requestMapping.path().length != 0 ? requestMapping.path()[0] : null;
        final JaxrsApplicationParser.ResourceContext context = new JaxrsApplicationParser.ResourceContext(cls, path);
        parseController(result, context, cls);
        return result;
    }

    return null;
}