Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Aug 14, 2018
1 parent c0c9e08 commit 6027cf2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ public ModelMap getDefaultModel() {

/**
* Provide a separate model instance to use in a redirect scenario.
* The provided additional model however is not used unless
* {@link #setRedirectModelScenario(boolean)} gets set to {@code true} to signal
* a redirect scenario.
* <p>The provided additional model however is not used unless
* {@link #setRedirectModelScenario} gets set to {@code true}
* to signal an actual redirect scenario.
*/
public void setRedirectModel(ModelMap redirectModel) {
this.redirectModel = redirectModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@ protected Object createDefaultStrategy(ApplicationContext context, Class<?> claz
*/
@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {

logRequest(request);

// Keep a snapshot of the request attributes in case of an include,
Expand Down Expand Up @@ -953,24 +952,21 @@ protected void doService(HttpServletRequest request, HttpServletResponse respons

private void logRequest(HttpServletRequest request) {
if (logger.isDebugEnabled()) {

String params;
if (isEnableLoggingRequestDetails()) {
params = request.getParameterMap().entrySet().stream()
.map(entry -> entry.getKey() + ":" + Arrays.toString(entry.getValue()))
.collect(Collectors.joining(", "));
}
else {
params = request.getParameterMap().isEmpty() ? "" : "masked";
params = (request.getParameterMap().isEmpty() ? "" : "masked");
}

String query = StringUtils.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString();

String dispatchType = !request.getDispatcherType().equals(DispatcherType.REQUEST) ?
"\"" + request.getDispatcherType().name() + "\" dispatch for " : "";

String message = dispatchType + request.getMethod() +
" \"" + getRequestUri(request) + query + "\", parameters={" + params + "}";
String dispatchType = (!request.getDispatcherType().equals(DispatcherType.REQUEST) ?
"\"" + request.getDispatcherType().name() + "\" dispatch for " : "");
String message = (dispatchType + request.getMethod() + " \"" + getRequestUri(request) +
query + "\", parameters={" + params + "}");

if (logger.isTraceEnabled()) {
List<String> values = Collections.list(request.getHeaderNames());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ else if (ex instanceof AsyncRequestTimeoutException) {
* @param handler the executed handler, or {@code null} if none chosen
* at the time of the exception (for example, if multipart resolution failed)
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -272,7 +272,7 @@ protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotS
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -296,7 +296,7 @@ protected ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupported
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -315,7 +315,7 @@ protected ModelAndView handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptab
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
* @since 4.2
*/
protected ModelAndView handleMissingPathVariable(MissingPathVariableException ex,
Expand All @@ -335,7 +335,7 @@ protected ModelAndView handleMissingPathVariable(MissingPathVariableException ex
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -353,7 +353,7 @@ protected ModelAndView handleMissingServletRequestParameter(MissingServletReques
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleServletRequestBindingException(ServletRequestBindingException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -371,7 +371,7 @@ protected ModelAndView handleServletRequestBindingException(ServletRequestBindin
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -392,7 +392,7 @@ protected ModelAndView handleConversionNotSupported(ConversionNotSupportedExcept
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -415,7 +415,7 @@ protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -428,17 +428,18 @@ protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableExcept
}

/**
* Handle the case where a {@linkplain org.springframework.http.converter.HttpMessageConverter message converter}
* Handle the case where a
* {@linkplain org.springframework.http.converter.HttpMessageConverter message converter}
* cannot write to a HTTP request.
* <p>The default implementation sends an HTTP 500 error, and returns an empty {@code ModelAndView}.
* Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could be
* rethrown as-is.
* Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could
* be rethrown as-is.
* @param ex the HttpMessageNotWritableException to be handled
* @param request current HTTP request
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -453,12 +454,12 @@ protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableExcept
/**
* Handle the case where an argument annotated with {@code @Valid} such as
* an {@link RequestBody} or {@link RequestPart} argument fails validation.
* An HTTP 400 error is sent back to the client.
* <p>By default, an HTTP 400 error is sent back to the client.
* @param request current HTTP request
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleMethodArgumentNotValidException(MethodArgumentNotValidException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -470,12 +471,12 @@ protected ModelAndView handleMethodArgumentNotValidException(MethodArgumentNotVa
/**
* Handle the case where an {@linkplain RequestPart @RequestPart}, a {@link MultipartFile},
* or a {@code javax.servlet.http.Part} argument is required but is missing.
* An HTTP 400 error is sent back to the client.
* <p>By default, an HTTP 400 error is sent back to the client.
* @param request current HTTP request
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleMissingServletRequestPartException(MissingServletRequestPartException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -488,12 +489,12 @@ protected ModelAndView handleMissingServletRequestPartException(MissingServletRe
* Handle the case where an {@linkplain ModelAttribute @ModelAttribute} method
* argument has binding or validation errors and is not followed by another
* method argument of type {@link BindingResult}.
* By default, an HTTP 400 error is sent back to the client.
* <p>By default, an HTTP 400 error is sent back to the client.
* @param request current HTTP request
* @param response current HTTP response
* @param handler the executed handler
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
*/
protected ModelAndView handleBindException(BindException ex, HttpServletRequest request,
HttpServletResponse response, @Nullable Object handler) throws IOException {
Expand All @@ -513,7 +514,7 @@ protected ModelAndView handleBindException(BindException ex, HttpServletRequest
* @param handler the executed handler, or {@code null} if none chosen
* at the time of the exception (for example, if multipart resolution failed)
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
* @since 4.0
*/
protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex,
Expand All @@ -532,7 +533,7 @@ protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex,
* @param handler the executed handler, or {@code null} if none chosen
* at the time of the exception (for example, if multipart resolution failed)
* @return an empty ModelAndView indicating the exception was handled
* @throws IOException potentially thrown from response.sendError()
* @throws IOException potentially thrown from {@link HttpServletResponse#sendError}
* @since 4.2.8
*/
protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,7 @@ public String toString() {
}

protected String formatViewName() {
return (getBeanName() != null ?
"name '" + getBeanName() + "'" : "[" + getClass().getSimpleName() + "]");
return (getBeanName() != null ? "name '" + getBeanName() + "'" : "[" + getClass().getSimpleName() + "]");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*
* @author Sebastien Deleuze
* @since 4.1
* @see org.springframework.web.servlet.view.json.MappingJackson2JsonView
*/
public class MappingJackson2XmlView extends AbstractJackson2View {

Expand Down Expand Up @@ -73,20 +74,12 @@ public MappingJackson2XmlView(XmlMapper xmlMapper) {
super(xmlMapper, DEFAULT_CONTENT_TYPE);
}

/**
* {@inheritDoc}
*/

@Override
public void setModelKey(String modelKey) {
this.modelKey = modelKey;
}

/**
* Filter out undesired attributes from the given model.
* The return value can be either another {@link Map} or a single value object.
* @param model the model, as passed on to {@link #renderMergedOutputModel}
* @return the value to be rendered
*/
@Override
protected Object filterModel(Map<String, Object> model) {
Object value = null;
Expand Down

0 comments on commit 6027cf2

Please sign in to comment.