List of usage examples for org.springframework.web.servlet.support RequestContextUtils findWebApplicationContext
@Nullable public static WebApplicationContext findWebApplicationContext(HttpServletRequest request)
From source file:ch.ralscha.extdirectspring.bean.ExtDirectResponseBuilder.java
/** * Creates an "exception" response. Calls {@link ExtDirectResponse#setType(String)} * with a value of "exception". Calls {@link ExtDirectResponse#setMessage(String)} and * {@link ExtDirectResponse#setWhere(String)} according to the {@link Configuration}. * * This is a method primarily used for implementations of * {@link HandlerExceptionResolver}.// ww w.j a v a 2s. c o m * * @param exception the exception that was thrown. * @return this instance */ public ExtDirectResponseBuilder setException(Exception exception) { unsuccessful(); WebApplicationContext ctx = RequestContextUtils.findWebApplicationContext(this.request); Configuration configuration; try { configuration = ctx.getBean(Configuration.class); } catch (NoSuchBeanDefinitionException e) { configuration = new Configuration(); } this.extDirectResponse.setType("exception"); this.extDirectResponse.setMessage(configuration.getMessage(exception)); if (configuration.isSendStacktrace()) { this.extDirectResponse.setWhere(ExtDirectSpringUtil.getStackTrace(exception)); } else { this.extDirectResponse.setWhere(null); } return this; }
From source file:ch.ralscha.extdirectspring.bean.ExtDirectResponseBuilder.java
/** * Builds and writes the response into the OutputStream of {@link HttpServletResponse} * . This methods has to be called at the end of a FORM_POST method. *///from w w w . j av a 2 s. com public void buildAndWrite() { try { RouterController routerController = RequestContextUtils.findWebApplicationContext(this.request) .getBean(RouterController.class); routerController.writeJsonResponse(this.request, this.response, this.extDirectResponse, this.jsonView); } catch (IOException e) { LogFactory.getLog(getClass()).error("buildAndWrite", e); throw new RuntimeException(e); } }