Terracotta and shiro - shiro

I want to use terracotta + Shiro in order to implement SSO. When I try to test it, I have the error:
The configuration data in the base configuration from server at 'localhost:9510' does not obey the Terracotta schema:
[0]: Line 4, column 5: Expected elements 'tc-properties servers clients' instead of 'system' here in element tc-config#http://www.terracotta.org/config
[1]: Line 16, column 13: Expected elements 'offheap authentication http-authentication data-backup tsa-port jmx-port tsa-group-port security' instead of 'statistics' here in element server
[2]: Line 19, column 13: Expected elements 'offheap authentication http-authentication data-backup tsa-port jmx-port tsa-group-port security' instead of 'dso-port' here in element server
[3]: Line 21, column 13: Expected elements 'offheap authentication http-authentication data-backup tsa-port tsa-group-port security' instead of 'l2-group-port' here in element server
[4]: Line 32, column 13: Expected elements 'offheap http-authentication data-backup tsa-port tsa-group-port security' instead of 'dso' here in element server
[5]: Line 50, column 9: Expected elements 'server mirror-group update-check garbage-collection restartable client-reconnect-window' instead of 'mirror-groups' here in element servers
[6]: Line 63, column 9: Expected elements 'server mirror-group update-check garbage-collection restartable client-reconnect-window' instead of 'ha' here in element servers
[7]: Line 86, column 5: Element not allowed: application in element tc-config#http://www.terracotta.org/config
Could anyone helps me to find what's wrong?
Here is my configuration:
ehcache.xml on the tc client:
<ehcache name="Plugin_Ehcache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false" monitoring="autodetect"
dynamicConfig="false">
<diskStore path="java.io.tmpdir/shiro-ehcache"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120">
<terracotta/>
</defaultCache>
<cache name="shiro-activeSessionCache"
maxElementsInMemory="10000"
eternal="true"
timeToLiveSeconds="0"
timeToIdleSeconds="0"
diskPersistent="false"
overflowToDisk="false"
diskExpiryThreadIntervalSeconds="600">
<terracotta/>
</cache>
<terracottaConfig url="localhost:9510"/>
</ehcache>
tc-config.xml on the tc server
<tc:tc-config xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-8.xsd"
xmlns:tc="http://www.terracotta.org/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tc-properties>
<property name="l2.l1reconnect.enabled" value="true"/>
<property name="l2.l1reconnect.timeout.millis" value="5000"/>
<property name="sigar.enabled" value="false"/>
<property name="search.use.commit.thread" value="false"/>
<property name="search.lucene.use.ram.directory" value="true"/>
<property name="search.query.wait.for.txns" value="false"/>
<property name="logging.maxLogFileSize" value="100"/>
<property name="logging.maxBackups" value="10"/>
</tc-properties>
<system>
<configuration-model>development</configuration-model>
</system>
<servers>
<server host="localhost" name="Terracotta Server1">
<!-- Specify the path where the server should store its data. -->
<data>C:\Program Files\Terracotta\terracotta-3.7.5\server\server-data</data>
<logs>C:\Program Files\Terracotta\terracotta-3.7.5\server\server-logs</logs>
<index>C:\Program Files\Terracotta\terracotta-3.7.5\server\server-index</index>
<statistics>C:\Program Files\Terracotta\terracotta-3.7.5\server\server-statistics</statistics>
<!-- Specify the port where the server should listen for client
traffic. -->
<dso-port bind="127.0.0.1">9510</dso-port>
<jmx-port bind="127.0.0.1">9520</jmx-port>
<l2-group-port bind="localhost">9530</l2-group-port>
<!--jmx-port bind="xxx.xxx.xxx.xxx">9520</jmx-port>
<tsa-port>9510</tsa-port>
<tsa-group-port>9530</tsa-group-port-->
<!-- Enable BigMemory on the server. -->
<!--offheap>
<enabled>true</enabled>
<maxDataSize>4g</maxDataSize>
</offheap-->
<authentication/>
<dso>
<client-reconnect-window>120</client-reconnect-window>
<persistence>
<mode>permanent-store</mode>
<!--mode>temporary-swap-only</mode-->
<!--<offheap>
<enabled>false</enabled>
<maxDataSize>450m</maxDataSize>
</offheap>-->
</persistence>
<garbage-collection>
<enabled>true</enabled>
<verbose>false</verbose>
<interval>300</interval>
</garbage-collection>
</dso>
</server>
<mirror-groups>
<mirror-group group-name="group1">
<members>
<member>Terracotta Server1</member>
</members>
<ha>
<mode>networked-active-passive</mode>
<networked-active-passive>
<election-time>5</election-time>
</networked-active-passive>
</ha>
</mirror-group>
</mirror-groups>
<ha>
<mode>networked-active-passive</mode>
<networked-active-passive>
<election-time>5</election-time>
</networked-active-passive>
</ha>
<update-check>
<enabled>false</enabled>
</update-check>
<!-- Add the restartable element for Fast Restartability (optional). -->
<!--restartable enabled="true"/-->
</servers>
<clients>
<logs>logs-%i</logs>
</clients>
</tc:tc-config>

Which version of Terracotta libraries are you using ? The tc-config.xml has some updated tags in 4.x version onwards. Please make sure the tc-config and ehcache xml obeys the schema.
Cheers,
Ridhav

I saw you tried to use the mirror-group tag in your tc config, but it seems you misplaced it.
For example, this config should work :
<?xml version="1.0" encoding="UTF-8" ?>
<tc:tc-config xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-8.xsd"
xmlns:tc="http://www.terracotta.org/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tc-properties>
<property name="l2.l1reconnect.enabled" value="true"/>
<property name="l2.l1reconnect.timeout.millis" value="5000"/>
<property name="sigar.enabled" value="false"/>
<property name="search.use.commit.thread" value="false"/>
<property name="search.lucene.use.ram.directory" value="true"/>
<property name="search.query.wait.for.txns" value="false"/>
<property name="logging.maxLogFileSize" value="100"/>
<property name="logging.maxBackups" value="10"/>
</tc-properties>
<servers>
<mirror-group group-name="group1">
<server host="localhost" name="Terracotta Server1">
<!-- Specify the path where the server should store its data. -->
<data>C:\Program Files\Terracotta\terracotta-3.7.5\server\server-data</data>
<logs>C:\Program Files\Terracotta\terracotta-3.7.5\server\server-logs</logs>
<index>C:\Program Files\Terracotta\terracotta-3.7.5\server\server-index</index>
<!--<statistics>C:\Program Files\Terracotta\terracotta-3.7.5\server\server-statistics</statistics>-->
<!-- Specify the port where the server should listen for client
traffic. -->
<tsa-port>9510</tsa-port>
<jmx-port>9520</jmx-port>
<tsa-group-port>9530</tsa-group-port>
<authentication/>
</server>
</mirror-group>
<update-check>
<enabled>false</enabled>
</update-check>
<!-- Add the restartable element for Fast Restartability (optional). -->
<!--restartable enabled="true"/-->
</servers>
<clients>
<logs>logs-%i</logs>
</clients>
</tc:tc-config>

Take a look at this line that defines the schema used to construct your xml configuration file:
<tc:tc-config xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-8.xsd
Enter the address provided and take a look at how nested xml elements and attributes are allowed to be used.
For instance, element dso-port is allowed in terracotta-6.xsd and terracotta-7.xsd, but not in the terracotta-8.xsd, which is the one you declared.
By the way, depending on the version of terracotta server you use, the appropriate xml schema should be declared due to element incompatibilities.

Related

How to specify character encoding for h2 in memory database scripts?

I have troubles with character encoding in my JPA test class.
In my h2 in memory database I have this insert query :
INSERT INTO MYTABLE (ID,FIELD1,FIELD2) VALUES (100,'ABC','Réclamation');
(please notice the "é" character in "Réclamation")
In my JUnit Test, I try to assert that the value of FIELD2 column is equal to "Réclamation" (which is the case as you can see)
But it fails with the following error :
org.junit.ComparisonFailure: expected:R[é]clamation but
was: R[�]clamation
I wonder if there is a way to specify character encoding in persistence.xml file (maybe ? or somewhere else)
Here is my persistence.xml test file :
<?xml version="1.0" encoding="UTF-8"?>
<persistence
version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="myTestPU">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.myproject.myclass1</class>
<class>com.myproject.myclass2</class>
<properties>
<property
name="javax.persistence.schema-generation.database.action"
value="none" />
<property
name="javax.persistence.sharedCache.mode"
value="ENABLE_SELECTIVE" />
<property
name="javax.persistence.jdbc.url"
value="jdbc:h2:mem:test;INIT=RUNSCRIPT FROM 'classpath:ddl/schema.sql'\;RUNSCRIPT FROM 'classpath:ddl/data.sql'" />
<property
name="javax.persistence.jdbc.driver"
value="org.h2.Driver" />
<property
name="hibernate.dialect"
value="org.hibernate.dialect.H2Dialect" />
<property
name="hibernate.show_sql"
value="true" />
<property
name="hibernate.format_sql"
value="true" />
</properties>
</persistence-unit>
</persistence>
I've already tried these solutions :
adding the following properties in persistence.xml test file :
<property
name="hibernate.connection.characterEncoding"
value="utf8" />
<property
name="hibernate.connection.useUnicode"
value="true" />
<property
name="hibernate.connection.charSet"
value="UTF-8" />
adding ?useUnicode=yes&characterEncoding=UTF-8 in my URL property
None of them worked for me...
NB : I don't use spring framework in my application
I had my insert queries in an import.sql file and those values were encoded incorrectly.
Adding the property
<property name="hibernate.hbm2ddl.charset_name" value="UTF-8" />
fixed it for me.
If you have an older version of hibernate (pre 5.2.3 apparently), maybe try the other solutions in this thread:
Hibernate/JPA import.sql utf8 characters corrupted

JPA 2.0 Ehcache configuration for L2 cache throwing Error

I am trying to configure Ehcache for JPA 2.0.
first i have setup following into persistance.xml
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
I have ehcache.xml in my class path.
configure #Cacheable(true) to my #Entity class.
I am getting following error.
net.sf.ehcache.config.InvalidConfigurationException: There is one error in your configuration:
* Cache 'net.sf.ehcache.constructs.asynchronous.MessageCache' error: If your CacheManager has no maxBytesLocalHeap set, you need to either set maxEntriesLocalHeap or maxBytesLocalHeap at the Cache level
ehcache.xml
<?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">
<!-- By default, Ehcache stored the cached files in temp folder. -->
<!-- <diskStore path="java.io.tmpdir" /> -->
<!-- Ask Ehcache to store cache in this path -->
<diskStore path="c:\\cache" />
<!-- Sample cache named cache1
This cache contains a maximum in memory of 10000 elements, and will expire
an element if it is idle for more than 5 minutes and lives for more than
10 minutes.
If there are more than 10000 elements it will overflow to the
disk cache, which in this configuration will go to wherever java.io.tmp is
defined on your system. On a standard Linux system this will be /tmp" -->
<Cache name = "com.test.myDataDE"
maxEntriesLocalHeap="10000"
maxEntriesLocalDisk="1000"
eternal="false"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
<persistence strategy="localTempSwap" />
</Cache>
</ehcache>
Please help me understand any mistake I am doing?
I had the same problem today, solved it by adding:
maxBytesLocalHeap="100M"
and removing:
maxEntriesLocalHeap
in my ehcache.xml configuration.
Without your ehcache.xml content, it is hard to be definitive.
However, given the error message, I believe the issue is that you did not specify a heap size to your cache, either in entries or in bytes.

Access to Derby database from another project using EclipseLink

I have a dynamic web project that creates and writes Derby database. Everything works fine. Here is the persistence.xml I used:
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="alerts" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>test.Alert</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:databases/bDb;create=true" />
<property name="javax.persistence.jdbc.user" value="user" />
<property name="javax.persistence.jdbc.password" value="user-pwd" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.logging.level.sql" value="FINEST" />
</properties>
</persistence-unit>
Now I would like to create a java project that reads the same database. So I use the same persistence.xml (except that I change "create=true" to "create=false" since I don't want to create a new table). but I got this error:
[EL Severe]: ejb: 2014-12-28 22:27:20.379--ServerSession(1488953836)--Thread(Thread[DefaultQuartzScheduler_Worker-7,5,main])--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Database 'databases/bDb' not found.
Error Code: 40000
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:326)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:138)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
If I use "create=true", it will create a new database instance (it is different from the one I created from the web project). How do I fix this problem? Thanks a lot!
Since you're using a relative filename in your jdbc.url (databases/bDb), Derby is looking for the database relative to your application start directory.
And your two separate applications have two separate directories in which they are being run.
You could address this in a number of ways:
Arrange for each application to be run from the same directory
Use an absolute database path name, not a relative one, in your jdb.url value
Use the Derby Network Server configuration, not the Derby Embedded configuration
And there are undoubtedly other approaches.

Mybatis caching and concurrent modfications

I am using mybatis 3.0.4 for a test against a mysql 5.5 database with mysql-connector JDBC driver, version 5.1.16.
The problem I am experiencing is that if I get a SqlSession via openSession() method and i retrieve data via a select from database, subsequent selects in same session are not aware of changes made (and committed) to database even if i call clearCache() on session. To concurrently modify database I am using Mysql command line client. Setting cacheEnabled as false in configuration file doesn't help too.
I enclose configuration file.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
<settings>
<setting name="lazyLoadingEnabled" value="false"/>
<setting name="cacheEnabled" value="false"/>
</settings>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="poolMaximumIdleConnections" value="20"></property>
<property name="poolMaximumActiveConnections" value="80"></property>
<property name="poolMaximumCheckoutTime" value="600"></property>
<property name="poolTimeToWait" value="600"></property>
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/testdb"/>
<property name="username" value="root"/>
<property name="password" value="password"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mappers/TestMapper.xml" />
</mappers>
</configuration>
Ok, solved by myself. It was not a mybatis issue, it depended on Transaction isolation on JDBC driver, which was by default TRANSACTION_REPEATABLE_READ, I needed TRANSACTION_READ_COMMITTED instead. Solved with:
getSessionFactory().openSession(TransactionIsolationLevel.READ_COMMITTED);

Configure the mail-service.xml in JBoss with a Gmail account

I want to configure my mail-service.xml to send emails from my Gmail account. I have made a configuration, but it doesn't work
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.mail.MailService"
name="jboss:service=Mail">
<attribute name="JNDIName">java:/Mail</attribute>
<attribute name="User">***#gmail.com</attribute>
<attribute name="Password">***</attribute>
<attribute name="Configuration">
<configuration>
<property name="mail.smtp.auth" value="true"/>
<property name="mail.smtp.starttls.enable" value="true"/>
<property name="mail.smtp.socketFactory.class" value="javax.net.ssl.SSLSocketFactory"/>
<!-- Change to your mail server prototocol -->
<property name="mail.store.protocol" value="pop3"/>
<property name="mail.transport.protocol" value="smtp"/>
<!-- Change to the user who will receive mail -->
<property name="mail.user" value="nobody"/>
<!-- Change to the mail server -->
<property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/>
<!-- Change to the SMTP gateway server -->
<property name="mail.smtp.host" value="smtp.gmail.com"/>
<!-- The mail server port -->
<property name="mail.smtp.port" value="465"/>
<!-- Change to the address mail will be from -->
<property name="mail.from" value="nobody#nosuchhost.nosuchdomain.com"/>
<!-- Enable debugging output from the javamail classes -->
<property name="mail.debug" value="false"/>
</configuration>
</attribute>
<depends>jboss:service=Naming</depends>
</mbean>
</server>
I struggled with this too, but eventually got it working. I wrote up what I did here:
http://mrmcgeek.blogspot.com/2010/09/confguring-java-mail-with-jboss-as-5.html
You need to add the following to the mail-service.xml:
<property name="mail.smtp.user" value="${username}#gmail.com" />
<property name="mail.smtp.password" value="${password}" />
<property name="mail.smtp.ssl.enable" value="true" />
You didn't set the host properly.Try this one
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: mail-service.xml 62350 2007-04-15 16:50:12Z dimitris#jboss.org $ -->
<server>
<mbean code="org.jboss.mail.MailService"
name="jboss:service=Mail">
<attribute name="JNDIName">java:/Mail</attribute>
<attribute name="User">type sender mail id here</attribute>
<attribute name="Password">type password</attribute>
<attribute name="Configuration">
<!-- A test configuration -->
<configuration>
<property name="mail.smtp.auth" value="true"/>
<property name="mail.smtp.starttls.enable" value="true"/>
<property name="mail.smtp.socketFactory.class" value="javax.net.ssl.SSLSocketFactory"/>
<!-- Change to your mail server prototocol -->
<property name="mail.store.protocol" value="pop3"/>
<property name="mail.transport.protocol" value="smtp"/>
<!-- Change to the user who will receive mail -->
<property name="mail.user" value="nobody"/>
<!-- Change to the SMTP gateway server -->
<property name="mail.smtp.host" value="smtp.gmail.com"/>
<!-- The mail server port -->
<property name="mail.smtp.port" value="465"/>
<!-- Change to the address mail will be from -->
<property name="mail.from" value=""/>
<!-- Enable debugging output from the javamail classes -->
<property name="mail.debug" value="false"/>
</configuration>
</attribute>
<depends>jboss:service=Naming</depends>
</mbean>
</server>