我在嵌入式Jetty服务器上安装了一个restlet应用程序。 一个ServerResource通过represent()方法实现HTTP Get请求。 我们希望URL形成如下:server:port / model?id = 345
@Get
public Representation represent() {
String id = getQuery().getFirstValue("id");
Representation result = null;
Model model = daoFactory.getModelDao().findById(id);
File modelFile = model.getFile();
FileRepresentation fr = new FileRepresentation(modelFile, MediaType.APPLICATION_OCTET_STREAM, -1);
result = new InputRepresentation(fr.getStream(), fr.getMediaType());
setStatus(Status.SUCCESS_ACCEPTED);
return result;
}
当执行请求时(我尝试使用文本和二进制文件),http连接由服务器关闭,显示以下跟踪
déc. 15, 2015 5:10:30 PM org.restlet.engine.adapter.ServerAdapter commit
GRAVE: An exception occured writing the response entity
org.eclipse.jetty.io.EofException
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:192)
at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:408)
at org.eclipse.jetty.io.WriteFlusher.completeWrite(WriteFlusher.java:364)
at org.eclipse.jetty.io.SelectChannelEndPoint.onSelected(SelectChannelEndPoint.java:111)
at org.eclipse.jetty.io.SelectorManager$ManagedSelector.processKey(SelectorManager.java:636)
at org.eclipse.jetty.io.SelectorManager$ManagedSelector.select(SelectorManager.java:607)
at org.eclipse.jetty.io.SelectorManager$ManagedSelector.run(SelectorManager.java:545)
at org.eclipse.jetty.util.thread.NonBlockingThread.run(NonBlockingThread.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Une connexion établie a été abandonnée par un logiciel de votre ordinateur hôte
at sun.nio.ch.SocketDispatcher.writev0(Native Method)
at sun.nio.ch.SocketDispatcher.writev(SocketDispatcher.java:55)
at sun.nio.ch.IOUtil.write(IOUtil.java:148)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:524)
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:172)
... 10 more
2015-12-15 17:10:30.972:WARN:oejs.Response:qtp20590698-20: Committed before 500 An exception occured writing the response entity
déc. 15, 2015 5:10:30 PM org.restlet.engine.adapter.HttpServerHelper handle
AVERTISSEMENT: Error while handling an HTTP server call:
déc. 15, 2015 5:10:30 PM org.restlet.engine.adapter.HttpServerHelper handle
INFOS: Error while handling an HTTP server call
java.lang.IllegalStateException: Committed
at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1253)
at org.eclipse.jetty.server.Response.sendError(Response.java:567)
at org.restlet.ext.servlet.internal.ServletCall.sendResponse(ServletCall.java:397)
at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:214)
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:245)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
使用文本文件(json)和MediaType.APPLICATION_JSON实现相同的代码确实有效,但仅适用于小文件(大约100KB以下)