Reputation: 813
This is my spring integration case:
1) ftp adapter to download a pdf file
2) pdf2TextTransformer transform pdf to text by using pdfbox
3) pdfText2CsvTransformer transform text to csv
I add an enricher in the chain, however, seems header doesn't propagate to myErrorChannel, anyone can tell me why?
Here is my debug log, header file_originalFile doesn't propagate to myErrorChannel
][Headers={file_originalFile=D:\projects\DMTP\ftp\local2\6000047256 - Copy - Copy.pdf, file_name=6000047256 - Copy - Copy.pdf, id=a091fe5e-83f3-e48c-4be5-927849dbf31a, timestamp=1501472718172}]
11:45:18.180 DEBUG [task-scheduler-2][org.springframework.integration.channel.PublishSubscribeChannel] preSend on channel 'errorChannel', message: [Payload MessageTransformationException content=org.springframework.integration.transformer.MessageTransformationException: org.springframework.messaging.MessageHandlingException: java.lang.StringIndexOutOfBoundsException: String index out of range: -3][Headers={id=251c77f0-30e8-e18c-6980-ebfb289f79a4, timestamp=1501472718180}]
11:45:18.180 DEBUG [task-scheduler-2][org.springframework.integration.handler.ServiceActivatingHandler] ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@56eacc77] received message: [Payload MessageTransformationException content=org.springframework.integration.transformer.MessageTransformationException: org.springframework.messaging.MessageHandlingException: java.lang.StringIndexOutOfBoundsException: String index out of range: -3][Headers={id=251c77f0-30e8-e18c-6980-ebfb289f79a4, timestamp=1501472718180}]
file_originalFile:null
MessageHeaders: {id=251c77f0-30e8-e18c-6980-ebfb289f79a4, timestamp=1501472718180}
MessagePayload: org.springframework.integration.transformer.MessageTransformationException: org.springframework.messaging.MessageHandlingException: java.lang.StringIndexOutOfBoundsException: String index out of range: -3
11:45:18.182 DEBUG [task-scheduler-2][org.springframework.integration.handler.ServiceActivatingHandler] handler 'ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@56eacc77]' produced no reply for request Message: [Payload MessageTransformationException content=org.springframework.integration.transformer.MessageTransformationException: org.springframework.messaging.MessageHandlingException: java.lang.StringIndexOutOfBoundsException: String index out of range: -3][Headers={id=251c77f0-30e8-e18c-6980-ebfb289f79a4, timestamp=1501472718180}]
here is my configuration:
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${host}"/>
<property name="port" value="${availableServerPort}"/>
<property name="username" value="${userid}"/>
<property name="password" value="${password}"/>
</bean>
<bean id="cachingSessionFactory" class="org.springframework.integration.file.remote.session.CachingSessionFactory">
<constructor-arg ref="ftpClientFactory"/>
</bean>
<int:channel id="ftpChannelIn">
<int:queue capacity="1"/>
</int:channel>
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannelIn"
session-factory="cachingSessionFactory"
filename-pattern="*.pdf"
auto-create-local-directory="true"
delete-remote-files="true"
remote-directory="/in2"
local-directory="D:/projects/DMTP/ftp/local2">
<!--<int:poller fixed-rate="1000"/>-->
<int:poller fixed-delay="1"/>
</int-ftp:inbound-channel-adapter>
<int:chain input-channel="ftpChannelIn">
<int:header-enricher>
<int:header name="foo" value="bar"/>
</int:header-enricher>
<file:file-to-bytes-transformer/>
<int:transformer ref="pdf2TextTransformer"/>
<int:transformer ref="pdfText2CsvTransformer"/>
<int-ftp:outbound-channel-adapter
remote-directory="/out"
session-factory="cachingSessionFactory"
remote-filename-generator="filenameGenerator"/>
</int:chain>
<int:channel id="ftpChannelOut">
</int:channel>
<bean id="filenameGenerator" class="file.DatedDirectoryFactory "/>
<int:poller default="true" fixed-delay="50"/>
<int:channel id="myErrorChannel"/>
<int:service-activator input-channel="errorChannel" ref="errorLogger"/>
Upvotes: 0
Views: 1354
Reputation: 121337
The ErrorMessage
is built in the Poller and it is based on the exception:
try {
getMessagingTemplate().send(errorChannel, getErrorMessageStrategy().buildErrorMessage(t, null));
sent = true;
}
There is no any info about original headers.
Your headers, in particular <int:header name="foo" value="bar"/>
is presented on the downstream requestMessage
. Typically, when exception happens in the Integration Component, the MessagingException
is thrown.
In your case it is MessageTransformationException
. That kind of exception has failedMessage
property. This is exactly your requestMessage
what is "guilty" in the error. And, as you understand, already here you can get access to you headers - MessagingException.getFailedMessage().getHeaders()get("foo")
. And, of course, file_originalFile
will be available here as well.
Upvotes: 2
Reputation: 174584
If your transformers are returning Message<?>
then they are responsible for copying the headers; the framework assumes that. If your transformers are POJO, and return just the transformed payload (the recommended programming model), the framework will take care of propagating the headers.
Turn on debug logging to examine the message flow; if you still think it "doesn't work", explain in more detail and edit the question to show the log.
BTW, "doesn't work" is not an adequate description of a problem.
Upvotes: 1