List of usage examples for javax.servlet ServletResponse getWriter
public PrintWriter getWriter() throws IOException;
PrintWriter
object that can send character text to the client. From source file:com.netsteadfast.greenstep.sys.GreenStepBaseFormAuthenticationFilter.java
@Override protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception { HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response; if (!this.isAjaxRequest(httpServletRequest)) { httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + this.getSuccessUrl()); } else {/*from w ww . ja va 2 s. c o m*/ response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.getWriter().write(Constants.NO_AUTHZ_JSON_DATA); } return false; }
From source file:com.netsteadfast.greenstep.sys.GreenStepMobileFormAuthenticationFilter.java
@Override protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception { HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response; if (!this.isAjaxRequest(httpServletRequest)) { httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + this.getSuccessUrl()); } else {// www . j a v a 2s . c o m response.setCharacterEncoding(Constants.BASE_ENCODING); response.setContentType("application/json"); response.getWriter().write(Constants.NO_AUTHZ_JSON_DATA); } return false; }
From source file:com.edgenius.wiki.security.acegi.CaptchaValidationProcessingFilter.java
private void processVerify(ServletRequest request, ServletResponse response, FilterChain chain, boolean valid) throws IOException, ServletException { if (valid) {/*from ww w .ja va2 s.com*/ //success chain.doFilter(request, response); } else { //failed if (((HttpServletRequest) request).getRequestURI().endsWith("j_spring_security_check")) { //as user login using Form submit style authentication rather than RPC's so that I have to do special handling here //code ugly, it could be changed to RPC authentication in future. response.getWriter() .write(SharedConstants.FORM_RET_HEADER + SharedConstants.FORM_RET_HEADER_ERROR_CAPTCHA); } else { // Put exception into request scope (perhaps of use to a view) ((HttpServletRequest) request).setAttribute(ACEGI_SECURITY_CAPTCHA_VALID_FAILED, true); // Perform RequestDispatcher "forward" RequestDispatcher rd = request.getRequestDispatcher(errorPage); rd.forward(request, response); } } }
From source file:de.betterform.agent.web.filter.XSLTFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; ServletContext servletContext = filterConfig.getServletContext(); /* TODO: clean up, styleFile is never used */ String stylePath = null;/*from ww w. j a v a 2s . c om*/ try { stylePath = WebFactory.getRealPath(xsltPath, servletContext); } catch (XFormsConfigException e) { throw new ServletException(e); } File styleFile = new File(stylePath, xslFile); PrintWriter out = response.getWriter(); CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response); try { URI uri = new File(WebFactory.getRealPath(xsltPath, servletContext)).toURI().resolve(new URI(xslFile)); XSLTGenerator generator = WebFactory.setupTransformer(uri, servletContext); wrapper.setContentType("text/html"); chain.doFilter(request, wrapper); StringReader sr = new StringReader(wrapper.toString()); generator.setInput(sr); // Source xmlSource = new StreamSource((Reader) sr); CharArrayWriter caw = new CharArrayWriter(); generator.setOutput(caw); // StreamResult result = new StreamResult(caw); // transformer.transform(xmlSource, result); generator.generate(); response.setContentLength(caw.toString().length()); out.write(caw.toString()); } catch (URISyntaxException e) { out.println(e.toString()); out.write(wrapper.toString()); } catch (XFormsException e) { out.println(e.toString()); out.write(wrapper.toString()); } }
From source file:com.shopzilla.ducky.WadlXsltFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (this.requestMatcher.match(request)) { LOG.debug("adding transform"); ByteBufferResponseWrapper wrapper = new ByteBufferResponseWrapper((HttpServletResponse) response); String styleSheetPath = makeProcessingInstruction(request); chain.doFilter(request, wrapper); wrapper.getWriter().flush();/*from w w w.j a v a2s . co m*/ String responseStr = injectStyleSheet(wrapper.toString(), styleSheetPath); response.setContentLength(responseStr.length()); PrintWriter out = response.getWriter(); out.append(responseStr); out.flush(); } else { LOG.debug("NOT adding transform"); // just pass it along chain.doFilter(request, response); } }
From source file:cn.powerdash.libsystem.common.security.authc.SessionTimeoutAuthenticationFilter.java
@Override protected void saveRequestAndRedirectToLogin(ServletRequest request, ServletResponse response) throws IOException { saveRequest(request);/*from ww w. ja v a 2 s .c om*/ HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; if (WebUtil.isAjaxRequest(req)) { ObjectMapper objectMapper = new ObjectMapper(); res.setContentType("application/json;charset=UTF-8"); res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); ResultDto<String> error = new ResultDto<String>(); error.setCode(ResultCode.SESSION_TIME_OUT); error.setMessage(MessageUtil.getMessage(SESSION_TIMEOUT_MSG)); objectMapper.writeValue(response.getWriter(), error); LOGGER.debug("session time out for ajax request:{}", req.getRequestURI()); } else { LOGGER.debug("session time out for request:{}", req.getRequestURI()); req.getSession().setAttribute(SESSION_TIMEOUT, true); redirectToLogin(request, response); } HttpSession session = req.getSession(false); if (session != null) { LOGGER.debug( "session time out with id: {}, is sesion new:{}, started: {}, last accessed: {}, request headers: {}", session.getId(), session.isNew(), DateFormatUtils.format(session.getCreationTime(), DATE_FORMAT), DateFormatUtils.format(session.getLastAccessedTime(), DATE_FORMAT), getHeaderString(request)); } else { LOGGER.debug("session time out, no session available for current request"); } }
From source file:org.frat.common.security.authc.SessionTimeoutAuthenticationFilter.java
@Override protected void saveRequestAndRedirectToLogin(ServletRequest request, ServletResponse response) throws IOException { saveRequest(request);/*from w w w . j av a2 s .c o m*/ HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; if (WebUtil.isAjaxRequest(req)) { ObjectMapper objectMapper = new ObjectMapper(); res.setContentType("application/json;charset=UTF-8"); res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); ResultDto error = new ResultDto(); error.setCode(ResultCode.SESSION_TIME_OUT); error.setMessage(MessageUtil.getMessage(SESSION_TIMEOUT_MSG)); objectMapper.writeValue(response.getWriter(), error); LOGGER.debug("session time out for ajax request:{}", req.getRequestURI()); } else { LOGGER.debug("session time out for request:{}", req.getRequestURI()); req.getSession().setAttribute(SESSION_TIMEOUT, true); redirectToLogin(request, response); } HttpSession session = req.getSession(false); if (session != null) { LOGGER.debug( "session time out with id:" + " {}, is sesion new:{}, started: {}, last accessed: {}, request headers: {}", session.getId(), session.isNew(), DateFormatUtils.format(session.getCreationTime(), DATE_FORMAT), DateFormatUtils.format(session.getLastAccessedTime(), DATE_FORMAT), getHeaderString(request)); } else { LOGGER.debug("session time out, no session available for current request"); } }
From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java
private void finishResponse(ServletResponse res) throws ServletException, IOException { if (res instanceof HttpServletResponseImpl) { res.flushBuffer(); // we sure that all data has already put to the ByteBuf? } else {/* ww w . j ava 2 s . c o m*/ try { OutputStream os = res.getOutputStream(); os.flush(); // os.close(); } catch (Exception e) { } try { PrintWriter out = res.getWriter(); out.flush(); // out.close(); } catch (Exception e) { } } }
From source file:org.apache.myfaces.tomahawk.application.jsp.JspTilesTwoViewHandlerImpl.java
private void renderTilesView(FacesContext facesContext, Object[] requestObjects, TilesContainer container, UIViewRoot viewToRender, String viewId, String tilesId) throws IOException { ExternalContext externalContext = facesContext.getExternalContext(); handleCharacterEncoding(viewId, externalContext, viewToRender); container.startContext(requestObjects); try {//from w w w .j a va 2s . co m //container.render(tilesId,requestObjects); buildTilesViewLikeContainer(externalContext, container, tilesId, requestObjects); } catch (TilesException e) { throw new FacesException(e); } finally { container.endContext(requestObjects); } handleCharacterEncodingPostDispatch(externalContext); // render the view in this method (since JSF 1.2) RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder .getFactory(FactoryFinder.RENDER_KIT_FACTORY); RenderKit renderKit = renderFactory.getRenderKit(facesContext, viewToRender.getRenderKitId()); ServletResponse response = (ServletResponse) requestObjects[1]; ResponseWriter responseWriter = facesContext.getResponseWriter(); if (responseWriter == null) { responseWriter = renderKit.createResponseWriter(response.getWriter(), null, ((HttpServletRequest) externalContext.getRequest()).getCharacterEncoding()); facesContext.setResponseWriter(responseWriter); } ResponseWriter oldResponseWriter = responseWriter; StateMarkerAwareWriter stateAwareWriter = null; StateManager stateManager = facesContext.getApplication().getStateManager(); if (stateManager.isSavingStateInClient(facesContext)) { stateAwareWriter = new StateMarkerAwareWriter(); // Create a new response-writer using as an underlying writer the stateAwareWriter // Effectively, all output will be buffered in the stateAwareWriter so that later // this writer can replace the state-markers with the actual state. responseWriter = oldResponseWriter.cloneWithWriter(stateAwareWriter); facesContext.setResponseWriter(responseWriter); } actuallyRenderView(facesContext, viewToRender); //We're done with the document - now we can write all content //to the response, properly replacing the state-markers on the way out //by using the stateAwareWriter if (stateManager.isSavingStateInClient(facesContext)) { stateAwareWriter.flushToWriter(response.getWriter()); } else { stateManager.saveView(facesContext); } // Final step - we output any content in the wrappedResponse response from above to the response, // removing the wrappedResponse response from the request, we don't need it anymore ViewResponseWrapper afterViewTagResponse = (ViewResponseWrapper) externalContext.getRequestMap() .get(AFTER_VIEW_TAG_CONTENT_PARAM); externalContext.getRequestMap().remove(AFTER_VIEW_TAG_CONTENT_PARAM); if (afterViewTagResponse != null) { afterViewTagResponse.flushToWriter(response.getWriter(), facesContext.getExternalContext().getResponseCharacterEncoding()); } response.flushBuffer(); }
From source file:org.uberfire.server.locale.GWTLocaleHeaderFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { final CharResponseWrapper wrappedResponse = getWrapper((HttpServletResponse) response); chain.doFilter(request, wrappedResponse); final String output; final Locale locale = getLocale(request); final String injectedScript = "<meta name=\"gwt:property\" content=\"locale=" + locale.toString() + "\">"; final Document document = Jsoup.parse(wrappedResponse.toString()); document.head().append(injectedScript); output = document.html();//w ww . ja va 2 s.co m final byte[] outputBytes = output.getBytes("UTF-8"); response.setContentLength(outputBytes.length); response.getWriter().print(output); }