Passing original request object in chain filter in Sling filter

swathiv54399501 14-11-2018

Hi,

We have one sling filter performing some business logic and this is chain filter. But in the logic, we are processing Iterator Object from request attributes. And the same iterator is getting used in next level of chain.

When we try to parse the Iterator in next level we are getting error"Parameter not available" as we have already pasrsed the Iterator Object.

If there any way to pass the original request object in the chain from first filter?

Thanks,

Swati

Accepted Solutions (1)

Accepted Solutions (1)

Jörg_Hoh
Employee
15-11-2018

What iterator from the request are you processing?

(I know that there is an issue when dealing with multi-part POST requiests. If you have functionality which first casts the SlingHttpServletRequest to a HttpServletRequest and reads it using this API, all subsequent calls to read the body will fail, because the input stream has already been consumed. The Sling implementation consumes it already and provides dedicated methods to access it. We came across this a year or two ago, so I don't know the details anymore.)

Answers (4)

Answers (4)

Arun_Patidar
MVP
15-11-2018

Nops, I am saying you can all doFilter with original request and response.It should be available.

Or you can check same in single filter by referencing other filters logic in same filter something like below:

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain filterChain)
throws IOException, ServletException {
doMyJob(request, response, params);
filterChain.doFilter(request, response);
}

I am not sure if is this suitable for your use case.

swathiv54399501 15-11-2018

In filter I am parsing one of the request attribute ('request-parts-iterator') to fetch uploaded file from OOTB DAM upload buttton. I am reading the inputstream stream from it and enabling antivirus scan for the uploaded file. Once scan done, I am doing chain filter(chainfiltter.doFilter(request,response)) but as I already read the Inputstream Once , CreateAssetFilter unable to read the stream again to process upload action.

I even tried to wrapping of the request. That dint worked too.

I am totally blocked here.

Thanks,

swathiv54399501 15-11-2018

Hi Arun,

You suggesting to call doFilter twice?

I noticed the actual problem is reading the attribute twice. When I read the request attribute in filter and again in next level when actual logic is using the same parameter then it is not available and the actual functionality is breaking.

Thanks,

Swati