Note that there are some explanatory texts on larger screens.

plurals
  1. POJava-Servlet: Streaming of a Quicktime-video causes a ClientAbortException
    text
    copied!<p>I am trying to program a small webproxy based on a java-servlet. This proxy has only one task:</p> <ol> <li>HTML shall be passed to the client which sent the request (GET requests with destination port 80 are rerouted to the proxy by firewall rules).</li> <li>An embedded quicktime-video shall be replaced by another quicktime-video and shall be passed to the client instead of the initially requested (here, too, the initially sent GET request of the client is rerouted to the proxy first. The proxy detects that the requested content type is not HTML and concludes from this issue that the content must be a quicktime-video in this special case (see HTML below)). As a result the proxy shall send/stream a particular video to the client.</li> </ol> <p>This should happen for the following HTML document that is going to be requested by the client:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;h1&gt; Heading!&lt;/h1&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;My First Heading&lt;/h1&gt; &lt;object width="160" height="144" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"&gt; &lt;param name="src" value="final_lion.mov"&gt; &lt;param name="autoplay" value="true"&gt; &lt;param name="controller" value="false"&gt; &lt;embed src="final_lion.mov" width="480" height="432" autoplay="true" controller="false" pluginspage="http://www.apple.com/quicktime/download/"&gt; &lt;/embed&gt; &lt;/object&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The source code of the proxy-servlet is as follows:</p> <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext context = getServletContext(); PrintWriter out = null; try { String result = new String(); String urlStr = request.getRequestURL().toString(); URL url = new URL(urlStr); URLConnection conn = url.openConnection(); response.setContentType(conn.getContentType()); if (conn.getContentType().contains("text/")) { out = response.getWriter(); out.write(getTextContent(conn)); out.flush(); out.close(); } else { File file = new File("/var/www/final_lion.mov"); response.setContentType("video/quicktime"); response.setHeader("Content-Length", Long.toString(file.length())); response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\""); FileInputStream input = new FileInputStream(file); OutputStream output = response.getOutputStream(); byte[] buffer = new byte[4096]; int read = 0; while((read = input.read(buffer)) != -1 ){ output.write(buffer,0,read); } input.close(); output.flush(); output.close(); } } catch (Exception e) { context.log("error", e); } } private String getTextContent(URLConnection conn) { try{ BufferedReader rd = new BufferedReader(new InputStreamReader( conn.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = rd.readLine()) != null) { sb.append(line + "\n"); } rd.close(); return sb.toString(); }catch (Exception e){ return "error: " + e.toString(); } } </code></pre> <p>The HTML document is delivered by the proxy and rendered by the browser correctly. But the GET request for the quicktime-video respectively the response of the proxy causes a <i><b>ClientAbortException: java.net.SocketException: Broken pipe</b></i> at line 34 of the servlet-sourcecode.</p> <p>I tried various kinds of OutputStreams (BufferedOutputStream, DataOutputStream, PipedOutputStream, ServletOutputStream). None of them did work...</p> <p>Does anybody see my mistake?</p> <p>Yours faithfully, Ashiaka</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload