使用 Jersey 传输视频

发布于 2025-01-06 15:21:38 字数 1522 浏览 2 评论 0原文

我目前正在尝试通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女净妖师 2025-01-13 15:21:38

好的,问题是 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 );
    }
}}

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:

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 );
    }
}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文