servlets - 添加 servlet 以在 Intershop 7.4 应用程序服务器上下文中运行

标签 servlets guice intershop

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

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

编辑:

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

)绑定(bind) 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.在您的 Cartridge build.gradle 中声明对 Guice Servlet 的依赖。 示例:

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

2.在卡盒objectgraph.properties中定义servlet模块。 示例:

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.创建模块实现。 问题:名称应以 /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 通过网络适配器可见,您必须允许它。

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

关于servlets - 添加 servlet 以在 Intershop 7.4 应用程序服务器上下文中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41035113/

相关文章:

java - 特定使用 Servlet 后将 mysql 列值重置为默认值

intershop - 从 Intershop 7.7 更新到 7.9 后未加载 Pipelet

java - 依赖注入(inject)在javafx谷歌果汁中抛出空指针异常

json - 在 Intershop 上解析 JSON 的推荐方法是什么?

intershop - 如何将占位符属性添加到输入字段

java - 使用过滤器在登录尝试失败后重定向

java - 从 web.xml 中的库导入 servlet

java - 使用 servlet 显示图像

java - Guice 会降低我的代码的可读性吗?

java - Guice 导致抛出 UncaughtExceptionHandler