Am facing the issue while running the application in xml - spring

<?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).

Related

Spring integration - Retry to establish connection on exception scenarios

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

Apache Camel invalid namespace handler

I have an application that has been developed (reworked) on Eclipse. It works fine in the development environment. However when it is loaded into Tomcat it fails with a namespace exception:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [camel-config.xml]
Offending resource: class path resource [spring-config.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [camel-config.xml]; nested exception is
org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class [org.apache.camel.spring.handler.CamelNamespaceHandler] for namespace [http://camel.apache.org/schema/spring]: problem with handler class file or dependent class; nested excep
tion is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
my spring-config and camel-config are below
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<context:component-scan base-package="foo.bar.agent" />
<task:annotation-driven />
<import resource="camel-config.xml" />
</beans>
camel-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- enable Spring #Component scan -->
<context:component-scan base-package="com.altegix.agent.hl7" />
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="ignoreMissingLocation" value="true" />
<property name="locations">
<list>
<value>classpath:default.properties</value>
<value>file:/opt/altegix/agent/application.properties</value>
</list>
</property>
</bean>
<bean id="myhl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
<property name="charset" value="iso-8859-1" />
<property name="validate" value="false" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring"
id="resultsCamelContext">
<contextScan />
<camel:endpoint id="hl7listener"
uri="mina2:tcp://{{results.endpoint.server}}:{{results.endpoint.port}}?sync=true&codec=#myhl7codec" />
</camelContext>
<context:annotation-config />
<bean class="com.altegix.agent.hl7.HL7ListenerConfiguration" />
I don't understand why I would be getting a InvalidNamespace Exception? There is also the noClassDefFoundError which I have not seen before - maybe am I missing some classes that are in Eclipse?

Spring’s cache in Alfresco

I am trying to use the spring's cache in Alfresco, but when I start tomcat I get the following exception:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 14 in XML document from class path resource [alfresco/module/PolmanProject-alfresco-repo/context/service-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 8; cvc-elt.1.a: Cannot find the declaration of element 'beans'.
I have the following module-context:
?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
...
<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
name="cacheService" />
</set>
</property>
</bean>
</beans>
If I remove and the bean cacheManager, then, I don't get the exception.
What is wrong in my context?
You should comment the line
<!-- <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> -->
and replace the tag with
<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:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
And that will solve your issue. However, it's neccesary take into account another details to use the cache. This post explains how to use the cache step by step

Could not convert constructor argument value of type [java.util.ArrayList] to required type [java.util.List]

I have a spring xml file like this named "request-details-upload.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:util="http://www.springframework.org/schema/util"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
">
<import resource="classpath:META-INF/jobs/environment.xml" />
<import resource="classpath:META-INF/jobs/clients.xml" />
<import resource="classpath:META-INF/jobs/edx/request-details.xml" />
<import resource="classpath:META-INF/jobs/dynamoDbClients.xml" />
<bean id="requestDetailsFetchAndDecryptDataDao" class="com.amazon.edx.dao.FetchAndDecryptDataDaoDynamoDbImpl"
c:dataUploadDao-ref="requestDetailsDataUploadDao"
c:dataTransformer-ref="requestDetailsDataTransformer"
/>
<util:list id="requestDetailsKeyItemAttributesMetadata" value-type="com.amazon.edx.manager.ItemAttributesMetaData">
<ref bean="RequestId"/>
<ref bean="RequestDate"/>
</util:list>
<util:list id="requestDetailsNonKeyItemAttributesMetadata" value-type="com.amazon.edx.manager.ItemAttributesMetaData">
<ref bean="CreatedBy"/>
<ref bean="UpdatedTime"/>
</util:list>
<bean id="RequestId" class="com.amazon.edx.manager.ItemAttributesMetaData"
c:itemAttributeName="RequestId"
/>
<bean id="RequestDate" class="com.amazon.edx.manager.ItemAttributesMetaData"
c:itemAttributeName="RequestDate"
/>
<bean id="CreatedBy" class="com.amazon.edx.manager.ItemAttributesMetaData"
c:itemAttributeName="CreatedBy"
/>
<bean id="UpdatedTime" class="com.amazon.edx.manager.ItemAttributesMetaData"
c:itemAttributeName="UpdatedTime"
/>
<!-- upload manager -->
<bean id = "requestDetailsDataUploadManager" class ="com.amazon.edx.manager.DataUploadManagerImpl"
c:fetchAndDecryptDataDao-ref="requestDetailsFetchAndDecryptDataDao"
c:keyAttributes-ref="requestDetailsKeyItemAttributesMetadata"
c:nonKeyAttributes-ref="requestDetailsNonKeyItemAttributesMetadata"
/>
<bean id = "requestDetailsUploadToEdx" class = "com.amazon.edx.UploadDataToEdx"
c:dataUploadManager-ref ="requestDetailsDataUploadManager"
/>
</beans>
and another xml named request-details.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:util="http://www.springframework.org/schema/util"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
">
<bean id="requestDetailsDataUploadDao" class="com.amazon.edx.dao.DataUploadClientImpl"
c:someName="xxxxxxxxxx"
c:otherName="yyyyyyyyy"
/>
<util:list id="requestDetailsColumnMetaData" value-type="com.amazon.edx.transformer.ColumnMetaData">
<ref bean="RequestId"/>
<ref bean="RequestDate"/>
<ref bean="CreatedBy"/>
<ref bean="UpdatedTime"/>
</util:list>
<bean id="RequestId" class="com.amazon.edx.transformer.ColumnMetaData"
c:attributeName="RequestId"
c:dataType="VARCHAR2"
c:columnDisplayName="REQUEST_ID"
/>
<bean id="RequestDate" class="com.amazon.edx.transformer.ColumnMetaData"
c:attributeName="RequestDate"
c:dataType="VARCHAR2"
c:columnDisplayName="REQUEST_DATE"
/>
<bean id="CreatedBy" class="com.amazon.edx.transformer.ColumnMetaData"
c:attributeName="CreatedBy"
c:dataType="VARCHAR2"
c:columnDisplayName="CREATED_BY"
/>
<bean id="UpdatedTime" class="com.amazon.edx.transformer.ColumnMetaData"
c:attributeName="UpdatedTime"
c:dataType="NUMBER"
c:columnDisplayName="UPDATED_TIME"
/>
<bean id="requestDetailsDataTransformer" class="com.amazon.edx.transformer.DataTransformerImpl"
c:dataFlattener-ref="requestDetailsDataFlattener"
c:columnMetadata-ref="requestDetailsColumnMetaData"
c:delimiter="{tabDelimiter}"
/>
<util:constant id="tabDelimiter"
static-field="com.amazon.edx.transformer.Delimiters.TAB_DELIMITER" />
<bean id="requestDetailsDataFlattener" class="com.amazon.edx.flattener.JsonDataFlattenerImpl"
c:multipleRowColumnName=""
/>
</beans>
I am getting the following error:
Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestDetailsDataTransformer' defined in class path resource [META-INF/jobs/edx/request-details.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [java.util.List]: Could not convert constructor argument value of type [java.util.ArrayList] to required type [java.util.List]: Failed to convert value of type 'java.util.ArrayList' to required type 'java.util.List'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.amazon.edx.manager.ItemAttributesMetaData] to required type [com.amazon.edx.transformer.ColumnMetaData]: no matching editors or conversion strategy found
It says cannot convert from java.util.ArrayList to java.util.List. I am not even using java.util.ArrayList. I am new to Spring and not able to understand the exact cause of this error.
Any help is appreciated.
Thanks
Ahh...figured out the issue. There is a conflict in the bean ids present in the lists in both the files. Bean id's should be unique even if they are in different .xml files. There would be a conflict when we import one file into other.
If you use List type dependency, since it is a interface, spring container create an object of its implementation class ArrayList.
For Set type dependency, spring container creates an object of its implementation class LinkedHashSet.
For Map type dependency, spring container creates an object of its implementation class LinkedHashMap.
For Properties type dependency, since it is a class, spring container creates an object of class Properties only.

jaxws:client address property not resolving placeholder

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

Resources