Search code examples
servletsguiceintershop

Adding a servlet to run in Intershop 7.4 application server context


I'm trying to include a 3rd party servlet to run in our IS7 application server's context. How would I go about adding the servlet and mapping to the web.xml?

In the knowledge base I have only found information regarding Enfinity Suite 6. None of the steps provided seem to work.

EDIT:

I found a proposed solution for IS7 using Guice and binding the servlet via a specific Servlet module like

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);
    }
}

I have added my ServletModule to the objectgraph.properties file but my servlet still isn't called when I try accessing it.

Any suggestions?


Solution

  • I know that this works in ICM 7.7 but I believe it has been around since 7.4.

    You may use the Guice Servlet Extension.

    1.Declare dependency to the Guice Servlet in your cartridge build.gradle. Example:

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

    2.Define a servlet module in the cartridge objectgraph.properties. Example:

    global.modules = com.example.modules.DemoServletModule
    

    3.Implement your servlet. Example:

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

    4.Create the module implementation. Gotcha: The name should start with /servlet/ as pointed in the comments. 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.Build, restart, try. Example:

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

    Reposnse:

    Hello, world!
    

    UPDATE:

    If you would like that your servlet is visible through the webadapter you have to allow it.

    1.Open IS_SHARE\system\config\cluster\webadapter.properties

    2.Navigate to this section:

    ## 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.Add entry for your servlet. Example:

    servlet.allow.4=/DEMO
    

    4.Access the servlet on a similar URL:

    https://example.com/INTERSHOP/servlet/WFS/DEMO/hey