在 Intershop 7.4 应用程序服务器上下文中将 servlet 添加到 运行

Adding a servlet to run in Intershop 7.4 application server context

我正在尝试在我们的 IS7 应用程序服务器上下文中将第 3 方 servlet 添加到 运行。我将如何添加 servlet 并映射到 web.xml?

在知识库中,我只找到了有关 Enfinity Suite 6 的信息。None 所提供的步骤似乎有效。

编辑:

我找到了一个针对 IS7 的建议解决方案,它使用 Guice 并通过特定的 Servlet 模块绑定 servlet,例如

package com.intershop.test;

import com.google.inject.servlet.ServletModule;

public class MyServletModule extends ServletModule
{
    @Override
    protected void configureServlets()
    {
        bind(MyServlet.class).in(Singleton.class);
        serve("/my/*").with(MyServlet.class);
    }
}

我已经将我的 ServletModule 添加到 objectgraph.properties 文件中,但是当我尝试访问它时我的 servlet 仍然没有被调用。

有什么建议吗?

我知道这在 ICM 7.7 中有效,但我相信它从 7.4 开始就存在了。

您可以使用 Guice Servlet Extension.

1.Declare 依赖于您的插件中的 Guice Servlet build.gradle示例

dependencies 
{
    ...
    compile group: 'com.intershop.platform', name: 'servletengine'
    compile 'com.google.inject.extensions:guice-servlet'
    ...
}

2.Define 一个 servlet 模块在墨盒中 objectgraph.properties示例

global.modules = com.example.modules.DemoServletModule

3.Implement 你的 servlet。 示例

public class DemoServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        resp.getWriter().append("Hello, world!");
    }
}

4.Create 模块实现。 陷阱: 名称应以 /servlet/ 开头,如评论中所指出的那样。 示例

import javax.inject.Singleton;
import com.google.inject.servlet.ServletModule;

public class DemoServletModule extends ServletModule
{
    @Override
    protected void configureServlets()
    {
        bind(DemoServlet.class).in(Singleton.class);

        serve("/servlet/DEMO/*").with(DemoServlet.class);
    }
}

4.Build,重启,试试。 示例

GET /servlet/DEMO/hey HTTP/1.1
Host: example.com:10054
....

回复:

Hello, world!

更新:

如果您希望您的 servlet 通过 webadapter 可见,您必须允许它。

1.Open IS_SHARE\system\config\cluster\webadapter.properties

2.Navigate 至此部分:

## The list of servlets, which can be accessed through the generic
## .servlet mapping. The WebAdapter forwards only requests of the form
## /servlet/<group><servlet.allow.x>...

3.Add 您的 servlet 条目。 示例

servlet.allow.4=/DEMO

4.Access这个servlet就类似URL:

https://example.com/INTERSHOP/servlet/WFS/DEMO/hey