/** * Redirect the browser to a location which may be... * <ul> * <li>relative to the current request * <li>relative to the servlet container root (if location starts with '/') * <li>an absolute url * </ul> * If you want a context-relative redirect, use the * {@link ro.pippo.core.Response#redirectToContextPath(String)} method. * If you want an application-relative redirect, use the * {@link ro.pippo.core.Response#redirectToApplicationPath(String)} method. * <p>This method commits the response.</p> * * @param location * Where to redirect */ public void redirect(String location) { checkCommitted(); finalizeResponse(); try { httpServletResponse.sendRedirect(location); } catch (IOException e) { throw new PippoRuntimeException(e); } }
private void commit(CharSequence content) { checkCommitted(); finalizeResponse(); // content type to TEXT_HTML if it's not set if (getContentType() == null) { contentType(HttpConstants.ContentType.TEXT_HTML); } try { if (content != null) { contentLength(content.toString().getBytes().length); httpServletResponse.getWriter().append(content); } log.trace("Response committed"); if (chunked) { httpServletResponse.flushBuffer(); } finishGZip(); } catch (IOException e) { throw new PippoRuntimeException(e); } }
public PrintWriter getWriter() { checkCommitted(); finalizeResponse(); if (getContentType() == null) { contentType(HttpConstants.ContentType.TEXT_HTML); } try { return httpServletResponse.getWriter(); } catch (IOException e) { throw new PippoRuntimeException(e); } }
public ServletOutputStream getOutputStream() { checkCommitted(); finalizeResponse(); // content type to OCTET_STREAM if it's not set if (getContentType() == null) { contentType(HttpConstants.ContentType.APPLICATION_OCTET_STREAM); } try { return httpServletResponse.getOutputStream(); } catch (IOException e) { throw new PippoRuntimeException(e); } }
/** * A permanent (3XX status code) redirect. * <p>This method commits the response.</p> * * @param location * @param statusCode */ public void redirect(String location, int statusCode) { checkCommitted(); finalizeResponse(); status(statusCode); header(HttpConstants.Header.LOCATION, location); header(HttpConstants.Header.CONNECTION, "close"); try { httpServletResponse.sendError(statusCode); } catch (IOException e) { throw new PippoRuntimeException(e); } }
/** * Copies the input stream to the response output stream and closes the input stream upon completion. * <p>This method commits the response.</p> * * @param input */ public void resource(InputStream input) { checkCommitted(); finalizeResponse(); // content type to OCTET_STREAM if it's not set if (getContentType() == null) { contentType(HttpConstants.ContentType.APPLICATION_OCTET_STREAM); } try { send(input); } catch (IOException e) { throw new PippoRuntimeException(e); } }
/** * Copies the input stream to the response output stream as a download and closes the input stream upon completion. * <p>This method commits the response.</p> * * @param filename * @param input */ public void file(String filename, InputStream input) { checkCommitted(); // content type to OCTET_STREAM if it's not set if (getContentType() == null) { contentType(mimeTypes.getContentType(filename, HttpConstants.ContentType.APPLICATION_OCTET_STREAM)); } if (isHeaderEmpty(HttpConstants.Header.CONTENT_DISPOSITION)) { filenameHeader(filename); } finalizeResponse(); try { send(input); } catch (IOException e) { throw new PippoRuntimeException(e); } }