gpt4 book ai didi

java - 带有 GWT RemoteServiceServlet 的 GWTP NullPointerException

转载 作者:行者123 更新时间:2023-11-29 08:59:44 25 4
gpt4 key购买 nike

我在部署到 Tomcat 时遇到 NPE(这种情况不会每次都发生,只有在我重新部署时才会发生)。当 RemoteServiceServlet 尝试 loadSerializationPolicy(..) 时,错误是 NullPointerException。我注意到问题出在 servlet.log 方法调用上,当 loadSerializationPolicy 找不到序列化策略文件时(这似乎是另一个问题?也许不是,序列化会跳过它,idk),所以它尝试记录它却因 NPE 而倒下。

如此处解释:https://github.com/ArcBees/GWTP/issues/289#issuecomment-21675896问题是 RemoteServiceServlet 找不到记录器?我尝试了建议的解决方案,即在我的项目中创建一个新的 DispatchServiceImpl 来替换标准 GWTP 服务实现并使用 ServletConfig 对象实现 ServletConfigAware 并覆盖 getServletConfig() 和 setServletConfig(...)。但是,这并没有为我解决问题。当我仅使用 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 ...

}

最佳答案

好吧,我做了显而易见的 Overrode getServletName,现在它工作正常。奇怪的是,ServletConfigAware 并没有帮助解决这个问题。

关于java - 带有 GWT RemoteServiceServlet 的 GWTP NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18245873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com