我正在尝试包含一个第 3 方 servlet 以在我们的 IS7 应用程序服务器的上下文中运行。我将如何添加 servlet 并映射到 web.xml?
在知识库中,我只找到了有关 Enfinity Suite 6 的信息。所提供的步骤似乎都不起作用。
编辑:
我找到了一个建议的 IS7 解决方案,使用 Guice 并通过特定的 Servlet 模块(如
)绑定(bind) servletpackage 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/