cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

HTTP response 410 code when product is discontinued

former_member1049674
Participant
0 Kudos
683

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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;
former_member1049674
Participant
0 Kudos

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

Former Member
0 Kudos

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.

former_member1049674
Participant
0 Kudos

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

Answers (0)