org.springframework.web.bind.support.WebRequestDataBinder Java Examples

The following examples show how to use org.springframework.web.bind.support.WebRequestDataBinder. 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: AbstractRequestAttributesArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolveOptional() throws Exception {
	WebDataBinder dataBinder = new WebRequestDataBinder(null);
	dataBinder.setConversionService(new DefaultConversionService());
	WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
	given(factory.createBinder(this.webRequest, null, "foo")).willReturn(dataBinder);

	MethodParameter param = initMethodParameter(3);
	Object actual = testResolveArgument(param, factory);
	assertNotNull(actual);
	assertEquals(Optional.class, actual.getClass());
	assertFalse(((Optional<?>) actual).isPresent());

	Foo foo = new Foo();
	this.webRequest.setAttribute("foo", foo, getScope());

	actual = testResolveArgument(param, factory);
	assertNotNull(actual);
	assertEquals(Optional.class, actual.getClass());
	assertTrue(((Optional<?>) actual).isPresent());
	assertSame(foo, ((Optional<?>) actual).get());
}
 
Example #2
Source File: AbstractRequestAttributesArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolveOptional() throws Exception {
	WebDataBinder dataBinder = new WebRequestDataBinder(null);
	dataBinder.setConversionService(new DefaultConversionService());
	WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
	given(factory.createBinder(this.webRequest, null, "foo")).willReturn(dataBinder);

	MethodParameter param = initMethodParameter(3);
	Object actual = testResolveArgument(param, factory);
	assertNotNull(actual);
	assertEquals(Optional.class, actual.getClass());
	assertFalse(((Optional<?>) actual).isPresent());

	Foo foo = new Foo();
	this.webRequest.setAttribute("foo", foo, getScope());

	actual = testResolveArgument(param, factory);
	assertNotNull(actual);
	assertEquals(Optional.class, actual.getClass());
	assertTrue(((Optional<?>) actual).isPresent());
	assertSame(foo, ((Optional<?>) actual).get());
}
 
Example #3
Source File: TicketResource.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * Obtain credentials from the request.
 *
 * @return the credential
 */
protected Credential obtainCredentials() {
    final UsernamePasswordCredential c = new UsernamePasswordCredential();
    final WebRequestDataBinder binder = new WebRequestDataBinder(c);
    final RestletWebRequest webRequest = new RestletWebRequest(getRequest());

    final Form form = new Form(getRequest().getEntity());
    logFormRequest(form);

    if (!form.isEmpty()) {
        binder.bind(webRequest);
        return c;
    }
    LOGGER.trace("Failed to bind the request to credentials. Resulting form is empty");
    return null;
}
 
Example #4
Source File: ModelAttributeMethodProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void getAttributeFromModel(String expectedAttributeName, MethodParameter param) throws Exception {
	Object target = new TestBean();
	mavContainer.addAttribute(expectedAttributeName, target);

	WebDataBinder dataBinder = new WebRequestDataBinder(target);
	WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
	given(factory.createBinder(webRequest, target, expectedAttributeName)).willReturn(dataBinder);

	processor.resolveArgument(param, mavContainer, webRequest, factory);
	verify(factory).createBinder(webRequest, target, expectedAttributeName);
}
 
Example #5
Source File: ModelAttributeMethodProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void resovleArgumentViaDefaultConstructor() throws Exception {
	WebDataBinder dataBinder = new WebRequestDataBinder(null);

	WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
	given(factory.createBinder((NativeWebRequest) anyObject(), notNull(), eq("attrName"))).willReturn(dataBinder);

	processor.resolveArgument(paramNamedValidModelAttr, mavContainer, webRequest, factory);

	verify(factory).createBinder((NativeWebRequest) anyObject(), notNull(), eq("attrName"));
}
 
Example #6
Source File: TicketResource.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
protected Credential obtainCredentials() {
    final UsernamePasswordCredential c = new UsernamePasswordCredential();
    final WebRequestDataBinder binder = new WebRequestDataBinder(c);
    final RestletWebRequest webRequest = new RestletWebRequest(getRequest());

    logFormRequest(new Form(getRequest().getEntity()));
    binder.bind(webRequest);

    return c;
}
 
Example #7
Source File: ModelAttributeMethodProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void testGetAttributeFromModel(String expectedAttrName, MethodParameter param) throws Exception {
	Object target = new TestBean();
	this.container.addAttribute(expectedAttrName, target);

	WebDataBinder dataBinder = new WebRequestDataBinder(target);
	WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
	given(factory.createBinder(this.request, target, expectedAttrName)).willReturn(dataBinder);

	this.processor.resolveArgument(param, this.container, this.request, factory);
	verify(factory).createBinder(this.request, target, expectedAttrName);
}
 
Example #8
Source File: ModelAttributeMethodProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveArgumentViaDefaultConstructor() throws Exception {
	WebDataBinder dataBinder = new WebRequestDataBinder(null);
	WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
	given(factory.createBinder(any(), notNull(), eq("attrName"))).willReturn(dataBinder);

	this.processor.resolveArgument(this.paramNamedValidModelAttr, this.container, this.request, factory);
	verify(factory).createBinder(any(), notNull(), eq("attrName"));
}
 
Example #9
Source File: ModelAttributeMethodProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void testGetAttributeFromModel(String expectedAttrName, MethodParameter param) throws Exception {
	Object target = new TestBean();
	this.container.addAttribute(expectedAttrName, target);

	WebDataBinder dataBinder = new WebRequestDataBinder(target);
	WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
	given(factory.createBinder(this.request, target, expectedAttrName)).willReturn(dataBinder);

	this.processor.resolveArgument(param, this.container, this.request, factory);
	verify(factory).createBinder(this.request, target, expectedAttrName);
}
 
Example #10
Source File: ModelAttributeMethodProcessorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void resolveArgumentViaDefaultConstructor() throws Exception {
	WebDataBinder dataBinder = new WebRequestDataBinder(null);
	WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
	given(factory.createBinder(any(), notNull(), eq("attrName"))).willReturn(dataBinder);

	this.processor.resolveArgument(this.paramNamedValidModelAttr, this.container, this.request, factory);
	verify(factory).createBinder(any(), notNull(), eq("attrName"));
}
 
Example #11
Source File: HandlerMethodInvoker.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName)
		throws Exception {

	return new WebRequestDataBinder(target, objectName);
}
 
Example #12
Source File: HandlerMethodInvoker.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected void doBind(WebDataBinder binder, NativeWebRequest webRequest) throws Exception {
	((WebRequestDataBinder) binder).bind(webRequest);
}
 
Example #13
Source File: HandlerMethodInvoker.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName)
		throws Exception {

	return new WebRequestDataBinder(target, objectName);
}
 
Example #14
Source File: HandlerMethodInvoker.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected void doBind(WebDataBinder binder, NativeWebRequest webRequest) throws Exception {
	((WebRequestDataBinder) binder).bind(webRequest);
}
 
Example #15
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
@Test
public void missingRequestParamEmptyValueConvertedToNull() throws Exception {

	WebDataBinder binder = new WebRequestDataBinder(null);
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

	WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
	given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);

	this.request.addParameter("stringNotAnnot", "");

	Object arg = resolver.resolveArgument(paramStringNotAnnot, null, webRequest, binderFactory);

	assertNull(arg);
}
 
Example #16
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
@Test
public void missingRequestParamEmptyValueNotRequired() throws Exception {

	WebDataBinder binder = new WebRequestDataBinder(null);
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

	WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
	given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);

	this.request.addParameter("name", "");

	Object arg = resolver.resolveArgument(paramNotRequired, null, webRequest, binderFactory);

	assertNull(arg);
}
 
Example #17
Source File: ModelAttributeMethodProcessor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Extension point to bind the request to the target object.
 * @param binder the data binder instance to use for the binding
 * @param request the current request
 */
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
	((WebRequestDataBinder) binder).bind(request);
}
 
Example #18
Source File: ModelAttributeMethodProcessor.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Extension point to bind the request to the target object.
 * @param binder the data binder instance to use for the binding
 * @param request the current request
 */
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
	((WebRequestDataBinder) binder).bind(request);
}
 
Example #19
Source File: ModelAttributeMethodProcessor.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Extension point to bind the request to the target object.
 * @param binder the data binder instance to use for the binding
 * @param request the current request
 */
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
	((WebRequestDataBinder) binder).bind(request);
}
 
Example #20
Source File: ModelAttributeMethodProcessor.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Extension point to bind the request to the target object.
 * @param binder the data binder instance to use for the binding
 * @param request the current request
 */
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
	((WebRequestDataBinder) binder).bind(request);
}