on 2017 Mar 13 12:55 PM
Hi,
I want to do 2 things when a product is discontinued and the product Details Page is been hit:
Redirect to a new page.
Return 410 HTTP code.
Interestingly there is a way to do it through ModelAndView Object: https://answers.sap.com/questions/12761623/http-status-code-301-for-categorypagecontroller.html
I need to do this solution from ProductPageController in productDetails method. The method returns String so I need to return String and not ModelAndView.
Can anyone let me know if there is any solution for this issue?
Thank you
Request clarification before answering.
Gorka, hi
"Redirect to a new page" means sending the 301 status code, so it's kind of impossible to combine your two requirements.
And redirect using String is very simple:
return "redirect:" + redirectUrl;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Evgeny,
thank you for your quick answer. What about this code:
RedirectView rv = new RedirectView();
rv.setStatusCode(HttpStatus.GONE);
rv.setUrl("/410");
return new ModelAndView(rv);
It sends 410 HTTP status code and it shows me the page for url "/410". And this is working.
Any idea?
Thank you
Gorka, redirecting without 3XX code breaks the HTTP specification - https://tools.ietf.org/html/rfc7231#section-6.4
That means that some browsers can reject to follow the Location header as Response Code is inconsistent with action.
However, that's not about the techniques; to create your own Controller method and override the standart one you can use the @RequestMappingOverride annotation provided by hybris and return the value you want.
Hi Evgeny,
thank you for your comment. I had a look on this issue again and I realized that as soon as you add the response http status in DefaultPageController I have a HTTP status 410.
First I added the http 410 status to the page in DefaultPageController:
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.MOVED_PERMANENTLY);
And in the ProductPageController:
return ControllerConstants.Views.Pages.Error.ErrorNotFoundPage;
This is going to open the PageNotFound page and will return a http 410 status.
I hope this makes sense for you.
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.