Example usage for org.springframework.web.servlet HandlerAdapter handle

List of usage examples for org.springframework.web.servlet HandlerAdapter handle

Introduction

In this page you can find the example usage for org.springframework.web.servlet HandlerAdapter handle.

Prototype

@Nullable
ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception;

Source Link

Document

Use the given handler to handle this request.

Usage

From source file:org.openmrs.module.clinicalsummary.web.service.PatientIndexControllerTest.java

/**
 * @verifies return empty list when no index found for the patient
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientIndexController#searchIndex(String, String, Integer, javax.servlet.http.HttpServletResponse)
 *//*from  ww w  . ja  v  a 2 s  .  co  m*/
@Test
public void searchIndex_shouldReturnEmptyListWhenNoIndexFoundForThePatient() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/index");
    request.setParameter("patientId", String.valueOf(8));
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSummaryControllerTest.java

/**
 * @verifies return summary data for patient and summary
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSummaryController#searchSummary(String, String, String, Integer, javax.servlet.http.HttpServletResponse)
 *///  www .  j  av  a 2 s  . c  o  m
@Test
public void searchSummary_shouldReturnSummaryDataForPatientAndSummary() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/summary");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");
    request.setParameter("patientId", "7");
    request.setParameter("summaryId", "3");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertFalse(StringUtils.isNotEmpty(response.getContentAsString()));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSummaryControllerTest.java

/**
 * @verifies return empty data when no index found for the patient and summary
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSummaryController#searchSummary(String, String, String, Integer, javax.servlet.http.HttpServletResponse)
 *//*from   w  ww .  j  a v a 2 s.  c  o  m*/
@Test
public void searchSummary_shouldReturnEmptyDataWhenNoIndexFoundForThePatientAndSummary() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/summary");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");
    request.setParameter("patientId", "7");
    request.setParameter("summaryId", "4");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertFalse(StringUtils.isNotEmpty(response.getContentAsString()));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientIndexControllerTest.java

/**
 * @verifies return indexes for the patient
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientIndexController#searchIndex(String, String, Integer, javax.servlet.http.HttpServletResponse)
 *//*from   w w w  .j  a  v a 2s.c o  m*/
@Test
public void searchIndex_shouldReturnIndexesForThePatient() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/index");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");
    request.setParameter("patientId", String.valueOf(7));

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "Collet Test Chebaskwony"));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "6TS-4"));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSearchControllerTest.java

/**
 * @verifies should return empty list when no patient match search term
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSearchController#searchPatient(String, String, String, javax.servlet.http.HttpServletResponse)
 *//*from  w  w  w  . j  av a  2s. com*/
@Test
public void searchPatient_shouldReturnEmptyListWhenNoPatientMatchSearchTerm() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/search");
    request.setParameter("term", "999-3");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
    Assert.assertFalse(StringUtils.contains(response.getContentAsString(), "999-3"));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSearchControllerTest.java

/**
 * @verifies should return patients with name search term
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSearchController#searchPatient(String, String, String, javax.servlet.http.HttpServletResponse)
 *///from   w w w .  j a va2s. co m
@Test
public void searchPatient_shouldReturnPatientsWithNameSearchTerm() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/search");
    request.setParameter("term", "Collet");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "Collet Test Chebaskwony"));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "6TS-4"));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSearchControllerTest.java

/**
 * @verifies should return patients with identifier search term
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSearchController#searchPatient(String, String, String, javax.servlet.http.HttpServletResponse)
 *//*from w w  w  .j ava  2s .  c o  m*/
@Test
public void searchPatient_shouldReturnPatientsWithIdentifierSearchTerm() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/search");
    request.setParameter("term", "6TS-4");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "Collet Test Chebaskwony"));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "6TS-4"));
}

From source file:au.com.gaiaresources.bdrs.controller.test.TestDataCreator.java

private ModelAndView handle(HttpServletRequest request, HttpServletResponse response) throws Exception {
    final HandlerMapping handlerMapping = appContext.getBean(HandlerMapping.class);
    final HandlerAdapter handlerAdapter = appContext.getBean(HandlerAdapter.class);
    final HandlerExecutionChain handler = handlerMapping.getHandler(request);

    Object controller = handler.getHandler();
    // if you want to override any injected attributes do it here

    HandlerInterceptor[] interceptors = handlerMapping.getHandler(request).getInterceptors();
    for (HandlerInterceptor interceptor : interceptors) {
        if (handleInterceptor(interceptor)) {
            final boolean carryOn = interceptor.preHandle(request, response, controller);
            if (!carryOn) {
                return null;
            }//from  ww w.  j  ava2s  . co  m
        }
    }
    ModelAndView mv = handlerAdapter.handle(request, response, controller);
    return mv;
}

From source file:com.mystudy.source.spring.mvc.DispatcherServlet.java

/** 1:?.
 *  2:HandlerExecutionChain,Handler,handlerHandlerInterceptor?
 *  3:?HandlerExecutionChain.handlerHandlerAdapter,HadnlerAdapter.supports()????Handler
 *  4:?lastModified?servlet???,?,?/*from w w w  .j a  v a  2s. c om*/
 *  5:mappedHandler.applyPreHandle??
 *  6:ha.handle(processedRequest, response, mappedHandler.getHandler())??
 *  7:asyncManager.isConcurrentHandlingStarted()??
 *  9?
 *  10:?postHandle
 *  WebAsyncManager:?web
 *  ????
 *  1:
 *  HandlerExecutionChain:?Handler.
 *  getHandler()??
 *  ???handlerMappings???,
 *  for (HandlerMapping hm : this.handlerMappings) {
 if (logger.isTraceEnabled()) {
    logger.trace(
          "Testing handler map [" + hm + "] in DispatcherServlet with name '" + getServletName() + "'");
 }
 HandlerExecutionChain handler = hm.getHandler(request);
 if (handler != null) {
    return handler;
 }
   }
   return null;
   }
           
HandlerExecutionChain:
:
private final Object handler;
        
private HandlerInterceptor[] interceptors;
        
private List<HandlerInterceptor> interceptorList;
        

1handler?HandlerInterceptor????
2preHandle??handler
 3handler??????HttpServletResponse?SpringMVCpostHandle????afterCompletion?web??
        
        
 ????????
  ?HandlerMapping,handlerMappings.?? HandlerInterceptor?
HandlerInterceptor
HandlerInterceptorSpringMVC?????????????
LocaleChangeInterceptor??
        
HandlerAdapter
boolean supports(Object handler);
ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception;
long getLastModified(HttpServletRequest request, Object handler);

1:RequestMappingHandlerAdapter??
        
 * Process the actual dispatching to the handler.
 * <p>The handler will be obtained by applying the servlet's HandlerMappings in order.
 * The HandlerAdapter will be obtained by querying the servlet's installed HandlerAdapters
 * to find the first that supports the handler class.
 * <p>All HTTP methods are handled by this method. It's up to HandlerAdapters or handlers
 * themselves to decide which methods are acceptable.
 * @param request current HTTP request
 * @param response current HTTP response
 * @throws Exception in case of any kind of processing failure
 */
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
    HttpServletRequest processedRequest = request;
    HandlerExecutionChain mappedHandler = null;
    boolean multipartRequestParsed = false;

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);

    try {
        ModelAndView mv = null;
        Exception dispatchException = null;

        try {
            //?
            processedRequest = checkMultipart(request);
            multipartRequestParsed = processedRequest != request;

            //??handler
            // Determine handler for the current request.
            mappedHandler = getHandler(processedRequest, false);
            if (mappedHandler == null || mappedHandler.getHandler() == null) {
                noHandlerFound(processedRequest, response);
                return;
            }

            // ??HandlerAdapter Determine handler adapter for the current request.
            HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());

            // Process last-modified header, if supported by the handler.
            String method = request.getMethod();
            boolean isGet = "GET".equals(method);
            if (isGet || "HEAD".equals(method)) {
                long lastModified = ha.getLastModified(request, mappedHandler.getHandler());
                if (logger.isDebugEnabled()) {
                    String requestUri = urlPathHelper.getRequestUri(request);
                    logger.debug("Last-Modified value for [" + requestUri + "] is: " + lastModified);
                }
                if (new ServletWebRequest(request, response).checkNotModified(lastModified) && isGet) {
                    return;
                }
            }
            //?
            if (!mappedHandler.applyPreHandle(processedRequest, response)) {
                return;
            }

            try {
                //?? Actually invoke the handler.
                mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
            } finally {
                if (asyncManager.isConcurrentHandlingStarted()) {
                    return;
                }
            }

            applyDefaultViewName(request, mv);
            mappedHandler.applyPostHandle(processedRequest, response, mv);
        } catch (Exception ex) {
            dispatchException = ex;
        }
        processDispatchResult(processedRequest, response, mappedHandler, mv, dispatchException);
    } catch (Exception ex) {
        triggerAfterCompletion(processedRequest, response, mappedHandler, ex);
    } catch (Error err) {
        triggerAfterCompletionWithError(processedRequest, response, mappedHandler, err);
    } finally {
        if (asyncManager.isConcurrentHandlingStarted()) {
            // Instead of postHandle and afterCompletion
            mappedHandler.applyAfterConcurrentHandlingStarted(processedRequest, response);
            return;
        }
        // Clean up any resources used by a multipart request.
        if (multipartRequestParsed) {
            cleanupMultipart(processedRequest);
        }
    }
}