Apache Camel invalid namespace handler - spring

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?

Related

Spring <context:component-scan base-package="groupid.aop"/> cannot be defined

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 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"
>
<bean id="triangle1" class="groupid.aop.triangle">
<property name="name" value="triangle bean"></property>
</bean>
<bean id="circle1" class="groupid.aop.circle">
<property name="name" value="circle bean"></property>
</bean>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:component-scan base-package="groupid.aop"/>
</beans>
im getting error on <context:component-scan base-package="groupid.aop"/>
this line. im using maven to add dependencies for both spring and aop dependencies. I also added namespace for context. please let me know if im missing anything.
You were wrong in namespaces declaration.
This xml should solve the issue:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
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">
<bean id="triangle1" class="groupid.aop.triangle">
<property name="name" value="triangle bean" />
</bean>
<bean id="circle1" class="groupid.aop.circle">
<property name="name" value="circle bean" />
</bean>
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:component-scan
base-package="groupid.aop" />
</beans>
In your original XML you have:
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
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"
As you can see you declared twice spring-beans (http://www.springframework.org/schema/beans/spring-beans.xsd and http://www.springframework.org/schema/beans/spring-beans-3.0.xsd) and you used the 3.0 context version (http://www.springframework.org/schema/context/spring-context-3.0.xsd)
I hope it's usefull
Angelo

Java Spring batch access command line arguments in XML and Java Annotation config

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']}" />

autowiring spring bean in camel processor

I am building OSGI bundle for running in Jboss Fuse 6.1 container. Project contains blueprint.xml (in src/main/resoureces/OSGI-INF/blueprint). It is content:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"
>
<bean id="MyProcessor" class="com.test.MyProcessor" />
<camelContext trace="false" id="blueprintContext" xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="activemq:queue:paymentsqueue?username=admin&password=admin" id="NotificationRoute">
<description/>
</from>
<log message="The message contains ${body}"/>
<process ref="MyProcessor"/>
</route>
</camelContext>
</blueprint>
My goal is using spring beans in MyProcessor. This is code for MyProcessor:
public class MyProcessor implements Processor {
#Aurowired
private Sender sender;
#Override
public void process(Exchange x) throws Exception {
log.info("test: " +sender.getSenderId());
}
}
But it gives me nullpointerexception. What I am doing wrong?
This is content of my spring configuration file(i placed it in src/main/resoureces/META-INF/spring)
<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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.username"/>
<bean id="sender" class="com.username.Sender" scope="prototype">
<property name="senderId" value="sendername" />
<property name="password" value="senderpassword" />
</bean>
I think you have not declared the Processor MyProcessor as a bean in spring like
<bean id="myProcessor"
class="com.test.MyProcessor" />
then you can use it as
<process ref="myProcessor"/>
Also the
#Aurowired
private Sender sender;
should be #Autowired(This should be a typo but pointed it out.)

Cannot find the declaration of element 'beans' on the bean tag recursively

I am getting below error:
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
my context.xml is as follows
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="no"
xmlns="http://www.springframework.org/schema/beans"
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/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="fileParser" class="com.xxx.xx.xx.oxm.FileInputParser" >
<property name="unmarshaller" ref ="jaxb2Marshaller" />
</bean>
<bean id = "jaxb2Marshaller" class = "org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name = "classesToBeBound">
<array>
<value>com.xxx.xx.xx.oxm.XutoxenPathInfo</value>
</array>
</property>
</bean>
</beans>
Your schemaLocation is not written correctly. The location needs to follow the namespace name.
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-3.1.xsd">
Yours wasn't doing that. It was
beansNS
contextNS
contextLocation
beansLocation

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