我知道这在 ICM 7.7 中有效,但我相信它从 7.4 起就已经存在了。
您可以使用Guice Servlet 扩展 https://github.com/google/guice/wiki/Servlets.
1.声明对墨盒中 Guice Servlet 的依赖关系build.gradle
. Example:
dependencies
{
...
compile group: 'com.intershop.platform', name: 'servletengine'
compile 'com.google.inject.extensions:guice-servlet'
...
}
2.在cartridge中定义servlet模块objectgraph.properties
. Example:
global.modules = com.example.modules.DemoServletModule
3.实现您的servlet。Example:
public class DemoServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
resp.getWriter().append("Hello, world!");
}
}
4.创建模块实现。Gotcha:名称应该以/servlet/
正如评论中指出的。Example:
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.构建、重启、尝试。Example:
GET /servlet/DEMO/hey HTTP/1.1
Host: example.com:10054
....
回复:
Hello, world!
UPDATE:
如果您希望您的 servlet 通过网络适配器可见,您必须允许它。
1.Open 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 添加条目。Example:
servlet.allow.4=/DEMO
4.通过类似的 URL 访问 servlet:
https://example.com/INTERSHOP/servlet/WFS/DEMO/hey