/** * Add a header which will be added to any responses * * @param theName The header name * @param theValue The header value * @return Returns a reference to <code>this</code> for easy method chaining * @since 2.0 */ public BaseServerResponseException addResponseHeader(String theName, String theValue) { Validate.notBlank(theName, "theName must not be null or empty"); Validate.notBlank(theValue, "theValue must not be null or empty"); if (getResponseHeaders().containsKey(theName) == false) { getResponseHeaders().put(theName, new ArrayList<String>()); } getResponseHeaders().get(theName).add(theValue); return this; }
private void writeExceptionToResponse(HttpServletResponse theResponse, BaseServerResponseException theException) throws IOException { theResponse.setStatus(theException.getStatusCode()); addHeadersToResponse(theResponse); if (theException.hasResponseHeaders()) { for (Entry<String, List<String>> nextEntry : theException.getResponseHeaders().entrySet()) { for (String nextValue : nextEntry.getValue()) { if (isNotBlank(nextValue)) { theResponse.addHeader(nextEntry.getKey(), nextValue); } } } } theResponse.setContentType("text/plain"); theResponse.setCharacterEncoding("UTF-8"); theResponse.getWriter().write(theException.getMessage()); }
Map<String, List<String>> additional = theException.getResponseHeaders(); for (Entry<String, List<String>> next : additional.entrySet()) { if (isNotBlank(next.getKey()) && next.getValue() != null) {
/** * Add a header which will be added to any responses * * @param theName The header name * @param theValue The header value * @return Returns a reference to <code>this</code> for easy method chaining * @since 2.0 */ public BaseServerResponseException addResponseHeader(String theName, String theValue) { Validate.notBlank(theName, "theName must not be null or empty"); Validate.notBlank(theValue, "theValue must not be null or empty"); if (getResponseHeaders().containsKey(theName) == false) { getResponseHeaders().put(theName, new ArrayList<String>()); } getResponseHeaders().get(theName).add(theValue); return this; }
private void writeExceptionToResponse(HttpServletResponse theResponse, BaseServerResponseException theException) throws IOException { theResponse.setStatus(theException.getStatusCode()); addHeadersToResponse(theResponse); if (theException.hasResponseHeaders()) { for (Entry<String, List<String>> nextEntry : theException.getResponseHeaders().entrySet()) { for (String nextValue : nextEntry.getValue()) { if (isNotBlank(nextValue)) { theResponse.addHeader(nextEntry.getKey(), nextValue); } } } } theResponse.setContentType("text/plain"); theResponse.setCharacterEncoding("UTF-8"); theResponse.getWriter().write(theException.getMessage()); }
Map<String, List<String>> additional = theException.getResponseHeaders(); for (Entry<String, List<String>> next : additional.entrySet()) { if (isNotBlank(next.getKey()) && next.getValue() != null) {