|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -71,7 +71,7 @@ public class MockHttpServletResponse implements HttpServletResponse { |
|
|
|
|
|
|
|
|
|
|
|
private boolean charset = false; |
|
|
|
private boolean charset = false; |
|
|
|
|
|
|
|
|
|
|
|
private final ByteArrayOutputStream content = new ByteArrayOutputStream(); |
|
|
|
private final ByteArrayOutputStream content = new ByteArrayOutputStream(1024); |
|
|
|
|
|
|
|
|
|
|
|
private final ServletOutputStream outputStream = new ResponseServletOutputStream(this.content); |
|
|
|
private final ServletOutputStream outputStream = new ResponseServletOutputStream(this.content); |
|
|
|
|
|
|
|
|
|
|
|
@ -189,8 +189,8 @@ public class MockHttpServletResponse implements HttpServletResponse { |
|
|
|
|
|
|
|
|
|
|
|
public String getContentAsString() throws UnsupportedEncodingException { |
|
|
|
public String getContentAsString() throws UnsupportedEncodingException { |
|
|
|
flushBuffer(); |
|
|
|
flushBuffer(); |
|
|
|
return (this.characterEncoding != null) ? |
|
|
|
return (this.characterEncoding != null ? |
|
|
|
this.content.toString(this.characterEncoding) : this.content.toString(); |
|
|
|
this.content.toString(this.characterEncoding) : this.content.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -218,8 +218,7 @@ public class MockHttpServletResponse implements HttpServletResponse { |
|
|
|
if (contentType != null) { |
|
|
|
if (contentType != null) { |
|
|
|
int charsetIndex = contentType.toLowerCase().indexOf(CHARSET_PREFIX); |
|
|
|
int charsetIndex = contentType.toLowerCase().indexOf(CHARSET_PREFIX); |
|
|
|
if (charsetIndex != -1) { |
|
|
|
if (charsetIndex != -1) { |
|
|
|
String encoding = contentType.substring(charsetIndex + CHARSET_PREFIX.length()); |
|
|
|
this.characterEncoding = contentType.substring(charsetIndex + CHARSET_PREFIX.length()); |
|
|
|
this.characterEncoding = encoding; |
|
|
|
|
|
|
|
this.charset = true; |
|
|
|
this.charset = true; |
|
|
|
} |
|
|
|
} |
|
|
|
updateContentTypeHeader(); |
|
|
|
updateContentTypeHeader(); |
|
|
|
@ -416,11 +415,13 @@ public class MockHttpServletResponse implements HttpServletResponse { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public String encodeUrl(String url) { |
|
|
|
public String encodeUrl(String url) { |
|
|
|
return encodeURL(url); |
|
|
|
return encodeURL(url); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public String encodeRedirectUrl(String url) { |
|
|
|
public String encodeRedirectUrl(String url) { |
|
|
|
return encodeRedirectURL(url); |
|
|
|
return encodeRedirectURL(url); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -505,11 +506,12 @@ public class MockHttpServletResponse implements HttpServletResponse { |
|
|
|
|
|
|
|
|
|
|
|
private boolean setSpecialHeader(String name, Object value) { |
|
|
|
private boolean setSpecialHeader(String name, Object value) { |
|
|
|
if (CONTENT_TYPE_HEADER.equalsIgnoreCase(name)) { |
|
|
|
if (CONTENT_TYPE_HEADER.equalsIgnoreCase(name)) { |
|
|
|
setContentType((String) value); |
|
|
|
setContentType(value.toString()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (CONTENT_LENGTH_HEADER.equalsIgnoreCase(name)) { |
|
|
|
else if (CONTENT_LENGTH_HEADER.equalsIgnoreCase(name)) { |
|
|
|
setContentLength(Integer.parseInt((String) value)); |
|
|
|
setContentLength(value instanceof Number ? ((Number) value).intValue() : |
|
|
|
|
|
|
|
Integer.parseInt(value.toString())); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
@ -534,14 +536,15 @@ public class MockHttpServletResponse implements HttpServletResponse { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setStatus(int status) { |
|
|
|
public void setStatus(int status) { |
|
|
|
if(!this.isCommitted()) { |
|
|
|
if (!this.isCommitted()) { |
|
|
|
this.status = status; |
|
|
|
this.status = status; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public void setStatus(int status, String errorMessage) { |
|
|
|
public void setStatus(int status, String errorMessage) { |
|
|
|
if(!this.isCommitted()) { |
|
|
|
if (!this.isCommitted()) { |
|
|
|
this.status = status; |
|
|
|
this.status = status; |
|
|
|
this.errorMessage = errorMessage; |
|
|
|
this.errorMessage = errorMessage; |
|
|
|
} |
|
|
|
} |
|
|
|
|