My application communicates to a third party system using spring integration. I send a payload for which I get a response that I parse and use. All good. Please find below the SI xml that I use.
Now I want to application retry to establish connection on exception scenarios where the server I'm trying to connect isn't available or on time outs or if it refuses to connect etc.
How can I achieve this using SI xml configuration? Please guide.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
<int:gateway id="gw" service-interface=" com.RxGateway"
default-request-channel="objectOut" />
<int:channel id="objectOut" />
<int-ip:tcp-connection-factory id="client"
type="client" host="10.236.249.xx" port="9103" single-use="false"
so-timeout="50000000" using-nio="false" so-keep-alive="true"
serializer="customDSerializer" deserializer="customDSerializer" />
<bean id="customDSerializer" class="com.CustomSerializerDeserializer">
<property name="maxMessageSize" value="4096" />
</bean>
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="objectOut" reply-channel="toSA" connection-factory="client"
request-timeout="100000" reply-timeout="50000"/>
<int:service-activator input-channel="toSA"
ref="rxService" method="parseResponse"/>
<bean id="rxService" class="com.RxService"/>
<int:channel id="toSA" />
<int:channel id="bytesIn" />
</beans>
You can add a retry-advice into your <int-ip:tcp-outbound-gateway>:
<int-ip:tcp-outbound-gateway>
<int-ip:request-handler-advice-chain>
<int:retry-advice/>
</int-ip:request-handler-advice-chain>
</int-ip:tcp-outbound-gateway>
See more info in the Reference Manual: https://docs.spring.io/spring-integration/docs/current/reference/html/#message-handler-advice-chain
Related
How can I get the command line arguments in a xml configuration file with spring?
With property file I can write this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder location="file:///my.property" />
<bean id="mybean">
<property name="prop1" ref="#{jobParameters['value.from.property']}" />
</bean>
<bean id="mybean2">
<property name="prop1" ref="#{jobParameters['value2.from.property']}" />
</bean>
<bean id="mybean3">
<property name="prop1" ref="#{jobParameters['value3.from.property']}" />
</bean>
<import resource="classpath:/META-INF/spring/module-context.xml" />
</beans>
But how can I explain Spring to get the values from command line arguments instead of property file specified in property-placeholder?
Thanks
To read from property file use
<property name="prop1" value="${value.from.property}" />
To read from Job Parameter use
<property name="prop1" value="#{jobParameters['value.from.jobParameter']}" />
I have xml configuration in my project, what means the code below? because when I run with mvn camel:run. the error show in line 21, in osgix:cm-properties, persistent-id tag. what means the code for? thanks
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:camel="http://cxf.apache.org/transports/camel"
xmlns:osgi="http://camel.apache.org/schema/osgi" xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd
http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium-1.2.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://cxf.apache.org/transports/camel http://cxf.apache.org/transports/camel.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
">
<!-- FOR READ OSGI CONFIGURATION -->
<osgix:cm-properties
id="com.prudential.integration.middleware.crm.services"
persistent-id="com.prudential.integration.middleware.crm.services" />
<ctx:property-placeholder
properties-ref="com.prudential.integration.middleware.crm.services" />
<!-- FOR READ OSGI CONFIGURATION -->
<bean id="crmProcess" class="com.prudential.integration.middleware.crm.services.process.CRMProcess">
<property name="urlNewEmail" value="${urlNewEmail}" />
<property name="reportLoc" value="${reportLoc}" />
<property name="prefixReportName" value="${prefixReportName}" />
<property name="csvDelimiter" value="${csvDelimiter}" />
<property name="crmRequestTimeOut" value="${crmRequestTimeOut}" />
<property name="crmReadTimeOut" value="${crmReadTimeOut}" />
</bean>
<cxf:rsServer id="crmEndPoint" address="/crm"
serviceClass="com.prudential.integration.middleware.crm.services.service.CRMServices" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mongodb
http://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="messageDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="messageQueue1" />
</bean>
<!-- spring integration beans -->
<int:channel id="jmsMessages">
<int:queue capacity="1000" />
</int:channel>
<jms:inbound-channel-adapter id="jmsMsgAdapter"
connection-factory="connectionFactory" destination="messageDestination"
channel="jmsMessages">
<int:poller fixed-rate="500" />
</jms:inbound-channel-adapter>
<mongo:db-factory id="mongoDbFactory" dbname="DeviceTrack"
port="27017" host="localhost" />
<int-mongodb:outbound-channel-adapter
channel="jmsMessages" collection-name="jmsMessage" mongodb-factory="mongoDbFactory" />
</beans>
Error :
Caused by: groovy.lang.MissingMethodException: No signature of method: static ajsc.util.AjscLogMessageService.formatExceptionDetails() is applicable for argument types: (org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException) values: [org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 30 in XML document from URL [file:D:/LucyWorkspace/ExistingDeviceFlow/target/swm/package/nix/dist_files/appl/ExistingDeviceFlow/conf/YOUR_SERVICE/v1/appMessageContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 30; columnNumber: 32; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'int:channel'.]
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1500)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1486)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.callStatic(StaticMetaClassSite.java:65)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:206)
at ajsc.util.AjscLogMessageService.logMessage(AjscLogMessageService.groovy:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
enter code here
when I used without spring integration every thing worked well. When am integrating with Spring I am not able build the xml properly. I think I have done
some xml parsing problems because of some missing xsd.
Can any one help me to resolve the issue...
no declaration can be found for element 'int:channel'
It generally means you don't have the spring-integration-core jar on your classpath; the xsd in in that jar (mapped by /META-INF/spring.schemas).
I have the following mongo db configuration for spring framework:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<mongo:mongo host="127.0.0.1" port="27017" />
<mongo:db-factory id="mongoDbFactory" username="admin" password="abc" dbname="test123"
mongo-ref="mongo" />
<!-- <mongo:db-factory dbname="test123" /> -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
</bean>
However when I start up spring framework it doesn't seems like it is connecting to the test123 database. And it is connecting to the default test database. Anyone has any ideas?
Can you change the xml to following xml.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- Default bean name is 'mongo' -->
<mongo:mongo host="localhost" port="27017" />
<bean id="mongoTemplate"
class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongo" />
<constructor-arg name="databaseName" value="test123" />
</bean>
<!-- To translate any MongoExceptions thrown in #Repository annotated classes -->
<context:annotation-config />
</beans>
Having the strangest problem right now - have a Spring XML file where the address property of the jaxws:client is using a property placeholder for the address attribute but it is refusing to resolve the address attribute.
This is the log file error:
Caused by: java.net.MalformedURLException: no protocol: ${member.service.uri}
at java.net.URL.(URL.java:567) ~[na:1.6.0_33]
at java.net.URL.(URL.java:464) ~[na:1.6.0_33]
at java.net.URL.(URL.java:413) ~[na:1.6.0_33]
at org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:700) ~[cxf-
bundle-2.6.0.jar:2.6.0]
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:474) ~[cxf-
bundle-2.6.0.jar:2.6.0]
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46) ~[cxf-api-2.6.0.jar:2.6.0]
... 43 common frames omitted
Here is the excerpt from my Spring XML file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" \
xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<http:conduit name="https://.*">
<http:tlsClientParameters>
<sec:trustManagers>
<sec:keyStore type="JKS" password="${jkspass}" file="${jkslocation}" />
</sec:trustManagers>
</http:tlsClientParameters>
<http:client AutoRedirect="true" Connection="Keep-Alive" />
</http:conduit>
<!-- Member Service -->
<!--<bean id="memberServiceProxy" class="com.loyalty.tp.ets.common.member.ws.Member"
factory-bean="memberServiceProxyFactory" factory-method="create"/> -->
<jaxws:client id="memberServiceProxy"
serviceClass="com.loyalty.tp.ets.common.member.ws.Member"
address="${member.service.uri}">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:client>
<bean id="memberServiceProxyFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.loyalty.tp.ets.common.member.ws.Member"/>
<property name="address" value="${member.service.uri}"/>
</bean>
<!-- ETS Collector Service -->
<bean id="collectorServiceProxy" class="com.loyalty.tp.ets.collectorservice.Collector"
factory-bean="collectorServiceProxyFactory" factory-method="create"/>
<bean id="collectorServiceProxyFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.loyalty.tp.ets.collectorservice.Collector"/>
<property name="address" value="${ets.collector.service.uri}"/>
</bean>
</beans>
It resolves the ${jksLocation} and ${jkspassword} just fine. What is going on here ?
It seems to be an incompatibility between certain versions of cxf and spring try finding a couple wich work together.
I have camel-cxf:2.12.0.redhat-610379 which bring cxf 2.7.0 and spring 3.2.8.RELEASE and everything is ok