apache / apache/grails-core

Exisiting controller overridden by generated controller when using @Resource

Open
#11,671 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List

- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### Steps to Reproduce

Clone the repo here: https://github.com/beechovsky/test-rest-resource-controller

NOTE: This app was created using create-app, domain created using create-domain-class, and everything else using generate-all for the Student domain.

On the master branch, run the application and save a new Student (via the GUI). Check the terminal output and verify seeing the log message from hitting the save() and show() methods in the controller.

Next, checkout the with-jackson branch and run the app again.

Save a new instance (view is no longer accessible):
`curl -i -X POST -H "Content-Type: application/json" -d '{"firstName":"New","lastName":"Kid","age":21}' localhost:8080/students`

You should see the following or similar:

````
HTTP/1.1 201
Location: http://localhost:8080/students/3
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 23 Dec 2020 14:34:01 GMT

{"id":3,"firstName":"New","age":21,"lastName":"Kid"}
````

Let’s also hit the ‘native’ existing endpoint from our _existing_ controller:

`curl -i -X POST -H "Content-Type: application/json" -d '{"firstName":"New","lastName":"Kid","age":21}' localhost:8080/student/save`

You should again see the following or similar:

```
HTTP/1.1 201
Location: http://localhost:8080/students/3
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 23 Dec 2020 15:49:28 GMT

{"id":3,"firstName":"New","age":21,"lastName":"Kid"}
```

For both actions, review log output and see there is no indication we hit the save() or show() methods in the _existing_ controller despite a successful save.

In fact, simply navigate to localhost:8080/students/1 (and /student/show/1) and note the lack of logs from the controller at either endpoint.

Now, checkout the with-restful-controller branch and repeat the steps above.

Finally, check out with-ajax branch. NOTE: This branch most accurately mimics the real-world project.

Navigate to http://localhost:8080/ajax/ (create is the only action so it’s accessible here).

Click the ‘Save a Student’ button.

Return to the student list (it will be JSON) to verify the save worked. NOTE: The params are hard-coded for simplicity’s sake; if you need to save another entry just update the parameters in the Javascript in the create.gsp view for the AJAX controller.

### Expected Behaviour

The methods in the existing controller should be hit.

### Actual Behaviour

The methods in the existing controller are bypassed/overridden.

### Environment Information

- **Operating System(s)**: MacOS Catalina 10.15.7, RHEL 7, and Linux Mint 19 Tara
- **Grails Version(s):** 4.0.3, 4.0.5
- **JDK Version:** 1.8.0_242
- **Container Version (If Applicable):** N/A

### Example Application

- https://github.com/beechovsky/test-rest-resource-controller

Contributor guide

Open the contributing guide

Research direction

Reproduce the behavior in the linked test-rest-resource-controller application, comparing the master, with-jackson, with-restful-controller, and with-ajax branches. Start with the /students, /student/save, /students/1, and /student/show/1 endpoints and inspect their logs; done means the existing controller methods are invoked rather than bypassed or overridden.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.