在GAE上部署时,在localhost上工作的Restlet会抛出NullPointerException

时间:2010-12-21 17:47:26

标签: google-app-engine restlet

以下简单方法在我的本地计算机上运行良好,但在将其部署到App Engine时会抛出NullPointerException。在memberVO上调用任何方法(如getId())会抛出NullPointerException。我无法理解为什么这可以在我的本地网络上运行,但不能在appspot.com上运行。

我尝试用基元和字符串替换可序列化对象仅用于测试目的,但没有一个可以传递给GAE。全部都变为空。

如果有人有任何想法,我也会在日志中加入例外。

提前感谢您的任何见解。

奥维尔

@Override
public Boolean updateMember(MemberVO memberVO) { 
        PersistenceManager pm = PMF.get().getPersistenceManager();

        try { 
                Member member = pm.getObjectById(Member.class, memberVO.getId());

                member.setFirstName(memberVO.getFirstName()); 
                member.setLastName(memberVO.getLastName());

                pm.makePersistent(member); 
        } catch (NullPointerException npe) { 
                npe.printStackTrace(); 
        } catch (Exception e) { 
                e.printStackTrace(); 
        } finally { 
                pm.close(); 
        }

        return true; 
}



@Override 
public Boolean updateMember(MemberVO memberVO) { 
        PersistenceManager pm = PMF.get().getPersistenceManager(); 
        try { 
                Member member = pm.getObjectById(Member.class, memberVO.getId()); 
                member.setFirstName(memberVO.getFirstName()); 
                member.setLastName(memberVO.getLastName()); 
                pm.makePersistent(member); 
        } catch (NullPointerException npe) { 
                npe.printStackTrace(); 
        } catch (Exception e) { 
                e.printStackTrace(); 
        } finally { 
                pm.close(); 
        } 
        return true; 
} 

堆栈跟踪:

12-20 05:23PM 48.523 /rest/member 500 3162ms 3858cpu_ms 8api_cpu_ms 0kb Restlet-Framework/2.0snapshot,gzip(gfe) 
72.27.92.51 - - [20/Dec/2010:17:23:51 -0800] "POST /rest/member HTTP/1.1" 500 549 - "Restlet-Framework/2.0snapshot,gzip(gfe)" 
"myapp.appspot.com" ms=3162 cpu_ms=3858 api_cpu_ms=8 cpm_usd=0.307323
loading_request=1 pending_ms=977 
I 12-20 05:23PM 50.343 
javax.servlet.ServletContext log: adapter: [Restlet] Attaching 
application: com.myapp.MyApplication@1a3b359 to URI: 
W 12-20 05:23PM 51.656 
org.restlet.resource.UniformResource doCatch: Exception or error 
caught in resource 
java.lang.NullPointerException 
        at com.myapp.MemberResource.updateMember(MemberResource.java:67) 
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
57) 
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.java: 
43) 
        at java.lang.reflect.Method.invoke(Method.java:43) 
        at org.restlet.resource.ServerResource.doHandle(ServerResource.java: 
453) 
        at org.restlet.resource.ServerResource.post(ServerResource.java:1095) 
        at org.restlet.resource.ServerResource.doHandle(ServerResource.java: 
506) 
        at 
org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java: 
563) 
        at 
org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java : 
299) 
        at org.restlet.resource.ServerResource.handle(ServerResource.java: 
821) 
        at org.restlet.resource.Finder.handle(Finder.java:513) 
        at org.restlet.routing.Filter.doHandle(Filter.java:156) 
        at org.restlet.routing.Filter.handle(Filter.java:203) 
        at org.restlet.routing.Router.doHandle(Router.java:495) 
        at org.restlet.routing.Router.handle(Router.java:735) 
        at org.restlet.routing.Filter.doHandle(Filter.java:156) 
        at org.restlet.routing.Filter.handle(Filter.java:203) 
        at org.restlet.routing.Filter.doHandle(Filter.java:156) 
        at org.restlet.routing.Filter.handle(Filter.java:203) 
        at org.restlet.routing.Filter.doHandle(Filter.java:156) 
        at 
org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java: 
154) 
        at org.restlet.routing.Filter.handle(Filter.java:203) 
        at org.restlet.routing.Filter.doHandle(Filter.java:156) 
        at org.restlet.routing.Filter.handle(Filter.java:203) 
        at org.restlet.engine.ChainHelper.handle(ChainHelper.java:111) 
        at 
org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.j ava: 
72) 
        at org.restlet.Application.handle(Application.java:382) 
        at org.restlet.routing.Filter.doHandle(Filter.java:156) 
        at org.restlet.routing.Filter.handle(Filter.java:203) 
        at org.restlet.routing.Router.doHandle(Router.java:495) 
        at org.restlet.routing.Router.handle(Router.java:735) 
        at org.restlet.routing.Filter.doHandle(Filter.java:156) 
        at org.restlet.routing.Filter.handle(Filter.java:203) 
        at org.restlet.routing.Router.doHandle(Router.java:495) 
        at org.restlet.routing.Router.handle(Router.java:735) 
        at org.restlet.routing.Filter.doHandle(Filter.java:156) 
        at org.restlet.routing.Filter.handle(Filter.java:203) 
        at org.restlet.engine.ChainHelper.handle(ChainHelper.java:111) 
        at org.restlet.Component.handle(Component.java:387) 
        at org.restlet.Server.handle(Server.java:488) 
        at org.restlet.engine.ServerHelper.handle(ServerHelper.java:71) 
        at 
org.restlet.engine.http.HttpServerHelper.handle(HttpServerHelper.java: 
150) 
        at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java: 
1037) 
        at 
org.restlet.ext.gwt.GwtShellServletWrapper.service(GwtShellServletWrapper.j ava:
189) 
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java: 
511) 
        at org.mortbay.jetty.servlet.ServletHandler 
$CachedChain.doFilter(ServletHandler.java:1166) 
        at org.mortbay.jetty.servlet.ServletHandler 
$CachedChain.doFilter(ServletHandler.java:1157) 
        at org.mortbay.jetty.servlet.ServletHandler 
$CachedChain.doFilter(ServletHandler.java:1157) 
        at org.mortbay.jetty.servlet.ServletHandler 
$CachedChain.doFilter(ServletHandler.java:1157) 
        at 
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java: 
388) 
        at 
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java: 
216) 
        at 
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java: 
182) 
        at 
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java: 
765) 
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java: 
418) 
        at 
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java: 
152) 
        at org.mortbay.jetty.Server.handle(Server.java:326) 
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java: 
542) 
        at org.mortbay.jetty.HttpConnection 
$RequestHandler.headerComplete(HttpConnection.java:923) 
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
        at 
com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest(BlockingAp plicationHandler.java: 
24) 
        at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java: 
435) 
        at com.google.net.rpc.impl.Server$RpcTask.runInContext(Server.java: 
572) 
        at com.google.tracing.TraceContext$TraceContextRunnable 
$1.run(TraceContext.java:448) 
        at com.google.tracing.TraceContext.runInContext(TraceContext.java: 
688) 
        at com.google.tracing.TraceContext 
$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.jav a: 
326) 
        at com.google.tracing.TraceContext 
$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java: 
318) 
        at com.google.tracing.TraceContext 
$TraceContextRunnable.run(TraceContext.java:446) 
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 
1110) 
        at java.util.concurrent.ThreadPoolExecutor 
$Worker.run(ThreadPoolExecutor.java:603) 
        at java.lang.Thread.run(Thread.java:636) 
I 12-20 05:23PM 51.684 
This request caused a new process to be started for your application, 
and thus caused your application code to be loaded for the first time. 
This request may thus take longer and use more CPU than a typical 
request for your application.

1 个答案:

答案 0 :(得分:0)

这是由于已知GAE与HTTP分块编码的限制(与Restlet无关)。

但是,Restlet确实在最近的2.1快照中提供了一种方便的解决方法,以防止在客户端进行分块。详情请见: http://wiki.restlet.org/docs_2.1/13-restlet/21-restlet/318-restlet/303-restlet.html