public final void setResponse(HttpServletResponse response) { this.response = response; this.fakeResponse = new FakeHttpServletResponse(response); }
@Override public void addHeader(String name, String value) { doAddHeader(name, value); }
public String getContentAsString() throws UnsupportedEncodingException { return this.fakeResponse.getContentAsString(); }
/** * Gets the content as byte array. * * @return the content as byte array */ public byte[] getContentAsByteArray() { flushBuffer(); return this.content != null ? this.content.toByteArray() : new byte[0]; }
@Override public ServletOutputStream getOutputStream() { init(); return this.outputStream; }
@Override public void reset() { resetBuffer(); this.characterEncoding = null; this.contentLength = 0; this.contentType = null; this.locale = null; this.cookies = null; this.headers = null; this.status = HttpServletResponse.SC_OK; this.errorMessage = null; }
@Override public void setContentType(String contentType) { this.contentType = contentType; if (contentType != null) { int charsetIndex = contentType.toLowerCase().indexOf(FakeHttpServletResponse.CHARSET_PREFIX); if (charsetIndex != -1) { String encoding = contentType.substring(charsetIndex + FakeHttpServletResponse.CHARSET_PREFIX.length()); setCharacterEncoding(encoding); } } }
/** * Gets the content as byte array. * * @return the content as byte array */ public byte[] getContentAsByteArray() { flushBuffer(); return this.content != null ? this.content.toByteArray() : new byte[0]; }
@Override public ServletOutputStream getOutputStream() { init(); return this.outputStream; }
@Override public void reset() { resetBuffer(); this.characterEncoding = null; this.contentLength = 0; this.contentType = null; this.locale = null; this.cookies = null; this.headers = null; this.status = HttpServletResponse.SC_OK; this.errorMessage = null; }
@Override public void setContentType(String contentType) { this.contentType = contentType; if (contentType != null) { int charsetIndex = contentType.toLowerCase().indexOf(FakeHttpServletResponse.CHARSET_PREFIX); if (charsetIndex != -1) { String encoding = contentType.substring(charsetIndex + FakeHttpServletResponse.CHARSET_PREFIX.length()); setCharacterEncoding(encoding); } } }
@Override public void addHeader(String name, String value) { doAddHeader(name, value); }
public final void setResponse(HttpServletResponse response) { this.response = response; this.fakeResponse = new FakeHttpServletResponse(response); }
/** * Gets the content as string. * * @return the content as string * @throws UnsupportedEncodingException * the unsupported encoding exception */ public String getContentAsString() throws UnsupportedEncodingException { String contentToReturn = ""; flushBuffer(); if (this.content != null) { contentToReturn = this.characterEncoding != null ? this.content.toString(this.characterEncoding) : this.content.toString(); } else { // No action required. Content already initialised to empty string. } return contentToReturn; }
public String getContentAsString() throws UnsupportedEncodingException { return this.fakeResponse.getContentAsString(); }
@Override public void addDateHeader(String name, long value) { doAddHeader(name, new Long(value)); }
/** * <p>This switches the <code>RequestContext</code> into or out of "passive mode" (depending upon * the value of the supplied <code>passiveMode</code> argument). In "passive mode" any output generated * will be written to a <code>FakeHttpServletResponse</code> rather than the genuine <code>HttpServletResponse</code>. * This is useful so that we can generate data that we want to "save for later" (i.e. we generate all the head * ouput needed without writing it to the response stream and store it in the model to be accessed at the * appropriate time).</p> */ public final void setPassiveMode(boolean passiveMode) { this.passiveMode = passiveMode; if (passiveMode) { fakeResponse = new FakeHttpServletResponse(this.response); } }
/** * Gets the content as string. * * @return the content as string * @throws UnsupportedEncodingException * the unsupported encoding exception */ public String getContentAsString() throws UnsupportedEncodingException { String contentToReturn = ""; flushBuffer(); if (this.content != null) { contentToReturn = this.characterEncoding != null ? this.content.toString(this.characterEncoding) : this.content.toString(); } else { // No action required. Content already initialised to empty string. } return contentToReturn; }
@Override public void addIntHeader(String name, int value) { doAddHeader(name, new Integer(value)); }
/** * <p>This switches the <code>RequestContext</code> into or out of "passive mode" (depending upon * the value of the supplied <code>passiveMode</code> argument). In "passive mode" any output generated * will be written to a <code>FakeHttpServletResponse</code> rather than the genuine <code>HttpServletResponse</code>. * This is useful so that we can generate data that we want to "save for later" (i.e. we generate all the head * ouput needed without writing it to the response stream and store it in the model to be accessed at the * appropriate time).</p> */ public final void setPassiveMode(boolean passiveMode) { this.passiveMode = passiveMode; if (passiveMode) { fakeResponse = new FakeHttpServletResponse(this.response); } }