Issue: Using spring batch, i need to read a file which has todays date. E.g test_02032015.txt.This file will be in a directory /test/example. Its an unix environment that i need to fetch file from.
question is how to configure spring batch xml so that above mentioned file is read
Any pointers to relevant website or solution would be of great help.
You have a few ways to address a requirement like this:
If you don't need to worry about the other files in a directory, you can just use a wild card in the file name like this:
<property name="resource" value="data/iosample/input/*.xml" />
Another alternative would be to pass the value into the job as a parameter and reference it like this:
<property name="resource" value="#{jobParameters['input.file']}" />
Finally you could use SpEL to build the file name (Sorry I don't have an example of that handy).
Related
Source files are not deleting from s3 bucket once after successfully transfer it to target directory.
steps 1. Using Inbound streaming channel adapter to stream source files from S3 to local directory.(working fine)
step 2 : Want to delete source files once successfully transferred (not working)
configuration code are below
<int-aws:s3-inbound-streaming-channel-adapter id="s3FilesInbound"
channel="s3FilesChannel"
session-factory="s3SessionFactory"
filename-regex="^.*\\.(txt|csv)$"
remote-directory-expression="bucket_name"
auto-startup="true" >
<integration:poller id="s3FilesChannelPoller"
fixed-delay="1000"
max-messages-per-poll="1">
</integration:poller>
</int-aws:s3-inbound-streaming-channel-adapter>
<integration:stream-transformer id="streamTransformer" input-channel="s3FilesChannel" output-channel="s3FilesChannelOut"/>
<integration:chain id="filesS3ChannelChain"
input-channel="s3FilesChannelOut">
<file:outbound-gateway
id="fileInS3ArchiveChannel"
directory="local_directory"
filename-generator-expression="headers.file_remoteFile">
<file:request-handler-advice-chain>
<ref bean="retryAdvice" />
</file:request-handler-advice-chain>
</file:outbound-gateway>
<integration:gateway request-channel="nullChannel"
error-channel="errorChannel" />
</integration:chain>
Regards,
Since you use there a <integration:stream-transformer>, I don't see reason to rely on the <int-aws:s3-inbound-streaming-channel-adapter>. With the first one you just eliminate the streaming purpose of the last one.
I'd suggest you take a look into the regular <int-aws:s3-inbound-channel-adapter>, which already has a delete-remote-files="true" option.
On the other hand you still can do that with what you have so far, but you need to something like <integration:outbound-channel-adapter expression="#s3SessionFactory.getSession().remove(headers[file_remoteDirectory] + '/' + headers[file_remoteFile])">.
Those headers are populated by the AbstractRemoteFileStreamingMessageSource.
new to Spring and could use some help on figuring out how to correctly chain together an sftp outbound gateway with a file outbound gateway. I want to confirm a file has sftp'ed, and then move it to an archive location.
Essentially, I have a directory where files are sent to be sftp'd somewhere else. The file is then supposed to be moved to an Archive directory, after the file has been transferred.
Each code piece works independently, but fails when I attempt to connect the two. I am unable to use the reply channel that I would normally because the reply channel confirms where the file has been saved to remotely, and that .msg is moved to the archive directory.
I suspect that order does not do what I think it does.
Currently, the file moves 90% of the time to the archive directory, without sftping the file.
Is this possible, or am I just barking up the wrong tree? Is there a way to configure the sftp:outbound-gateway downstream, or should I try using a different method?
<!-- START: SFTP files-->
<int-file:inbound-channel-adapter
directory="file:${sftp.repo}"
channel="SFTPchannel"
prevent-duplicates="false"
ignore-hidden="true" />
<int-sftp:outbound-gateway
session-factory="SFTPFactory"
request-channel="SFTPchannel"
order="1"
command="mput"
command-options="-1"
expression="payload"
mode="REPLACE"
use-temporary-file-name="false"
remote-filename-generator="filenameGenerator"
auto-create-directory="false"
remote-directory="${sftp.remote.destination}"/>
<int-file:outbound-gateway
request-channel="SFTPchannel"
order="2"
directory-expression="'${repository.directory}/'+new java.text.SimpleDateFormat('yyyyMMdd').format(new java.util.Date())"
mode="REPLACE"
auto-create-directory="true"
filename-generator="filenameGenerator"
delete-source-files="true"
reply-channel="nullChannel" />
<!-- END: SFTP files-->
See the retry-and-more sample, and particularly the Expression Evaluating Advice Demo therein. It covers your exact use case.
I have a Spring project named 'finman'.
The directory structure
As you can see on the image the folder with properties (named 'config') is on the same level as 'src'. So I need to locate that path using
systemEnvironment['FINMAN_ROOT']
The code fragment from 'spring-mvc.xml' responsible for the resource bundle location:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:cacheSeconds="60"
p:defaultEncoding="UTF-8">
<property name="basenames" value="file:///#{systemEnvironment['FINMAN_ROOT']}/config/messages/app"/>
</bean>
The problem is that I don't know how to set that variable.
Environment variables set in OS:
Windows: https://www.chem.gla.ac.uk/~louis/software/faq/q1.html
Linux: http://www.cyberciti.biz/faq/set-environment-variable-linux/
After it do not forget to restart java (or IDE), as they get environments, when started.
Is there any easy way to get the host name in spring configuration file ? Currently I am using Java code to get the host name and and auto wire the property in the bean . But looking for less coding approach if any !
Thanks
The following will give you the hostname in java
return InetAddress.getLocalHost().getHostName();
where InetAddress belongs to the java.net package. You can add that to your java configuration file. If you want to do it in xml, you can do the following
<bean id="localhostInetAddress"
class="java.net.InetAddress"
factory-method="getLocalHost"/>
<bean id="hostname"
factory-bean="localhostInetAddress"
factory-method="getHostName"/>
When i try to load a property file from the filesystem using util:properties, the property file is not found. I placed it on my root drive and all kinds of places but i seem not to be able to load a property file from the filesystem using util:properties.
Is it possible to do this?
<util:properties id="configProperties" location="file:///d:/config.properties"/>
Loading it from the classpath works ok.. but i want to configure the application so a system admin can change the properties.
<util:properties id="configProperties" location="classpath:/config.properties"/>
I have this in a Linux project and it works fine:
<util:properties id="jdbcConfiguration" location="file:///home/reporting/jdbc.properties"/>
so the problem is probably with the way you specify the path. Try it this way:
<util:properties id="configProperties" location="file:d:/config.properties"/>