我目前正在尝试通过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()方法中有几个断点,但似乎没有达到。我有第二个休息方法将视频作为完整的实体返回。
那么,有没有人意识到这个例外意味着什么,我能改进什么?谢谢!
答案 0 :(得分:0)
好的,问题是Jersey LinkFilter获取解析StreamingOutput的异常。我的解决方案是编写自己的LinkFilter,扩展现有的LinkFilter,如下所示:
public class LinkFilter extends com.sun.jersey.server.linking.LinkFilter {
@Override
public ContainerResponse filter( ContainerRequest request, ContainerResponse response ){
if ( request.getPath( true ).endsWith( "mov" ) )
{
return response;
}
else
{
return super.filter( request, response );
}
}}