[
https://issues.apache.org/jira/browse/SLING-9036?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Henry Kuijpers updated SLING-9036:
----------------------------------
Description:
Sling Model:
{code:java}
class MySlingModel {
@Inject
public MySlingModel(@Self SlingHttpServletRequest req) {
logger.log(req.getResourceBundle().getClass().getName());
}
}
{code}
Calling code:
{code:java}
// req obtained via JSP/HTL
final SlingHttpServletRequest myWrappedReq = new
SlingHttpServletRequestWrapper(req) {
@Override
public ResourceBundle getResourceBundle() {
return new MyCustomResourceBundle();
}
};
final MySlingModel myModel = myWrappedReq.adaptTo(MySlingModel.class);
{code}
I would expect the log file to contain "MyCustomResourceBundle". Instead it
contains "NullResourceBundle".
This is because the request is being "unwrapped" when doing the adaptTo() call:
It keeps on delegating to the wrapped request. This should not have happened,
i.e. how can we otherwise overwrite (parts of) requests and resources?
See also:
[https://github.com/apache/sling-org-apache-sling-api/blob/master/src/main/java/org/apache/sling/api/wrappers/SlingHttpServletRequestWrapper.java#L147]
was:
Pseudo code:
class MySlingModel {
@Inject
public MySlingModel(@Self SlingHttpServletRequest req) {
logger.log(req.getResourceBundle().getClass().getName());
}
}
var myWrappedReq = new SlingHttpServletRequestWrapper(req) {
@Override
public ResourceBundle getResourceBundle() {
return new MyCustomResourceBundle();
}
}
var myModel = myWrappedReq.adaptTo(MySlingModel.class);
I would expect the log file to contain "MyCustomResourceBundle"
Instead it contains "NullResourceBundle".
This is because the request is being "unwrapped" when doing the adaptTo() call:
This should not have happened, i.e. how can we otherwise overwrite (parts of)
requests and resources?
> Sling Models: SlingHttpServletRequestWrapper.adaptTo() unwraps before adapting
> ------------------------------------------------------------------------------
>
> Key: SLING-9036
> URL: https://issues.apache.org/jira/browse/SLING-9036
> Project: Sling
> Issue Type: New Feature
> Components: Sling Models
> Reporter: Henry Kuijpers
> Priority: Major
>
> Sling Model:
> {code:java}
> class MySlingModel {
> @Inject
> public MySlingModel(@Self SlingHttpServletRequest req) {
> logger.log(req.getResourceBundle().getClass().getName());
> }
> }
> {code}
> Calling code:
> {code:java}
> // req obtained via JSP/HTL
> final SlingHttpServletRequest myWrappedReq = new
> SlingHttpServletRequestWrapper(req) {
> @Override
> public ResourceBundle getResourceBundle() {
> return new MyCustomResourceBundle();
> }
> };
>
> final MySlingModel myModel = myWrappedReq.adaptTo(MySlingModel.class);
> {code}
> I would expect the log file to contain "MyCustomResourceBundle". Instead it
> contains "NullResourceBundle".
> This is because the request is being "unwrapped" when doing the adaptTo()
> call: It keeps on delegating to the wrapped request. This should not have
> happened, i.e. how can we otherwise overwrite (parts of) requests and
> resources?
> See also:
> [https://github.com/apache/sling-org-apache-sling-api/blob/master/src/main/java/org/apache/sling/api/wrappers/SlingHttpServletRequestWrapper.java#L147]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)