Skip to content

Commit 49ced81

Browse files
authored
Merge pull request #15234 from apache/fix/issue_15228-respond-errors
fix: Re-implemented ContainerRenderer on AbstractJsonViewContainerRenderer
2 parents c8a02b7 + 1c7fa75 commit 49ced81

File tree

23 files changed

+534
-33
lines changed

23 files changed

+534
-33
lines changed

grails-rest-transforms/src/main/groovy/grails/rest/render/ContainerRenderer.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package grails.rest.render
2424
* @author Graeme Rocher
2525
* @since 2.3
2626
*/
27-
interface ContainerRenderer<C, T> extends Renderer<C> {
27+
interface ContainerRenderer<C, T> extends Renderer<T> {
2828

2929
/**
3030
* @return The underlying type wrapped by the container. For example with List<Book>, this method would return Book

grails-rest-transforms/src/main/groovy/grails/rest/render/Renderer.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ interface Renderer<T> extends MimeTypeProvider {
3939
* @param object The object to render
4040
* @param context The {@link RenderContext}
4141
*/
42-
void render(T object, RenderContext context)
42+
void render(Object object, RenderContext context)
4343
}

grails-rest-transforms/src/main/groovy/grails/rest/render/errors/VndErrorJsonRenderer.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import groovy.transform.CompileStatic
2525
import org.springframework.http.HttpMethod
2626
import org.springframework.http.HttpStatus
2727
import org.springframework.validation.BeanPropertyBindingResult
28-
import org.springframework.validation.Errors
2928
import org.springframework.validation.ObjectError
3029

3130
import grails.rest.render.RenderContext
@@ -48,7 +47,7 @@ class VndErrorJsonRenderer extends AbstractVndErrorRenderer {
4847
MimeType[] mimeTypes = [MIME_TYPE, MimeType.HAL_JSON, MimeType.JSON, MimeType.TEXT_JSON] as MimeType[]
4948

5049
@Override
51-
void render(Errors object, RenderContext context) {
50+
void render(Object object, RenderContext context) {
5251
if (messageSource == null) throw new IllegalStateException('messageSource property null')
5352
if (object instanceof BeanPropertyBindingResult) {
5453

grails-rest-transforms/src/main/groovy/grails/rest/render/errors/VndErrorXmlRenderer.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import groovy.transform.CompileStatic
2222

2323
import org.springframework.http.HttpStatus
2424
import org.springframework.validation.BeanPropertyBindingResult
25-
import org.springframework.validation.Errors
2625
import org.springframework.validation.ObjectError
2726

2827
import grails.rest.render.RenderContext
@@ -50,7 +49,7 @@ class VndErrorXmlRenderer extends AbstractVndErrorRenderer {
5049
MimeType[] mimeTypes = [MIME_TYPE, MimeType.HAL_XML, MimeType.XML, MimeType.TEXT_XML] as MimeType[]
5150

5251
@Override
53-
void render(Errors object, RenderContext context) {
52+
void render(Object object, RenderContext context) {
5453
if (object instanceof BeanPropertyBindingResult) {
5554
def errors = object as BeanPropertyBindingResult
5655
context.setContentType(GrailsWebUtil.getContentType(MIME_TYPE.name, encoding))

grails-rest-transforms/src/main/groovy/grails/rest/render/hal/HalJsonRenderer.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class HalJsonRenderer<T> extends AbstractLinkingRenderer<T> {
108108
}
109109

110110
@Override
111-
void renderInternal(T object, RenderContext context) {
111+
void renderInternal(Object object, RenderContext context) {
112112
final mimeType = context.acceptMimeType ?: mimeTypes[0]
113113
final responseWriter = context.writer
114114
Writer targetWriter = prettyPrint ? new StringWriter() : responseWriter

grails-rest-transforms/src/main/groovy/grails/rest/render/util/AbstractLinkingRenderer.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ abstract class AbstractLinkingRenderer<T> extends AbstractIncludeExcludeRenderer
107107
}
108108

109109
@Override
110-
void render(T object, RenderContext renderContext) {
110+
void render(Object object, RenderContext renderContext) {
111111
def mimeType = renderContext.acceptMimeType ?: getMimeTypes()[0]
112112
def contentType = GrailsWebUtil.getContentType(mimeType.name, encoding)
113113
renderContext.setContentType(contentType)
@@ -123,7 +123,7 @@ abstract class AbstractLinkingRenderer<T> extends AbstractIncludeExcludeRenderer
123123
}
124124
}
125125

126-
abstract void renderInternal(T object, RenderContext context)
126+
abstract void renderInternal(Object object, RenderContext context)
127127

128128
protected boolean isDomainResource(Class clazz) {
129129
if (mappingContext != null) {

grails-rest-transforms/src/main/groovy/org/grails/plugins/web/rest/render/json/DefaultJsonRenderer.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class DefaultJsonRenderer<T> implements Renderer<T> {
7676
}
7777

7878
@Override
79-
void render(T object, RenderContext context) {
79+
void render(Object object, RenderContext context) {
8080
final mimeType = context.acceptMimeType ?: MimeType.JSON
8181
context.setContentType(GrailsWebUtil.getContentType(mimeType.name, encoding))
8282
def viewName = context.viewName ?: context.actionName
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
version = '0.1'
21+
group = 'issue11767.app'
22+
23+
apply plugin: 'org.apache.grails.gradle.grails-web'
24+
25+
dependencies {
26+
implementation platform(project(':grails-bom'))
27+
28+
implementation 'org.springframework.boot:spring-boot-starter-logging'
29+
implementation 'org.apache.grails:grails-dependencies-starter-web'
30+
31+
implementation 'org.apache.grails:grails-views-gson'
32+
implementation 'org.apache.grails:grails-rest-transforms'
33+
34+
testAndDevelopmentOnly platform(project(':grails-bom'))
35+
36+
testImplementation 'org.apache.grails:grails-testing-support-views-gson'
37+
testImplementation 'org.apache.grails.testing:grails-testing-support-core'
38+
39+
integrationTestImplementation 'com.fasterxml.jackson.core:jackson-databind'
40+
integrationTestImplementation "io.micronaut:micronaut-http-client:$micronautHttpClientVersion"
41+
integrationTestImplementation "io.micronaut:micronaut-jackson-databind:$micronautHttpClientVersion"
42+
}
43+
44+
apply {
45+
from rootProject.layout.projectDirectory.file('gradle/functional-test-config.gradle')
46+
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
47+
from rootProject.layout.projectDirectory.file('gradle/grails-extension-gradle-config.gradle')
48+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
info:
17+
app:
18+
name: '@info.app.name@'
19+
version: '@info.app.version@'
20+
grailsVersion: '@info.app.grailsVersion@'
21+
grails:
22+
mime:
23+
disable:
24+
accept:
25+
header:
26+
userAgents:
27+
- Gecko
28+
- WebKit
29+
- Presto
30+
- Trident
31+
types:
32+
all: '*/*'
33+
atom: application/atom+xml
34+
css: text/css
35+
csv: text/csv
36+
form: application/x-www-form-urlencoded
37+
html:
38+
- text/html
39+
- application/xhtml+xml
40+
js: text/javascript
41+
json:
42+
- application/json
43+
- text/json
44+
multipartForm: multipart/form-data
45+
pdf: application/pdf
46+
rss: application/rss+xml
47+
text: text/plain
48+
hal:
49+
- application/hal+json
50+
- application/hal+xml
51+
xml:
52+
- text/xml
53+
- application/xml
54+
micronaut:
55+
http:
56+
client:
57+
readTimeout: PT10M
58+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<configuration>
23+
24+
<conversionRule conversionWord="clr" class="org.springframework.boot.logging.logback.ColorConverter" />
25+
<conversionRule conversionWord="wex" class="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
26+
27+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
28+
<withJansi>true</withJansi>
29+
<encoder>
30+
<charset>UTF-8</charset>
31+
<pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex</pattern>
32+
</encoder>
33+
</appender>
34+
35+
<root level="info">
36+
<appender-ref ref="STDOUT" />
37+
</root>
38+
39+
</configuration>

0 commit comments

Comments
 (0)