我知道这在 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