Puneet,
here is a short example how to do it:
In your file-su look at the xbean.xml: (find my example below)
<i>
<f:poller
service="cp:filePoller"
endpoint="pollerEndpoint"
file="file:///home/lhe/smxtest/input/"
targetService="cp:workflow"
period="5000"
recursive="true"
autoCreateDirectory="true">
<property name="marshaler">
<bean class="net.compart.shared.CpFileMarshaler" />
</property>
</f:poller>
</i>
That will configure your su to poll the directory and use a specific
marshaller for
transmitting the files polled to the bus.
Then add a src/main/java/ folder to your su's folder structure.
There you can put your marshaller class.
Below find my example:
<i>
public class CpFileMarshaler
extends MarshalerSupport
implements FileMarshaler
{
/**
* default constructor
*/
public CpFileMarshaler()
{
super();
}
/**
* now add the real xml content generated by this method
*
* @param message
* @param path
* @throws IOException
* @throws JBIException
* @throws ParserConfigurationException
*/
private void fillContent(NormalizedMessage message, String path)
throws IOException, JBIException, ParserConfigurationException
{
// here you can transform your polled file object into a
message to be sent to the bus
}
/**
*
*/
public String getOutputName(MessageExchange exchange,
NormalizedMessage message) throws MessagingException
{
// here you can define a logic for getting the name of the
output file if a message should be transformed to a file by this component
}
/**
*
*/
public void readMessage(MessageExchange exchange, NormalizedMessage
message, InputStream in, String path)
throws IOException, JBIException
{
try
{
fillContent(message, path);
}
catch (ParserConfigurationException pcEx)
{
throw new JBIException("CpFileMarshaler.readMessage(): Error
building XML message for " + path, pcEx);
}
}
/**
*
*/
public void writeMessage(MessageExchange exchange, NormalizedMessage
message, OutputStream out, String path)
throws IOException, JBIException
{
// here you can specify a logic how to transform a message
from the bus into a file on the file system
}
}
</i>
I hope this clarifies how to write your own marshallers.
Regards,
Lars
[EMAIL PROTECTED] schrieb:
hello,
afaik, BinaryFileMarshaller comes along with ServiceMix.
it's here
org.apache.servicemix.components.util.BinaryFileMarshaler
haven't uploaded servicemix sources in Eclipse, so i cannot know
but , after building it, it'll end up in a jar called
servicemix-components-<version>-SNAPSHOT.jar, which
you can find under the <servicemixdir>\extras
1 qestion for ya: why would you need to create ur own Binary Marshaller?
do you mean that you want tow rite your marshaller so you can 'decode'
what's in the file?
for writing ur own marshaller, have a look here
http://servicemix.apache.org/7-intermediate-writing-a-http-upload-application.html
this is a tutorial for an http uploader where u have to write ur own
marshaller.
my guess is that what u want to achieve is to 'upload' a file via
file:poller, send it to your SE, which will do something with it..?
regards
marco
Internet
[EMAIL PROTECTED]
05/02/2008 09:59
Please respond to
[email protected]
To
users
cc
Subject
Re: Problem facing in creating servicemix application
Hi marco,
I really thanksful for your reply.
The input are really needful to me.
Could u please explain me how can i write my own BinaryFileMarshaler for
polling the file.
I tried to create my own marshler
Steps are as below:
1. Created the eclipse project using below command:
mvn ecplise:clean ecplise:ecplise
2. Write a My own marshler class. declaration is as follow:
public class MyBinaryFileMarshaler extends BinaryFileMarshaler{
......
}
But BinaryFileMarshaler class is not found in the build path of the
project.
Apart from this activation.jar file is also missing in the build path of
eclipse.
If I provide these file manually in the eclipse, maven build failed while
installing the project using below command.
mvn clear install
Please help me to resolve these issues.
Regards,
Puneet
Thanks,
Puneet
marco.mistroni wrote:
Hi,
my 2 cents......but just for task 2 i m afraid
if u want to send 'any' kind of file, write your file service unit as
htis
<file:poller service="tut:file"
endpoint="poller"
file="file:///c:/servicemix-projects/in/"
targetService="tut:wiretap">
<property name="marshaler">
<bean
class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
</property>
</file:poller>
hth
marco
Internet
[EMAIL PROTECTED]
05/02/2008 09:15
Please respond to
[email protected]
To
users
cc
Subject
Re: Problem facing in creating servicemix application
Hi Chris,
Thanks a lot for your reply. The inputs are really usefull to me
The exception at the startup is removed now.
I am facing difficulty to perform following tasks:
Task 1:
====
I need to read the content of the file send in the bean component.
When I print the exchange object, the content of my file is displayed on
the
console along with other data stored in the Exchange. It prints the
content
of the file if front of "in" key, where the normalize message object is
kept.
How can I retrieve the content of the file in String format in
servicemix-bean compnent.
Task2:
====
This component is polling only xml file.
How can i read a text file using the same compnent.
Task3:
====
When I shut down servicemix, exception is thrown. Details of Exception
is
given below:
INFO - JBIContainer - Shutting down ServiceMix JBI
Container (ServiceMix) stopped
INFO - JBIContainer - Deactivating component
#SubscriptionManager#
INFO - QuartzScheduler - Scheduler
DefaultQuartzScheduler_$_NON_CLUSTERED paused.
INFO - QuartzScheduler - Scheduler
DefaultQuartzScheduler_$_NON_CLUSTERED shutting down.
INFO - QuartzScheduler - Scheduler
DefaultQuartzScheduler_$_NON_CLUSTERED paused.
INFO - QuartzScheduler - Scheduler
DefaultQuartzScheduler_$_NON_CLUSTERED shutdown complete.
INFO - ServiceAssemblyLifeCycle - Stopping service assembly:
tutorial-sa
INFO - ServiceUnitLifeCycle - Stopping service unit:
perftester-file-su
INFO - ServiceUnitLifeCycle - Stopping service unit:
perftester-http-handler-su
INFO - ServiceAssemblyLifeCycle - Shutting down service assembly:
tutorial-sa
INFO - ServiceUnitLifeCycle - Shutting down service unit:
perftester-file-su
INFO - ServiceUnitLifeCycle - Shutting down service unit:
perftester-http-handler-su
ERROR - FileComponent - Failed to process file:
D:\poller\build.xml. Reason: javax.jbi.messaging.MessagingException:
java.lang.InterruptedException
javax.jbi.messaging.MessagingException: java.lang.InterruptedException
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:498)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:442)
at
org.apache.servicemix.common.EndpointDeliveryChannel.sendSync(EndpointDeliveryChannel.java:95)
at
org.apache.servicemix.common.endpoints.SimpleEndpoint.sendSync(SimpleEndpoint.java:71)
at
org.apache.servicemix.file.FilePollerEndpoint.processFile(FilePollerEndpoint.java:282)
at
org.apache.servicemix.file.FilePollerEndpoint.processFileAndDelete(FilePollerEndpoint.java:253)
at
org.apache.servicemix.file.FilePollerEndpoint$1.run(FilePollerEndpoint.java:231)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.waitForExchange(DeliveryChannelImpl.java:699)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:472)
... 9 more
INFO - JBIContainer - ServiceMix JBI Container
(ServiceMix) stopped
Terminate batch job (Y/N)? Y
Thanks for your reply.
Puneet
Chris Custine (Apache) wrote:
I think these errors are because the file poller starts before the
target
endpoint is finished starting. I recommend trying the delay parameter
to
the file:poller endpoint. For example, setting delay="5000" will tell
the
poller to wait 5 seconds before processing files on startup.
Good luck,
Chris
On Feb 4, 2008 1:25 PM, puneetjain <[EMAIL PROTECTED]> wrote:
Hi,
I am new to servicemix. I am trying to write an application which read
a
text file and from the file system and send to a service engine.
Service
Engine process the file data and send the write the process data on
console
or send to a jms.
Environment:
Servicemix version : 3.2.1
Operation System: Windows XP
Java: jdk1.5
Step Performed:
1. Created a project using maven.
2. Created a servicemix-file component. Xbean file configuration
is
as
follow:
<beans xmlns:file="http://servicemix.apache.org/file/1.0"
xmlns:tut="urn:servicemix:tutorial"
xmlns:ex="http://www.servicemix.org/example">
<file:poller service="tut:file"
endpoint="poller"
file="file:///D:/poller"
targetService="ex:httphandler"
targetEndpoint="handlerEndpoint">
</file:poller>
</beans>
3. Created a servicemix-bean. xbean.xml is given below
<beans xmlns:bean="http://servicemix.apache.org/bean/1.0"
xmlns:ex="http://www.servicemix.org/example">
<bean:endpoint service="ex:httphandler" endpoint="handlerEndpoint"
bean="#reverserBean"/>
<bean id="reverserBean"
class="com.wipro.oki.servicemix.sample.StringReverserBean" />
</beans>
4. When I deployed the application on servicemix, following
exception
raised:
Exception Raised:
http://www.nabble.com/file/p15276742/servicemix.log servicemix.log
--
View this message in context:
http://www.nabble.com/Problem-facing-in-creating-servicemix-application-tp15276742s12049p15276742.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
--
View this message in context:
http://www.nabble.com/Problem-facing-in-creating-servicemix-application-tp15276742s12049p15286174.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
This communication is confidential, may be privileged and is meant only
for the intended recipient. If you are
not the intended recipient, please notify the sender by reply and delete
this message from your system. Any
unauthorised dissemination, distribution or copying hereof is
prohibited.
BNP Paribas Fund Services UK Limited, BNP Paribas Trust Corporation UK
Limited, BNP Paribas UK Limited,
BNP Paribas Commodity Futures Ltd and Investment Fund Services Limited
are
authorised and regulated by
the Financial Services Authority.
BNP Paribas, BNP Paribas Securities Services and BNP Paribas Private
Bank
are authorised by the CECEI
and AMF. BNP Paribas London Branch, BNP Paribas Securities Services
London Branch and BNP Paribas
Private Bank London Branch are regulated by the Financial Services
Authority for the conduct of their UK
business. BNP Paribas Securities Services London Branch is also a
member
of the London Stock Exchange.