当我部署到Tomcat时,我得到了NPE(这并非每次都发生,只有在我重新部署时才发生)。当RemoteServiceServlet尝试加载loadSerializationPolicy(..)时,错误为NullPointerException。我注意到问题出在servlet.log方法调用上,当loadSerializationPolicy无法找到序列化策略文件时(这似乎是另一个问题?也许不是,序列化只会跳过它,idk),所以它尝试记录日志但是它被NPE淘汰了。

因此,如下所述:https://github.com/ArcBees/GWTP/issues/289#issuecomment-21675896问题是RemoteServiceServlet无法找到记录器?我尝试了建议的解决方案,该解决方案是在我的项目中创建一个新的DispatchServiceImpl,以替换标准的GWTP服务实现,并使用ServletConfig对象并覆盖getServletConfig()和setServletConfig(...)来实现ServletConfigAware。但是,这并没有为我解决问题。当我仅使用Chrome浏览器Firefox和IE(已测试)时,不会发生这种情况。我认为Chrome浏览器没有找到策略文件?还是不执行不必要的检查?

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)


现在,在开发模式下不会发生此问题。仅在随机情况下,我才重新部署到Tomcat。如果有人有任何有用的建议或曾经遇到过此问题,我将非常感谢您的帮助!

以下是一些可能有助于确定问题的类:

DispatchServiceImpl.java(替换标准的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 ...

}

最佳答案

好吧,我做了显而易见的并覆盖了getServletName,现在它可以正常工作了。奇怪的是ServletConfigAware不能解决这个问题。

08-03 17:38