Avoid 302 redirection on controller's requestmapping method
<p>I use spring 3.x and tomcat 7
I have a controller with asterisk mapping which has a method that detects redirection path. 
Here:</p>

<pre><code>@RequestMapping(value = "/**/t")
public class TopCategoryPageController extends AbstractSearchPageController
{
...
    //@ResponseStatus(HttpStatus.MOVED_PERMANENTLY/* this is 301 */)
    @RequestMapping(value = TOP_CATEGORY_CODE_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)
    public String topCategory(@PathVariable("categoryCode") final String categoryCode, final Model model,
            final HttpServletRequest request, final HttpServletResponse response)
                    throws UnsupportedEncodingException, CMSItemNotFoundException
    {
    ...
    if any redirection 
    {
        response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
        return redirection;
    }   
    else
    return getViewForPage(categoryCode);
}
</code></pre>

<p>When request comes, it executes first topCategory method above</p>

<p>In addition, i have an interceptor such as below. It executes after topCategory method as expected. Although i tried to insert 301 status in there, i could not get what i want.</p>

<p>Here:</p>

<pre><code>public class BeforeViewHandlerInterceptor extends HandlerInterceptorAdapter
{
    ...
    public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler,
            final ModelAndView modelAndView) throws Exception
    {
    ...
            if (isRedirectView(modelAndView))
        {
            String uri = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                    + request.getContextPath();
            uri += modelAndView.getViewName().substring(modelAndView.getViewName().indexOf(":") + 1,
                    modelAndView.getViewName().length());
            modelAndView.setViewName("redirect:" + uri);
            response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            response.setHeader("Location", response.encodeRedirectURL(uri));
        }
   }
</code></pre>

<p>Neverthless setting 301 status in postHandle. It is still redirecting with 302.</p>

<p>That is the link that i clicked on my page like that: domain/context/t/categoryCode
When i analyse chrome network tab, i see first redirection with 302 with Other initiator. Second one is 301. Note that, I need to make it redirects firstly 301. So, i could not find the place where it redirects with 302. Thx and brgds</p>