List of usage examples for org.springframework.web.servlet.mvc Controller handleRequest
@Nullable
ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception;
From source file:com.bstek.dorado.web.resolver.AbstractControllerResolver.java
@Override protected ModelAndView doHandleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String uri = getRelativeRequestURI(request); if (!PathUtils.isSafePath(uri)) { throw new PageAccessDeniedException("[" + request.getRequestURI() + "] Request forbidden."); }// w ww.ja va 2 s . c o m String controllerName = extractControllerName(uri); Controller controller = getController(controllerName); return controller.handleRequest(request, response); }
From source file:com.googlecode.psiprobe.controllers.BeanToXmlController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String path = request.getServletPath(); String internalPath = path.replaceAll(xmlMarker, ""); Controller controller = (Controller) getApplicationContext().getBean(internalPath); if (controller != null) { ModelAndView modelAndView = controller.handleRequest(request, response); if (modelAndView.getModel() != null) { TransportableModel tm = new TransportableModel(); tm.putAll(modelAndView.getModel()); XStream x = new XStream(); x.toXML(tm, response.getWriter()); }//from w w w. j ava2 s . co m } return null; }
From source file:psiprobe.controllers.BeanToXmlController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String path = request.getServletPath(); String internalPath = path.replaceAll(xmlMarker, ""); Controller controller = (Controller) getApplicationContext().getBean(internalPath); if (controller != null) { ModelAndView modelAndView = controller.handleRequest(request, response); if (modelAndView.getModel() != null) { TransportableModel tm = new TransportableModel(); tm.putAll(modelAndView.getModel()); new XStream().toXML(tm, response.getWriter()); }/*from w ww.j av a 2 s.c om*/ } return null; }
From source file:no.dusken.aranea.web.spring.ChainedController.java
/** * Calls the handleRequest controller for each of the Controllers in the * chain sequentially, merging the ModelAndView objects returned after each * call and returning the merged ModelAndView object. An exception thrown by * any of the controllers in the chain will propagate upwards through the * handleRequest() method of the ChainedController. The ChainedController * itself does not support any communication between the controllers in the * chain, but this can be effected by the controllers posting to a common * accessible object such as the ApplicationContext. Note that this will * introduce coupling between the controllers and will be difficult to * arrange into a parallel chain. A controller can stop processing of the * chain by returning a null ModelAndView object. Enhanced with adding the * chained views to the controller. This enables the controller to render * the views from the chained controllers. * * @param request the HttpServletRequest object. * @param response the HttpServletResponse object. * @return the merged ModelAndView object for all the controllers. * @throws Exception if one is thrown by one of the controllers in the chain. *///from ww w. ja v a2s.com public ModelAndView handleRequestSequentially(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mergedModel = new ModelAndView(); List<String> mergedViews = new ArrayList<String>(); for (Controller controller : controllers) { try { ModelAndView model = controller.handleRequest(request, response); if (model == null) { // chain will stop if a controller returns a null // ModelAndView object. break; } mergedModel.addAllObjects(model.getModel()); mergedViews.add(model.getViewName()); } catch (Exception e) { throw new Exception( "Controller: " + controller.getClass().getName() + " threw exception: " + e.getMessage(), e); } } mergedModel.addObject("views", mergedViews); if (StringUtils.isNotEmpty(this.viewName)) { mergedModel.setViewName(this.viewName); } return mergedModel; }
From source file:org.castafiore.web.servlet.CastafioreMethodServlet.java
@Override public void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { if (request.getParameter("controller") != null) { String controller = request.getParameter("controller"); Controller c = (Controller) BaseSpringUtil.getBean(controller); c.handleRequest(request, response); return;/*from w w w .ja v a2s.c om*/ } String applicationid = request.getParameter("applicationid"); String componentid = request.getParameter("componentid"); String methodName = request.getParameter("method"); String param = request.getParameter("paramName") != null ? request.getParameter(request.getParameter("paramName")) : null; try { Application applicationInstance = (Application) ((HttpServletRequest) request).getSession() .getAttribute(applicationid); Container c = ComponentUtil.getContainerById(applicationInstance, componentid); if (c instanceof Controller) { ((Controller) c).handleRequest(request, response); return; } Object o = c.getClass().getMethod(methodName, String.class).invoke(c, param); if (o != null) { if (o instanceof InputStream) { ChannelUtil.TransferData((InputStream) o, response.getOutputStream()); response.getOutputStream().flush(); } else if (o instanceof JSObject) { response.getOutputStream().write(((JSObject) o).getJavascript().getBytes()); response.getOutputStream().flush(); } else { response.getOutputStream().write(o.toString().getBytes()); response.getOutputStream().flush(); } //response.setContentType(MimeUtility); ((HttpServletResponse) response).setHeader("Content-Disposition", "filename=" + methodName.replace("_", ".")); } } catch (Exception e) { throw new ServletException("unable to load method since the params passed are not correct", e); } }