3

I am getting an NPE when I deploy to Tomcat (this doesn't happen every time, only sometimes when I re-deploy). The error is a NullPointerException when the RemoteServiceServlet tries to loadSerializationPolicy(..). I noticed that the issue was with the servlet.log method call, when the loadSerializationPolicy fails to find the serialization policy file (which seems like another problem? Perhaps its not and the serialization will just skip it, idk), so it tries to log it but falls over with an NPE.

So as explained here: https://github.com/ArcBees/GWTP/issues/289#issuecomment-21675896 the issue is that RemoteServiceServlet cannot find the logger? I tried the proposed solution which was to create a new DispatchServiceImpl in my project that replaces the standard GWTP service implementation and implement ServletConfigAware with a ServletConfig object and overriding getServletConfig() and setServletConfig(...). This did not resolve the issue for me however. This doesn't happen when I use Chrome browser only Firefox and IE (that I have tested). I assume Chrome isn't failing to find the policy file? Or isn't performing an unnecessary check?

java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletName(GenericServlet.java:238)
at javax.servlet.GenericServlet.log(GenericServlet.java:190)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.loadSerializationPolicy(RemoteServiceServlet.java:103)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doGetSerializationPolicy(RemoteServiceServlet.java:293)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.getSerializationPolicy(RemoteServiceServlet.java:157)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.prepareToRead(ServerSerializationStreamReader.java:491)
at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:240)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:206)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at com.gwtplatform.dispatch.server.spring.DispatchServiceImpl.handleRequest(DispatchServiceImpl.java:68)
at org.springframework.web.context.support.HttpRequestHandlerServlet.service(HttpRequestHandlerServlet.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Now this issue doesn't take place in Dev Mode. Only on random occasions that I redeploy to Tomcat. If anyone has any useful advice or have ran into this issue before, I would be really grateful for the help!

Here are some classes that might help with identifying the issue:

DispatchServiceImpl.java (replacing the standard GWTP DispatchServiceImpl)

@Component("dispatch")
public class DispatchServiceImpl extends AbstractDispatchServiceImpl implements HttpRequestHandler,
        ServletContextAware, ServletConfigAware {

    private static final long serialVersionUID = 136176741488585959L;

    private ServletContext servletContext;
    private ServletConfig servletConfig;

    @Autowired(required = false)
    protected String securityCookieName;

    @Autowired
    public DispatchServiceImpl(final Logger logger, final Dispatch dispatch,
            RequestProvider requestProvider) {
        super(logger, dispatch, requestProvider);
    }

    @Override
    public String getSecurityCookieName() {
        return securityCookieName;
    }

    public void setSecurityCookieName(String securityCookieName) {
        this.securityCookieName = securityCookieName;
    }

    @Override
    public void handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    public void setServletContext(ServletContext arg0) {
        this.servletContext = arg0;
    }

    @Override
    public ServletContext getServletContext() {
        return servletContext;
    }

    @Override
    public void setServletConfig(ServletConfig servletConfig) {
        this.servletConfig = servletConfig;
    }

    @Override
    public ServletConfig getServletConfig() {
        return servletConfig;
    }
}

ServerModule.java

/**
 * Module which binds the handlers and configurations.
 */
@Configuration
@Import({
    DefaultModule.class,
    PropertyModule.class,
    ConfigLoader.class
})
@ComponentScan({
    "nz.co.doltech.ims",
    "nz.co.doltech.ims.framework.extensions.platform.dispatch.server.spring"
})
@ImportResource("classpath:META-INF/properties.xml")
@EnableAspectJAutoProxy
@EnableTransactionManagement
public class ServerModule extends HandlerModule {

... snip ...

}
Ben Dol
  • 427
  • 6
  • 18

1 Answers1

1

Well I did the obvious and Overrode getServletName and now it works fine. Strange that ServletConfigAware didn't help with this issue though.

Ben Dol
  • 427
  • 6
  • 18