I am trying to create a jms-bridge from JBoss EAP 6.4 to TIbco EMS 8 (I think).
I setup the below in the standalone config:
<jms-bridge name="TibcoBridge" module="org.tbco">
<source>
<connection-factory name="ConnectionFactory"/>
<destination name="mdm.output.queue"/>
</source>
<target>
<connection-factory name="XAQueueConnectionFactory"/>
<destination name="sync.queue.test"/>
<context>
<property key="java.naming.factory.initial" value="com.tibco.tibjms.naming.TibjmsInitialContextFactory"/>
<property key="java.naming.provider.url" value="tibjmsnaming://jms:7222"/>
<property key="java.naming.security.principal" value="consumer"/>
<property key="java.naming.security.credentials" value="password"/>
</context>
</target>
<quality-of-service>AT_MOST_ONCE</quality-of-service>
<failure-retry-interval>100000</failure-retry-interval>
<max-retries>10</max-retries>
<max-batch-size>10</max-batch-size>
<max-batch-time>100</max-batch-time>
</jms-bridge>
I setup the below directory structure for the module:
[jboss#poc-informatica-jboss01 /usr/share/jbossas/modules/system/layers/base/org/tbco]$ ls -ltr main
total 592
-rw-r--r--. 1 jboss jboss 271790 Sep 19 13:00 tibcrypt.jar
-rw-r--r--. 1 jboss jboss 323650 Sep 19 13:00 tibjms.jar
drwxr-xr-x. 2 jboss jboss 6 Sep 19 13:03 attachments
-rw-r--r--. 1 jboss jboss 734 Sep 19 13:31 module.xml
-rw-r--r--. 1 jboss jboss 0 Sep 19 14:09 derby.log
[jboss#poc-informatica-jboss01 /usr/share/jbossas/modules/system/layers/base/org/tbco/main]$ cat module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.tbco">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<resources>
<!-- Insert resources required to connect to the source or target -->
<resource-root path="."/>
<resource-root path="tibcrypt.jar"/>
<resource-root path="tibjms.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.jms.api"/>
<module name="javax.transaction.api"/>
<module name="javax.resource.api"/>
<module name="org.hornetq"/>
<module name="org.jboss.common-core"/>
<module name="javax.management.j2ee.api"/>
<module name="org.jboss.logging"/>
</dependencies>
</module>
[jboss#poc-informatica-jboss01 /usr/share/jbossas/modules/system/layers/base/org/tbco/main]$
Upon startup, I am seeing the below error message:
14:15:37,039 WARN [org.hornetq.jms.server] (Thread-98) HQ122010: Failed to connect JMS Bridge TibcoBridge: javax.jms.JMSSecurityException: invalid name or password
at com.tibco.tibjms.Tibjmsx.buildException(Tibjmsx.java:575)
at com.tibco.tibjms.TibjmsConnection._create(TibjmsConnection.java:1330)
at com.tibco.tibjms.TibjmsConnection.<init>(TibjmsConnection.java:4115)
at com.tibco.tibjms.TibjmsQueueConnection.<init>(TibjmsQueueConnection.java:36)
at com.tibco.tibjms.TibjmsxCFImpl._createImpl(TibjmsxCFImpl.java:173)
at com.tibco.tibjms.TibjmsxCFImpl._createConnection(TibjmsxCFImpl.java:253)
at com.tibco.tibjms.TibjmsXAConnectionFactory.createConnection(TibjmsXAConnectionFactory.java:54)
at org.hornetq.jms.bridge.impl.JMSBridgeImpl.createConnection(JMSBridgeImpl.java:1155)
at org.hornetq.jms.bridge.impl.JMSBridgeImpl.setupJMSObjects(JMSBridgeImpl.java:1370)
at org.hornetq.jms.bridge.impl.JMSBridgeImpl.setupJMSObjectsWithRetry(JMSBridgeImpl.java:1504)
at org.hornetq.jms.bridge.impl.JMSBridgeImpl.access$2400(JMSBridgeImpl.java:80)
at org.hornetq.jms.bridge.impl.JMSBridgeImpl$FailureHandler.run(JMSBridgeImpl.java:2132)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_121]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_121]
Reached here after half a day of struggle tweaking numerous mistakes.
I have confirmed that the user and password works. Even tried with admin user and password but same error.
Does tibco expect password to be encrypted or something?
Please assist with jumping across hopefully the final hurdle.
Please see here for answer:
https://developer.jboss.org/message/976162#976162
The credentials you need to specify are for JMS, not for JNDI.
Have you tried to set it in the target'user and password?
<target>
<connection-factory name="XAQueueConnectionFactory"/>
<destination name="sync.queue.test"/>
<user>consumer</user>
<password>password</password>
<context>
<property key="java.naming.factory.initial" value="com.tibco.tibjms.naming.TibjmsInitialContextFactory"/>
<property key="java.naming.provider.url" value="tibjmsnaming://jms:7222"/>
<property key="java.naming.security.principal" value="consumer"/>
<property key="java.naming.security.credentials" value="password"/>
</context>
</target>
Related
When I try to start my WildFly server, I got this error :
2018-11-17 21:29:55,203 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "org.postgresql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.postgresql]"
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "swap")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]"
]}
2018-11-17 21:30:07,625 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "swap")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]"
]}
And my standalone.xml :
<datasources>
<datasource jndi-name="java:jboss/datasources/swap" pool-name="swap" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&characterEncoding=UTF-8</connection-url>
<driver>org.postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
</datasource>
<drivers>
<driver name="org.postgresql" module="org.postgresql">
<driver-class>org.postgresql.Driver</driver-class>
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
</drivers>
</datasources>
My PostgreSQL module.xml :
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
What could be the problem? Please help and Thanks.
Your module.xml is invalid. A <dependencies> tag is missing. Try it with the following:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
EDIT:
The module.xml file and the postgresql-42.2.5.jar have to be in
C:\wildfly\wildfly-9.0.2.Final\modules\system\layers\base\org\postgresql\main.
It is also recommended to put your modules directly into
C:\wildfly\wildfly-9.0.2.Final\modules\.
So in your case C:\wildfly\wildfly-9.0.2.Final\modules\org\postgresql\main, that can be problem.
For reference, also have a look at the EAP7 Documentation and you should also think about using the jboss-cli.
For configuration of PostgresSQL for WildFly server, you should follow the following steps.
Step 1 : Adding PostgreSQL Module
Create new folder ${wildfly_home}/modules/system/layers/base/org/postgresql/main/ if not exist.
Download Latest Driver Jar via this link => https://jdbc.postgresql.org/download.html and put under the above folder.
Also in that new folder, Create module.xml and put the following config.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.23.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
May be jar version need to update in resource-root.
Step 2 : Update DB configs from standalone.xml
Remove Existing <driver> config and add new config as follow.
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
Remove existing <datasource> config and add new config as follow.
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&characterEncoding=UTF-8</connection-url>
<driver>postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
</datasource>
Modify default-bindings datasource name to PostgresDS from ExampleDS.
<default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/datasources/PostgresDS" ...
Make sure that you have created your swap database in PostgreSQL database server.
Now, run server and it will be fine.
I am trying to get a Java8EE application working on Wildfly10 and Postgres 9.6.6.
Somehow I allways bump into the error that the relation cannot be found.
My Postgres is running on localhost, default port. I am connecting with the user postgres and the correct password. The database (hbnac) has a schema with the same name.
Wildfly is configured to use the database and the “Test connection” is confirming a successful connection.
Using pgAdmin 4 I can also browse the database, see the schema, as well as the table group_member.
The config in Jboss looks as follow:
<datasource jta="false" jndi-name="java:jboss/datasources/hbnac" pool-name="hbnac" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
<pool>
<min-pool-size>1</min-pool-size>
<initial-pool-size>1</initial-pool-size>
<max-pool-size>10</max-pool-size>
<flush-strategy>Gracefully</flush-strategy>
</pool>
<security>
<user-name>postgres</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
</validation>
</datasource>
However, my application fails to select a record from the very same table, resulting in the following error:
Caused by: org.postgresql.util.PSQLException: ERROR: relation "group_member" does not exist
The configuration of my persistence.xml is doing a jndi lookup of the connection defined in Wildfly:
<persistence-unit name="hbnac">
<jta-data-source>java:jboss/datasources/hbnac</jta-data-source>
<class>hbnac.birthday.domain.groupmember.GroupMember</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />
<!--property name="hibernate.hbm2ddl.auto" value="validate"/-->
<!--property name="hibernate.default_schema" value="hbnac"/-->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
And obviously, the jta-data-source is matching the working datasource in Wildfly. As you can see, I have experimented a bit with the validate (which fails for the same reason at startup) and with the schema name, which also does not make a difference.
The entity itsel is annoted:
#Entity
#Table(name = "group_member")
public class GroupMember extends AbstractEntity {
public final static String FACEBOOK_NAME_FIELD = "facebookName";
public final static String BIRTHDAY_FIELD = "birthday";
#Id
#GeneratedValue(strategy= GenerationType.IDENTITY)
private long id;
It has getters, setters, hashcode and equals methode for all fields available.
If I copy the query generated by hibernate into pgadmin it also works perfectly...
Any ideas left?
success to test connection, but even couldn't find table
that indicates ,perhaps schema setting is not defined correctly.
then, should put a currentSchema like this
<connection-url>jdbc:postgresql://localhost:5432/hbnac?currentSchema=hbnac</connection-url>
and if you use Hibernate to issue query should enable this comment outed code
<!--property name="hibernate.default_schema" value="hbnac"/-->
I found the error after many tries! It was caused by the configuration of the Postgres module in Wildfly itself.
What I had before:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-42.1.4.jar" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true" />
</dependencies>
and in the standalone.xml:
<driver name="postgres" module="org.postgres">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
<datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>
</driver>
for the datasource itself:
<datasource jta="false" jndi-name="java:jboss/datasources/hbnac" pool-name="hbnac" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
...
This configuration gave a successful connection but the error that a relation could not be found.
By replacing it with the following configuration, everything is working fine:
For the module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-42.1.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
For the driver in the standalone.xml:
<driver name="postgresql" module="org.postgres">
<driver-class>org.postgresql.Driver</driver-class>
</driver>
And finally for the db connection:
<datasource jta="true" jndi-name="java:/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver>postgresql</driver>
<security>
...
I want to use apache ignite as a cache for my database and I use persitent store for this.
My database is Cassandra and for configuration I use this wiki.
With this initialization I run ignite in windows:
ignite.bat cassandra-ignite-config.xml
cassandra-ignite-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Cassandra connection settings -->
<import resource="connection-settings.xml" />
<!-- Persistence settings for 'cache1' -->
<bean id="cache1_persistence_settings" class="org.apache.ignite.cache.store.cassandra.utils.persistence.KeyValuePersistenceSettings">
<constructor-arg type="org.springframework.core.io.Resource" value="persistence-settings-1.xml" />
</bean>
<!-- Persistence settings for 'cache2' -->
<bean id="cache2_persistence_settings" class="org.apache.ignite.cache.store.cassandra.utils.persistence.KeyValuePersistenceSettings">
<constructor-arg type="org.springframework.core.io.Resource" value="classpath:org/apache/ignite/tests/persistence/blob/persistence-settings-3.xml" />
</bean>
<!-- Ignite configuration -->
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="cacheConfiguration">
<list>
<!-- Configuring persistence for "cache1" cache -->
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="cache1"/>
<property name="readThrough" value="true"/>
<property name="writeThrough" value="true"/>
<property name="cacheStoreFactory">
<bean class="org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory">
<property name="dataSourceBean" value="cassandraAdminDataSource"/>
<property name="persistenceSettingsBean" value="cache1_persistence_settings"/>
</bean>
</property>
</bean>
<!-- Configuring persistence for "cache2" cache -->
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="cache2"/>
<property name="readThrough" value="true"/>
<property name="writeThrough" value="true"/>
<property name="cacheStoreFactory">
<bean class="org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory">
<property name="dataSourceBean" value="cassandraAdminDataSource"/>
<property name="persistenceSettingsBean" value="cache2_persistence_settings"/>
</bean>
</property>
</bean>
</list>
</property>
<!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<!--
Ignite provides several options for automatic discovery that can be used
instead os static IP based discovery. For information on all options refer
to our documentation: http://apacheignite.readme.io/docs/cluster-config
-->
<!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
<!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
<property name="addresses">
<list>
<!-- In distributed environment, replace with actual host IP address. -->
<value>127.0.0.1:47500..47509</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</beans>
connection-setting.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="cassandraAdminCredentials" class="org.apache.ignite.tests.utils.CassandraAdminCredentials"/>
<bean id="loadBalancingPolicy" class="com.datastax.driver.core.policies.RoundRobinPolicy"/>
<bean id="contactPoints" class="org.apache.ignite.tests.utils.CassandraHelper" factory-method="getContactPointsArray"/>
<bean id="cassandraAdminDataSource" class="org.apache.ignite.cache.store.cassandra.utils.datasource.DataSource">
<property name="credentials" ref="cassandraAdminCredentials"/>
<property name="contactPoints" ref="contactPoints"/>
<property name="readConsistency" value="ONE"/>
<property name="writeConsistency" value="ONE"/>
<property name="loadBalancingPolicy" ref="loadBalancingPolicy"/>
</bean>
</beans>
persistence-setting-1.xml:
<persistence keyspace="test1" table="my_table">
<keyPersistence class="java.lang.Integer" strategy="PRIMITIVE" column="my_key"/>
<valuePersistence class="java.lang.String" strategy="PRIMITIVE" />
</persistence>
but I have this error:
class org.apache.ignite.IgniteException: Failed to instantiate Spring
XML application context (make sure all classes used in Spring
configuration are present at CLASSPATH)
[springUrl=file:~/config/cassandra-ignite-config.xml]
at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:927)
at org.apache.ignite.Ignition.start(Ignition.java:350)
at org.apache.ignite.startup.cmdline.CommandLineStartup.main(CommandLineStartup.java:302)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to
instantiate Spring XML application context (make sure all classes used
in Spring configuration are present at CLASSPATH)
[springUrl=file:~/config/cassandra-ignite-config.xml]
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.applicationContext(IgniteSpringHelperImpl.java:387)
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:104)
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:98)
at org.apache.ignite.internal.IgnitionEx.loadConfigurations(IgnitionEx.java:638)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:839)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:748)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:618)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:588)
at org.apache.ignite.Ignition.start(Ignition.java:347)
... 1 more Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot
find class [org.apache.ignite.tests.utils.CassandraAdminCredentials]
for bean with name 'cassandraAdminCredentials' defined in URL
[file:~/config/connection-settings.xml]; nested exception is
java.lang.ClassNotFoundException: org.apache.ignite.tests.utils.Cassan
draAdminCredentials
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:623)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:592)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1394)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:957)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:705)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.applicationContext(IgniteSpringHelperImpl.java:381)
... 9 more Caused by: java.lang.ClassNotFoundException: org.apache.ignite.tests.utils.CassandraAdminCredentials
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:246)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1346)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1317)
... 17 more Failed to start grid: Failed to instantiate Spring XML application context (make sure all classes used in Spring
configuration are present at CLASSPATH)
[springUrl=~/config/cassandra-ignite-config.xml]
Note! You may use 'USER_LIBS' environment variable to specify your classpath. Press any key to continue . . .
it seems there is something missed but I don't understand it.
Update:
I use base-concepts and example number 4 of the examples.
but know I have the serialization problem for pojo example.
error:
[16:24:11,033][SEVERE][tcp-disco-msg-worker-#2%null%][TcpDiscoverySpi] Failed to unmarshal discovery data for component: 1
class org.apache.ignite.IgniteCheckedException: Failed to deserialize object with given class loader: sun.misc.Launcher$AppClassLoader#5e9f23b4
at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:128)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:94)
at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:142)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:82)
at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9779)
at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.onExchange(TcpDiscoverySpi.java:1716)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processNodeAddedMessage(ServerImpl.java:4216)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processMessage(ServerImpl.java:2538)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processMessage(ServerImpl.java:2362)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$MessageWorkerAdapter.body(ServerImpl.java:6436)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.body(ServerImpl.java:2445)
at org.apache.ignite.spi.IgniteSpiThread.run(IgniteSpiThread.java:62)
Caused by: java.io.InvalidClassException: org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings; local class incompatible: stream classdesc serialVersionUID = -3543390829981374356, local class serialVersionUID = 4263059111698998196
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:616)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1630)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1781)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2018)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1942)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1808)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2018)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1942)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1808)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2018)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1942)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1808)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
at java.util.ArrayList.readObject(ArrayList.java:791)
at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1909)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1808)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2018)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1942)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1808)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:120)
... 11 more
Update 2:
my pom file:
<?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>aryahamrah.ds</groupId>
<artifactId>igniteHello</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>1.8.0</version>
</dependency>
<!--for cassandra -->
<!-- https://mvnrepository.com/artifact/org.apache.cassandra/cassandra-all -->
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>3.9</version>
</dependency>
<!--<!– https://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-core –>-->
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.collections/google-collections -->
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
<!--<!– https://mvnrepository.com/artifact/org.apache.ignite/ignite-cassandra-store –>-->
<!--<dependency>-->
<!--<groupId>org.apache.ignite</groupId>-->
<!--<artifactId>ignite-cassandra-store</artifactId>-->
<!--<version>1.8.0</version>-->
<!--</dependency>-->
<!-- https://mvnrepository.com/artifact/org.apache.ignite/ignite-cassandra -->
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-cassandra</artifactId>
<version>1.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.22</version>
</dependency>
</dependencies>
</project>
connection-setting.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="loadBalancingPolicy" class="com.datastax.driver.core.policies.TokenAwarePolicy">
<constructor-arg type="com.datastax.driver.core.policies.LoadBalancingPolicy">
<bean class="com.datastax.driver.core.policies.RoundRobinPolicy"/>
</constructor-arg>
</bean>
<bean id="cassandraAdminDataSource" class="org.apache.ignite.cache.store.cassandra.datasource.DataSource">
<property name="readConsistency" value="ONE"/>
<property name="writeConsistency" value="ONE"/>
<property name="loadBalancingPolicy" ref="loadBalancingPolicy"/>
</bean>
<bean id="cassandraRegularDataSource" class="org.apache.ignite.cache.store.cassandra.datasource.DataSource">
<property name="readConsistency" value="ONE"/>
<property name="writeConsistency" value="ONE"/>
<property name="loadBalancingPolicy" ref="loadBalancingPolicy"/>
</bean>
</beans>
Update 3:
when I put to the cache nothing happens but when I want to get, I have these errors:
[15:16:16,008][SEVERE][pub-#53%null%][GridTaskWorker] Failed to obtain remote job result policy for result from ComputeTask.result(..) method (will fail the whole task): GridJobResultImpl [job=C4V2 [r=HelloWorld$$Lambda$8/98974893#5977d9a0], sib=GridJobSiblingImpl [sesId=c92fc496951-0257bdb2-3066-4861-8c60-47febea167d5, jobId=d92fc496951-0257bdb2-3066-4861-8c60-47febea167d5, nodeId=f2c7d14b-401f-4aea-a9af-50deeb7cb85e, isJobDone=false], jobCtx=GridJobContextImpl [jobId=d92fc496951-0257bdb2-3066-4861-8c60-47febea167d5, timeoutObj=null, attrs={}], node=TcpDiscoveryNode [id=f2c7d14b-401f-4aea-a9af-50deeb7cb85e, addrs=[0:0:0:0:0:0:0:1, 127.0.0.1, 192.168.1.113], sockAddrs=[LT-88273/169.254.247.78:47500, /0:0:0:0:0:0:0:1:47500, /127.0.0.1:47500, /192.168.1.113:47500], discPort=47500, order=1, intOrder=1, lastExchangeTime=1483530374957, loc=false, ver=1.8.0#20161205-sha1:9ca40dbe, isClient=false], ex=class o.a.i.IgniteException: HelloWorld, hasRes=true, isCancelled=false, isOccupied=true]
class org.apache.ignite.IgniteException: Remote job threw user exception (override or implement ComputeTask.result(..) method if you would like to have automatic failover for this exception).
at org.apache.ignite.compute.ComputeTaskAdapter.result(ComputeTaskAdapter.java:101)
at org.apache.ignite.internal.processors.task.GridTaskWorker$5.apply(GridTaskWorker.java:1030)
at org.apache.ignite.internal.processors.task.GridTaskWorker$5.apply(GridTaskWorker.java:1023)
at org.apache.ignite.internal.util.IgniteUtils.wrapThreadLoader(IgniteUtils.java:6596)
at org.apache.ignite.internal.processors.task.GridTaskWorker.result(GridTaskWorker.java:1023)
at org.apache.ignite.internal.processors.task.GridTaskWorker.onResponse(GridTaskWorker.java:841)
at org.apache.ignite.internal.processors.task.GridTaskProcessor.processJobExecuteResponse(GridTaskProcessor.java:996)
at org.apache.ignite.internal.processors.job.GridJobWorker.finishJob(GridJobWorker.java:843)
at org.apache.ignite.internal.processors.job.GridJobWorker.finishJob(GridJobWorker.java:745)
at org.apache.ignite.internal.processors.job.GridJobWorker.execute0(GridJobWorker.java:608)
at org.apache.ignite.internal.processors.job.GridJobWorker.body(GridJobWorker.java:479)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: class org.apache.ignite.IgniteException: HelloWorld
at org.apache.ignite.internal.processors.job.GridJobWorker.initialize(GridJobWorker.java:447)
at org.apache.ignite.internal.processors.job.GridJobProcessor.processJobExecuteRequest(GridJobProcessor.java:1108)
at org.apache.ignite.internal.processors.job.GridJobProcessor$JobExecutionListener.onMessage(GridJobProcessor.java:1894)
at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1082)
at org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:710)
at org.apache.ignite.internal.managers.communication.GridIoManager.access$1700(GridIoManager.java:102)
at org.apache.ignite.internal.managers.communication.GridIoManager$5.run(GridIoManager.java:673)
... 3 more
Caused by: class org.apache.ignite.IgniteCheckedException: HelloWorld
at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9785)
at org.apache.ignite.internal.processors.job.GridJobWorker.initialize(GridJobWorker.java:428)
... 9 more
Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException: HelloWorld
at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:689)
at org.apache.ignite.internal.binary.BinaryUtils.doReadClass(BinaryUtils.java:1480)
at org.apache.ignite.internal.binary.BinaryUtils.doReadClass(BinaryUtils.java:1418)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.readClass(BinaryReaderExImpl.java:370)
at org.apache.ignite.internal.binary.BinaryFieldAccessor$DefaultFinalClassAccessor.readFixedType(BinaryFieldAccessor.java:828)
at org.apache.ignite.internal.binary.BinaryFieldAccessor$DefaultFinalClassAccessor.read(BinaryFieldAccessor.java:639)
at org.apache.ignite.internal.binary.BinaryClassDescriptor.read(BinaryClassDescriptor.java:829)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1498)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1450)
at org.apache.ignite.internal.binary.BinaryUtils.doReadObject(BinaryUtils.java:1634)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.readObject(BinaryReaderExImpl.java:1124)
at org.apache.ignite.internal.processors.closure.GridClosureProcessor$C4V2.readBinary(GridClosureProcessor.java:2230)
at org.apache.ignite.internal.binary.BinaryClassDescriptor.read(BinaryClassDescriptor.java:819)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1498)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1450)
at org.apache.ignite.internal.binary.GridBinaryMarshaller.deserialize(GridBinaryMarshaller.java:298)
at org.apache.ignite.internal.binary.BinaryMarshaller.unmarshal0(BinaryMarshaller.java:100)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:82)
at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9779)
... 10 more
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8393)
at org.apache.ignite.internal.MarshallerContextAdapter.getClass(MarshallerContextAdapter.java:185)
at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:680)
... 28 more
For using ignite as a cache for cassandra database, at first, it's better to read these documentations:
Ignite With Apache Cassandra
BaseConcepts
Examples
Now, you can run ignite with any nodes you want, but you must consider two things:
first, you must run ignite with the configured xml for cassandra
connection
second, you must add dependent jar files for running
ignite-cassandra
For simple cassandra configuration, you can use this and for generate dependency jar files for your code, you can use maven-dependency-plugin with copy-dependency goal to generate jar files in the dependency folder of your target files.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
After compiling your code, you can add dependency folder to the path of ignite libs or add to the USER_LIBS path. Now, you need to implement your java code. For this, I use the class PersonId and configure it with this xml. [hint: you need to add your project jar file to the ignite path.]
Now, you can run your ignite and after that run your code and see the result.
For using Cassandra as a persistent store you don't need CassandraAdminCredentials cause it's just used for tests. Example configuration you can look at https://apacheignite-mix.readme.io/docs/ignite-with-apache-cassandra and https://apacheignite-mix.readme.io/docs/base-concepts
CassandraAdminCredentials class is only available in Ignite unit tests sources. If you want to use it you should build Ignite from source code. Such way, it will create ignite-cassandra-tests-${project.version}.zip where jar may find jar file containing all the test classes.
I am trying to create a test application that accesses a postgres database using JavaEE and Wildly 9.
So I downloaded Wildfly 9 and followed these instructions to add the driver to it. When I run
/subsystem=datasources:installed-drivers-list
I get
{
"driver-name" => "postgresql-9.4-1201.jdbc41.jar",
"deployment-name" => "postgresql-9.4-1201.jdbc41.jar",
"driver-module-name" => undefined,
"module-slot" => undefined,
"driver-datasource-class-name" => undefined,
"driver-xa-datasource-class-name" => undefined,
"driver-class-name" => "org.postgresql.Driver",
"driver-major-version" => 9,
"driver-minor-version" => 4,
"jdbc-compliant" => false
}
so it seems ok.
I also copied the jar ( postgresql-9.4-1201.jdbc41.jar ) file to the deployment folder in Wildfly.
I added this dependency to my pom.xml:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
and this is my persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="postgres">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/test" />
<property name="hibernate.connection.username" value="test" />
<property name="hibernate.connection.password" value="test" />
<!-- <property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
<property name="hibernate.hbm2ddl.auto" value="update" />-->
</properties>
</persistence-unit>
</persistence>
But overtime I try to run my application I get:
java.lang.ClassNotFoundException: Could not load requested class :
org.postgresql.Driver
What am I missing? I can't find any other procedure to do in order to make it work. I am sitting in this problem for some hours now and I can't see anything else I can do.
edit: I created a data source and it works (so the dependencies are all there, there must be something wrong with the persistence.xml itself). I would rather have it working using the persistence.xml file, due to configurability.
here is my datasource as configured in the standalone.xml
<datasource jta="true" jndi-name="java:/PostgresDS" pool-name="PostgresDS" enabled="true" use-ccm="true">
<connection-url>jdbc:postgresql://localhost:5432/stats</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgresql</driver>
<security>
<user-name>test</user-name>
<password>test</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
</validation>
</datasource>
I have a problem when running arquillian tests against postgres db using tomee.
With all the info on the web I'm still struggling to get the problem solved.
javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: CREDENTIALS
Error Code: -5501
Call: SELECT ID, PASSWORD, USERNAME FROM credentials WHERE (USERNAME = ?)
bind => [phil]
The DB:
Name: registry
Table: credentials
Sits under manually created Schema: postgres
persistence.xml under directory src/main/resources
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="registry" transaction-type="JTA">
<jta-data-source>RegistryDS</jta-data-source>
<non-jta-data-source>UnmanagedRegistryDS</non-jta-data-source>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>za.co.registry.client.login.Credentials</class>
<properties>
<property name="eclipselink.debug" value="OFF"/>
<property name="eclipselink.weaving" value="static"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
<property name="eclipselink.logging.logger" value="DefaultLogger"/>
</properties>
</persistence-unit>
</persistence>
tomee.xml
<Resource id="RegistryDS" type="DataSource">
jdbcDriver=org.postgresql.Driver
jdbcUrl=jdbc:postgresql://127.0.0.1:5432/registry
userName=postgres
password=postgres
JtaManaged=true
</Resource>
<Resource id="UnmanagedRegistryDS" type="DataSource">
jdbcDriver=org.postgresql.Driver
jdbcUrl=jdbc:postgresql://127.0.0.1:5432/registry
userName=postgres
password=postgres
JtaManaged=false
</Resource>
pom.xml extract for arquillian tests
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>arquillian-tomee-embedded</artifactId>
<version>1.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.3.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
arquillian.xml extract
<container qualifier="tomee" default="true">
<configuration>
<property name="httpPort">-1</property>
<property name="stopPort">-1</property>
<property name="dir">target/apache-tomee-remote</property>
<property name="appWorkingDir">target/arquillian-test-working-dir</property>
<property name="properties" />
</configuration>
</container>
The ServiceTest.java file when loading the resources.
#Deployment
public static WebArchive createDeployment() {
WebArchive webArchive = newArchive();
webArchive.addClasses(Credentials.class);
webArchive.addAsResource("META-INF/persistence.xml");
webArchive.addAsResource("META-INF/beans.xml");
return webArchive;
}
And last the test findCredentialsByUsernameTest method in ServiceTest.java
#Test
public void findCredentialsByUsernameTest() {
Credentials login = LoginService.findByUsername("phil");
Assert.assertNotNull(login);
}
I do not start or end any EntityTransaction's in the test class.
It works injecting a EJB when the DB call in the service is removed.
What am I missing in the config or doing wrong for this not to be working?
Ok I think I know what I did wrong.
I need to run the tests against a embedded db.
The steps that I followed to get Arquillian tests to work against a embedded db;
Removed un-managed data source from tomee.xml, I added it because I wanted to use it for my tests. The other data source is still there because it is used when deploying to tomee to connect to postgres db.
<Resource id="UnmanagedRegistryDS" type="DataSource">
jdbcDriver=org.postgresql.Driver
jdbcUrl=jdbc:postgresql://127.0.0.1:5432/registry
userName=postgres
password=postgres
JtaManaged=false
</Resource>
I'm going to connect to HSQLDB.
HSQLDB (HyperSQL DataBase) is the leading SQL relational database software written in Java. It offers a small, fast multithreaded and transactional database engine with in-memory and disk-based tables and supports embedded and server modes
Next I create a second persistence.xml in src/test/resources called test-persistence.xml. Keep in mind the persistence-unit name testDatabase it is going to be used in the arquillian.xml file
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="test" transaction-type="JTA">
<jta-data-source>testDatabase</jta-data-source>
<class>za.co.registry.client.login.Credentials</class>
<properties>
<property name="openejb.jpa.init-entitymanager" value="true" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>
</persistence>
The arquillian.xml, I'm setting the testDatabase persistence unit properties in the file. See below under properties.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="openejb-embedded" default="true">
<configuration>
<property name="httpPort">-1</property>
<property name="stopPort">-1</property>
<property name="dir">target/apache-tomee-remote</property>
<property name="appWorkingDir">target/arquillian-test-working-dir</property>
<property name="properties">
testDatabase = new://Resource?type=DataSource
testDatabase.JdbcUrl = jdbc:hsqldb:mem:my-datasource
</property>
</configuration>
</container>
</arquillian>
Configuring my ServiceTest.java file to include the new persistence.xml file.
webArchive.addAsWebInfResource("META-INF/test-persistence.xml", "persistence.xml");
webArchive.addAsResource("META-INF/beans.xml");
Now I can run the findCredentialsByUsernameTest method.
#Test
public void findCredentialsByUsernameTest() {
//create credentials first
Credentials newCredentials = loginService.newCredentials(new Credentials("john", "password"));
//search for credentails
Credentials login = loginService.findByUsername("john");
Assert.assertNotNull(login);
Assert.assertEquals(newCredentials.getUsername(), login.getUsername());
}