java-servlet视频流ClientAbortException
作者:互联网
当我尝试从服务器流式传输视频文件时,我就遇到了servlet的问题.
服务器文件的代码
if (contentType == null) {
contentType = "application/octet-stream";
}
response.reset();
response.setBufferSize(ServerConfiguration.DEFAULT_BUFFER_SIZE);
response.setContentType(contentType);
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
response.setHeader("Cache-Control", "public") ;
BufferedInputStream input = null;
BufferedOutputStream output = null;
try {
// Open streams.
input = new BufferedInputStream(new FileInputStream(file), ServerConfiguration.DEFAULT_BUFFER_SIZE);
output = new BufferedOutputStream(response.getOutputStream(), ServerConfiguration.DEFAULT_BUFFER_SIZE);
// Write file contents to response.
byte[] buffer = new byte[ServerConfiguration.DEFAULT_BUFFER_SIZE];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
}
catch (Exception e) {
log(e);
}
finally {
// Gently close streams.
close(output);
close(input);
}
我已经将content-disposition设置为“ inline”,并且当我调试时,我可以看到请求在无限循环中到达服务器,并且每次它引发此错误时:
ClientAbortException: java.io.IOException
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:369)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:327)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:392)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:381)
at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:93)
at java.io.BufferedOutputStream.write(Unknown Source)
at com.venividi.ResourceManager.UploadFileManager.getMediaFiles(UploadFileManager.java:118)
at com.venividi.Servlet.VenividiServlet.doGet(VenividiServlet.java:182)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.venividi.Servlet.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:29)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:306)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:322)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1732)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException
at org.apache.coyote.http11.InternalAprOutputBuffer.flushBuffer(InternalAprOutputBuffer.java:208)
at org.apache.coyote.http11.InternalAprOutputBuffer$SocketOutputBuffer.doWrite(InternalAprOutputBuffer.java:238)
at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:84)
at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:190)
at org.apache.coyote.Response.doWrite(Response.java:533)
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:364)
... 28 more
如果我将内容处置类型更改为附件-我能够下载文件并从localsytem播放文件(这意味着数据正确),但无法使用VLC播放器(网络)播放此视频文件(通过url)流选项)或我的自定义iphone媒体播放器.
我想做类似服务器-http://www.yo-yo.org/mp4/yu.mp4的操作.我可以通过提供VLC的URL或我的Iphone应用程序..网站的文件(http://www.yo-yo.org/mp4/)来播放此文件. .
yo-yo mp4文件的响应标头是
接受范围:字节
连接:保持活动
内容长度:7846115
内容类型:文本/纯文本;字符集= UTF-8
日期:2011年8月15日星期一18:01:12 GMT
ETag:“ 32a000f-77b8e3-3bd314df3c340”
保持活动:超时= 2
上次修改时间:2003年5月9日星期五,格林尼治标准时间
伺服器:Apache / 2.2.8(Fedora)
而我服务器的响应头是
缓存控制:公共
内容处置:内联; filename =“ 3648ef48-71bf-4393-9c0e-89fda68a683c.mp4”
内容长度:7846115
内容类型:视频/ mp4
日期:2011年8月15日星期一18:10:07 GMT
伺服器:Apache-Coyote / 1.1
请提供一些建议.我将非常感谢您的帮助
问候
苏里亚
解决方法:
我已经解决了上述问题. chrome发送字节范围的请求,服务器应处理此类请求,而不是在单个请求中写入完整的文件.
该链接是有帮助的:Servlet Supporting Resume
标签:servlets,streaming,java 来源: https://codeday.me/bug/20191208/2088547.html