File and Bean component
manta7 Apr 6, 2011 12:05 PMHello guys,
I'm trying to make a simple project where I poll a directory, I modify the new file (with a bean) and I move this file.
The workflow is:
File Poller -> Bridge -> Bean -> Bridge -> File Sender
So I create 4 projects:
1. A SA project wich contains every SU
2. A File-SU project with this xbean.xml (sorry for the un-indentation):
<file:sender service="msl:file"
endpoint="sender"
directory="file:///c:/tmp/sender">
<property name="marshaler">
<bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
</property>
</file:sender>
<file:poller service="msl:file"
endpoint="poller"
file="file:///c:/tmp/poller"
targetService="msl:pipeline"
targetEndpoint="endpoint">
<property name="marshaler">
<bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
</property>
</file:poller>
3. Then a Bridge-SU which invoke my bean transformation and send the following result to my file sender. The xbean is:
<eip:pipeline service="msl:pipeline" endpoint="endpoint">
<eip:transformer>
<eip:exchange-target service="msl:toxml" endpoint="bean"/>
</eip:transformer>
<eip:target>
<eip:exchange-target service="msl:file" endpoint="sender"/>
</eip:target>
</eip:pipeline>
4. Next a bean SU which must transform my file content, with this xbean:
<bean:endpoint service="mls:toxml" endpoint="bean" bean="#myBean"/>
<bean id="myBean" class="X.X.X.X.MyBean"/>
And this MyBean.java:
public void onMessageExchange(MessageExchange exchange) throws MessagingException {
if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
NormalizedMessage message = exchange.getMessage("in");
Source content = message.getContent();
try {
String body = (new SourceTransformer()).toString(content);
System.out.println("body=" + body);
System.out.println("content=" + content);
System.out.println("message=" + message);
} catch(TransformerException e) {
e.printStackTrace();
}
message.setContent(content);
exchange.setMessage(message, "out");
channel.send(exchange);
}
}
So, when I put a file on my directory, the workflow is working cause I see my bean's logs and the file is moved.
But I have a problem with my log:
System.out.println("message=" + message); => org.apache.servicemix.jbi.runtime.impl.NormalizedMessageImpl@c20590 (OK)
System.out.println("content=" + content); => null
System.out.println("body=" + body); => null
Why the content and the body of the message is null ?
Shouldn't have I to display the content of the file which is polled ?
This is my main question, how can I, in my bean-SU, receive the content of the newly created file ??
Edited by: manta7 on Apr 6, 2011 4:05 PM