使用 Jersey 传输视频
我目前正在尝试通过 Jersey REST 服务流式传输视频文件,并在返回响应时遇到神秘的异常:
ERROR WebApplicationImpl - The RuntimeException could not be mapped to a response, re-throwing to the HTTP container java.lang.NullPointerException
at com.sun.jersey.core.util.KeyComparatorHashMap$Entry.hashCode(KeyComparatorHashMap.java:735)
at java.util.HashMap.getEntry(HashMap.java:344)
at java.util.HashMap.containsKey(HashMap.java:335)
at java.util.HashSet.contains(HashSet.java:184)
at com.sun.jersey.server.linking.impl.RefProcessor.processLinks(RefProcessor.java:85)
at com.sun.jersey.server.linking.impl.RefProcessor.processMember(RefProcessor.java:120)
at com.sun.jersey.server.linking.impl.RefProcessor.processLinks(RefProcessor.java:113)
at com.sun.jersey.server.linking.impl.RefProcessor.processMember(RefProcessor.java:120)
at com.sun.jersey.server.linking.impl.RefProcessor.processLinks(RefProcessor.java:113)
at com.sun.jersey.server.linking.impl.RefProcessor.processMember(RefProcessor.java:120)
....
创建响应的代码如下所示:(
return Response.ok( new StreamingOutput( )
{
@Override
public void write( OutputStream output ) throws WebApplicationException
{
PrintWriter out = new PrintWriter( output );
out.println( "Foo" );
out.close( );
}
}, MediaType.MULTIPART_FORM_DATA ).build( );
我已经删除了额外的范围标头和内容)。我在 StreamingOutput.write() 方法中有几个断点,但似乎没有达到。我有第二个休息方法,将视频作为完整的实体返回,该方法有效。
那么,有人知道异常意味着什么以及我可以改进什么吗?谢谢!
i'm currently trying to stream a video file over Jersey REST service and get a mysterious exception on returning the response:
ERROR WebApplicationImpl - The RuntimeException could not be mapped to a response, re-throwing to the HTTP container java.lang.NullPointerException
at com.sun.jersey.core.util.KeyComparatorHashMap$Entry.hashCode(KeyComparatorHashMap.java:735)
at java.util.HashMap.getEntry(HashMap.java:344)
at java.util.HashMap.containsKey(HashMap.java:335)
at java.util.HashSet.contains(HashSet.java:184)
at com.sun.jersey.server.linking.impl.RefProcessor.processLinks(RefProcessor.java:85)
at com.sun.jersey.server.linking.impl.RefProcessor.processMember(RefProcessor.java:120)
at com.sun.jersey.server.linking.impl.RefProcessor.processLinks(RefProcessor.java:113)
at com.sun.jersey.server.linking.impl.RefProcessor.processMember(RefProcessor.java:120)
at com.sun.jersey.server.linking.impl.RefProcessor.processLinks(RefProcessor.java:113)
at com.sun.jersey.server.linking.impl.RefProcessor.processMember(RefProcessor.java:120)
....
The code creating the response looks like follows:
return Response.ok( new StreamingOutput( )
{
@Override
public void write( OutputStream output ) throws WebApplicationException
{
PrintWriter out = new PrintWriter( output );
out.println( "Foo" );
out.close( );
}
}, MediaType.MULTIPART_FORM_DATA ).build( );
(I already deleted additional range headers and stuff). I have several breakpoints in the StreamingOutput.write() method, but none seems to be reached. I have a second rest method returning the video as complete entity which works.
So, has anybody an ideo what the exception means and what can i improve? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,问题是 Jersey LinkFilter 在解析 StreamingOutput 时出现异常。我的解决方案是编写自己的 LinkFilter 来扩展现有的 LinkFilter,如下所示:
OK, problem is that the Jersey LinkFilter gets an exception parsing StreamingOutput. My solution was to write my own LinkFilter extending the existing one like follows: