spring-bootservletshessian

Add in Spring boot application a servlet that is not extending jakarta.servlet


I have a legacy application that has this servlet configuration in the web.xml file:

<servlet>
    <servlet-name>HessianServlet</servlet-name>
    <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
    <init-param>
      <param-name>home-class</param-name>
      <param-value>com.api.HessianServiceImpl</param-value>
    </init-param>
    <init-param>
      <param-name>home-api</param-name>
      <param-value>com.api.ServicePort</param-value>
    </init-param>       
</servlet>

<servlet-mapping>
    <servlet-name>HessianServlet</servlet-name>
    <url-pattern>/myhessian/*</url-pattern>
</servlet-mapping>

Now I am migrating some parts of the code of the legacy project to another new application that uses spring boot application and also uses other dependencies with more recent versions.

Part of the code that I want to migrate to this new spring boot application would be this HessianServlet configuration added in the web.xml file.

The problem I'm running into is that in order to add servlets in spring boot configuration it looks like it needs to be done through the ServletRegistrationBean, and this ServletRegistrationBean only accepts servlets that extend from jakarta.servlet, and the problem is that com.caucho.hessian.serverHessianServlet extends from javax.servlet.

The spring boot version I'm using is 3.1.0, and the hessian version is 4.0.66

I tried by creating a custom HessianServletWrapper that was extending com.caucho.hessian.server.HessianServlet and implementing jakarta.servlet.Servlet

private static class HessianServletWrapper extends HessianServlet implements Servlet {
        @Override
        public void init(ServletConfig servletConfig) throws ServletException {

        }

        @Override
        public ServletConfig getServletConfig() {
            return null;
        }
        ...

So maybe with this wrapper created I could set it as servlet in the ServletRegistrationBean, but the problem is that com.caucho.hessian.server.HessianServlet and jakarta.servlet.Servlet override the same getServletConfig() method and this gives a compilation error.

Anyone would know how could be added in a Spring boot application a servlet that is not extending the jakarta.servlet?

Thanks in advance.


Solution

  • Perhaps a bad news for you as Spring Boot 3 requires to use at least Jakarta EE 9 for the Servlet API (i.e use jakarta.servlet instead of javax.servlet). And mixing the jakarta.servlet and javax.servlet is not recommended. I can think some of your best bets are :

    1. Use spring boot 2.7
    2. Try to make HessianServlet to be compatible with jakarta.servlet by copying all of its source codes to your project and update everything from javax.servlet to jakarta.servlet. If it works , then you can use spring boot 3+.