GAE应用程序的500内部服务器错误

时间:2014-02-03 05:24:30

标签: java javascript google-app-engine

从数据存储区检索图像时收到错误。

以下是此错误的完整堆栈跟踪:

 /getImage.jsp
 java.lang.IllegalStateException: STREAM
at com.google.appengine.runtime.Request.process-aacbf0abf7a842c8(Request.java)
at org.mortbay.jetty.Response.getWriter(Response.java:616)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:188)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
at org.apache.jasper.runtime.JspFactoryImpl.access$100(JspFactoryImpl.java:40)
at org.apache.jasper.runtime.JspFactoryImpl$PrivilegedReleasePageContext.run(JspFactoryImpl.java:166)
at java.security.AccessController.doPrivileged(AccessController.java:34)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
at org.apache.jsp.getImage_jsp._jspService(getImage_jsp.java:81)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
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$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.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
at java.lang.Thread.run(Thread.java:724)

以下是getImage.jsp的相关代码:

<%@ page import="javax.jdo.*" %>
<%@ page import="com.todtm.*" %>
<%
// This code was borrowed from the captionator lecture code and modified for this project
// Comments added to show knowledge of what the code does

PersistenceManager pm = PMF.getPMF().getPersistenceManager(); // instantiates persistence manager
try {
    String imageId = request.getParameter("image");  // gets the image id

    Image thisImage = (Image)pm.getObjectById(Image.class, Long.parseLong(imageId)); // gets the object from the datastore
    byte[] photo = thisImage.getImage(); // retrieves the bitarray containing image data from the object
    response.setContentType("image/jpeg");   // sets content type
    response.getOutputStream().write(photo);  // sends image data
} catch (Exception cannotLoad) {    
} finally {
    pm.close();
}
%>

我很感激帮助解开这个。

1 个答案:

答案 0 :(得分:0)

它表示输出流处于错误状态。使用某些调试日志记录验证您是否拥有正确的数据,例如:

java.util.logging.Logger.getLogger("todtm.getImage").warning(
    "photo.length:" + photo.length
);

尝试注释掉response.setContentType行,以防它影响输出流。

尝试用以下代码替换'//发送图像数据'行:

javax.servlet.ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(photo);  // sends image data

更准确地隔离操作抛出异常。

将至少最小的日志记录放入catch块:

java.util.logging.Logger.getLogger("todtm.getImage").warning(
    "cannotLoad:" + cannotLoad.getMessage();
);