0

ProductDisplayCmd のカスタム実装は次のようになります...

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

現在、製品が利用できない場合、スーパーは次のメッセージで ECApplicationException をスローします。

com.ibm.commerce.exception.ECApplicationException: カタログ・エントリー番号「253739」および部品番号「9788703055992」は、現在の契約には無効です。

SEO 対応の URL を使用すると、カスタム 404 ページにリダイレクトされます (「申し訳ありません。その製品はもう入手できません。素晴らしい代替品を試してください...」)。

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 ページにリダイレクトするオプションがあると思いますが、それでよいのでしょうか? 特に: 例外の種類は何が問題なのかを正確に教えてくれないようです。

4

1 に答える 1

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);
    }
}
于 2013-08-27T05:47:10.997 に答える