Hello again,
ok i found a new problem in my service. i have implemented the bean, and put
your example code into my java file. I add a try - catch block for the
SourceTransformer. After that, i worte the xbean.xml and add the routing.
It's now structured like this: Filepoller -> Errorlistener -> Pipeline <->
XsltTransformer
|
JMS Consumer
in the xbean.xml from the Errorlistener i wrote the pipeline as
targetservice an in filepoller the targetservice is set to the
Errorlistener.
My xbean.xml from the Errorlistener:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:bean="http://servicemix.apache.org/bean/1.0"
xmlns:b="http://servicemix.apache.org/myProjekt/bridge">
<bean:endpoint service="b:ErrorListener" endpoint="ErrorListener"
bean="#Error" targetService="b:Pipeline">
<bean id="Error"
class="org.apache.servicemix.myProject.MyErrorListener"/>
</beans>
The Class is now (only the onMessage Method):
public void onMessageExchange(MessageExchange exchange) throws
MessagingException {
if (exchange.getStatus() == ExchangeStatus.ERROR) {
NormalizedMessage message = exchange.getMessage("in");
Source content = message.getContent();
try {
String body = (new
SourceTransformer()).toString(content);
} catch (TransformerException e){
System.out.println("Caught: " + e);
e.printStackTrace();
}
// ***** Write the message to a directory ****
channel.send(exchange);
} else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
channel.send(exchange);
} else if (exchange.getStatus() == ExchangeStatus.DONE) {
channel.send(exchange);
}
}
It throws this Errormessage:
for service: {http://servicemix.apache.org/myProject/bridge}ErrorListener
and interface: null
at
org.apache.servicemix.jbi.nmr.DefaultBroker.sendExchangePacket(DefaultBroker.java:297)
at
org.apache.servicemix.jbi.security.SecuredBroker.sendExchangePacket(SecuredBroker.java:88)
at
org.apache.servicemix.jbi.container.JBIContainer.sendExchange(JBIContainer.java:894)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.doSend(DeliveryChannelImpl.java:395)
at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.send(DeliveryChannelImpl.java:431)
at
org.apache.servicemix.common.EndpointDeliveryChannel.send(EndpointDeliveryChannel.java:88)
at
org.apache.servicemix.common.endpoints.SimpleEndpoint.send(SimpleEndpoint.java:66)
at
org.apache.servicemix.file.FilePollerEndpoint.processFile(FilePollerEndpoint.java:352)
at
org.apache.servicemix.file.FilePollerEndpoint.processFileNow(FilePollerEndpoint.java:333)
at
org.apache.servicemix.file.FilePollerEndpoint$1.run(FilePollerEndpoint.java:317)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
What does it mean? Is the Message emty or is it necessary to put the message
in the xbean.xml of the Errorlistener into a container to send it to the
pipeline?
Thanks for your help,
Cheers Stefan
smo001 wrote:
>
>
> Hello,
>
> thanks for your answer. Now i understand how it works. My solution with
> the bean component was the right way, but i didn't see that i have to put
> it between the two components. I'll test it and if there are questions
> i'll write again.
>
> Thanks Ashwin
>
> Cheers,
> Stefan
>
>
>
>
>
>
>
>
>
>
>
>
>
> Ashwin Karpe wrote:
>>
>> Oops, the code should be
>>
>> example of this code is
>>
>> import org.apache.servicemix.jbi.listener.MessageExchangeListener;
>> import org.apache.servicemix.jbi.util.MessageUtil;
>>
>> import javax.annotation.Resource;
>> import javax.jbi.messaging.DeliveryChannel;
>> import javax.jbi.messaging.ExchangeStatus;
>> import javax.jbi.messaging.MessageExchange;
>> import javax.jbi.messaging.MessagingException;
>>
>> public class ListenerBean implements MessageExchangeListener {
>>
>> @Resource
>> private DeliveryChannel channel;
>>
>> public void onMessageExchange(MessageExchange exchange) throws
>> MessagingException {
>> if (exchange.getStatus() == ExchangeStatus.ERROR) {
>> NormalizedMessage message = exchange.getMessage("in");
>> Source content = message.getContent();
>> String body = (new SourceTransformer()).toString(content);
>>
>> // ***** Write the message to a directory ****
>> channel.send(exchange);
>>
>> }
>> }
>>
>> }
>>
>>
>> Ashwin Karpe wrote:
>>>
>>> Hi,
>>>
>>> The way to do this is the following.
>>>
>>> - Create a servicemix-bean that exclusively does error handling (i.e
>>> check the exchange for Exchange status to be Error/Fault) and writes the
>>> message to a specific directory. The Exception handling bean will
>>> typically be a pass through and only kkick in when an exceptionis
>>> received in the Message Exchange
>>> - Introduce this bean between the File SU and the Transformer by
>>> changing the target Service in the File SU and the Exception Handling
>>> Bean
>>> File SU --> Exception Processing Bean --> Transformer
>>>
>>> An example of this code is
>>>
>>> import org.apache.servicemix.jbi.listener.MessageExchangeListener;
>>> import org.apache.servicemix.jbi.util.MessageUtil;
>>>
>>> import javax.annotation.Resource;
>>> import javax.jbi.messaging.DeliveryChannel;
>>> import javax.jbi.messaging.ExchangeStatus;
>>> import javax.jbi.messaging.MessageExchange;
>>> import javax.jbi.messaging.MessagingException;
>>>
>>> public class ListenerBean implements MessageExchangeListener {
>>>
>>> @Resource
>>> private DeliveryChannel channel;
>>>
>>> public void onMessageExchange(MessageExchange exchange) throws
>>> MessagingException {
>>> if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
>>> NormalizedMessage message = exchange.getMessage("in");
>>> Source content = message.getContent();
>>> String body = (new SourceTransformer()).toString(content);
>>>
>>> // ***** Write the message to a directory ****
>>> channel.send(exchange);
>>>
>>> }
>>> }
>>>
>>> }
>>>
>>> Hope this helps.
>>>
>>> Cheers,
>>>
>>> Ashwin...
>>>
>>>
>>> smo001 wrote:
>>>>
>>>>
>>>> Hi all,
>>>>
>>>> i'v got some questions about the exchange status which is used in the
>>>> Servicemix ESB.
>>>> i'd like to use it to get a user defined handling if an error occurs.
>>>> My projekt is a file - unit which sends the file into a pipeline. the
>>>> pipeline sends it to a xslt - transformer unit which returns the
>>>> transformed message back to the pipeline.
>>>>
>>>> on Success: the message will be received to a jms unit which writes the
>>>> message to a messagequeue
>>>>
>>>> on Error: the file shoud be moved to an other directory.
>>>>
>>>> I think, an error could only occur in the tranformation unit if the
>>>> xml document is not valid. So the component receives the exchange
>>>> status = error back to the pipeline.
>>>>
>>>> The Filepoller only deletes the file if it got the status done (is it
>>>> write?) . Therefore i think it should be possible to add for example a
>>>> bean with an own class to copy the file to an other directory, but i
>>>> don't know how to implement the bean in the file component.
>>>>
>>>> Has anybody en idea how to realize it?
>>>>
>>>> My filepoller is a simple one like this:
>>>> <beans xmlns:f="http://servicemix.apache.org/file/1.0"
>>>> xmlns:b="http://servicemix.apache.org/OpenTransToPdf/bridge">
>>>>
>>>> <f:poller
>>>> service="b:FilePoller"
>>>> endpoint="FilePoller"
>>>> file="file:///C:\Servicemix\inbox"
>>>> targetService="b:Pipeline"
>>>> period="30000"
>>>> recursive="true"
>>>> autoCreateDirectory="true">
>>>>
>>>> <property name="filter">
>>>> <bean
>>>> class="org.apache.commons.io.filefilter.WildcardFilter">
>>>> <constructor-arg value="*.xml" />
>>>> </bean>
>>>> </property>
>>>>
>>>> <property name="marshaler">
>>>> <bean
>>>>
>>>> class="org.apache.servicemix.components.util.DefaultFileMarshaler">
>>>> </bean>
>>>> </property>
>>>>
>>>> </f:poller>
>>>>
>>>> Thanks for your Help
>>>> Regards Stefan
>>>>
>>>
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/Exchange-Status-to-handle-Errors-tp21328296p21350724.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.