Adilmo
Adilmo

Reputation: 117

Modify slinghttpresponse through wrapper

I am trying to override default sendredirect funtionality in AEM.

I would like to redirect to https urls from my server.

FOr the same I have implemented a sling filter. Implemented SlingHttpServletResponseWrapper class and overridden sendredirect function.

However, in filter when I try to

final SlingHttpServletResponse slingResponse = (ModifyLocResponse) response;

At runtime I get

org.apache.sling.security.impl.ContentDispositionFilter$RewriterResponse cannot be cast to com.adobe.acs.samples.filters.wrappers.ModifyLocResponse

Upvotes: 1

Views: 199

Answers (1)

Shawn
Shawn

Reputation: 9402

Instead of casting, try instantiating it by something like this:

final SlingHttpServletResponse slingResponse = new ModifyLocResponse(response);

Of course you'll need to make sure the constructor for that class has this pattern too:

class ModifyLocResponse extends SlingHttpServletResponseWrapper {
    public ModifyLocResponse(SlingHttpServletResponse response) {
        super(response);
    }
    ...
}

Upvotes: 1

Related Questions