JBoss Fuse/REST DSL - Why do my modifications (to use IBM MQ) not work? - java-8

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

Related

Is using hibernate type property names when using spring boot a good approach

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);
}
}

Spring Framework 5 and EhCache 3.5

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>

How to precompile jsp in a spring boot application?

I'm using Spring boot and we were using Spring with Tomcat before that.
When we used Spring and Tomcat two years ago, we used a maven plugin to precompile the jsp.
It was really useful to avoid this compilation to be made for every first visits after a deployement.
However all maven plugin that we know dumps a web.xml file that list all jsp and associated generated servlets.
With Spring boot, it don't use web.xml anymore, so this file is ignored.
We still have the compilation and that's a security belt but there is a penalty for every first visit on each page.
Does anybody know if it's possible to precompile jsp in a Spring boot application ?
I got precompiling to work either at server start time (don't have to use JspC, so simpler build file) and at build time (much quicker server start time). I register the resulting servlets dynamically, so you don't have to manually change any files if you add/remove JSPs.
At server start time
Use ServletRegistration.Dynamic to register a JSP_SERVLET_CLASS Servlet for each JSP.
Use the initParameter jspFile to set the JSP filename (ref)
e.g. for SpringBoot in a ServletContextInitializer (ref):
#Bean
public ServletContextInitializer preCompileJspsAtStartup() {
return servletContext -> {
getDeepResourcePaths(servletContext, "/WEB-INF/jsp/").forEach(jspPath -> {
log.info("Registering JSP: {}", jspPath);
ServletRegistration.Dynamic reg = servletContext.addServlet(jspPath, Constants.JSP_SERVLET_CLASS);
reg.setInitParameter("jspFile", jspPath);
reg.setLoadOnStartup(99);
reg.addMapping(jspPath);
});
};
}
private static Stream<String> getDeepResourcePaths(ServletContext servletContext, String path) {
return (path.endsWith("/")) ? servletContext.getResourcePaths(path).stream().flatMap(p -> getDeepResourcePaths(servletContext, p))
: Stream.of(path);
}
At build time
Generate Java source files for each JSP and a web.xml with their servlet mappings using JspC (ref).
Then register these with the ServletContext (by parsing the web.xml with Tomcat's WebXmlParser, e.g. for SpringBoot:
#Value("classpath:precompiled-jsp-web.xml")
private Resource precompiledJspWebXml;
#Bean
public ServletContextInitializer registerPreCompiledJsps() {
return servletContext -> {
// Use Tomcat's web.xml parser (assume complete XML file and validate).
WebXmlParser parser = new WebXmlParser(false, true, true);
try (InputStream is = precompiledJspWebXml.getInputStream()) {
WebXml webXml = new WebXml();
boolean success = parser.parseWebXml(new InputSource(is), webXml, false);
if (!success) {
throw new RuntimeException("Error parsing Web XML " + precompiledJspWebXml);
}
for (ServletDef def : webXml.getServlets().values()) {
log.info("Registering precompiled JSP: {} = {} -> {}", def.getServletName(), def.getServletClass());
ServletRegistration.Dynamic reg = servletContext.addServlet(def.getServletName(), def.getServletClass());
reg.setLoadOnStartup(99);
}
for (Map.Entry<String, String> mapping : webXml.getServletMappings().entrySet()) {
log.info("Mapping servlet: {} -> {}", mapping.getValue(), mapping.getKey());
servletContext.getServletRegistration(mapping.getValue()).addMapping(mapping.getKey());
}
} catch (IOException e) {
throw new RuntimeException("Error registering precompiled JSPs", e);
}
};
}
Example Maven config to generate and compile the JSP classes, and generate the precompiled-jsp-web.xml:
<!-- Needed to get the jasper Ant task to work (putting it in the plugin's dependencies didn't work) -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina-ant</artifactId>
<version>8.0.32</version>
<scope>provided</scope>
</dependency>
<!-- ... -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>precompile-jsp-generate-java</id>
<!-- Can't be generate-sources because we need the compiled Henry taglib classes already! -->
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo message="Precompiling JSPs"/>
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="target_dir" value="${project.basedir}/generated-sources/jspc" />
<path id="jspc_classpath">
<path path="${compile_classpath}"/>
</path>
<typedef resource="org/apache/catalina/ant/catalina.tasks" classpathref="jspc_classpath"/>
<mkdir dir="${target_dir}/java"/>
<mkdir dir="${target_dir}/resources"/>
<jasper
validateXml="false"
uriroot="${project.basedir}/src/main/webapp"
compilertargetvm="1.8"
compilersourcevm="1.8"
failonerror="true"
javaencoding="UTF-8"
webXml="${target_dir}/resources/precompiled-jsp-web.xml"
outputDir="${target_dir}/java/" >
</jasper>
<!-- Can't use Maven to compile the JSP classes because it has already compiled the app's classes
(needed to do that becuase JspC needs compiled app classes) -->
<javac srcdir="${target_dir}/java" destdir="${project.build.outputDirectory}" classpathref="jspc_classpath" fork="true"/>
<!-- Have to copy the web.xml because process-resources phase has already finished (before compile) -->
<copy todir="${project.build.outputDirectory}">
<fileset dir="${target_dir}/resources"/>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<!-- Not strictly necessary, because Ant does the compilation, but at least attempts to keep it in sync with Maven -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-precompiled-jsp-java-sources</id>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>${project.basedir}/generated-sources/jspc/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-precompiled-jsp-resources</id>
<phase>generate-resources</phase>
<goals><goal>add-resource</goal></goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/generated-sources/jspc/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Based on the excellent answer of paulcm I came up with my own solution as the above solution didn't work for me and I couldn't track down the error. Maybe the answer above is outdated for tomcat9. Or it had some problem with multi-module setup. However: All credits belong to paulcm
This is only the compile time solution.
Add these two plugins to your pom.xml
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jspc-maven-plugin</artifactId>
<version>9.4.15.v20190215</version>
<executions>
<execution>
<id>jspc</id>
<goals>
<goal>jspc</goal>
</goals>
<configuration>
<mergeFragment>true</mergeFragment>
<sourceVersion>1.8</sourceVersion>
<targetVersion>1.8</targetVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${project.basedir}/target/web.xml</webXml>
</configuration>
</plugin>
Add an empty web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
<session-config>
<cookie-config>
</cookie-config>
</session-config>
</web-app>
Add a Registry
import org.apache.tomcat.util.descriptor.web.ServletDef;
import org.apache.tomcat.util.descriptor.web.WebXml;
import org.apache.tomcat.util.descriptor.web.WebXmlParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.xml.sax.InputSource;
import javax.servlet.ServletRegistration;
import java.io.InputStream;
import java.util.Map;
#Configuration
public class PreCompileJspRegistry {
private Logger logger = LoggerFactory.getLogger(this.getClass());
#Bean
public ServletContextInitializer registerPreCompiledJsps() {
return servletContext -> {
InputStream inputStream = servletContext.getResourceAsStream("/WEB-INF/web.xml");
if (inputStream == null) {
logger.info("Could not read web.xml");
return;
}
try {
WebXmlParser parser = new WebXmlParser(false, false, true);
WebXml webXml = new WebXml();
boolean success = parser.parseWebXml(new InputSource(inputStream), webXml, false);
if (!success) {
logger.error("Error registering precompiled JSPs");
}
for (ServletDef def : webXml.getServlets().values()) {
logger.info("Registering precompiled JSP: {} = {} -> {}", def.getServletName(), def.getServletClass());
ServletRegistration.Dynamic reg = servletContext.addServlet(def.getServletName(), def.getServletClass());
reg.setLoadOnStartup(99);
}
for (Map.Entry<String, String> mapping : webXml.getServletMappings().entrySet()) {
logger.info("Mapping servlet: {} -> {}", mapping.getValue(), mapping.getKey());
servletContext.getServletRegistration(mapping.getValue()).addMapping(mapping.getKey());
}
} catch (Exception e) {
logger.error("Error registering precompiled JSPs", e);
}
};
}
}
A comment for "At server start time" outlined above: the servlet you create will by default be in development mode if the application is packaged in an executable jar, so you if you use it in production mode, you should also set development = false ++ to prevent the jsps from being compiled again:
reg.setInitParameter("genStringAsCharArray", "true");
reg.setInitParameter("trimSpaces", "true");
reg.setInitParameter("development", "false");

Ehcache, CacheException with JMS replication and activemq

I'm trying to implement a hibernate clustered 2nd level cache with ehcache, using JMS replication.
Hibernate version is 3.6.10.final, spring version is 3.2.2.
When the servlet is starting, I get the following error:
Caused by: org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Failure cloning default cache. Initial cause was not supported
at net.sf.ehcache.hibernate.AbstractEhcacheProvider.buildCache(AbstractEhcacheProvider.java:73)
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.buildEntityRegion(RegionFactoryCacheProviderBridge.java:104)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:280)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
at com.targa.fleetGateway.HibernateUtil.<init>(HibernateUtil.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 73 more
Caused by: net.sf.ehcache.CacheException: Failure cloning default cache. Initial cause was not supported
at net.sf.ehcache.CacheManager.cloneDefaultCache(CacheManager.java:1877)
at net.sf.ehcache.CacheManager.addCache(CacheManager.java:1173)
at net.sf.ehcache.hibernate.AbstractEhcacheProvider.buildCache(AbstractEhcacheProvider.java:66)
... 82 more
Caused by: java.lang.CloneNotSupportedException: not supported
at net.sf.ehcache.distribution.jms.JMSCacheLoader.clone(JMSCacheLoader.java:269)
at net.sf.ehcache.Cache.clone(Cache.java:2846)
at net.sf.ehcache.Cache.clone(Cache.java:163)
at net.sf.ehcache.CacheManager.cloneDefaultCache(CacheManager.java:1875)
... 84 more
My ehcache.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true">
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
properties="initialContextFactoryName=com.targa.fleetGateway.ExampleActiveMQInitialContextFactory,
providerURL=tcp://127.0.0.1:61616, replicationTopicConnectionFactoryBindingName=topicConnectionFactory,
replicationTopicBindingName=ehcache, getQueueConnectionFactoryBindingName=queueConnectionFactory, getQueueBindingName=ehcacheGetQueue, topicConnectionFactoryBindingName=topicConnectionFactory, topicBindingName=ehcache"
propertySeparator="," />
<defaultCache
maxElementsInMemory="100"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jms.JMSCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
replicateUpdatesViaCopy=true, replicateRemovals=true, asynchronousReplicationIntervalMillis=1000"
propertySeparator="," />
<cacheLoaderFactory class="net.sf.ehcache.distribution.jms.JMSCacheLoaderFactory"
properties="initialContextFactoryName=com.targa.fleetGateway.ExampleActiveMQInitialContextFactory,
providerURL=tcp://127.0.0.1:61616, replicationTopicConnectionFactoryBindingName=topicConnectionFactory,
getQueueConnectionFactoryBindingName=queueConnectionFactory, replicationTopicBindingName=ehcache,
getQueueBindingName=ehcacheGetQueue, timeoutMillis=10000" />
</defaultCache>
</ehcache>
If I comment out the cacheLoaderFactory section, things start working again.
The same configuration works in another application where I'm using hibernate 4.2, but I can't upgrade to 4.2 on this one.
Has anybody got any clue about this?
Below are the other relevant pieces of my configuration. Please tell me if anything is missing.
POM.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.8</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-jmsreplication</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
Hibernate properties:
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">
net.sf.ehcache.hibernate.SingletonEhCacheProvider</property>
ExampleActiveMQInitialContextFactory.java
public class ExampleActiveMQInitialContextFactory extends
ActiveMQInitialContextFactory {
/**
* {#inheritDoc}
*/
#Override
public Context getInitialContext(Hashtable environment) throws NamingException {
Map<String, Object> data = new ConcurrentHashMap<String, Object>();
String replicationTopicConnectionFactoryBindingName = (String) environment
.get(JMSUtil.TOPIC_CONNECTION_FACTORY_BINDING_NAME);
if (replicationTopicConnectionFactoryBindingName != null) {
try {
data.put(replicationTopicConnectionFactoryBindingName,
createConnectionFactory(environment));
} catch (URISyntaxException e) {
throw new NamingException(
"Error initialisating TopicConnectionFactory with message "
+ e.getMessage());
}
}
String getQueueConnectionfactoryBindingName = (String) environment
.get(JMSUtil.GET_QUEUE_CONNECTION_FACTORY_BINDING_NAME);
try {
data.put(getQueueConnectionfactoryBindingName,
createConnectionFactory(environment));
} catch (URISyntaxException e) {
throw new NamingException(
"Error initialisating TopicConnectionFactory with message "
+ e.getMessage());
}
String replicationTopicBindingName = (String) environment
.get(JMSUtil.REPLICATION_TOPIC_BINDING_NAME);
String getQueueBindingName = (String) environment
.get(JMSUtil.GET_QUEUE_BINDING_NAME);
if (replicationTopicBindingName != null) {
data.put(replicationTopicBindingName,
createTopic(replicationTopicBindingName));
}
data.put(getQueueBindingName, createQueue(getQueueBindingName));
return createContext(environment, data);
}
}
I faced this problem today: the reason is that defaultCache should not have: cacheLoaderFactory.
Strange that it does not mentioned in the documentation(
So I removed cacheLoaderFactory from defaultCache - and everything works fine;

How to deploy Maven project to Glassfish Server in Intellij Idea 13

I am developing a sample Java EE applicaiton with Intellij Idea 13. Simply, my project is a Maven project and has JPA end EJB modules. But when deploying and running application on Glassfish server I get errors.
I created a Maven project named SimpleEE and added JPA, EJB modules.
Here is my project structure:
|-SampleEE
| |+.idea
| |-src
| | |-main
| | | |-java
| | | | |-beans
| | | | | |-MyBean.java
| | | | |-entities
| | | | |-Staff.java
| | | |-resources
| | | |-META-INF
| | | |-ejb-jar.xml
| | | |-persistence.xml
| | |+test
| |-pom.xml
| |-SampleEE.iml
| |-SampleEE.jpr
|+ExternalLibraries
MyBean.java:
package beans;
import entities.Staff;
import javax.annotation.PostConstruct;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
#Startup
#LocalBean
#Singleton
public class MyBean {
public MyBean() {
}
#PostConstruct
public void myMain() {
EntityManager em = Persistence.createEntityManagerFactory("mysqlPU").createEntityManager();
em.getTransaction().begin();
Staff staff = new Staff();
staff.setAge(44);
staff.setGender("M");
staff.setSalary(123);
staff.setName("Staff Name");
em.persist(staff);
em.getTransaction().commit();
}
}
Staff.java
package entities;
import javax.persistence.*;
#Entity
public class Staff {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "STAFF_ID")
private int id;
#Column(name = "NAME")
private String name;
#Column(name = "AGE")
private Integer age;
#Column(name = "GENDER")
private String gender;
#Column(name = "SALARY")
private Integer salary;
#Lob
#Column(name = "IMAGE", nullable = true)
private byte[] image;
// Getters and setters
// ...
#Override
public int hashCode() {
// implementation ignored here for simplicity
}
#Override
public boolean equals(Object o) {
// implementation ignored here for simplicity
}
}
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="mysqlPU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>entities.Staff</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dbName"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="mysqlUsername"/>
<property name="javax.persistence.jdbc.password" value="mysqlPassword"/>
</properties>
</persistence-unit>
</persistence>
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>SampleEE</groupId>
<artifactId>SampleEE</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
</dependencies>
</project>
I created an EJB Application:Exploded artifact from project structure. In Run/Debug configurations window I built a Glassfish configuration. But when running this configuration, Idea complains that it can not find classes in mysql jdbc driver and shows errors emerging from this error. Server is started but application is not deployed. Error message snippet from Idea output log:
....
[2013-12-13 04:07:31,362] Artifact SampleEE:ejb exploded: Artifact is being deployed, please wait...
[2013-12-13 04:07:33,011] Artifact SampleEE:ejb exploded: Error during artifact deployment. See server log for details.
[2013-12-13 04:07:33,018] Artifact SampleEE:ejb exploded: java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton MyBean. Please see server.log for more details.
Last error in Glassfish log
....
Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [com.mysql.jdbc.Driver] not found.
....
I guess jar files of libraries are not deployed. But my maven configuration is valid. M2_HOME is set correctly and IDEA resolves maven path. The jar files are also available in local repository.
I created a same structured project in Netbeans and it runs succesfully. I don't know what I am doing wrong or what configuration parameters I am missing.
You need to add a JavaEE module and add create a JavaEE artifact. Then add all libraries you need to that artifact.

Resources