camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdomingo ...@domingo.nl>
Subject Re: bridging binary files over http
Date Mon, 12 Apr 2010 15:19:50 GMT

Created issue for this, see issue 2636:
https://issues.apache.org/activemq/browse/CAMEL-2636

I fixed this by (checking out apache camel-core and camel-http 2.2.0):
In FileInputStreamCache.java:
In method close() wrapped getInputStream().close() in if:
if (stream != null && stream instanceof FileInputStream &&
((FileInputStream) stream).getChannel().isOpen()) { getInputStream().close()
; }

In method reset() also:
if (stream != null && stream instanceof FileInputStream &&
((FileInputStream) stream).getChannel().isOpen()) { getInputStream().close()
; }
}

Second I needed to fix a filenotfoundexception, the tempfile created by
camel was deleted to early.
I changed CachedOutputStream.java

    * Reimplemented constructor:
      public CachedOutputStream(Exchange exchange) {
      String hold = exchange.getContext().getProperties().get(THRESHOLD);
      String dir = exchange.getContext().getProperties().get(TEMP_DIR);
      if (hold != null) { this.threshold =
exchange.getContext().getTypeConverter().convertTo(Long.class, hold); }
      if (dir != null) { this.outputDir =
exchange.getContext().getTypeConverter().convertTo(File.class, dir); }

// add on completion so we can cleanup after the exchange is done such
// as deleting temporary files
exchange.addOnCompletion(new SynchronizationAdapter() {
@Override
public void onDone(Exchange exchange) {
try {
// close the stream and FileInputStreamCache
// close();
// for (FileInputStreamCache cache : fileInputStreamCaches)
// { // cache.close(); // }
// cleanup temporary file
if (tempFile != null) {
System.err.println("####################################################");
System.err.println("DISABLED tempFile.delete:89");
System.err.println("####################################################");
// boolean deleted = tempFile.delete();
// if (!deleted) { // LOG.warn("Cannot delete temporary cache file: " + //
tempFile); // } else if (LOG.isTraceEnabled()) { // LOG.trace("Deleted
temporary cache file: " + // tempFile); // }
tempFile = null;
}
} catch (Exception e) { LOG.warn("Error deleting temporary cache file: " +
tempFile, e); }
}

@Override
public String toString() { return "OnCompletion[CachedOutputStream]"; }
});
}

Reimplemented close():
public void close() throws IOException {
System.err.println("####################################################");
System.err.println("outputStream.close:119 -> delete tempFile");
System.err.println("####################################################");
new Exception().printStackTrace();
currentStream.close();
boolean deleted = tempFile.delete();
if (!deleted) { LOG.warn("Cannot delete temporary cache file: " + tempFile);
} else if (LOG.isTraceEnabled()) { LOG.trace("Deleted temporary cache file:
" + tempFile); }
}


rdomingo wrote:
> 
> Damn, It seems I'm running in to a Java Bug :(
> 
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 
> 
> 
> rdomingo wrote:
>> 
>> Hello,
>> 
>> 1 - I have a http service setup (using camel)
>>         <route>
>>             <from uri="jetty:http://0.0.0.0:9101/clipboard/download" />
>>             <to uri="bean:clipboardBean?method=download" async="false" />
>>         </route>
>> 
>> 2 - When I download a (txt or binary) file directly from this http
>> service, download is ok.
>> 
>> 3 - When I add a http bridge between the service and downloader BINARY
>> files can't be downloaded -> 0KB, text files still download ok.
>>        <route>
>>             <from
>> uri="jetty:http://0.0.0.0:8201/clipboard?matchOnUriPrefix=true" />
>>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" />
>>         </route>
>> 
>> How can I enable bridging of binary file downloads over HTTP ???
>> 
>> In my logging I see  an Exception:
>> java.io.IOException: Bad file descriptor
>> 	at java.io.FileInputStream.available(Native Method)
>> 	at
>> org.apache.camel.converter.stream.FileInputStreamCache.available(FileInputStreamCache.java:70)
>> 	at org.apache.camel.util.IOHelper.copy(IOHelper.java:85)
>> 	at org.apache.camel.util.IOHelper.copy(IOHelper.java:81)
>> 	at
>> org.apache.camel.component.http.DefaultHttpBinding.doWriteDirectResponse(DefaultHttpBinding.java:183)
>> 	at
>> org.apache.camel.component.http.DefaultHttpBinding.doWriteResponse(DefaultHttpBinding.java:169)
>> 	at
>> org.apache.camel.component.http.DefaultHttpBinding.writeResponse(DefaultHttpBinding.java:116)
>> 	at
>> org.apache.camel.component.http.CamelServlet.service(CamelServlet.java:61)
>> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
>> 	at
>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
>> 	at
>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
>> 	at
>> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
>> 	at
>> org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
>> 	at
>> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
>> 	at org.mortbay.jetty.Server.handle(Server.java:326)
>> 	at
>> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
>> 	at
>> org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
>> 	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
>> 	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
>> 	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
>> 	at
>> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
>> 	at
>> org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
>> 2010-04-08 15:37:45.911:WARN::/clipboard/download: java.io.IOException:
>> Bad file descriptor
>> 
>> 
>> Best regards,
>> Raymond Domingo
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/bridging-binary-files-over-http-tp28178639p28219133.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message