You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Spring, when we need to access HttpServletRequest / HttpServletResponse ) in controller we can define them as parameters in method signature, as in this example:
/**
* Generate a PDF report...
*/
@RequestMapping(value = "/report", method = RequestMethod.POST)
@ResponseBody
public void generateReport(
HttpServletRequest request,
HttpServletResponse response,
@RequestBody ReportData sourceData) {
// ...
// Here you can use the request and response objects like:
// response.setContentType("application/pdf");
// response.getOutputStream().write(...);
}
Of course there are alternative ways to do it, but this is what I have actually in my controllers.
Maybe SpringAnnotationScanner could manage these "framework" classes as JaxRsAnnotationScanner does for javax.ws.rs.core.Request and other class of the same package.
I refer to this implementation in JaxRsAnnotationScanner:
public boolean isFrameworkContextType(Type type) {
return JaxRsConstants.CONTEXTS.contains(type.name());
}
The text was updated successfully, but these errors were encountered:
Seems reasonable. @morettileo do you have any interest in doing a PR with the change? It should be simply an override of boolean isFrameworkContextType(Type type) as you mentioned, plus adjusting some of the tests to verify it.
morettileo
changed the title
SpringAnnotationScanner doesn't manage any "framework" context annotation
SpringAnnotationScanner doesn't manage any "framework" context classes
May 7, 2024
In Spring, when we need to access HttpServletRequest / HttpServletResponse ) in controller we can define them as parameters in method signature, as in this example:
Of course there are alternative ways to do it, but this is what I have actually in my controllers.
This generate the following OpenAPI YAML:
while if I remove HttpServletRequest \ HttpServletResponse I get the expected YAML:
Maybe SpringAnnotationScanner could manage these "framework" classes as JaxRsAnnotationScanner does for javax.ws.rs.core.Request and other class of the same package.
I refer to this implementation in JaxRsAnnotationScanner:
The text was updated successfully, but these errors were encountered: