Search in sources :

Example 1 with RequestDataValueProcessor

use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.

the class FormTag method processAction.

/**
	 * Process the action through a {@link RequestDataValueProcessor} instance
	 * if one is configured or otherwise returns the action unmodified.
	 */
private String processAction(String action) {
    RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
    ServletRequest request = this.pageContext.getRequest();
    if (processor != null && request instanceof HttpServletRequest) {
        action = processor.processAction((HttpServletRequest) request, action, getHttpMethod());
    }
    return action;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestDataValueProcessor(org.springframework.web.servlet.support.RequestDataValueProcessor)

Example 2 with RequestDataValueProcessor

use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.

the class FormTagTests method requestDataValueProcessorHooks.

@Test
public void requestDataValueProcessorHooks() throws Exception {
    String action = "/my/form?foo=bar";
    RequestDataValueProcessor processor = getMockRequestDataValueProcessor();
    given(processor.processAction(this.request, action, "post")).willReturn(action);
    given(processor.getExtraHiddenFields(this.request)).willReturn(Collections.singletonMap("key", "value"));
    this.tag.doStartTag();
    this.tag.doEndTag();
    this.tag.doFinally();
    String output = getOutput();
    assertEquals("<div>\n<input type=\"hidden\" name=\"key\" value=\"value\" />\n</div>", getInputTag(output));
    assertFormTagOpened(output);
    assertFormTagClosed(output);
}
Also used : RequestDataValueProcessor(org.springframework.web.servlet.support.RequestDataValueProcessor) Test(org.junit.Test)

Example 3 with RequestDataValueProcessor

use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.

the class RedirectViewTests method updateTargetUrl.

@Test
public void updateTargetUrl() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
    wac.setServletContext(new MockServletContext());
    wac.refresh();
    RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
    wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
    RedirectView rv = new RedirectView();
    // Init RedirectView with WebAppCxt
    rv.setApplicationContext(wac);
    rv.setUrl("/path");
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
    rv.render(new ModelMap(), request, response);
    verify(mockProcessor).processUrl(request, "/path");
}
Also used : RequestDataValueProcessor(org.springframework.web.servlet.support.RequestDataValueProcessor) RequestDataValueProcessorWrapper(org.springframework.web.servlet.support.RequestDataValueProcessorWrapper) ModelMap(org.springframework.ui.ModelMap) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 4 with RequestDataValueProcessor

use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.

the class RedirectViewTests method updateTargetUrlWithContextLoader.

@Test
public void updateTargetUrlWithContextLoader() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
    MockServletContext servletContext = new MockServletContext();
    ContextLoader contextLoader = new ContextLoader(wac);
    contextLoader.initWebApplicationContext(servletContext);
    try {
        RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
        wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
        RedirectView rv = new RedirectView();
        rv.setUrl("/path");
        given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
        rv.render(new ModelMap(), request, response);
        verify(mockProcessor).processUrl(request, "/path");
    } finally {
        contextLoader.closeWebApplicationContext(servletContext);
    }
}
Also used : ContextLoader(org.springframework.web.context.ContextLoader) RequestDataValueProcessor(org.springframework.web.servlet.support.RequestDataValueProcessor) RequestDataValueProcessorWrapper(org.springframework.web.servlet.support.RequestDataValueProcessorWrapper) ModelMap(org.springframework.ui.ModelMap) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 5 with RequestDataValueProcessor

use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.

the class UrlTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    String url = createUrl();
    RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
    ServletRequest request = this.pageContext.getRequest();
    if ((processor != null) && (request instanceof HttpServletRequest)) {
        url = processor.processUrl((HttpServletRequest) request, url);
    }
    if (this.var == null) {
        // print the url to the writer
        try {
            pageContext.getOut().print(url);
        } catch (IOException ex) {
            throw new JspException(ex);
        }
    } else {
        // store the url as a variable
        pageContext.setAttribute(var, url, scope);
    }
    return EVAL_PAGE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) RequestDataValueProcessor(org.springframework.web.servlet.support.RequestDataValueProcessor) IOException(java.io.IOException)

Aggregations

RequestDataValueProcessor (org.springframework.web.servlet.support.RequestDataValueProcessor)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ServletRequest (javax.servlet.ServletRequest)4 Test (org.junit.Test)4 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)3 RequestDataValueProcessorWrapper (org.springframework.web.servlet.support.RequestDataValueProcessorWrapper)3 MockServletContext (org.springframework.mock.web.test.MockServletContext)2 ModelMap (org.springframework.ui.ModelMap)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 JspException (javax.servlet.jsp.JspException)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 CsrfToken (org.springframework.security.web.csrf.CsrfToken)1 DefaultCsrfToken (org.springframework.security.web.csrf.DefaultCsrfToken)1 ContextLoader (org.springframework.web.context.ContextLoader)1