【问题标题】:Issues with custom URLRewrite rules in 7.97.9 中自定义 URLRewrite 规则的问题
【发布时间】:2019-04-10 15:17:54
【问题描述】:

目前,我在 ISH 7.9 中遇到了一些自定义 URL 重写规则的问题。

对于我们的某些环境,它可以正常工作(例如本地和测试),但在 ACC 和 PROD 上,它似乎只是在多次部署/重新启动系统后不时工作。

我们创建了一个自定义墨盒,其中包含 deploy.gradle 文件以从原始墨盒中排除文件 urlrewriterules.xmldomainsplittings.xmlsyndication-targets.properties。它们被share/system/config/cluster 文件夹中的自定义文件替换。 urlrewriterules.xml 中应用的静态规则始终可以正常工作。但是,来自自定义 Java 类的规则有时无法通过 RewriteRuleFactoryImpl 返回以下错误来很好地加载:

[2018-11-07 08:20:37.906 +0100] WARN localhost ES1 appserver0 [ShipSupport-ebusiness-Site] [-] com.intershop.component.urlrewrite.internal.factory.RewriteRuleFactoryImpl [] [Storefront] [wJ5DCcg2CM5DCZPUUqdNu2D2fj8NZHaXjvP9qIZb] [yFAAAFvikjkOsqjA-0-00] "yFAAAFvikjkOsqjA-0-00" An implementation of rewrite rule type 'CustomCategory' does not exist.

urlrewriterules.xml 中将调用此 java 类的部分代码如下:

<!-- Custom Category Rule /c/<NAME_OF_LOWEST_CATEGORY> -->
<rule type="CustomCategory" priority="1000" name="custom category rule">
    <configurations>
       <configuration id="pathPrefix">/catalog</configuration>
        <configuration id="partsCatalogID">4393</configuration>
   </configurations>
</rule>

我们还在我们自己的盒式磁带中很好地创建了类,例如扩展BaseRewriteRuleCustomCategoryRewriteRule。为这些频道启用了 URL 重写,我们始终使启用它的频道中的缓存无效。

CustomCategory 的扩展名(在同一墨盒中定义)定义如下:

<?xml version="1.0" encoding="UTF-8"?>
<extensionpoint:ExtensionPointModel xmlns:extensionpoint="http://www.intershop.de/extensionpoint/2011" name="CustomCategoryRewriteRule"> 
  <extensionBindings type="java" extensionPoint="com.intershop.component.urlrewrite.capi.RewriteRule-RewriteRule.create" extension="com.package.CustomCategoryRewriteRule" priority="1"/>
</extensionpoint:ExtensionPointModel>

app-extension.component 也定义在同一个插件中,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://www.intershop.de/component/2010" scope="global">
    <fulfill requirement="selectedCartridge" value="cartridge_name" of="intershop.SLDSystem.Cartridges"/>
    <fulfill requirement="selectedCartridge" value="cartridge_name" of="intershop.EnterpriseBackoffice.Cartridges"/>
</components>

我们按照这篇文章来确认如何做到这一点:https://support.intershop.com/kb/index.php/Display/B28069 我们在另一个项目中也可以正常工作,但使用的是 Intershop 7.8

你知道可能是什么原因吗?

谢谢!

【问题讨论】:

    标签: intershop


    【解决方案1】:

    除了实现之外,还需要在&lt;cartridge&gt;/staticfiles/cartridge/extensions中创建一个扩展文件。这是查找机制的重写规则的实际注册。请参阅以下示例:

    <?xml version="1.0" encoding="UTF-8"?>
    <extensionpoint:ExtensionPointModel xmlns:extensionpoint="http://www.intershop.de/extensionpoint/2011" name="CustomRewriteRule.extension">
        <extensionBindings type="java" extensionPoint="com.intershop.component.urlrewrite.capi.RewriteRule-RewriteRule.create" extension="com.package.CustomCategoryRewriteRule " priority="1"/>
    </extensionpoint:ExtensionPointModel>
    

    还需要通过&lt;cartridge&gt;/staticfiles/cartridge/components 中的组件文件在应用程序类型中注册包含这些扩展的插件。这是必需的,以便在正确的应用程序上下文中正确加载扩展。看这个例子:

    <?xml version="1.0" encoding="UTF-8" ?>
    <components xmlns="http://www.intershop.de/component/2010">
        <fulfill requirement="selectedCartridge" value="your_custom_cartridge" of="intershop.SLDSystem.Cartridges" /> 
        <fulfill requirement="selectedCartridge" value="your_custom_cartridge" of="intershop.B2CBackoffice.Cartridges" />
        <fulfill requirement="selectedCartridge" value="your_custom_cartridge" of="intershop.B2CResponsive.Cartridges" />
    </components>
    

    我不太确定您是否需要为所有这些应用程序注册它,但这些是我们在上一个项目中使用的。如果您使用不同的应用程序类型或有自定义的应用程序类型,请确保相应地添加它们。

    【讨论】:

    • 我们确实有所有这些配置,否则它将无法在任何环境中工作。我们遇到的问题是,对于某些环境,它只能在一定数量的重建/部署后“不时”起作用。
    • 这似乎是RewriteRuleFactoryImpl的实现问题:这个工厂注册为单例,规则只延迟加载一次,然后缓存。但是,对于加载规则,仅考虑查找时的当前应用程序。如果这是一个不包含墨盒的应用程序,那么它可能会丢失并且永远不会被加载。 /edit:作为一种解决方法,您可以尝试为更多应用程序类型(尤其是店面应用程序类型)注册墨盒,然后查看问题是否仍然存在。
    • 我只是通过为应用程序SLDSystemEnterpriseBackoffice 注册一个墨盒(带有一些自定义重写规则)(就像在您的示例中一样),设法在本地重现了这个问题。启动应用服务器后,首先打开了一个店面页面(应用类型B2CResponsive)。在这种情况下不会加载重写规则,并且永远不会重写 URL。但是,如果我在服务器启动后首先打开后台,那么规则将被加载并且一切正常。
    • 添加店面应用程序类型似乎确实解决了我们的问题。谢谢!
    • 我们进行了相同的测试,但使用的是 SMBResponsive 墨盒。你的代码和我们的代码的细微差别也引起了我的注意。谢谢!
    【解决方案2】:

    我们最终也通过使用 SMBResponsive 墨盒解决了这个问题。

    <?xml version="1.0" encoding="UTF-8"?>
    <components xmlns="http://www.intershop.de/component/2010" scope="global">
        <fulfill requirement="selectedCartridge" value="royalihc_sldsystem" of="intershop.SLDSystem.Cartridges"/>
        <fulfill requirement="selectedCartridge" value="royalihc_sldsystem" of="intershop.EnterpriseBackoffice.Cartridges"/>
        <fulfill requirement="selectedCartridge" value="royalihc_sldsystem" of="intershop.SMBResponsive.Cartridges" />
    </components>

    感谢安德烈亚斯的所有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      • 2013-06-21
      • 2020-08-04
      • 2018-03-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-21
      相关资源
      最近更新 更多