I am currently learning to use Apache Camel. To serve my needs I am trying a project I downloaded from the internet but the whole thing seemed to be stuck on an error that I can't debug. It's been a week, I would appreciate if anybody could explain to me what is going wrong or give me a lead in a specific direction. Thank you all.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://${input.dir}?fileName=input-message.csv"/>
<log message="Before SmooksComponent ${body}"/>
<to uri="smooks://smooks-config.xml"/>
<log message="After SmooksComponent ${body}"/>
</route>
</camelContext>
</beans>
private static final String camelConfig = "META-INF/spring/camel-context.xml";
public static void main(String... args) throws Exception
{
CamelContext camelContext = configureAndStartCamel(camelConfig);
// Give Camel time to process the file.
Thread.sleep(3000);
camelContext.stop();
printEndMessage();
}
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://camel.apache.org/schema/spring] Offending resource: class path resource [META-INF/spring/camel-context.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:119)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:111)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1388)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1371)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:179)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:149)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:96)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:511)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:338)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:671)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at org.smooks.examples.camel.csv2xml.Main.configureAndStartCamel(Main.java:87)
at org.smooks.examples.camel.csv2xml.Main.main(Main.java:64)
For anybody who might encounter the situation kindly note the imports were incomplete.
I did not import the camel-spring of course which should be same version as camel-core.
Regards all.
In my current codebase, I have a RestController, and I am using hibernate with it. As of now, I am using the same hibernate configuration which one would usually use
<?xml version="1.0" encoding="UTF-8" ?>
<hibernate-configuration xmlns="http://www.hibernate.org/xsd/orm/cfg">
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>
Also, in my pom.xml, I have added:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
But to get this working I had to add the attribute exclude like this :
#SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
Otherwise, it was throwing some error. Another issue I noticed was even though
hbm2ddl.auto is set to true, which would have created the tables in a simple hibernate application. But it's not happening now. It throws an error if the table is not there but seems to be working fine if it's there.
I changed the MySQL dialect in the hibernate.cfg.xml to :
org.hibernate.dialect.MySQL8Dialect
And now it's automatically creating the table. That's weird when I was using the same hibernate code without spring boot the earlier Dialect was working
This is the main code that starts the application:
#SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class SpringServerMain {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(SpringServerMain.class, args);
}
}
I tried to use EhCache 3.5 caching features in our web application based on Spring Boot 2/Spring Framework 5.
I added EHCache dependency:
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.0.0</version>
</dependency>
Then created ehcache.xml file in src/main/resources folder:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<cache name="orders" maxElementsInMemory="100"
eternal="false" overflowToDisk="false"
memoryStoreEvictionPolicy="LFU" copyOnRead="true"
copyOnWrite="true" />
</ehcache>
Spring 5 reference guide does't mention EHCache usage, Spring 4 reference guide states: "Ehcache 3.x is fully JSR-107 compliant and no dedicated support is required for it."
So I created controller OrderController and REST endpoint:
#Cacheable("orders")
#GetMapping(path = "/{id}")
public Order findById(#PathVariable int id) {
return orderRepository.findById(id);
}
Spring Boot configuration:
#SpringBootApplication
#EnableCaching
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
But when I call this endpoint I get an exception:
Cannot find cache named 'orders' for Builder[public org.Order org.OrderController.findById(int)] caches=[orders] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
Then I tried to use example from Spring Framework 4:
#Bean
public CacheManager cacheManager() {
return new EhCacheCacheManager(ehCacheCacheManager().getObject());
}
#Bean
public EhCacheManagerFactoryBean ehCacheCacheManager() {
EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
cmfb.setShared(true);
return cmfb;
}
But it doesn't compile because of exception:
The type net.sf.ehcache.CacheManager cannot be resolved. It is indirectly referenced from required .class file
Please, advise.
There is a mix of things here. Ehcache 3, which you are using, is used with Spring through JCache.
Which is why you need to use spring.cache.jcache.config=classpath:ehcache.xml.
Then, your Ehcache configuration is indeed an Ehcache 2 configuration. So is the EhCacheCacheManager. For JCache, you should use JCacheCacheManager. But in fact, you don't even need it with an ehcache.xml.
Here are the steps to make it work
Step 1: Set the correct dependencies. Note that you don't need to specify any version as they are provided by the parent pom dependency management. javax.cache is now version 1.1.
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
Step 2: Add an ehcache.xml file in src/main/resources. An example below.
<?xml version="1.0" encoding="UTF-8"?>
<config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.5.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.5.xsd">
<service>
<jsr107:defaults enable-management="false" enable-statistics="true"/>
</service>
<cache alias="value">
<resources>
<heap unit="entries">2000</heap>
</resources>
</cache>
</config>
Step 3: An application.properties with this line is needed to find the ehcache.xml
spring.cache.jcache.config=classpath:ehcache.xml
Note that since JCache is found in the classpath, Spring Cache will pick it as the cache provider. So there's no need to specify spring.cache.type=jcache.
Step 4: Enable caching like you did
#SpringBootApplication
#EnableCaching
public class Cache5Application {
private int value = 0;
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Cache5Application.class, args);
Cache5Application app = context.getBean(Cache5Application.class);
System.out.println(app.value());
System.out.println(app.value());
}
#Cacheable("value")
public int value() {
return value++;
}
}
You need to force it to use ehcache version 2
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.3</version>
</dependency>
To use ehcache 3:
Here is the application:
#SpringBootApplication
#EnableCaching
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Here is the application.yml
spring:
cache:
ehcache:
config: ehcache.xml
Here a service with a counter for testing
#Service
public class OrderService {
public static int counter=0;
#Cacheable("orders")
public Order findById(Long id) {
counter++;
return new Order(id, "desc_" + id);
}
}
Here is a test to prove it is using the cache:
#RunWith(SpringRunner.class)
#SpringBootTest
public class OrderServiceTest {
#Autowired
private OrderService orderService;
#Test
public void getHello() throws Exception {
orderService.findById(1l);
assertEquals(1, OrderService.counter);
orderService.findById(1l);
assertEquals(1, OrderService.counter);
orderService.findById(2l);
assertEquals(2, OrderService.counter);
}
}
See here for working example.
I made additional research. The following configuration isn't picked up by Spring Boot(from application.properties):
spring.cache.ehcache.config=classpath:ehcache.xml
So I created jcache.xml and also put into src/main/resource folder:
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd">
<cache alias="orders">
<key-type>org.springframework.cache.interceptor.SimpleKey</key-type>
<value-type>java.util.Collections$SingletonList</value-type>
<heap unit="entries">200</heap>
</cache>
</config>
Then I changed setting in application.properties to
spring.cache.jcache.config=classpath:jcache.xml
Now Spring Caching works correctly. However it's still a question how to pick up ehcache.xml
Facing the same issue.
My ehcache.xml looks like
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<service>
<jsr107:defaults>
<jsr107:cache name="vehicles" template="heap-cache" />
</jsr107:defaults>
</service>
<cache-template name="heap-cache">
<heap unit="entries">20</heap>
</cache-template>
</config>
Have configured spring.cache.jcache.config=classpath:ehcache.xml in application.properties
Have #EnableCaching on my application class.
Have #CacheResult on my service implementation.
#CacheResult(cacheName = "vehicles") public VehicleDetail
getVehicle(#CacheKey String vehicleId) throws VehicleServiceException
Do NOTE that I do not have a CacheManager bean.
Would be really helpful if someone can point out what am I missing.
hmm.. changing ehcache.xml to, did the trick ..
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<service>
<jsr107:defaults enable-management="true"
enable-statistics="true" />
</service>
<cache alias="vehicles" uses-template="heap-cache" />
<cache-template name="heap-cache">
<heap unit="entries">20</heap>
</cache-template>
</config>
BACKGROUND:
I assembled a "relatively" compact JBossFuse, REST-DSL example (from disparate posts/articles) that routes to an ActiveMQ queue (see working example, further below).
PROBLEM: I want to route to an "IBM MQ" queue, instead.
QUESTION:
What has to change for me to route to "IBM MQ" instead of "ActiveMQ"?
I've tried the following...:
(A) building an IBM MQ "support bundle" and deploying it to Fuse and adding the dep. to the app's pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ibm</groupId>
<artifactId>ibm-mq-lib</artifactId>
<version>9.0.0.0</version>
<description>ibm-mq-lib</description>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>com.ibm.mq.osgi</groupId>
<artifactId>allclient</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/OSGi/com.ibm.mq.osgi.allclient_9.0.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq.osgi</groupId>
<artifactId>allclientprereqs</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/OSGi/com.ibm.mq.osgi.allclientprereqs_9.0.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>allclient</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/com.ibm.mq.allclient.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>traceControl</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/com.ibm.mq.traceControl.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>fscontext</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/fscontext.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>jms</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/jms.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>providerutil</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/providerutil.jar</systemPath>
<scope>system</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Description>description</Bundle-Description>
<Bundle-Vendor>IBM MQ 9.0.0.0</Bundle-Vendor>
<Import-Package></Import-Package>
<Export-Package>*</Export-Package>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<name>ibm-mq-lib</name>
</project>
(B) modified the "camel-route.xml" file (added the following)
...
<bean id="connectionFactory"
class="com.ibm.mq.jms.MQConnectionFactory">
<property name="transportType" value="1"/>
<property name="hostName" value="localhost"/>
<property name="port" value="1414"/>
<property name="queueManager" value="QM1"/>
<property name="channel" value="DEV.APP.SVRCONN" />
</bean>
<bean id="ibmMqConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="ibmMq"
class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="ibmMqConfig"/>
</bean>
</blueprint>
(C) modified "CamelRestRoutes.java" file to point to the IBM MQ queue (instead of the ActiveMQ queue)...
...
from("direct:thingZ")
.log("---------------------- (CCC) ----------------------> direct:thingZ...:" + body().toString())
.to("ibmMq:queue:bubblegum?jmsMessageType=Text&exchangePattern=InOnly");
Call the "getAll" method in the REST service results in an exception with the following log/exception output
...
WorkQueueMananger Contents
--------------------------
| Maintain ThreadPool size :- false
| Maximum ThreadPool size :- -1
| ThreadPool inactive timeout :- 0
| unavailable - :- com.ibm.msg.client.commonservices.CSIException: JMSCS0002
Runtime properties
------------------
| Available processors :- 4
| Free memory in bytes (now) :- 737153288
| Max memory in bytes :- 954728448
| Total memory in bytes (now) :- 875036672
Component Manager Contents
--------------------------
Common Services Components:
Messaging Provider Components:
| CMVC :- p900-L160512.4
| Class Name :- class com.ibm.msg.client.wmq.factories.WMQComponent
| Component Name :- com.ibm.msg.client.wmq
| Component Title :- IBM MQ JMS Provider
| Factory Class :- class com.ibm.msg.client.wmq.factories.WMQFactoryFactory
| Jar location :- bundle://530.0:1/com/ibm/msg/client/wmq/factories/WMQComponent.class
| Version :- 9.0.0.0
Provider Specific Information
-----------------------------
Overview of JMS System
Num. Contexts : 0
Num. Connections : 0
Num. Sessions : 0
Num. Consumers : 0
Num. Producers : 0
Detailed JMS System Information
Contexts :
Connections :
Sessions :
Consumers :
Producers :
2017-08-08 09:44:57,407 | ERROR | estlet-672518929 | DefaultErrorHandler | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Failed delivery for (MessageId: ID-AAXA22A747-53217-1502199741603-0-3 on ExchangeId: ID-AAXA22A747-53217-1502199741603-0-2). Exhausted after delivery attempt: 1 caught: org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: null; nested exception is com.ibm.mq.MQException: JMSCMQ0001: JMSCMQ0001, 2, MQCC_FAILED, 2195, MQRC_UNEXPECTED_ERROR
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[route1 ] [route1 ] [http://localhost:8182/service/getAll?restletMethods=GET ] [ 4126]
[route1 ] [restBinding1 ] [ ] [ 4]
[route1 ] [route1 ] [direct:thingX ] [ 4119]
[route2 ] [to1 ] [bean:camelRestService?method=getAll ] [ 7]
[route2 ] [log1 ] [log ] [ 1]
[route2 ] [to2 ] [direct:thingY ] [ 4110]
[route3 ] [log2 ] [log ] [ 1]
[route3 ] [to3 ] [direct:thingZ ] [ 4109]
[route4 ] [log3 ] [log ] [ 0]
[route4 ] [to4 ] [ibmMq:queue:mylocalqueue?jmsMessageType=Text&exchangePattern=InOnly ] [ 4109]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: null; nested exception is com.ibm.mq.MQException: JMSCMQ0001: JMSCMQ0001, 2, MQCC_FAILED, 2195, MQRC_UNEXPECTED_ERROR
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:452)[244:org.apache.camel.camel-jms:2.17.0.redhat-630187]
at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:414)[244:org.apache.camel.camel-jms:2.17.0.redhat-630187]
at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:368)[244:org.apache.camel.camel-jms:2.17.0.redhat-630187]
at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:154)[244:org.apache.camel.camel-jms:2.17.0.redhat-630187]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:91)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.component.restlet.RestletConsumer$1.handle(RestletConsumer.java:68)[304:org.apache.camel.camel-restlet:2.17.0.redhat-630187]
at org.apache.camel.component.restlet.MethodBasedRouter.handle(MethodBasedRouter.java:54)[304:org.apache.camel.camel-restlet:2.17.0.redhat-630187]
at org.restlet.routing.Filter.doHandle(Filter.java:150)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.handle(Filter.java:197)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Router.doHandle(Router.java:422)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Router.handle(Router.java:639)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.doHandle(Filter.java:150)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.handle(Filter.java:197)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Router.doHandle(Router.java:422)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Router.handle(Router.java:639)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.doHandle(Filter.java:150)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:140)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.handle(Filter.java:197)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.doHandle(Filter.java:150)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.handle(Filter.java:197)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.Component.handle(Component.java:408)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.Server.handle(Server.java:507)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.connector.ServerHelper.handle(ServerHelper.java:63)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:143)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.connector.HttpServerHelper$1.handle(HttpServerHelper.java:64)[303:org.restlet:2.3.6.v20160126-1627]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)[:1.8.0_131]
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)[:1.8.0_131]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)[:1.8.0_131]
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)[:1.8.0_131]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)[:1.8.0_131]
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)[:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_131]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]
Caused by: com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: null
at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:595)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:215)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:422)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:8475)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:7814)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl._createConnection(JmsConnectionFactoryImpl.java:299)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:236)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6024)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jms.MQConnectionFactory.createConnection(MQConnectionFactory.java:6049)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:456)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
... 67 more
Caused by: com.ibm.mq.MQException: JMSCMQ0001: JMSCMQ0001, 2, MQCC_FAILED, 2195, MQRC_UNEXPECTED_ERROR
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
... 76 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2195;AMQ9204: Connection to host 'localhost(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2195],3=localhost(1414),5=JmqiDefaultThreadPool.enqueue]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:2280)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1285)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:355)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
... 75 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2195
at com.ibm.mq.jmqi.JmqiDefaultThreadPool.enqueue(JmqiDefaultThreadPool.java:97)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.setUpAsyncMode(RemoteConnection.java:1979)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.initSess(RemoteConnection.java:1741)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:863)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:409)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:305)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:146)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1721)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
... 77 more
Caused by: com.ibm.msg.client.commonservices.CSIException: JMSCS0002
at com.ibm.msg.client.commonservices.workqueue.PIWorkQueueManager.enqueueItem(PIWorkQueueManager.java:55)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.commonservices.workqueue.WorkQueueManager.enqueue(WorkQueueManager.java:232)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.commonservices.workqueue.WorkQueueManager.enqueue(WorkQueueManager.java:200)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.JmqiDefaultThreadPool.enqueue(JmqiDefaultThreadPool.java:79)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
... 84 more
2017-08-08 09:44:57,429 | INFO | estlet-672518929 | LogService | 303 - org.restlet - 2.3.6.v20160126-1627 | 2017-08-08 09:44:57 0:0:0:0:0:0:0:1 - - 8182 GET /service/getAll/ - 500 8856 0 4140 http://localhost:8182 Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0 -
For comparison/context, BELOW, is the working project that routes to an ActiveMQ queue...
Here is the project structure
aaa.bbb.ccc.CamelRestService.java
package aaa.bbb.ccc;
import aaa.bbb.ccc.model.CamelRestPojo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
#Path("/service/")
public class CamelRestService {
Map<Long, CamelRestPojo> itemMap = new HashMap<>();
public CamelRestService() {
init();
}
#GET
#Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
#Path("/getAll/")
public Collection<CamelRestPojo> getAll() {
return itemMap.values();
}
final void init() {
CamelRestPojo o = new CamelRestPojo();
o.setName("JOE BLOW");
o.setId(100);
itemMap.put(o.getId(), o);
}
}
aaa.bbb.ccc.CamelRestRoute.java
package aaa.bbb.ccc;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
public class CamelRestRoutes extends RouteBuilder {
public CamelRestRoutes() {
}
#Override
public void configure() throws Exception {
restConfiguration().component("restlet")
.host("localhost")
.port(8182)
.bindingMode(RestBindingMode.json_xml);
rest("/service")
.bindingMode(RestBindingMode.json_xml)
.get("/getAll")
.produces("application/json")
.to("direct:thingX");
from("direct:thingX")
.to("bean:camelRestService?method=getAll")
.log("---------------------- (AAA) ----------------------> direct:thingX...:" + body().toString())
.to("direct:thingY");
from("direct:thingY")
.log("---------------------- (BBB) ----------------------> direct:thingY...:" + body().toString())
.to("direct:thingZ");
from("direct:thingZ")
.log("---------------------- (CCC) ----------------------> direct:thingZ...:" + body().toString())
.to("activemq:queue:bubblegum?jmsMessageType=Text&exchangePattern=InOnly");
}
}
aaa.bbb.ccc.model.CamelRestPojo.java
package aaa.bbb.ccc.model;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "camelRestPojo")
public class CamelRestPojo implements Serializable {
#XmlElement
private long id;
#XmlElement
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Override
public String toString() {
return "CamelRestPojo{" + "id=" + id + ", name=" + name + '}';
}
}
camel-route.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.0.0"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.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
">
<camel:camelContext id="aaa.bbb.ccc.routing.poc" xmlns="http://camel.apache.org/schema/blueprint">
<packageScan>
<package>aaa.bbb.ccc</package>
</packageScan>
</camel:camelContext>
<bean id="camelRestService" class="aaa.bbb.ccc.CamelRestService"/>
<bean id = "activemq" class = "org.apache.activemq.camel.component.ActiveMQComponent">
<property name = "brokerURL" value = "tcp://localhost:61616"/>
<property name = "userName" value = "admin"/>
<property name = "password" value = "admin"/>
</bean>
</blueprint>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa.bbb.ccc</groupId>
<artifactId>camelRest</artifactId>
<version>1</version>
<packaging>bundle</packaging>
<name>camelRest</name>
<description>camelRest</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.11.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Export-Package>aaa.bbb.ccc*</Export-Package>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
test url/return value
URL:
http://localhost:8182/service/getAll/
RETURNS:
[{"id": 100,"name": "JOE BLOW"}]
Environment
IBM MQ server 9.0.3.0
IBM MQ client 8.0.0.7
jdk1.8.0_131
jboss-fuse-6.3.0.redhat-187
I've worked on a few Fuse/W-MQ integration exercises. Bundling the W-MQ client drivers into your application probably won't work on Fuse. You need to install the W-MQ client JARs into the Fuse run-time. IBM provides OSGi-compliant versions for that purpose.
My recollection is that there are nine in total, but not all are needed in all configurations. You can install them using osgi:install at the Karaf prompt, or just dump them in the deploy/ directory for testing purposes. Some configuration changes might need to be made in Fuse -- these depend on the specific version combination.
Your connection factory configuration looks broadly correct.
The "allcient" jars contain all of the other client bundles that Kevin was mentioning.
I'm a bit puzzled by what I am seeing, however. I downloaded the IBM MQ 9.0.3 client jars, and there is only the "com.ibm.mq.allclient.jar" in the zip.
For MQ 8, you would have the "com.ibm.mq.osgi.allclient.jar" and "com.ibm.mq.osgi.allclientprereqs.jar" bundles. The problem there is that the prereq bundle included the javax.jms interfaces. You would have to modify the prereq bundle to remove the JMS api jar in order to use it on Fuse. I do not know if this is still the case for MQ 9.
Specifically for Fuse 6.3:
My recollection is that Fuse 6.3 is tested against the client runtime for W-MQ 8, without needing modifications in Fuse. I can't remember whether that was with the individual 8-9 IBM bundles, or with the "allclient" bundle that Doug mentions. In any event, you need to avoid getting into a situation where you have a JMS 2.0 API JAR (that is, the bundle that includes the javax.jms.xxx classes) from both W-MQ and from Fuse -- they will clash. So if you install xxx_allclient.jar, you either need to not install xxx_allclientprereqs.jar, or uninstall the Fuse jms-api bundle from the Fuse runtime. If you go the route of using the heap of 8 or 9 bundles, you should install them all except one called something like xxx_jms.prereq_xxx.jar.
You can install using osgi:install or, for development, just copy them into the deploy/ directory on Fuse. In Fabric8 you'll need eventually to put the IBM JARs into some sort of repository and then create a profile that references them; but testing without Fabric8 in the first instance is probably worthwhile, to remove that additional source of complexity.
I haven't unpacked the W-MQ 9 allclient.jar, so I don't know what's inside it. If it contains javax.jms.xxx classes, either directly or in another internal JAR, then I guess you'll either need to unpack and repack the JAR without these classes, or uninstall the Fuse jms-api bundle.
In any event, Fuse 6.3 with W-MQ 8 client runtime is a good combination, and probably the easiest Fuse/W-MQ combination to get working. You don't necessarily have to use the W-MQ client runtime whose version that matches the W-MQ broker version, if a different client is easier to install on Fuse. However, you should check IBM's compatibility statement before going this way. My recollection is that the W-MQ 8 client runtime is certified by IBM to work with any 7.5.x broker, but I'm not sure whether compatibility works in the opposite direction.
FWIW my recommendation is that you shouldn't be afraid to use a bit of trial-and-error. I've been working with Fuse and W-MQ for a couple of years, and I still find I have to fiddle. Exceptions will help with troubleshooting.
(Posted solution on behalf of the question author, to move it to the answer space).
Thanks to help/postings from generous forum contributors, below, I arrived at a working solution, below.
I included relatively full code/context, i.e., to enable others to arrive at the solution more quickly than I did.
aaa.bbb.ccc.CamelRestRoutes.java
package aaa.bbb.ccc;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
public class CamelRestRoutes extends RouteBuilder {
public CamelRestRoutes() {
}
#Override
public void configure() throws Exception {
restConfiguration().component("restlet")
.host("localhost")
.port(8182)
//.bindingMode(RestBindingMode.json_xml);
.bindingMode(RestBindingMode.json);
rest("/service")
//.bindingMode(RestBindingMode.json_xml)
.bindingMode(RestBindingMode.json)
.get("/getAll")
.produces("application/json")
.to("direct:thingX");
from("direct:thingX")
.to("bean:camelRestService?method=getAll")
.log("---------------------- (AAA) ----------------------> direct:thingX...:" + body().toString())
.to("direct:thingY");
from("direct:thingY")
.log("---------------------- (BBB) ----------------------> direct:thingY...:" + body().toString())
.to("direct:thingZ");
from("direct:thingZ")
.log("---------------------- (CCC) ----------------------> direct:thingZ...:" + body().toString())
.to("wmq:queue:mylocalqueue?jmsMessageType=Text&exchangePattern=InOnly");
}
}
aaa.bbb.ccc.CamelRestService.java
package aaa.bbb.ccc;
import aaa.bbb.ccc.model.CamelRestPojo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
#Path("/service/")
public class CamelRestService {
Map<Long, CamelRestPojo> itemMap = new HashMap<>();
public CamelRestService() {
init();
}
#GET
//#Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
#Produces({MediaType.APPLICATION_JSON})
#Path("/getAll/")
public Collection<CamelRestPojo> getAll() {
System.out.println("====================== (getAll) ---------------------->");
return itemMap.values();
}
final void init() {
System.out.println("---------------------- (init) ---------------------->");
CamelRestPojo o = new CamelRestPojo();
o.setName("JOE BLOW");
o.setId(100);
itemMap.put(o.getId(), o);
}
}
aaa.bbb.ccc.model.CamelRestPojo
package aaa.bbb.ccc.model;
import java.io.Serializable;
public class CamelRestPojo implements Serializable {
private long id;
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Override
public String toString() {
return "CamelRestPojo{" + "id=" + id + ", name=" + name + '}';
}
}
camel-route.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.0.0"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.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
">
<camel:camelContext id="aaa.bbb.ccc.routing.poc" xmlns="http://camel.apache.org/schema/blueprint">
<packageScan>
<package>aaa.bbb.ccc</package>
</packageScan>
</camel:camelContext>
<bean id="camelRestService" class="aaa.bbb.ccc.CamelRestService"/>
<bean id="wmqcf" class="com.ibm.mq.jms.MQConnectionFactory">
<property name="hostName" value="localhost"/>
<property name="port" value="1414"/>
<property name="queueManager" value="QM1"/>
<property name="channel" value="DEV.ADMIN.SVRCONN"/>
<property name="transportType" value="1"/>
</bean>
<bean id="wmqcfw" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="wmqcf" />
<property name="username" value="admin" />
<property name="password" value="passw0rd" />
</bean>
<bean id="wmqcfg" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="wmqcfw"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="wmq" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="wmqcfg"/>
</bean>
</blueprint>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa.bbb.ccc</groupId>
<artifactId>camelRest</artifactId>
<version>1</version>
<packaging>bundle</packaging>
<name>camelRest</name>
<description>camelRest</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
<mq.version>8.0.0.7</mq.version>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>allclient</artifactId>
<version>${mq.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>jms</artifactId>
<version>${mq.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Export-Package>aaa.bbb.ccc*</Export-Package>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
here is the contents of the jboss fuse "deploy" folder
C:\tools\jboss-fuse-6.3.0.redhat-187\deploy>dir
Volume in drive C is OSDisk
Volume Serial Number is D89B-75DE
Directory of C:\tools\jboss-fuse-6.3.0.redhat-187\deploy
08/17/2017 01:49 PM <DIR> .
08/17/2017 01:49 PM <DIR> ..
08/17/2017 01:49 PM 7,975 camelRest-1.jar
06/29/2017 01:00 AM 159,649 com.ibm.mq.osgi.allclientprereqs_8.0.0.7.jar
06/29/2017 01:00 AM 8,011,749 com.ibm.mq.osgi.allclient_8.0.0.7.jar
06/29/2017 01:00 AM 4,088,715 com.ibm.mq.osgi.java_8.0.0.7.jar
06/29/2017 01:00 AM 171,064 com.ibm.msg.client.osgi.commonservices.j2se_8.0.0.7.jar
06/29/2017 01:00 AM 48,715 com.ibm.msg.client.osgi.jms.prereq_8.0.0.7.jar.DISABLE
06/29/2017 01:00 AM 639,807 com.ibm.msg.client.osgi.jms_8.0.0.7.jar
06/29/2017 01:00 AM 216,218 com.ibm.msg.client.osgi.nls_8.0.0.7.jar
06/29/2017 01:00 AM 279,861 com.ibm.msg.client.osgi.wmq.nls_8.0.0.7.jar
06/29/2017 01:00 AM 92,406 com.ibm.msg.client.osgi.wmq.prereq_8.0.0.7.jar
06/29/2017 01:00 AM 7,963,226 com.ibm.msg.client.osgi.wmq_8.0.0.7.jar
09/15/2016 04:19 AM 873 README
12 File(s) 21,680,258 bytes
2 Dir(s) 143,871,660,032 bytes free
C:\tools\jboss-fuse-6.3.0.redhat-187\deploy>
Other notes
For what it is worth, I had add following features:
-camel-jackson
-camel-restlet
(I'm sure your "mileage will vary" as you tinker to make your IBM MQ app work, etc).
Also, fwiw, running:
features:list | grep "jms"
yields:
JBossFuse:karaf#root> features:list | grep "jms"
[installed ] [2.4.0.redhat-630187 ] jms karaf-enterprise-2.4.0.redhat-630187 JMS service and commands
[installed ] [2.17.0.redhat-630187 ] camel-jms camel-2.17.0.redhat-630187
[uninstalled] [2.17.0.redhat-630187 ] camel-sjms camel-2.17.0.redhat-630187
[uninstalled] [3.1.5.redhat-630187 ] cxf-transports-jms cxf-3.1.5.redhat-630187
[uninstalled] [2.1.0.redhat-630187 ] switchyard-jms switchyard-2.1.0.redhat-630187
[uninstalled] [2.1.0.redhat-630187 ] switchyard-quickstart-bpel-jms-binding switchyard-2.1.0.redhat-630187
[uninstalled] [2.1.0.redhat-630187 ] switchyard-quickstart-camel-jms-binding switchyard-2.1.0.redhat-630187
[uninstalled] [2.1.0.redhat-630187 ] switchyard-demo-security-propagation-jms switchyard-2.1.0.redhat-630187
[uninstalled] [1.1 ] jms-spec activemq-core-5.11.0.redhat-630187 JMS spec 1.1 libraries
[installed ] [2.0 ] jms-spec activemq-core-5.11.0.redhat-630187 JMS spec 2.0 libraries
[uninstalled] [1.1 ] jms-spec-dep activemq-core-5.11.0.redhat-630187 JMS spec 1.1 dependency
[installed ] [2.0 ] jms-spec-dep activemq-core-5.11.0.redhat-630187 JMS spec 2.0 dependency
[uninstalled] [5.11.0.redhat-630187 ] activemq-jms-spec-dep activemq-core-5.11.0.redhat-630187 ActiveMQ broker libraries
[installed ] [3.2.16.RELEASE_1 ] spring-jms spring-2.4.0.redhat-630187 Spring 3.2.x JMS support
I am developing springboot-springsession-jdbc-demo. When I simply run the code I get the following error. It looks to me some property must need to set in application.properties in order create the schema/tables before hand. Required configuration is already in placed and still it gives error. The code is present in https://github.com/sivaprasadreddy/spring-session-samples
The error for reference:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM SPRING_SESSION WHERE LAST_ACCESS_TIME < ?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.spring_session' doesn't exist
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:649) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:870) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:931) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:941) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.session.jdbc.JdbcOperationsSessionRepository$6.doInTransaction(JdbcOperationsSessionRepository.java:481) ~[spring-session-1.2.1.RELEASE.jar:na]
at org.springframework.session.jdbc.JdbcOperationsSessionRepository$6.doInTransaction(JdbcOperationsSessionRepository.java:478) ~[spring-session-1.2.1.RELEASE.jar:na]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.session.jdbc.JdbcOperationsSessionRepository.cleanUpExpiredSessions(JdbcOperationsSessionRepository.java:478) ~[spring-session-1.2.1.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_45]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_45]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_45]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_45]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.spring_session' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_45]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_45]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_45]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:877) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:870) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633) ~[spring-jdbc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 21 common frames omitted
pom.xml
<!-- Parent pom providing dependency and plugin management for applications
built with Maven -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- Spring Boot Starter Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring Boot Starter JDBC -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- Spring Boot Starter Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Starter Thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Spring Session -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<!-- Spring Boot devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- H2 DB -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
</project>
Application.java
#SpringBootApplication
#EnableJdbcHttpSession
#EnableAutoConfiguration
public class Application{
public static void main(String[] args){
SpringApplication.run(Application.class, args);
}
}
HomeController.java
#Controller
public class HomeController {
private static final AtomicInteger UserId = new AtomicInteger(0);
#RequestMapping("/")
public String home(Model model){
return "index";
}
#RequestMapping("/add-simple-attrs")
public String handleSimpleSessionAttributes(HttpServletRequest req, HttpServletResponse resp){
String attributeName = req.getParameter("attributeName");
String attributeValue = req.getParameter("attributeValue");
req.getSession().setAttribute(attributeName, attributeValue);
User user = new User();
user.setName(attributeValue);
req.getSession().setAttribute(attributeName, user);
return "redirect:/";
}
#RequestMapping("/add-object-attrs")
public String handleObjectSessionAttributes(HttpServletRequest req, HttpServletResponse resp){
String name = req.getParameter("name");
User user = new User();
user.setId(UserId.incrementAndGet());
user.setName(name);
req.getSession().setAttribute("USER_ID_"+user.getId(), user);
return "redirect:/";
}
}
User.java
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String name;
public User(){
}
public User(Integer id, String name){
this.id = id;
this.name = name;
}
#Override
public String toString() {
return "User [id=" + id + ", name=" + name + "]";
}
public Integer getId(){
return id;
}
public void setId(Integer id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
application.properties
logging.level.org.springframework=INFO
################### DataSource Configuration ##########################
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.initialize=true
#spring.datasource.data=classpath:org/springframework/session/jdbc/schema-h2.sql
spring.datasource.data=classpath:org/springframework/session/jdbc/schema-mysql.sql
spring.datasource.continue-on-error=true
spring.jpa.hibernate.ddl-auto=create
#spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8"/>
<title>Home</title>
</head>
<body>
<h2 th:text="#{app.title}">App Title</h2>
<h4>Add Simple Attributes To Session</h4>
<form class="form-inline" role="form" action="add-simple-attrs" method="post">
<label for="attributeName">Attribute Name</label>
<input id="attributeName" type="text" name="attributeName"/>
<label for="attributeValue">Attribute Value</label>
<input id="attributeValue" type="text" name="attributeValue"/>
<input type="submit" value="Set Attribute"/>
</form>
<h4>Add Object Attributes To Session</h4>
<form class="form-inline" role="form" action="add-object-attrs" method="post">
<label for="name">User Name</label>
<input id="name" type="text" name="name"/>
<input type="submit" value="Save"/>
</form>
<h3>Session Attributes</h3>
<table>
<thead>
<tr>
<th>Attribute Name</th>
<th>Attribute Value</th>
</tr>
</thead>
<tbody>
<tr th:each="attr : ${session}">
<td th:text="${attr.key}">Name</td>
<td th:text="${attr.value}">Value</td>
</tr>
</tbody>
</table>
</body>
</html>
I've just had a quite similar error while using spring-boot 2.0.5 (as opposed to 1.4.0 used by OP) with Postgres driver:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM spring_sessions WHERE EXPIRY_TIME < ?]; nested exception is org.postgresql.u
til.PSQLException: ERROR: relation "spring_sessions" does not exist
Position: 13
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:234) ~[spring-jdbc-5.0.8.RELEASE.jar!/:5.0.8.RELEA
SE]
// redacted...
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
Caused by: org.postgresql.util.PSQLException: ERROR: relation "spring_sessions" does not exist
Position: 13
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433) ~[postgresql-42.2.2.jar!/:42.2.2]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2178) ~[postgresql-42.2.2.jar!/:42.2.2]
// redacted...
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605) ~[spring-jdbc-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
... 16 common frames omitted
According to documentation, setting up Spring Session backed by a relational database is as simple as adding a single configuration property to your application.properties:
spring.session.store-type=jdbc
Note that in order to get the session tables auto-created, I had to also specify:
spring.session.jdbc.initialize-schema=always
Once this setting specified, Spring used the correct SQL initialization script from spring-session-jdbc jar. My mistake was not specifying that option - in which case embedded was being used as default value.
I'm not sure this is the best solution (or even the solution as i'm new to spring and am not aware of the repercussions of doing this) but I was having the same issue, managed to solve it by deleting the annotation #EnableJdbcHttpSession
According to Vedran Pavic:
The reason spring.session.* do not work for you is because your are
using #EnableJdbcHttpSession. That means that you are configuring
Spring Session explicitly, so Spring Boot backs off with its
auto-configuration.
You should remove #EnableJdbcHttpSession and ensure Spring Boot is
auto-configuring Spring Session. Additionally, you could also leave
spring.session.store-type out, since Spring Boot should be able to
deduce which session repository implementation are you using as long
as you have only only SessionRepository implementation on the
classpath (i.e. you depend only on spring-session-jdbc and no other
Spring Session modules).
Original Post
This will solve your immediate problem, but i'm unsure if it will break something else...
I think you have multiple issues By default jdbc has H2 database. It is automatically created by spring.
Check if it is there. So first run it on H2. Then copy the same database and table to MySQL. create same schema and table to MySQL then change connection to MySQL.
Spring Boot automatically creates a DataSource that connects Spring Session to an embedded instance of H2 database
src/main/resources/application.properties
spring.datasource.url= # JDBC URL of the database.
spring.datasource.username= # Login username of the database.
spring.datasource.password= # Login password of the database.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root