Using JASYPT outside camel context - apache-camel

I am trying to decrypt properties using JASYPT in camel blueprint outside camel context like follows.
Is it not possible to use JASYPT + Property Component outside camel context?
I am using servciemix 5.0.0
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<cm:property-placeholder id="prop" persistent-id="mypersistent">
<!-- list some properties for this test -->
<cm:default-properties>
<cm:property name="cool.result" value="ENC(jU1ypXF709gpmOsJ2nKGgTbtd3oAs0n3rUNxEmMp2G8=)"/>
<cm:property name="jms.password" value="ENC(QhKlLI3eMKUhsUSPEWIRFw==)"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="blueprint:prop"/>
<property name="propertiesParser" ref="jasypt"></property>
</bean>
<!-- define the jasypt properties parser with the given password to be used -->
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
<property name="password" value="secret"/>
</bean>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://127.0.0.1:61616" />
<property name="userName" value="smx"/>
<property name="password" value="${jms.password}"/>
</bean>
</property>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- define the camel properties placeholder, and let it leverage jasypt -->
<!--<propertyPlaceholder id="properties"
location="blueprint:prop"
propertiesParserRef="jasypt"/>-->
<route>
<from uri="file://inputfolder"/>
<log message="jms password {{jms.password}}"/>
<setBody><constant>Foo message</constant></setBody>
<to uri="jms:queue:default.inputchannel?jmsMessageType=Text&transferExchange=true"/>
<to uri="{{cool.result}}"/>
</route>
</camelContext>
It is giving me following error
ava.lang.SecurityException: User name [smx] or password is invalid.
at org.apache.activemq.security.JaasAuthenticationBroker.addConnection(JaasAuthenticationBroker.java:80)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:97)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:733)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.jmx.ManagedTransportConnection.processAddConnection(ManagedTransportConnection.java:79)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:292)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:149)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.MutexTransport.onCommand(MutexTransport.java:50)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.WireFormatNegotiator.onCommand(WireFormatNegotiator.java:113)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.AbstractInactivityMonitor.onCommand(AbstractInactivityMonitor.java:270)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:214)[84:org.apache.activemq.activemq-osgi:5.9.0]
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)[84:org.apache.activemq.activemq-osgi:5.9.0]
at java.lang.Thread.run(Thread.java:745)[:1.7.0_60]

You cannot use org.apache.camel.component.jasypt.JasyptPropertiesParser outside Apache Camel, or the <camelContext>.
For <bean> then its the blueprint propertyplaceholder that is responsible for setting up the properties. So you need some way to hook in jasypt into osgi blueprint property placeholder, eg this stuff
<cm:property-placeholder id="prop" persistent-id="mypersistent">

Like Ibsen said, blueprint property placeholder needs to be looked into. Here is a working blueprint solving the above mentioned issue
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<ext:property-placeholder id="prop">
<!-- list some properties for this test -->
<ext:default-properties>
<ext:property name="cool.result" value="ENC(jU1ypXF709gpmOsJ2nKGgTbtd3oAs0n3rUNxEmMp2G8=)"/>
<ext:property name="jms.password" value="ENC(QhKlLI3eMKUhsUSPEWIRFw==)"/>
</ext:default-properties>
</ext:property-placeholder>
<enc:property-placeholder>
<enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config">
<bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
<property name="passwordEnvName" value="CAMEL_ENCRYPTION_PASSWORD" />
</bean>
</property>
</enc:encryptor>
</enc:property-placeholder>
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="blueprint:prop"/>
<property name="propertiesParser" ref="jasypt"></property>
</bean>
<!-- define the jasypt properties parser with the given password to be used -->
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
<property name="password" value="secret"/>
</bean>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://127.0.0.1:61616" />
<property name="userName" value="smx"/>
<property name="password" value="${jms.password}"/>
</bean>
</property>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- define the camel properties placeholder, and let it leverage jasypt -->
<!--<propertyPlaceholder id="properties"
location="blueprint:prop"
propertiesParserRef="jasypt"/>-->
<route>
<from uri="file://inputfolder"/>
<log message="jms password {{jms.password}}"/>
<setBody><constant>Foo message</constant></setBody>
<to uri="jms:queue:default.inputchannel?jmsMessageType=Text&transferExchange=true"/>
<to uri="{{cool.result}}"/>
</route>
</camelContext>
</blueprint>

Related

why CAMEL_MESSAGEPROCESSED created in SQL server db

I want to run Camel built application as stanalone. I am using maven to create standalone jar and execute route.When I run MainApp.java main method from eclipse or run using camel run then code runs as expected. But when I run using java -jar then 3 tables CAMEL_MESSAGEPROCESSED, CAMEL_MESSAGETRACED,hibernate_sequence are created into db. I do not want these tables created. Please help me find what I am doing wrong.
Camel, camel-jpa version 2.19.1
hibernate-entitymanager version 5.2.7.Final
Camel-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:prop="http://camel.apache.org/schema/placeholder"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-4.3.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="properties"
class="org.apache.camel.component.properti
es.PropertiesComponent">
<property name="location" value="classpath:db.properties" />
</bean>
<bean id="bridgePropertyPlaceholder"
class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="location" value="classpath:db.properties" />
</bean>
<camelContext id="camel5" xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="myBuilder" />
</camelContext>
<bean id="myBuilder"
class="com.aexp.gsnt.insight.updateCentralData.InsightRouterBuilder" />
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="transactionManager" ref="jpaTxManager" />
</bean>
<bean id="jpaTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="persistenceUnit" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
<property name="showSql" value="${showSQL}" />
<property name="generateDdl" value="${generateDdl}" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.format_sql">${formatSQL}</prop>
</props>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
</bean>
</beans>
Persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="persistenceUnit"
transaction-type="RESOURCE_LOCAL">
</persistence-unit>
</persistence>
MainApp.java
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
private static ClassPathXmlApplicationContext classPathXmlApplicationContext;
/* Invoked from Jar */
public static void main(String args[]) throws Exception {
System.out.println("Started Central Data Extractor");
System.setProperty("jsse.enableSNIExtension", "false");
classPathXmlApplicationContext = new ClassPathXmlApplicationContext("classpath:/META-INF/spring/camel-context.xml");
classPathXmlApplicationContext.start();
}
}

What is the correct way of setting up Basic Authentication for CXF/HTTP in JBoss Fuse?

I have been trying for quite some time now to set up Basic Authentication for all of my exposed web services but without any luck.
I am using JBoss Fuse 6.2.1 with the Karaf container (karaf-2.4.0.redhat-621117) and I currently have three integrations that are consuming from an equal amount of cxfEndpoints.
What I want to achieve is to prompt the users of said services with an auth-dialog when either calling the services or trying to view the WSDL.
Note that I don't want to use ws-security which places the authentication in the Soap-envelope but rather on http-level.
I have been looking at the following documentation entries:
[1]https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.2.1/html/Security_Guide/CamelJetty-BasicAuth.html
[2]http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html
[3]http://cxf.apache.org/docs/jetty-configuration.html
But I am confused as to which (if any) of these approaches I'm supposed to use.
In fact, none of them has worked for me so far but that might be down to a user error on my behalf.
Below I will show what I have tried (and subsequently failed) to do:
Using a mix of [1] and [3]
blueprint.xml:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cxf-core="http://cxf.apache.org/blueprint/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
xsi:schemaLocation="
http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd
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 http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="loginService" class="org.eclipse.jetty.plus.jaas.JAASLoginService">
<property name="name" value="karaf"/>
<property name="loginModuleName" value="karaf"/>
<property name="roleClassNames">
<list>
<value>org.apache.karaf.jaas.boot.principal.RolePrincipal</value>
</list>
</property>
</bean>
<bean id="identityService" class="org.eclipse.jetty.security.DefaultIdentityService"/>
<bean id="constraint" class="org.eclipse.jetty.util.security.Constraint">
<property name="name" value="BASIC"/>
<property name="roles" value="Administrator"/>
<property name="authenticate" value="true"/>
</bean>
<bean id="constraintMapping" class="org.eclipse.jetty.security.ConstraintMapping">
<property name="constraint" ref="constraint"/>
<property name="pathSpec" value="/*"/>
</bean>
<bean id="securityHandler" class="org.eclipse.jetty.security.ConstraintSecurityHandler">
<property name="authenticator">
<bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/>
</property>
<property name="constraintMappings">
<list>
<ref bean="constraintMapping"/>
</list>
</property>
<property name="loginService" ref="loginService"/>
<property name="strict" value="false"/>
<property name="identityService" ref="identityService"/>
</bean>
<httpj:engine-factory bus="cxf">
<httpj:engine port="8181">
<httpj:handlers>
<ref component-id="securityHandler" />
</httpj:handlers>
</httpj:engine>
</httpj:engine-factory>
</blueprint>
Using [2]
blueprint.xml:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cxf-core="http://cxf.apache.org/blueprint/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
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 http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<http-conf:conduit name="http://localhost:8181/.*" xmlns:sec="http://cxf.apache.org/configuration/security">
<http-conf:authorization>
<sec:UserName>test</sec:UserName>
<sec:Password>test</sec:Password>
<sec:AuthorizationType>BASIC</sec:AuthorizationType>
</http-conf:authorization>
</http-conf:conduit>
</blueprint>
The cxfEndpoint used in both cases
<cxf:cxfEndpoint address="${address}" id="myWs" serviceClass="com.company.test.CxfService">
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD" />
</cxf:properties>
</cxf:cxfEndpoint>
The optimum would be to be able to leverage the JAAS but I would settle for something simpler to start with.
I should add that I'm not getting any errors with any of these, I'm just not being prompted to provide any credentials either when browsing http://localhost:8181/cxf or when calling the services through SoapUI.
I would greatly appreciate if someone could point me in the right direction.
I managed to find a viable solution so I'll post my findings with the hope that someone else will be helped by this at some point.
blueprint.xml:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cxf-core="http://cxf.apache.org/blueprint/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
xsi:schemaLocation="
http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd
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 http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="loginService" class="org.eclipse.jetty.plus.jaas.JAASLoginService">
<property name="name" value="karaf"/>
<property name="loginModuleName" value="karaf"/>
<property name="roleClassNames">
<list>
<value>org.apache.karaf.jaas.boot.principal.RolePrincipal</value>
</list>
</property>
</bean>
<bean id="identityService" class="org.eclipse.jetty.security.DefaultIdentityService"/>
<bean id="constraint" class="org.eclipse.jetty.util.security.Constraint">
<property name="name" value="BASIC"/>
<property name="roles">
<list>
<value>admin</value>
</list>
</property>
<property name="authenticate" value="true"/>
</bean>
<bean id="constraintMapping" class="org.eclipse.jetty.security.ConstraintMapping">
<property name="constraint" ref="constraint"/>
<property name="pathSpec" value="/*"/>
</bean>
<bean id="securityHandler" class="org.eclipse.jetty.security.ConstraintSecurityHandler">
<property name="authenticator">
<bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/>
</property>
<property name="constraintMappings">
<list>
<ref component-id="constraintMapping"/>
</list>
</property>
<property name="loginService" ref="loginService"/>
<property name="strict" value="false"/>
<property name="identityService" ref="identityService"/>
</bean>
<httpj:engine-factory bus="cxf">
<httpj:engine port="8083">
<httpj:handlers>
<ref component-id="securityHandler" />
</httpj:handlers>
</httpj:engine>
</httpj:engine-factory>
<cxf:cxfEndpoint address="http://localhost:8083/MyService" id="myWs" serviceClass="com.company.test.CxfService">
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD" />
</cxf:properties>
</cxf:cxfEndpoint>
...
</blueprint>
It is also necessary to add the following to the pom.xml:
<Import-Package>
javax.security.auth,
javax.security.auth.callback,
javax.security.auth.login,
javax.security.auth.spi,
org.apache.karaf.jaas.modules,
org.apache.karaf.jaas.boot.principal,
org.eclipse.jetty.server,
org.eclipse.jetty.plus.jaas;version=${jetty-version},
org.eclipse.jetty.security;version=${jetty-version},
*
</Import-Package>
org.eclipse.jetty.server is needed for the httpj:engine-factory to work.
It would seem that you're not able to use the default port (8181) if you want to setup Basic Authentication. This solution instead sets up a custom jetty container on port 8083 (you can use a different port, just make sure that your cxfEndpoints are published on the same one.)

How to use Camel to get message from remote WMQ and place message in ActiveMQ?

I have been looking at these for days and still haven't have mush success.
I have install and run activeMQ on a server. Created a queue called "testUpdate". I also have another queue on another server, let call this "forward" and this is on the IBM MQ (WMQ).
So we have testUpdate on ActiveMQ and forward on WMQ. I want the message on forward queue to be placed into testUpdate queue. Trying to use Camel for this process.
So the setup in ActiveMQ has an XML(activemq.xml) that I can place spring beans and configure to do the routing. In this xml, I added http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd to the xmlns and then added
import resource="camel.xml"
In this new xml, I have the following:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<description>Example Camel Route</description>
<from uri="mqseries:forward"/>
<to uri="activemq:testUpdate"/>
</route>
</camelContext>
<bean id="mqseries" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="transportType" value="1"/>
<property name="hostName" value="172.00.12.21/>
<property name="port" value="xyza"/>
<property name="queueManager" value="manager"/>
<property name="channel" value="srvcChannel"/>
</bean>
<!--
Lets configure some Camel endpoints
http://camel.apache.org/components.html
-->
<!-- configure the camel activemq component to use the current broker -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://amq-broker?create=false"/>
<property name="userName" value="${activemq.username}"/>
<property name="password" value="${activemq.password}"/>
</bean>
</property>
</bean>
</beans>
I added the jar file com.ibm.mq.allclient.jar into the lib folder of ActiveMQ. When running the program, I am getting this exception:
java.lang.ClassNotFoundException: javax.jms.JMSRuntimeException
It sounds like I am missing the websphere jar file? Is this correct?
I use both IBM MQ and ActiveMQ on a regular basis. This example below will show you some sample configuration options. Please make sure you configure these to your own use cases.
//ActiveMQ connection factory
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" destroy-method="doStop">
<property name="configuration">
<bean class="org.apache.camel.component.jms.JmsConfiguration">
<property name="concurrentConsumers" value="1" />
<property name="maxConcurrentConsumers" value="1" />
<property name="acceptMessagesWhileStopping" value="true" />
<property name="acknowledgementModeName" value="CLIENT_ACKNOWLEDGE" />
<property name="cacheLevelName" value="CACHE_CONSUMER" />
<property name="connectionFactory">
<bean class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="1" />
<property name="MaximumActiveSessionPerConnection" value="500" />
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${activemq1.brokerUrl}" />
<property name="userName" value="${activemq1.username}" />
<property name="password" value="${activemq1.password}" />
<property name="redeliveryPolicy">
<bean class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="-1" />
</bean>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</property>
</bean>
//IBM MQ connection factory
<bean id="ibmmq" class="org.apache.camel.component.jms.JmsComponent" destroy-method="doStop">
<property name="concurrentConsumers" value="1" />
<property name="maxConcurrentConsumers" value="1" />
<property name="connectionFactory">
<bean class="org.springframework.jms.connection.SingleConnectionFactory" destroy-method="destroy">
<constructor-arg>
<bean class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="transportType" value="1" />
<property name="channel" value="${channel}" />
<property name="hostName" value="${hostname}" />
<property name="port" value="${port}" />
<property name="queueManager" value="${queueManager}" />
</bean>
</constructor-arg>
</bean>
</property>
</bean>
You can use jms component to consume the message from IBM MQ and use activemq component to post it to ActiveMQ
have a look at the following links
http://camel.apache.org/jms.html
http://camel.apache.org/activemq.html
Thanks,
Gibu
You can use users camel extra component https://github.com/camel-extra/camel-extra/blob/master/components/camel-wmq/README.md to get messages from wmq without using the JMS wrapping and then send messages to ActiveMQ with custom camel component https://camel.apache.org/components/latest/activemq-component.html. See also a similar topic Apache Camel with IBM MQ.

Hazelcast Blueprint Camel Karaf

I am new to hazelcast and trying to implement hazelcast using blueprint and karaf.
I am stuck at the first step in creating the instance although it working for me using just spring.
When I run the bundle on karaf, it times out.
Please ignore typo error in bean class name except the hazelcast ones as I changed the name for security purpose.
Here is my bluprint
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:camel="http://camel.apache.org/schema/blueprint" xmlns:hz="http://www.hazelcast.com/schema/spring"
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 http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd
">
<bean id="loaderCacheManager" class="com.LoaderCacheManagerImpl">
<property name="template" ref="producerTemplate" />
</bean>
<bean id="mconStatusMessage" class="com.impl.MCONStatusMessageImpl" />
<bean id="headerLookupResponseAggregator"
class="com.aggregator.HeaderLookupResponseAggregator" />
<bean id="headerLookupRequestProcessor" depends-on="producerTemplate"
class="com.processor.HeaderLookupRequestProcessor">
<property name="loaderCacheManager" ref="loaderCacheManager" />
<property name="assetObjidSQL" value="${lookup.asset_objid}" />
<property name="wlanConfigSQL" value="${lookup.wlan_config}" />
<property name="tlserrWpaEaptlsCodeSQL" value="${lookup.tlserr_wpa_eaptls_code}" />
<property name="currentDateSQL" value="${lookup.CurrentDate}" />
<property name="hdrObjidSQL" value="${lookup.HdrObjid}" />
<property name="deviceIdSQL" value="${device.lookup}" />
</bean>
<bean id="headerLookupResponseProcessor" depends-on="producerTemplate"
class="com.processor.HeaderLookupResponseProcessor">
<property name="loaderCacheManager" ref="loaderCacheManager" />
</bean>
<bean id="mconReferenceLookupProcessor"
class="com.processor.MCONReferenceLookupProcessor">
<property name="mconLookupQuerySQL" value="${MCON_LOOKUP_QUERY}" />
</bean>
<bean id="mconInsertDetailParamProcessor"
class="com.processor.MCONInsertDetailParamProcessor">
<property name="mconInsertQuery" value="${MCON_INSERT_QUERY}" />
</bean>
<bean id="rowCountAggregator"
class="com.aggregator.RowCountAggregator" />
<bean id="headerInsertSQLProcessor"
class="com.eaderInsertSQLProcessor">
<property name="headerInsertSQL" value="${Loader.InsertHeader}" />
</bean>
<bean id="postLoadSQLProcessor"
class="com.ostLoadSQLProcessor">
<property name="updateMCSAssetSQL" value="${PostLoader.updateCMUStatus}" />
</bean>
<bean id="hazelCacheDao" class="com.cache.ResetVehicleInitial" />
<hz:hazelcast id="instance">
<hz:config>
<hz:network port="5701" port-auto-increment="false">
<hz:join>
<hz:multicast enabled="false" />
</hz:join>
</hz:network>
<hz:map name="rmdMap" read-backup-data="true">
<hz:map-store enabled="true" write-delay-seconds="3"
initial-mode="EAGER" implementation="hazelCacheDao" />
</hz:map>
</hz:config>
</hz:hazelcast>
</blueprint>
Below is my referred maploader class. For now I am return null in all the methods for testing purpose.
public class ResetVehicleInitial implements MapLoader<String, String>{
private static final String DIRECT_LOAD_RESET_VEHICLE_INITIAL="direct:loadResetVehicleInitial";
#EndpointInject(uri=DIRECT_LOAD_RESET_VEHICLE_INITIAL)
private ProducerTemplate loadResetVehicleInitial;
#Override
public String load(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public Map<String, String> loadAll(Collection<String> vehicleintial) {
// TODO Auto-generated method stub
System.out.println("hello");
List loadValues = loadResetVehicleInitial.requestBody(DIRECT_LOAD_RESET_VEHICLE_INITIAL, vehicleintial, List.class);
System.out.println(loadValues);
return null;
}
#Override
public Iterable<String> loadAllKeys() {
// TODO Auto-generated method stub
return null;
}
}
After suggestion from Jereme, I modified my xml according to java class:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:camel="http://camel.apache.org/schema/blueprint" xmlns:hz="http://www.hazelcast.com/schema/spring"
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 http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd
">
<bean id="loaderCacheManager" class="com.LoaderCacheManagerImpl">
<property name="template" ref="producerTemplate" />
</bean>
<bean id="mconStatusMessage" class="com.impl.MCONStatusMessageImpl" />
<bean id="headerLookupResponseAggregator"
class="com.aggregator.HeaderLookupResponseAggregator" />
<bean id="headerLookupRequestProcessor" depends-on="producerTemplate"
class="com.processor.HeaderLookupRequestProcessor">
<property name="loaderCacheManager" ref="loaderCacheManager" />
<property name="assetObjidSQL" value="${lookup.asset_objid}" />
<property name="wlanConfigSQL" value="${lookup.wlan_config}" />
<property name="tlserrWpaEaptlsCodeSQL" value="${lookup.tlserr_wpa_eaptls_code}" />
<property name="currentDateSQL" value="${lookup.CurrentDate}" />
<property name="hdrObjidSQL" value="${lookup.HdrObjid}" />
<property name="deviceIdSQL" value="${device.lookup}" />
</bean>
<bean id="headerLookupResponseProcessor" depends-on="producerTemplate"
class="com.processor.HeaderLookupResponseProcessor">
<property name="loaderCacheManager" ref="loaderCacheManager" />
</bean>
<bean id="mconReferenceLookupProcessor"
class="com.processor.MCONReferenceLookupProcessor">
<property name="mconLookupQuerySQL" value="${MCON_LOOKUP_QUERY}" />
</bean>
<bean id="mconInsertDetailParamProcessor"
class="com.processor.MCONInsertDetailParamProcessor">
<property name="mconInsertQuery" value="${MCON_INSERT_QUERY}" />
</bean>
<bean id="rowCountAggregator"
class="com.aggregator.RowCountAggregator" />
<bean id="headerInsertSQLProcessor"
class="com.eaderInsertSQLProcessor">
<property name="headerInsertSQL" value="${Loader.InsertHeader}" />
</bean>
<bean id="postLoadSQLProcessor"
class="com.ostLoadSQLProcessor">
<property name="updateMCSAssetSQL" value="${PostLoader.updateCMUStatus}" />
</bean>
<bean id="hazelCacheDao" class="com.ge.trans.loader.qnx.cache.ResetVehicleInitial"/>
<bean id="instance" class="com.hazelcast.core.Hazelcast"
factory-method="newHazelcastInstance">
<constructor-arg>
<bean class="com.hazelcast.config.Config">
<property name="groupConfig">
<bean class="com.hazelcast.config.GroupConfig">
<property name="name" value="local" />
<property name="password" value="local" />
</bean>
</property>
<property name="networkConfig">
<bean class="com.hazelcast.config.NetworkConfig">
<property name="port" value="7001" />
<property name="portAutoIncrement" value="true" />
<property name="join">
<bean class="com.hazelcast.config.JoinConfig">
<property name="multicastConfig">
<bean class="com.hazelcast.config.MulticastConfig">
<property name="enabled" value="false" />
</bean>
</property>
<property name="tcpIpConfig">
<bean class="com.hazelcast.config.TcpIpConfig">
<property name="enabled" value="true" />
<property name="members" value="3.192.20.22, 3.192.18.110" />
</bean>
</property>
</bean>
</property>
</bean>
</property>
<property name="mapConfigs">
<map>
<entry key="dataSyncDetails">
<bean class="com.hazelcast.config.MapConfig">
<property name="name" value="rmdMap" />
<property name="backupCount" value="2" />
<property name="timeToLiveSeconds" value="0" />
<property name="evictionPolicy" value="LRU" />
<property name="maxIdleSeconds" value="0" />
<property name="evictionPercentage" value="25" />
<property name="maxSizeConfig">
<bean class="com.hazelcast.config.MaxSizeConfig">
<property name="size" value="10000"></property>
<property name="maxSizePolicy" value="USED_HEAP_PERCENTAGE"></property>
</bean>
</property>
<property name="mapStoreConfig">
<bean class="com.hazelcast.config.MapStoreConfig">
<property name="enabled" value="true"></property>
<property name="writeDelaySeconds" value="0"></property>
<property name="implementation" ref="hazelCacheDao" />
<property name="initialLoadMode" value="EAGER"></property>
</bean>
</property>
</bean>
</entry>
</map>
</property>
</bean>
</constructor-arg>
</bean>
</blueprint>
But getting the following error now:
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to validate xml
at org.apache.aries.blueprint.parser.Parser.validate(Parser.java:288)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:317)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:270)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:233)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[11:org.apache.aries.util:1.0.1.redhat-610379]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[11:org.apache.aries.util:1.0.1.redhat-610379]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[11:org.apache.aries.util:1.0.1.redhat-610379]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[11:org.apache.aries.util:1.0.1.redhat-610379]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[11:org.apache.aries.util:1.0.1.redhat-610379]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1103)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4650)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.felix.framework.Felix$4.run(Felix.java:2123)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.felix.framework.Felix.runInContext(Felix.java:2147)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2121)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:474)[22:org.apache.karaf.features.core:2.3.0.redhat-610379]
at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeature(FeaturesServiceImpl.java:404)[22:org.apache.karaf.features.core:2.3.0.redhat-610379]
at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeature(FeaturesServiceImpl.java:400)[22:org.apache.karaf.features.core:2.3.0.redhat-610379]
at org.apache.karaf.features.command.InstallFeatureCommand.doExecute(InstallFeatureCommand.java:62)[26:org.apache.karaf.features.command:2.3.0.redhat-610379]
at org.apache.karaf.features.command.FeaturesCommandSupport.doExecute(FeaturesCommandSupport.java:41)[26:org.apache.karaf.features.command:2.3.0.redhat-610379]
at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)[17:org.apache.karaf.shell.console:2.3.0.redhat-610379]
at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35)[17:org.apache.karaf.shell.console:2.3.0.redhat-610379]
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
at org.apache.karaf.shell.console.jline.Console.run(Console.java:189)[17:org.apache.karaf.shell.console:2.3.0.redhat-610379]
at org.apache.karaf.shell.console.jline.DelayedStarted.run(DelayedStarted.java:61)[17:org.apache.karaf.shell.console:2.3.0.redhat-610379]
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'constructor-arg'. One of '{"http://www.osgi.org/xmlns/blueprint/v1.0.0":description, "http://www.osgi.org/xmlns/blueprint/v1.0.0":argument, "http://www.osgi.org/xmlns/blueprint/v1.0.0":property, WC[##other:"http://www.osgi.org/xmlns/blueprint/v1.0.0"]}' is expected.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)[:]
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)[:]
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[:]
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[:]
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[:]
at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)[:]
at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)[:]
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)[:]
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)[:]
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)[:]
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)[:]
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)[:]
at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)[:]
at javax.xml.validation.Validator.validate(Unknown Source)[:2.3.0.redhat-610379]
at org.apache.aries.blueprint.parser.Parser.validate(Parser.java:285)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
... 34 more
You can't mix "spring namespaces" in a blueprint configuration, at least with the current version of aries (which, apparently, you are using)
You should create an HazelcastInstance in a java class, without the help of the 'hz' namespace.
Moreover :
Gemini blueprint, another implementation of blueprint, support the
use of spring namespace in a blueprint file
Spring DM, (which is now obsolete but still work with spring <= 3..), can either support the use of spring namespace, in a spring configuration in META-INF/spring
I have seen an experimental support of spring namespace in aries blueprint, but i have never tryied it personnally, it's a work-in-progress (i haven't seen any "official communication" about this feature)

ServiceMix + Camel transactional producer

I'm trying to send a messasge into an ActiveMQ queue from a web service which is deployed to ServiceMix 5.4.0. For that reason I obtain a producer template from the camel context and send the message in the following way:
ProducerTemplate template = camelContext.createProducerTemplate();
template.send(
"activemq://ExecutePaymentInputQueue",
new Processor() {
#Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(
...
);
}
}
);
The relevant parts from the blueprint.xml:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://www.osgi.org/xmlns/blueprint-ext/v1.1.0 https://svn.apache.org/repos/asf/aries/tags/blueprint-0.3.1/blueprint-core/src/main/resources/org/apache/aries/blueprint/ext/blueprint-ext.xsd
http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
">
<!-- Transaction manager setup -->
<reference id="jtaTransactionManager" interface="javax.transaction.TransactionManager"/>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<argument ref="jtaTransactionManager"/>
</bean>
<!-- Transaction policy setup -->
<bean id="DefaultTransactionPolicy" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="transactionManager"/>
</bean>
<!-- BEGIN ActiveMQ -->
<bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
<property name="userName" value="smx"/>
<property name="password" value="smx"/>
<property name="redeliveryPolicy">
<bean class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="360"/>
<property name="redeliveryDelay" value="10000"/>
</bean>
</property>
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="activemqConnectionFactory"/>
<property name="concurrentConsumers" value="8"/>
<property name="maxConcurrentConsumers" value="16"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
</bean>
<!-- JMS component setup -->
<!--<reference id="connectionFactory" interface="javax.jms.ConnectionFactory" />-->
<!-- END ActiveMQ -->
<!-- BEGIN SERVICE EXPORTS -->
<service interface="com.bssys.ebpp.core.api.PaymentService" >
<bean class="com.bssys.ebpp.core.services.impl.PaymentServiceImpl">
<tx:transaction method="*" value="Required"/>
</bean>
</service>
<!-- END SERVICE EXPORTS -->
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/blueprint"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint/camel-blueprint-2.13.2.xsd">
...
</camelContext>
</blueprint>
When the message is sent there should be an open JTA transaction (see the declarative aries configuration in blueprint.xml).
The problem is that the producer seems to ignore the jta transaction, and the message is being put to the destination queue outside that transaction (immediately after the send method returns). How can change this behaviour and make the producer join the JTA transaction?

Resources