You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by goldi <go...@freenet.de> on 2007/05/11 10:09:34 UTC

FileWriter to ServiceMix-Bean Problem!

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





-- 
View this message in context: http://www.nabble.com/FileWriter-to-ServiceMix-Bean-Problem%21-tf3726051s12049.html#a10427653
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: FileWriter to ServiceMix-Bean Problem!

Posted by goldi <go...@freenet.de>.
I think I found the mistake, there was a
"exchange.setStatus(ExchangeStatus.DONE);" before, how studip ... Thanks for
reply.

Greets Goldi

goldi wrote:
> 
> Using this:
> 
> Source source = exchange.getMessage("in").getContent();
> SourceTransformer sourceTransformer = new SourceTransformer();
> String inMessage = sourceTransformer.toString(source); 
> 
> 
> I get the following exception:
> 
> 
> javax.xml.transform.TransformerException: java.io.IOException: Stream
> closed
>         at
> org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:505)
>         at
> org.apache.servicemix.jbi.jaxp.SourceTransformer.toResult(SourceTransformer.java:85)
>         at
> org.apache.servicemix.jbi.jaxp.SourceTransformer.toString(SourceTransformer.java:101)
>         at
> de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.readStream(FileToTopicTransmitter.java:169)
>         at
> de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.onMessageExchange(FileToTopicTransmitter.java:70
>         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)
> Caused by: java.io.IOException: Stream closed
>         at
> java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
>         at java.io.BufferedInputStream.fill(BufferedInputStream.java:189)
>         at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
>         at
> org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown
> Source)
>         at
> org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
>         at
> org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown
> Source)
>         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> Source)
>         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> Source)
>         at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>         at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
> Source)
>         at
> org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
>         ... 16 more
> ---------
> java.io.IOException: Stream closed
>         at
> java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
>         at java.io.BufferedInputStream.fill(BufferedInputStream.java:189)
>         at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
>         at
> org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown
> Source)
>         at
> org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
>         at
> org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown
> Source)
>         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> Source)
>         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> Source)
>         at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>         at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
> Source)
>         at
> org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
>         at
> org.apache.servicemix.jbi.jaxp.SourceTransformer.toResult(SourceTransformer.java:85)
>         at
> org.apache.servicemix.jbi.jaxp.SourceTransformer.toString(SourceTransformer.java:101)
>         at
> de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.readStream(FileToTopicTransmitter.java:169)
>         at
> de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.onMessageExchange(FileToTopicTransmitter.java:70
>         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)
> 
> 
> Greets Goldi
> 
> 
> 
> Gert Vanthienen wrote:
>> 
>> 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
>>>
>>>
>>>
>>>
>>>
>>>   
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/FileWriter-to-ServiceMix-Bean-Problem%21-tf3726051s12049.html#a10430560
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: FileWriter to ServiceMix-Bean Problem!

Posted by goldi <go...@freenet.de>.
Using this:

Source source = exchange.getMessage("in").getContent();
SourceTransformer sourceTransformer = new SourceTransformer();
String inMessage = sourceTransformer.toString(source); 


I get the following exception:


javax.xml.transform.TransformerException: java.io.IOException: Stream closed
        at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:505)
        at
org.apache.servicemix.jbi.jaxp.SourceTransformer.toResult(SourceTransformer.java:85)
        at
org.apache.servicemix.jbi.jaxp.SourceTransformer.toString(SourceTransformer.java:101)
        at
de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.readStream(FileToTopicTransmitter.java:169)
        at
de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.onMessageExchange(FileToTopicTransmitter.java:70
        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)
Caused by: java.io.IOException: Stream closed
        at
java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:189)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
        at
org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown
Source)
        at
org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
        at
org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
        ... 16 more
---------
java.io.IOException: Stream closed
        at
java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:189)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
        at
org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown
Source)
        at
org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
        at
org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
        at
org.apache.servicemix.jbi.jaxp.SourceTransformer.toResult(SourceTransformer.java:85)
        at
org.apache.servicemix.jbi.jaxp.SourceTransformer.toString(SourceTransformer.java:101)
        at
de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.readStream(FileToTopicTransmitter.java:169)
        at
de.it4logistics.prologsSE.messageReceiver.FileToTopicTransmitter.onMessageExchange(FileToTopicTransmitter.java:70
        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)


Greets Goldi



Gert Vanthienen wrote:
> 
> 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
>>
>>
>>
>>
>>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/FileWriter-to-ServiceMix-Bean-Problem%21-tf3726051s12049.html#a10429803
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: FileWriter to ServiceMix-Bean Problem!

Posted by Gert Vanthienen <ge...@skynet.be>.
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
>
>
>
>
>
>