2

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

在知识库中,我只找到了有关 Enfinity Suite 6 的信息。提供的步骤似乎都不起作用。

编辑:

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

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 仍然没有被调用。

有什么建议么?

4

1 回答 1

2

我知道这在 ICM 7.7 中有效,但我相信它自 7.4 以来一直存在。

您可以使用Guice Servlet 扩展

1.声明依赖于你的插件中的 Guice Servlet build.gradle示例

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

2.在插件中定义一个servlet模块objectgraph.properties示例

global.modules = com.example.modules.DemoServletModule

3.实现你的servlet。示例

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

4.创建模块实现。Gotcha:名称应以/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.构建,重新启动,尝试。示例

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

回应:

Hello, world!

更新:

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

1.打开IS_SHARE\system\config\cluster\webadapter.properties

2.导航至此部分:

## 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.为您的 servlet 添加条目。示例

servlet.allow.4=/DEMO

4.通过类似的 URL 访问 servlet:

https://example.com/INTERSHOP/servlet/WFS/DEMO/hey
于 2016-12-08T13:32:57.973 回答