Goldi,

Does anything else happen in the onMessageExchange before the readStream? Have you tried using ServiceMix's built-in SourceTransformer.toString(Source) method to transform the Source to XML? Does that give you the same error message?

Gert

goldi wrote:
HI everybody,


I'm using the file poller to read a file from the file system and then send
the content of the file to a servicemix-bean component. There I want to do
something with the file content an then send to a topic.
So this is the code inside the servicemix-bean component.

public void onMessageExchange(MessageExchange exchange) {

String strFileContent=readStream(exchange);

... doSomething with the content

...send to Topic

}

private String readStream(MessageExchange exchange) {
                Source source = exchange.getMessage("in").getContent();
                StreamSource ssource = null;
                InputStream stream = null;
                String strFileContent = "";

                if (source instanceof StreamSource) {
                        ssource = (StreamSource) source;
                }

                if (ssource != null) {

                        stream = ssource.getInputStream();

                        byte buffer[] = new byte[10000];

                        int len = 0;
                        try {
                                len = stream.read(buffer, 0, 4000);
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        strFileContent = new String(buffer, 0, len);

                        return strFileContent;

                }

                return null;
        }


The problem is that I get the following exception:

java.io.IOException: Stream closed
        at
java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:304)
        at
de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.readStream(FileToTopicTransmitter.java:165)
        at
de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.onMessageExchange(FileToTopicTransmitter.java:64)
        at
org.apache.servicemix.bean.BeanEndpoint.onProviderExchange(BeanEndpoint.java:224)
        at
org.apache.servicemix.bean.BeanEndpoint.process(BeanEndpoint.java:201)
        at
org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:489)
        at
org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:441)
        at
org.apache.servicemix.common.BaseLifeCycle.onMessageExchange(BaseLifeCycle.java:46)
        at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:593)
        at
org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:174)
        at
org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:176)
        at
org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)
        at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
        at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
        at java.lang.Thread.run(Thread.java:595)


So I have the problem, that I do not get the content of the file. Has
someone a solution for this problem?


Greets goldi






Reply via email to