You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "raymond domingo (JIRA)" <ji...@apache.org> on 2010/04/12 17:18:43 UTC

[jira] Created: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

IOException: Bad file descriptor and FileNotFoundException
----------------------------------------------------------

                 Key: CAMEL-2636
                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
             Project: Apache Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 2.2.0
         Environment: Related to topic, I will post possible solution to this problem:
http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html

Other useful links:
http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml

My environment:

apache 2.2.0

java version "1.6.0_19"
Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)

no container, using:
mvn camel:run

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) 

Config:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
    <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
        <!-- clipboard download producer -->
        <route>
            <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
            <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
        </route>
    </camelContext>
</beans:beans>



            Reporter: raymond domingo
             Fix For: Future


When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
The pdf isn't recieved succesfully by reciever (0kb)

This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml

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);
        }
    }


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Assigned: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Willem Jiang reassigned CAMEL-2636:
-----------------------------------

    Assignee: Willem Jiang

> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: Future
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Raymond Domingo (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58969#action_58969 ] 

Raymond Domingo commented on CAMEL-2636:
----------------------------------------

I couldn't verify it using 2.3.0 BETA... when using this version my camel 'bus connector' didn't seem to work anymore....
Should it already be stable ?? (I don't really have time to look in to details right now)

I copied your new files to 2.2.0 (I checked out from svn) and rebuilded camel-core, files:
- CachedOutputStream.java
- FileInputStreamCache.java

And all is working correct now !

> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58904#action_58904 ] 

Willem Jiang commented on CAMEL-2636:
-------------------------------------

I committed the patch on base of Raymond's patch, and also added a unit test for it.
Now camel will delete the temp file when the CachedOutputStream is closed or the FileInputStream is closed.

@Raymond
Please check out the latest camel code or the snapshot release to verification it

> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: Future
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Raymond Domingo (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58947#action_58947 ] 

Raymond Domingo commented on CAMEL-2636:
----------------------------------------


   [[ Old comment, sent by email on Fri, 16 Apr 2010 15:03:20 +0200 ]]

I will check it first thing next week.

Did you also prevent the input stream from being closed twice ??
To prevent the bad file discriptor java bug ?






> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58900#action_58900 ] 

Willem Jiang commented on CAMEL-2636:
-------------------------------------

Hi Raymond, 

Now I can reproduce Bad file descriptor error with the route that you showed, and found the Exchange.done() is not helping us to clean up the temp file.
As CameServlet still need to access the InputStream from exchange after the process(exchange) is called.
I did some change and make sure the FileInputStream.close will help us to clean up the temp file and will commit the change after running the tests (it will take nearly 3 hours on my box).




> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: Future
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58897#action_58897 ] 

Willem Jiang commented on CAMEL-2636:
-------------------------------------

Hi Raymond 

I reviewed the change, and found your don't delete the file unless the CachedOutputStream is closed. 
If the CachedOutputStream is not closed after the exchange is processed, there could be lots of temp file. 
Can I see the route that you get the filenotfoundexception?

> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: Future
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Willem Jiang resolved CAMEL-2636.
---------------------------------

    Resolution: Fixed

> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59462#action_59462 ] 

Willem Jiang commented on CAMEL-2636:
-------------------------------------

Hi Roland,
We fix this issue of camel jetty and http component by not letting camel remove the temp file at the end of the route,
If you call the "exchange.getIn().getBody(String.class)" in your processor, the cached input stream will be closed, and temp file will be removed.
As you consumed the inputStream, you'd better reset the body with the String that your get.


> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Willem Jiang resolved CAMEL-2636.
---------------------------------

    Fix Version/s: 2.3.0
                       (was: Future)
       Resolution: Fixed

> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59489#action_59489 ] 

Willem Jiang commented on CAMEL-2636:
-------------------------------------

yes, this issue has been fixed month ago.

> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Raymond Domingo (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58949#action_58949 ] 

Raymond Domingo commented on CAMEL-2636:
----------------------------------------


   [[ Old comment, sent by email on Fri, 16 Apr 2010 11:43:10 +0200 ]]

Nice work !!!!

ps: It's my day off today. Next week I will look in to the details !







> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59488#action_59488 ] 

Claus Ibsen commented on CAMEL-2636:
------------------------------------

Willem did you fix this for the 2.3 release which is in vote now?

> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58816#action_58816 ] 

Claus Ibsen commented on CAMEL-2636:
------------------------------------

Note in the future we should switch to use HawtDB for temporary file based cache as its much faster and better than java.io.File based.


> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>             Fix For: Future
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Willem Jiang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58976#action_58976 ] 

Willem Jiang commented on CAMEL-2636:
-------------------------------------

Hi Raymond,

Thanks for your verification.
We are heading to Camel 2.3.0 release at end of this month, can you do some investigation on the "bus connector" issue when you have time?
Please feel free to log a JIRA for it.


> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (CAMEL-2636) IOException: Bad file descriptor and FileNotFoundException

Posted by "Roland Knight (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Roland Knight reopened CAMEL-2636:
----------------------------------


Removing the output temp file causes subsequent calls to FileInputStreamCache.reset() to fail since the file no longer exists. This will happen with a simple route such as:
        from(...).process(...).to(..)
This route will fail if the "process" step simply converts the body to string (exchange.getIn().getBody(String.class)). The "to" step then fails with a file not found error in FileInputStreamCache.reset.

Can deletion of the temp file be easily deferred to the end of the route?



> IOException: Bad file descriptor and FileNotFoundException
> ----------------------------------------------------------
>
>                 Key: CAMEL-2636
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2636
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: Related to topic, I will post possible solution to this problem:
> http://old.nabble.com/bridging-binary-files-over-http-ts28178639.html
> Other useful links:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> My environment:
> apache 2.2.0
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)
> no container, using:
> mvn camel:run
> 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) 
> Config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
>        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
>     <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true" autoStartup="true">
>         <!-- clipboard download producer -->
>         <route>
>             <from uri="jetty:http://0.0.0.0:8201/clipboard/download?chunked=true&amp;matchOnUriPrefix=true" />
>             <to uri="http://0.0.0.0:9101?bridgeEndpoint=true" async="false" />
>         </route>
>     </camelContext>
> </beans:beans>
>            Reporter: raymond domingo
>            Assignee: Willem Jiang
>             Fix For: 2.3.0
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When I try to stream BINARY (pdf) file using camel-http I get the java.io.IOException: Bad file descriptor
> The pdf isn't recieved succesfully by reciever (0kb)
> This seems to be caused by a bug in java (on linux systems), closing inputstream twice causes problems. It seemed to me this is exactly what is happening, see also link:
> http://256.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml
> 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);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.