I'm using the acs-commons error handling (https://adobe-consulting-services.github.io/acs-aem-commons/features/errorpagehandler.html) so that the error page can be a regular page using component.
Unfortunately this doesn't work out of the box. I get the error below. What happens is the Request object passed is null. On 404, we are redirect to the /apps/sling/servlet/errorhandler/404.jsp. This JSP calls the ACS-commons error handling service. The service retrieve the error page to display, set response status to 404 and does: RequestDispatcher dispatcher = request.getRequestDispatcher(path); dispatcher.include(new GetRequest(request), response); GetRequest is just a SlingHttpServletRequest wrapper class to force a Get Any idea why this doesn't work out of the box and how we could fix it? Somehow the SlingHttpServletRequest is not passed/found by Google Guice. Thanks, Richard Error in custom provider, java.lang.IllegalStateException: request has wrong class at com.cognifide.slice.core.internal.module.SlingModule.getSlingHttpServletRequest(SlingModule.java:66) at com.cognifide.slice.core.internal.module.SlingModule.getSlingHttpServletRequest(SlingModule.java:66) while locating org.apache.sling.api.SlingHttpServletRequest for field at com.test.aem.web.component.base.model.Model.request(Model.java:54) while locating com.test.aem.web.component.navigation.model.GlobalNavigation Caused by: java.lang.IllegalStateException: request has wrong class at com.cognifide.slice.util.ServletRequestResponseUtil.getSlingHttpServletRequest(ServletRequestResponseUtil.java:47) at com.cognifide.slice.core.internal.module.SlingModule.getSlingHttpServletRequest(SlingModule.java:66) at sun.reflect.GeneratedMethodAccessor125.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.google.inject.internal.ProviderMethod.get(ProviderMethod.java:104) at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40) at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031) at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) at com.cognifide.slice.core.internal.provider.ContextScopeProvider.get(ContextScopeProvider.java:56) at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40) at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:53) at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:110) at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:94) at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254) at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024) at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974) at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1009) at com.cognifide.slice.core.internal.provider.SliceModelProvider.get(SliceModelProvider.java:241) at com.cognifide.slice.core.internal.provider.SliceModelProvider.get(SliceModelProvider.java:228) at com.cognifide.slice.core.internal.provider.SliceModelProvider.get(SliceModelProvider.java:107) at com.cognifide.slice.core.internal.adapter.SliceAdapterFactory.getAdapter(SliceAdapterFactory.java:59) at org.apache.sling.adapter.internal.AdapterManagerImpl.getAdapter(AdapterManagerImpl.java:140) at org.apache.sling.api.adapter.SlingAdaptable.adaptTo(SlingAdaptable.java:104) at com.cognifide.slice.core.internal.provider.SliceBindingsProvider.addBindings(SliceBindingsProvider.java:52) |
After doing some more testing, it seems that replacing the call to:
dispatcher.include(new GetRequest(request), response); by dispatcher.forward(new GetRequest(request), response); Solves the issue. Unfortunately, in this case the HTTP Status code is lost. |
Administrator
|
The problem must be caused by the way we're looking for the request in SlingModule. Interesting thing is that it works for include but not for forward. This needs a bit of a deeper investigation. We're currently working on closing the Slice 4.3 release, so if you raise a ticket in our Jira I'll try to include it in upcoming release.
Best regards Maciej |
Here you go: https://cognifide.atlassian.net/projects/SLICE/issues/SLICE-133
By the way, this is the other way around, it works for forward but not include. I have a workaround overriding some of the acs-commons code using forward, but it would be great to have this working out of the box. |
ContextRequestFilter is associated with scope 'forward' only. We do not want allow 'include' scope on this filter.
See https://github.com/Cognifide/Slice/blob/master/slice-core/src/main/java/com/cognifide/slice/core/internal/filter/ContextRequestFilter.java |
In reply to this post by richardlhr
I am facing the same error as I am using requestDispatcher.include(). We can't use 'forward' scope as the HTTP status code is being lost. Is/Will 'include' scope will be added in current/future versions ? If not, what is the work around to retain status code by using forward() method. Please let me know.
|
Free forum by Nabble | Edit this page |