I want to convert my xml config into Java class config but i can't find a solution. For example a piece of my config:
<file:inbound-channel-adapter id="filesIn" directory="file:${java.io.tmpdir}/spring-integration-samples/input"
filename-regex="^.*\.(xml|json)$" >
<int:poller id="poller" fixed-delay="5000"/>
</file:inbound-channel-adapter>
<int:service-activator input-channel="filesIn"
output-channel="filesOut"
ref="handler"/>
<file:outbound-channel-adapter id="filesOut" directory="file:${java.io.tmpdir}/spring-integration-samples/output"
delete-source-files="true"/>
<file:inbound-channel-adapter id="filesContent" directory="file:${java.io.tmpdir}/spring-integration-samples/output"
filename-regex="^.*\.(xml|json)$" prevent-duplicates="true">
<int:poller id="poller2" fixed-delay="5000"/>
</file:inbound-channel-adapter>
How can i made the same thing but with use sftp (src directory) on my local machine and also how to write this config in java class. Give me any suggestion i looking for answer but i can't find the way out.
First of all you should start from the Spring Integration Java DSL Reference Manual. There you will find general concepts of the Java DSL and how that is related to the XML config.
The SFTP Inbound/Outbound Channel Adapter configuration samples you can find in the appropriate Reference Manual Chapter. For example that <int:service-activator> in Java DSL may look like:
.handle(handler)
Where you don't have channel definitions if you declare everything in a single IntegrationFLow.
Related
In my application I would like to re-use the same message transformer inside of multiple <int:chain>.
In such chains I perform http requests to different endpoints and I need to add the same basic authentication header. I would like to declare the code for adding a header only once, i.e:
<int:header-enricher id="authHeaderAdder">
<int:header expression="'Basic ' + new String(T(java.util.Base64).encoder.encode(('${http.user}' + ':' + '${http.password}').bytes))"
name="Authorization"/>
</int:header-enricher>
And then I would like to use it with ref in my chain before making http request:
<int:chain input-channel="someHttpChain">
<int:transformer ref="authHeaderAdder"/>
<http:outbound-gateway.../>
<int:transformer ref="someResponseTransformer"/>
</int:chain>
The problem is that I get an error on application startup:
Configuration problem: The 'input-channel' attribute is required for the top-level endpoint element: 'int:header-enricher' with id='authHeaderAdder'
How can I re-use authHeaderAdder without writing any java code and making a <bean/>?
You definitely need to use an input-channel on that <int:header-enricher>, e.g. input-channel="authChannel" but inside the <chain> you get a gain to use something like <int:gateway request-channel="authChannel"/>. That's all: you are reusing the same transformer, but via the Spring Integration trick with the MessageChannel.
Such an approach is cool the way that you can add more endpoint in that authChannel flow without any changes in the original flow where you use that gateway.
I am trying to use S3 inbound channel adapter to download files from S3. Here is my config:
s3.xml:
<int:chain input-channel="s3ReaderChannel" output-channel="uncompressPayloadChannel">
<int:service-activator ref="s3Bean" method="generateS3ObjectHash" />
<int-aws:s3-inbound-channel-adapter
bucket="${s3.bucket}"
session-factory="s3SessionFactory"
auto-create-local-directory="true"
auto-startup="false"
filename-pattern="*.gz"
local-directory="."
local-filename-generator-expression="#this"
temporary-file-suffix=".transffering"
remote-directory="/remote/mytransfers"
local-filter="acceptAllFilter"/>
</int:chain>
<bean id="s3SessionFactory"
class="org.springframework.integration.aws.support.S3SessionFactory"/>
aws-credentials.xml:
<!-- Define global credentials for all the AWS clients -->
<aws-context:context-credentials>
<aws-context:instance-profile-credentials/>
<aws-context:simple-credentials access-key="${aws.accesskey}"
secret-key="${aws.secretkey}"/>
</aws-context:context-credentials>
<!-- Define global region -->
<aws-context:context-region region="${aws.region}"/>
When I try to execute, I am getting:
Exception in thread "main"`
`org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected
exception parsing XML document from file`; nested exception is
java.lang.IllegalArgumentException: 'beanName' must not be empty
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
...30 more
Caused by: java.lang.IllegalArgumentException: 'beanName' must not be empty
at org.springframework.util.Assert.hasText(Assert.java:181)
at org.springframework.beans.factory.config.RuntimeBeanReference.<init>(RuntimeBeanReference.java:58)
at org.springframework.beans.factory.config.RuntimeBeanReference.<init>(RuntimeBeanReference.java:46)
at org.springframework.beans.factory.support.BeanDefinitionBuilder.addPropertyReference(BeanDefinitionBuilder.java:226)
at org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser.doParse(AbstractPollingInboundChannelAdapterParser.java:64)
...20 more
`
From the stack trace, AbstractPollingInboundChannelAdapterParser.java:64 is about outputChannel, which I dont understand since it is in a chain.
What am I missing here?
Right, Inbound Channel Adapter is the beginning of the flow and it can't be declared in the <chain> at all. More over you have that mess like you declare it after some <int:service-activator>.
You have to move the <int-aws:s3-inbound-channel-adapter> outside of the <chain> and keep in mind that this one is going to be the start of your flow.
I'm not sure what made you think wrong way, but looks like you need more info from the Reference Manual.
When porting from gridgain to ignite, I can't find matching properties for the following in IgniteConfiguration. Have they been totally purged or is there something else we should be using ?
<bean id="abstractGridConfiguration" abstract="true"
class="org.apache.ignite.configuration.IgniteConfiguration">
.......
<!--<property name="restEnabled" value="false"/>-->
<!--<property name="executorServiceShutdown" value="true"/>-->
<!--<property name="systemExecutorServiceShutdown" value="true"/>-->
To disable REST add this:
<property name="connectorConfiguration"><null/></property>
As for the thread pools, in Ignite you can only specify sizes (see IgniteConfiguration.setXxxThreadPoolSize() properties). Thus having shutdown flags doesn't make sense anymore.
Please bear with me as this is my first question. Let me know what I can do to improve future questions.
I am trying to learn Spring Webflow, and am slowly wrapping my head around it. I am finding that there are a lot of conventions that the programmer is expected to "just know", and the examples online don't seem to work.
I have cobbled together one example that works as expected, but now I am trying to extend my understanding to the next level in another small project, with my long term goal being a much more complex application. The goal of this exercise is to build a login system that supports different types of client (phone, desktop, etc) with different webflows.
As near as I can tell, I am having trouble configuring the flow registry, probably because I am misunderstanding the convention.
The textbook example I am emulating is this:
<!-- The registry of executable flow definitions -->
<webflow:flow-registry flow-builder-services="flowBuilderServices"
id="flowRegistry" base-path="/WEB-INF/flows/">
<webflow:flow-location path="/welcome/welcome.xml" />
</webflow:flow-registry>
My configuration is this:
<!-- The registry of executable flow definitions -->
<webflow:flow-registry id="flowRegistry"
flow-builder-services="flowBuilderServices"
base-path="/WEB-INF/pages/">
<webflow:flow-location path="d/login.xml" />
<webflow:flow-location path="d/signup.xml" />
</webflow:flow-registry>
The log states:
DEBUG o.s.w.d.r.FlowDefinitionRegistryImpl - Registering flow definition 'ServletContext resource [/WEB-INF/pages/d/login.xml]' under id 'd'
DEBUG o.s.w.d.r.FlowDefinitionRegistryImpl - Registering flow definition 'ServletContext resource [/WEB-INF/pages/d/signup.xml]' under id 'd'
Since, under the covers, the flow registry is a simple HashMap, only one of the flow files is being registered, and not as what I would expect.
What am I missing?
Change configuration as mentioned below, this might help you:
<webflow:flow-registry id="flowRegistry"
flow-builder-services="flowBuilderServices"
base-path="/WEB-INF/pages">
<webflow:flow-location path="/d/login.xml" />
<webflow:flow-location path="/d/signup.xml" />
</webflow:flow-registry>
also see Spring Webflow - How to Get List of FLOW IDs
My goal is to have some way of declaring my service classes as transactional. I dont want to leave it as an explicit declaration in spring configuration. Many times in past we have created new services and forgot to declare transactions around them. Hence my intention is that if i have something like #TransactionalService custom annotation, it should do the following :-
1. provides transactional support
2. declares some default rules for transactional support as spring currently provides as shown below. But unlike spring, i would like the below to be part of my #TransactionService annotation.
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
Any advice would be valuable?
Sure, instead of creating a new annotation, you could just put your transactionnal services in the same package, and then your pointcut (only one for all you transactionnal services) will look like this :
<aop:config>
<aop:pointcut id="transactionnalServiceMethods" expression="execution(* x.y.transactionnalservice.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionnalServiceMethods"/>
</aop:config>
The advice is the same as above :
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>