When my FTP mput transfer is successfully complete, I want to rename the file in the local directory. For this, I need to use the local dir path from PropertyPlaceholderConfigurer. But this doesn't seem to be working. Please can you suggest the syntaxt to expand the value of the property? ${local.request.dir} represents a directory path like /home/jainr/REQUEST.
<int-ftp:request-handler-advice-chain>
<bean id="requestFileRename" class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="trapException" value="true" />
<property name="onSuccessExpression" value="T(org.apache.commons.io.FileUtils).moveFile(new java.io.File(#{${local.request.dir}} + '/' + headers['RequestFileName']), new java.io.File(#{${local.request.dir}} + '/' + headers['RequestFileName'] + '.processed'))" />
</bean>
</int-ftp:request-handler-advice-chain>
You need to define the resolved placeholder as a literal, from a SpEL perspective...
new java.io.File('${local.request.dir}/' + headers...
Notice I also removed the #{...} - that is initialization time SpEL - this is runtime SpEL.
In future, instead of statements like...
But this doesn't seem to be working.
...provide the error message and/or stack trace.
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.
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.
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).
I am trying to read a xml file and parse it using Spring MVC, but for some reason it's not finding the file path. I tried different folder, even root, but still cant read or find the file in my project. I'm also using a bean and its not working ether.
<bean class="com.fdm.routePlanner.data.LineDataReader">
<property name="file">
<value>/resources/CompleteTube.xml</value>
</property>
</bean>
and
SAXBuilder saxbuilder = new SAXBuilder();
try {
return generateNetwork( saxbuilder.build(new File(file)) );
} catch (JDOMException e) {
When I try to parse the file using SAXBuilder it gives me a NullPointerException.
In WiX DirectorySearch can be used to determine if a specific directory exists on the target computer. But I don't understand if there's a consistent way to determine that a directory does not exist.
For example:
<Property Id="INSTALLDIR" Secure="yes">
<RegistrySearch Id='InstallDir' Type='directory'
Root='HKLM' Key='Software\Company\Product\Install' Name='InstallPath'/>
</Property>
<Property Id='IS_INSTALLED' Secure='yes'>
<DirectorySearch Id='IsInstalled' Path='[INSTALLDIR]' />
</Property>
When both the registry key and the directory exist, the IS_INSTALLED property is set to the path returned by DirectorySearch.
When the directory does not exist, IS_INSTALLED appears to be set to "C:\".
Is a condition like:
<Condition>NOT (IS_INSTALLED = "C:\")</Condition>
a reliable way to detect that the directory was found? Is there a better way?
Answer: Here is WiX code based on mrnxs answer that I accepted
<Property Id="PRODUCT_IS_INSTALLED" Secure="yes">
<RegistrySearch Id='RegistrySearch1' Type='directory'
Root='HKLM' Key='Software\Company\Product\Version\Install' Name='Path'>
<DirectorySearch Id='DirectorySearch1' Path='[PRODUCT_IS_INSTALLED]'/>
</RegistrySearch>
</Property>
<CustomAction Id='SET_INSTALLDIR'
Property='INSTALLDIR'
Value='[PRODUCT_IS_INSTALLED]'/>
<InstallExecuteSequence>
<Custom Action='SET_INSTALLDIR' After='AppSearch'></Custom>
</InstallExecuteSequence>
Usually this happens when the property is used as a property-based folder. In this case the CostFinalize action automatically sets the property to a valid path (for example "C:\") so the folder can be used by Windows Installer.
Since this path is generated automatically, you cannot be sure that it will be "C:\" on all your client machines, so you shouldn't use this value in your condition. Instead, you can try this:
use a custom property for your folder
use a type 51 custom action (property set with formatted text) to set this property to a valid default path (for example "[ProgramFilesFolder]MyCompany\MyProduct")
use another property for the search
use another type 51 custom action to set the folder property to your search property
For example, if your search is IS_INSTALLED your folder can use IS_INSTALLED_PATH. IS_INSTALLED_PATH can be set to a default path and after AppSearch action you can set it to IS_INSTALLED if the search found something.
This way you can use for conditioning:
IS_INSTALLED
or
NOT IS_INSTALLED
Understaing AppSearch's RegLocator and DrLocator patterns can be a little tricky. I reccomend ignoring the condition for a moment and logging the install to verify that AppSearch is properly setting the properties you want. Fix the problems you find on that end first. When it works the property will be set to the value of the registry or the path to the directory.
Then you should be able to use:
<Condition>IS_INSTALLED/> <!-- it's not important what the value is, just that it exists -->
<Condition>Not IS_INSTALLED/>
Btw, I would avoid using the property INSTALLDIR. In my installers ( InstallShield ) that has special meaning as the main focal point of the installation.
Another approach could be this, in this you can continue the Install Sequence if you want to set the InstallDir to anywhere else, if the SystemDir and RegisteryDir is not same
<Property Id="RegisteryDir" Secure="yes">
<RegistrySearch Id='InstallDir' Type='directory'
Root='HKLM' Key='Software\Company\Product\Install' Name='InstallPath'/>
</Property>
<Property Id='SystemDir' Secure='yes'>
<DirectorySearch Id='IsInstalled' Path='[RegisteryDir]' />
</Property>
<CustomAction Id="SET_INSTALL_DIR" Property="INSTALLDIR" Value="[SystemDir] />
<InstallExecuteSequence>
<Custom Action='SET_INSTALLDIR' After='AppSearch'>
SystemDir AND SystemDir=RegisteryDir
</Custom>
</InstallExecuteSequence>