Example usage for org.springframework.web.context.request ServletWebRequest ServletWebRequest

List of usage examples for org.springframework.web.context.request ServletWebRequest ServletWebRequest

Introduction

In this page you can find the example usage for org.springframework.web.context.request ServletWebRequest ServletWebRequest.

Prototype

public ServletWebRequest(HttpServletRequest request) 

Source Link

Document

Create a new ServletWebRequest instance for the given request.

Usage

From source file:io.pivotal.cla.mvc.support.ImportedSignaturesSessionAttrResolverTests.java

@Test
public void resolveArgumentTrue() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession().setAttribute(ImportedSignaturesSessionAttr.ATTR_NAME, true);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    MethodParameter parameter = new MethodParameter(method, 0);

    ImportedSignaturesSessionAttr resolved = (ImportedSignaturesSessionAttr) resolver.resolveArgument(parameter,
            null, webRequest, null);/*from   ww w.  j  a  v a  2 s .c o m*/
    assertThat(resolved.getValue()).isTrue();
}

From source file:testapp.web.OpenSessionInViewInterceptorFilter.java

/**
 * @see OpenSessionInViewInterceptor/*from ww  w.ja va2  s  .  c om*/
 * @see org.springframework.web.servlet.HandlerInterceptor#afterCompletion
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    log.debug("###### Opening session for request ########");
    OpenSessionInViewInterceptor interceptor = (OpenSessionInViewInterceptor) getApplicationContext()
            .getBean(getInterceptorBeanName());
    WebRequest webRequest = new ServletWebRequest((HttpServletRequest) request);
    interceptor.preHandle(webRequest);
    try {
        chain.doFilter(request, response);
        interceptor.postHandle(webRequest, null);
    } finally {
        interceptor.afterCompletion(webRequest, null);
        log.debug("############ Session closed ###########");
    }
}

From source file:org.openmrs.web.controller.user.UserFormControllerTest.java

/**
 * @see UserFormController#handleSubmission(WebRequest,HttpSession,String,String,String,null, String, User,BindingResult)
 *
 *//*from  w w  w.j  av  a2  s .  com*/
@Test
@Verifies(value = "Creates Provider Account when Provider Account Checkbox is selected", method = "handleSubmission(WebRequest,HttpSession,String,String,String,null, String, User,BindingResult)")
public void handleSubmission_createUserProviderAccountWhenProviderAccountCheckboxIsSelected() throws Exception {
    executeDataSet(TEST_DATA);
    WebRequest request = new ServletWebRequest(new MockHttpServletRequest());
    //A user with userId=2 is preset in the Test DataSet and the relevant details are passed
    User user = Context.getUserService().getUser(2);
    Assert.assertTrue(Context.getProviderService().getProvidersByPerson(user.getPerson()).isEmpty());
    ModelMap model = new ModelMap();
    model.addAttribute("isProvider", false);
    controller.showForm(2, "true", user, model);
    controller.handleSubmission(request, new MockHttpSession(), new ModelMap(), "", null, "Test1234",
            "valid secret question", "valid secret answer", "Test1234", false, new String[] { "Provider" },
            "true", "addToProviderTable", user, new BindException(user, "user"));
    Assert.assertFalse(Context.getProviderService().getProvidersByPerson(user.getPerson()).isEmpty());
}

From source file:gov.nih.nci.cabig.caaers.web.OpenSessionInViewInterceptorFilter.java

/**
 * @see OpenSessionInViewInterceptor/*from  w w  w .j a v  a  2  s . c o m*/
 * @see org.springframework.web.servlet.HandlerInterceptor#afterCompletion
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpReq = ((HttpServletRequest) request);

    if (log.isDebugEnabled()) {
        log.debug("Opening session for request " + httpReq.getMethod() + ' ' + httpReq.getRequestURI());
    }
    OpenSessionInViewInterceptor interceptor = (OpenSessionInViewInterceptor) getApplicationContext()
            .getBean(getInterceptorBeanName());
    WebRequest webRequest = new ServletWebRequest(httpReq);
    interceptor.preHandle(webRequest);
    try {
        chain.doFilter(request, response);
        interceptor.postHandle(webRequest, null);
    } catch (IOException e) {
        serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e);
        throw e;
    } catch (ServletException e) {
        serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e);
        throw e;
    } catch (RuntimeException e) {
        serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e);
        throw e;
    } finally {
        interceptor.afterCompletion(webRequest, null);
        log.debug("Session closed");
    }
}

From source file:org.synyx.hades.extensions.web.PageableArgumentResolverUnitTest.java

@Test(expected = IllegalStateException.class)
public void rejectsInvalidlyMappedPageables() throws Exception {

    MethodParameter parameter = new MethodParameter(failedMethod, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);

    new PageableArgumentResolver().resolveArgument(parameter, webRequest);
}

From source file:org.mytms.common.web.RequestContext.java

/**
 * Sets the current request on the context. Note that this also invokes {@link #setWebRequest(WebRequest)} by wrapping
 * <b>request</b> in a {@link ServletWebRequest}.
 *
 * @param request/*  w w  w . j a  v a 2  s . c  om*/
 */
public void setRequest(HttpServletRequest request) {
    this.request = request;
    this.webRequest = new ServletWebRequest(request);
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testPageableAndUnOrderedSort() throws Exception {

    int pn = 1;/*from w  w w.j  a va 2 s  . c  o m*/
    int pageSize = 10;
    request.setParameter("page.pn", String.valueOf(pn));
    request.setParameter("page.size", String.valueOf(pageSize));
    request.setParameter("sort.id", "desc");
    request.setParameter("sort.baseInfo.realname", "asc");

    MethodParameter parameter = new MethodParameter(pageableAndSort, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);

    //-10
    assertEquals(pn - 1, pageable.getPageNumber());
    assertEquals(pageSize, pageable.getPageSize());
    Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname")
            .and(new Sort(Sort.Direction.DESC, "id"));
    assertEquals(expectedSort, pageable.getSort());
}

From source file:org.openmrs.web.controller.patient.ShortPatientFormControllerTest.java

/**
 * @see ShortPatientFormController#saveShortPatient(WebRequest,ShortPatientModel,BindingResult,SessionStatus)
 *///from ww  w.  ja v a  2  s  .c  o m
@Test
@Verifies(value = "should pass if all the form data is valid", method = "saveShortPatient(WebRequest,ShortPatientModel,BindingResult,SessionStatus)")
public void saveShortPatient_shouldPassIfAllTheFormDataIsValid() throws Exception {
    Patient p = Context.getPatientService().getPatient(2);
    ShortPatientModel patientModel = new ShortPatientModel(p);

    WebRequest mockWebRequest = new ServletWebRequest(new MockHttpServletRequest());
    BindException errors = new BindException(patientModel, "patientModel");
    mockWebRequest.setAttribute("personNameCache", BeanUtils.cloneBean(p.getPersonName()),
            WebRequest.SCOPE_SESSION);
    mockWebRequest.setAttribute("personAddressCache", p.getPersonAddress().clone(), WebRequest.SCOPE_SESSION);
    mockWebRequest.setAttribute("patientModel", patientModel, WebRequest.SCOPE_SESSION);

    ShortPatientFormController controller = (ShortPatientFormController) applicationContext
            .getBean("shortPatientFormController");
    String redirectUrl = controller.saveShortPatient(mockWebRequest,
            (PersonName) mockWebRequest.getAttribute("personNameCache", WebRequest.SCOPE_SESSION),
            (PersonAddress) mockWebRequest.getAttribute("personAddressCache", WebRequest.SCOPE_SESSION), null,
            (ShortPatientModel) mockWebRequest.getAttribute("patientModel", WebRequest.SCOPE_SESSION), errors);

    Assert.assertTrue("Should pass with no validation errors", !errors.hasErrors());
    Assert.assertEquals("Patient.saved",
            mockWebRequest.getAttribute(WebConstants.OPENMRS_MSG_ATTR, WebRequest.SCOPE_SESSION));
    Assert.assertEquals("redirect:/patientDashboard.form?patientId=" + p.getPatientId(), redirectUrl);
}

From source file:org.synyx.hades.extensions.web.PageableArgumentResolverUnitTest.java

@Test(expected = IllegalStateException.class)
public void rejectsInvalidQualifiers() throws Exception {

    MethodParameter parameter = new MethodParameter(invalidQualifiers, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);

    new PageableArgumentResolver().resolveArgument(parameter, webRequest);
}

From source file:org.synyx.hades.extensions.web.PageableArgumentResolverUnitTest.java

@Test
public void assertDefaults() throws Exception {

    MethodParameter parameter = new MethodParameter(defaultsMethod, 0);
    NativeWebRequest webRequest = new ServletWebRequest(new MockHttpServletRequest());
    PageableArgumentResolver resolver = new PageableArgumentResolver();
    Object argument = resolver.resolveArgument(parameter, webRequest);

    assertTrue(argument instanceof Pageable);

    Pageable pageable = (Pageable) argument;
    assertEquals(SampleController.DEFAULT_PAGESIZE, pageable.getPageSize());
    assertEquals(SampleController.DEFAULT_PAGENUMBER, pageable.getPageNumber());
}