org.springframework.web.method.support.CompositeUriComponentsContributor Java Examples

The following examples show how to use org.springframework.web.method.support.CompositeUriComponentsContributor. 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
Source File: MvcUriComponentsBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static CompositeUriComponentsContributor getConfiguredUriComponentsContributor() {
	WebApplicationContext wac = getWebApplicationContext();
	if (wac == null) {
		return null;
	}
	try {
		return wac.getBean(MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class);
	}
	catch (NoSuchBeanDefinitionException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("No CompositeUriComponentsContributor bean with name '" +
					MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME + "'");
		}
		return null;
	}
}
 
Example #2
Source File: SpringletsMvcUriComponentsBuilder.java    From springlets with Apache License 2.0 6 votes vote down vote up
private static CompositeUriComponentsContributor getConfiguredUriComponentsContributor() {
	WebApplicationContext wac = getWebApplicationContext();
	if (wac == null) {
		return null;
	}
	try {
		return wac.getBean(MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class);
	}
	catch (NoSuchBeanDefinitionException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("No CompositeUriComponentsContributor bean with name '" +
					MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME + "'", ex);
		}
		return null;
	}
}
 
Example #3
Source File: MvcUriComponentsBuilder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private static CompositeUriComponentsContributor getConfiguredUriComponentsContributor() {
	WebApplicationContext wac = getWebApplicationContext();
	if (wac == null) {
		return null;
	}
	try {
		return wac.getBean(MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class);
	}
	catch (NoSuchBeanDefinitionException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("No CompositeUriComponentsContributor bean with name '" +
					MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME + "'");
		}
		return null;
	}
}
 
Example #4
Source File: WxApiMethodInfo.java    From FastBootWeixin with Apache License 2.0 6 votes vote down vote up
private UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
    CompositeUriComponentsContributor contributor = defaultUriComponentsContributor;
    int paramCount = method.getParameterTypes().length;
    int argCount = args.length;
    if (paramCount != argCount) {
        throw new IllegalArgumentException("方法参数量为" + paramCount + " 与真实参数量不匹配,真实参数量为" + argCount);
    }
    final Map<String, Object> uriVars = new HashMap<>(8);
    for (int i = 0; i < paramCount; i++) {
        MethodParameter param = new SynthesizingMethodParameter(method, i);
        param.initParameterNameDiscovery(parameterNameDiscoverer);
        contributor.contributeMethodArgument(param, args[i], builder, uriVars);
    }
    // We may not have all URI var values, expand only what we have
    return builder.build().expand(name -> uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE);
}
 
Example #5
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private static UriComponentsBuilder applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
	CompositeUriComponentsContributor contributor = getUriComponentsContributor();

	int paramCount = method.getParameterCount();
	int argCount = args.length;
	if (paramCount != argCount) {
		throw new IllegalArgumentException("Number of method parameters " + paramCount +
				" does not match number of argument values " + argCount);
	}

	final Map<String, Object> uriVars = new HashMap<>();
	for (int i = 0; i < paramCount; i++) {
		MethodParameter param = new SynthesizingMethodParameter(method, i);
		param.initParameterNameDiscovery(parameterNameDiscoverer);
		contributor.contributeMethodArgument(param, args[i], builder, uriVars);
	}

	// This may not be all the URI variables, supply what we have so far..
	return builder.uriVariables(uriVars);
}
 
Example #6
Source File: MvcUriComponentsBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
private static UriComponentsBuilder applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
	CompositeUriComponentsContributor contributor = getUriComponentsContributor();

	int paramCount = method.getParameterCount();
	int argCount = args.length;
	if (paramCount != argCount) {
		throw new IllegalArgumentException("Number of method parameters " + paramCount +
				" does not match number of argument values " + argCount);
	}

	final Map<String, Object> uriVars = new HashMap<>();
	for (int i = 0; i < paramCount; i++) {
		MethodParameter param = new SynthesizingMethodParameter(method, i);
		param.initParameterNameDiscovery(parameterNameDiscoverer);
		contributor.contributeMethodArgument(param, args[i], builder, uriVars);
	}

	// This may not be all the URI variables, supply what we have so far..
	return builder.uriVariables(uriVars);
}
 
Example #7
Source File: MvcUriComponentsBuilder.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static CompositeUriComponentsContributor getUriComponentsContributor() {
	WebApplicationContext wac = getWebApplicationContext();
	if (wac != null) {
		try {
			return wac.getBean(MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			// Ignore
		}
	}
	return defaultUriComponentsContributor;
}
 
Example #8
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static CompositeUriComponentsContributor getUriComponentsContributor() {
	WebApplicationContext wac = getWebApplicationContext();
	if (wac != null) {
		try {
			return wac.getBean(MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			// Ignore
		}
	}
	return defaultUriComponentsContributor;
}
 
Example #9
Source File: SpringletsMvcUriComponentsBuilder.java    From springlets with Apache License 2.0 5 votes vote down vote up
private static UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
	CompositeUriComponentsContributor contributor = getConfiguredUriComponentsContributor();
	if (contributor == null) {
		logger.debug("Using default CompositeUriComponentsContributor");
		contributor = defaultUriComponentsContributor;
	}

	int paramCount = method.getParameterTypes().length;
	int argCount = args.length;
	if (paramCount != argCount) {
		throw new IllegalArgumentException("Number of method parameters " + paramCount +
				" does not match number of argument values " + argCount);
	}

	final Map<String, Object> uriVars = new HashMap<String, Object>();
	for (int i = 0; i < paramCount; i++) {
		MethodParameter param = new SynthesizingMethodParameter(method, i);
		param.initParameterNameDiscovery(parameterNameDiscoverer);
		contributor.contributeMethodArgument(param, args[i], builder, uriVars);
	}

	// Custom implementation to remove uriVar if the value is null
	removeUriVarsWithNullValue(uriVars);

	// We may not have all URI var values, expand only what we have
	return builder.build().expand(new UriComponents.UriTemplateVariables() {
		@Override
		public Object getValue(String name) {
			return uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE;
		}
	});
}
 
Example #10
Source File: WebMvcConfigurationSupport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return an instance of {@link CompositeUriComponentsContributor} for use with
 * {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
 * @since 4.0
 */
@Bean
public CompositeUriComponentsContributor mvcUriComponentsContributor(
		FormattingConversionService mvcConversionService,
		RequestMappingHandlerAdapter requestMappingHandlerAdapter) {
	return new CompositeUriComponentsContributor(
			requestMappingHandlerAdapter.getArgumentResolvers(), mvcConversionService);
}
 
Example #11
Source File: MvcUriComponentsBuilder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private static UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
	CompositeUriComponentsContributor contributor = getConfiguredUriComponentsContributor();
	if (contributor == null) {
		logger.debug("Using default CompositeUriComponentsContributor");
		contributor = defaultUriComponentsContributor;
	}

	int paramCount = method.getParameterTypes().length;
	int argCount = args.length;
	if (paramCount != argCount) {
		throw new IllegalArgumentException("Number of method parameters " + paramCount +
				" does not match number of argument values " + argCount);
	}

	final Map<String, Object> uriVars = new HashMap<String, Object>();
	for (int i = 0; i < paramCount; i++) {
		MethodParameter param = new SynthesizingMethodParameter(method, i);
		param.initParameterNameDiscovery(parameterNameDiscoverer);
		contributor.contributeMethodArgument(param, args[i], builder, uriVars);
	}

	// We may not have all URI var values, expand only what we have
	return builder.build().expand(new UriComponents.UriTemplateVariables() {
		@Override
		public Object getValue(String name) {
			return uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE;
		}
	});
}
 
Example #12
Source File: MvcUriComponentsBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
	CompositeUriComponentsContributor contributor = getConfiguredUriComponentsContributor();
	if (contributor == null) {
		logger.debug("Using default CompositeUriComponentsContributor");
		contributor = defaultUriComponentsContributor;
	}

	int paramCount = method.getParameterTypes().length;
	int argCount = args.length;
	if (paramCount != argCount) {
		throw new IllegalArgumentException("Number of method parameters " + paramCount +
				" does not match number of argument values " + argCount);
	}

	final Map<String, Object> uriVars = new HashMap<String, Object>();
	for (int i = 0; i < paramCount; i++) {
		MethodParameter param = new SynthesizingMethodParameter(method, i);
		param.initParameterNameDiscovery(parameterNameDiscoverer);
		contributor.contributeMethodArgument(param, args[i], builder, uriVars);
	}

	// We may not have all URI var values, expand only what we have
	return builder.build().expand(new UriComponents.UriTemplateVariables() {
		@Override
		public Object getValue(String name) {
			return uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE;
		}
	});
}
 
Example #13
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Class<?> getObjectType() {
	return CompositeUriComponentsContributor.class;
}
 
Example #14
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Nullable
public CompositeUriComponentsContributor getObject() {
	return this.uriComponentsContributor;
}
 
Example #15
Source File: WebMvcConfigurationSupport.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return an instance of {@link CompositeUriComponentsContributor} for use with
 * {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
 * @since 4.0
 */
@Bean
public CompositeUriComponentsContributor mvcUriComponentsContributor() {
	return new CompositeUriComponentsContributor(
			requestMappingHandlerAdapter().getArgumentResolvers(), mvcConversionService());
}
 
Example #16
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() {
	this.uriComponentsContributor = new CompositeUriComponentsContributor(
			this.handlerAdapter.getArgumentResolvers(), this.conversionService);
}
 
Example #17
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CompositeUriComponentsContributor getObject() throws Exception {
	return this.uriComponentsContributor;
}
 
Example #18
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Class<?> getObjectType() {
	return CompositeUriComponentsContributor.class;
}
 
Example #19
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void afterPropertiesSet() {
	Assert.state(this.handlerAdapter != null, "No RequestMappingHandlerAdapter set");
	this.uriComponentsContributor = new CompositeUriComponentsContributor(
			this.handlerAdapter.getArgumentResolvers(), this.conversionService);
}
 
Example #20
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@Nullable
public CompositeUriComponentsContributor getObject() {
	return this.uriComponentsContributor;
}
 
Example #21
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void afterPropertiesSet() {
	Assert.state(this.handlerAdapter != null, "No RequestMappingHandlerAdapter set");
	this.uriComponentsContributor = new CompositeUriComponentsContributor(
			this.handlerAdapter.getArgumentResolvers(), this.conversionService);
}
 
Example #22
Source File: WebMvcConfigurationSupport.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Return an instance of {@link CompositeUriComponentsContributor} for use with
 * {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
 */
@Bean
public CompositeUriComponentsContributor mvcUriComponentsContributor() {
	return new CompositeUriComponentsContributor(
			requestMappingHandlerAdapter().getArgumentResolvers(), mvcConversionService());
}
 
Example #23
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() {
	this.uriComponentsContributor = new CompositeUriComponentsContributor(
			this.handlerAdapter.getArgumentResolvers(), this.conversionService);
}
 
Example #24
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public CompositeUriComponentsContributor getObject() throws Exception {
	return this.uriComponentsContributor;
}
 
Example #25
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Class<?> getObjectType() {
	return CompositeUriComponentsContributor.class;
}
 
Example #26
Source File: WebMvcConfigurationSupport.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return an instance of {@link CompositeUriComponentsContributor} for use with
 * {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
 * @since 4.0
 */
@Bean
public CompositeUriComponentsContributor mvcUriComponentsContributor() {
	return new CompositeUriComponentsContributor(
			requestMappingHandlerAdapter().getArgumentResolvers(), mvcConversionService());
}
 
Example #27
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Class<?> getObjectType() {
	return CompositeUriComponentsContributor.class;
}