3
我不能讓ChunkedOutput使用JAX-RS新澤西2.3.1和Tomcat 7.我想按照教程從Jersey Tutorial - Chapter 10. Asynchronous Services and Clients無法獲取使用JAX-RS新澤西2.3.1和Tomcat ChunkedOutput工作7
工作我的代碼如下所示
@GET
@Path("/asynchronous")
public ChunkedOutput<String> getAsyncResponse() {
final ChunkedOutput<String> output = new ChunkedOutput<String>(String.class);
new Thread() {
public void run() {
try {
String text;
for (int i = 0; i < 20; i++) {
text = String.valueOf(i);
output.write(text);
Thread.sleep(1000);
}
} catch (Throwable th) {
th.printStackTrace();
} finally {
try {
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}.start();
return output;
}
當我嘗試調用它是否通過捲曲或我的Java客戶端,我上了Web服務端以下異常。
org.glassfish.jersey.server.internal.process.MappableException: java.lang.NullPointerException
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:96)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1139)
at org.glassfish.jersey.server.ChunkedOutput$1.call(ChunkedOutput.java:148)
at org.glassfish.jersey.server.ChunkedOutput$1.call(ChunkedOutput.java:121)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:242)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:345)
at org.glassfish.jersey.server.ChunkedOutput.flushQueue(ChunkedOutput.java:121)
at org.glassfish.jersey.server.ChunkedOutput.write(ChunkedOutput.java:111)
at jaxrs.prototype.tomcat7.AsyncPrototype$1.run(AsyncPrototype.java:82)
Caused by: java.lang.NullPointerException
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:215)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
...
任何想法出了什麼問題?最初我在Tomcat 6上部署它,然後我意識到異步功能在Servlet 3.0 API中可用,並且Tomcat 6不支持該功能,因此我切換到了Tomcat 7.
即使在web.xml中添加異步支持,在Tomcat 7和JRE 1.7組合中仍面臨同樣的問題。 – Nagesh