2013-08-21 2 views
0

Мой заказ реализация ProductDisplayCmd выглядит следующим образом ...Перенаправление от CustomProductDisplayCmd до 404 страницы, если недоступен продукт

public void performExecute() throws ECException { 
    super.performExecute(); 
    (my code here) 

Теперь, если продукт недоступен, супер бросает ECApplicationException с этим сообщением:

com.ibm.commerce.exception.ECApplicationException: каталог запись номер «253739» и номером «9788703055992» не является действительным для текущего контракта.

С поддержкой SEO URL, я попадаю на нашу страницу 404 («Gee жаль, что продукт больше не доступен. Попробуйте один из наших фантастических вариантов ...»)

http://bktestapp01.tm.dom/shop/sbk/bent-isager-nielsen-efterforskerne

С URL старого стиля я вместо этого получаю страницу с ошибкой из-за незанятого исключения.

http://bktestapp01.tm.dom/webapp/wcs/stores/servlet/ProductDisplay?langId=100&storeId=10651&catalogId=10013&club=SBK&productId=253739

Так как я могу поймать исключение, я полагаю, у меня есть возможность вручную перенаправляется на страницу 404, но в том, что путь? В частности: тип исключения, похоже, не говорит мне точно, что не так, поэтому я мог бы случайно сделать 404 из другой ошибки.

ответ

0

Вот что я закончил: поймайте исключение из супер, а затем решите, вызвана ли причина, по которой продукт недоступен. Если это так, то переадресуйте на страницу 404, иначе повторите сброс исключения.

Реализация:

public void performExecute() throws ECException { 
try { 
    super.performExecute(); 
} catch (final ECApplicationException e) { 
    // Let's see if the problem is something that should really be causing a redirect 
    makeProductHelperAndRedirectTo404IfProductNotAvailable(e); 
    // If we get here, noting else was thrown 
    log.error("The reason super.performExecute threw an ECException is unknown and so we can't recover. Re-throwing it."); 
    throw e; 
} 

... и в методе makeProductblablabla:

private ProductDataHelper makeProductHelperAndRedirectTo404IfProductNotAvailable(final ECException cause) throws ECSystemException, 
     ECApplicationException { 
    final ProductDataHelper productHelper; 
    try { 
     log.trace("Trying to determine if the reason super.performExecute threw an ECException is that the product is unavailable in the store. The execption is attached to this logline.", cause); 
     productHelper = makeProductHelper(getProductId()); 
     if (productHelper != null) { 
      if (!productHelper.isActiveInClub()) { 
       log.trace("Decided that the reason super.performExecute threw an ECException is that the product is unavailable in the store. The execption is attached to this logline. NB! That exception is DISCARDED", cause); 
       final String pn = productHelper.getISBN(); 
       final ECApplicationException systemException = new ECApplicationException(ECMessage._ERR_PROD_NOT_EXISTING, this.getClass().getName(), "productIsPublished", new Object[]{ pn }); 
       systemException.setErrorTaskName("ProductDisplayErrorView"); 
       throw systemException; 
      } 
     } 
     return productHelper; 
    } catch (RemoteException e) { 
     log.error("I was trying to determine if the reason super.performExecute threw an ECException is that the product is unavailable in the store. The original ECException is attached to this logline. NB! That exception is DISCARDED", cause); 
     throw new ECSystemException(ECMessage._ERR_GENERIC, super.getClass().getName(), "performExecute",ECMessageHelper.generateMsgParms(e.getMessage()), e); 
    } catch (NamingException e) { 
     log.error("I was trying to determine if the reason super.performExecute threw an ECException is that the product is unavailable in the store. The original ECException is attached to this logline. NB! That exception is DISCARDED", cause); 
     throw new ECSystemException(ECMessage._ERR_GENERIC, super.getClass().getName(), "performExecute",ECMessageHelper.generateMsgParms(e.getMessage()), e); 
    } catch (FinderException e) { 
     log.error("I was trying to determine if the reason super.performExecute threw an ECException is that the product is unavailable in the store. The original ECException is attached to this logline. NB! That exception is DISCARDED", cause); 
     throw new ECSystemException(ECMessage._ERR_GENERIC, super.getClass().getName(), "performExecute",ECMessageHelper.generateMsgParms(e.getMessage()), e); 
    } catch (CreateException e) { 
     log.error("I was trying to determine if the reason super.performExecute threw an ECException is that the product is unavailable in the store. The original ECException is attached to this logline. NB! That exception is DISCARDED", cause); 
     throw new ECSystemException(ECMessage._ERR_GENERIC, super.getClass().getName(), "performExecute",ECMessageHelper.generateMsgParms(e.getMessage()), e); 
    } 
} 
Смежные вопросы