Infinispan configuration with Wilfdfly-Swarm - java-ee-7

I have a project on Wildfly-Swarm. I need to use query cache, so I put Infinispan dependency on my POM.
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>infinispan</artifactId>
</dependency>
I setup Infinispan on my persistence.xml
<persistence-unit name="Condominio" transaction-type="JTA">
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.infinispan.entity.expiration.max_idle" value="300000"/>
...
<properties>
</persistence-unit>
It's work well, the cache works. But I read the documentation of Infinispan Wildfly-Swarm fraction (https://reference.wildfly-swarm.io/fractions/infinispan.html) and I was in doubt if should setup it on project-defaults.yml using those configurations.
I don't know which configurations of Infinispan Wildfly-Swarm fraction are equivalents to persistence.xml configurations.

Related

How to make Log4j2 configurable by environment using Spring Boot 1.3.6.RELEASE

I would like to change some properties from the log4j2.xml file depending on the my application.properties, for example define some properties and then substitute in the log4j2 those properties that are parameters.
I ran different approaches but I still did not get the right thing. I would like to have different configs depending on the environment (DEV, QA or PROD). How to accomplish this?
I'm trying to have this in my properties
#Place holders for log4j2.xml file
log.file.path=/opt/tomcat/logs
log.file.name=dummydummy
log.file.size=100 MB
log.level=DEBUG
My log4j2 below.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Properties>
<Property name="PID">????</Property>
<property name="name">my-log</property>
</Properties>
<Appenders>
<RollingFile name="file" fileName="${log.file.path}${log.file}.log"
filePattern="${log.file.path}${log.file}-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${sys:PID} --- [%t] %c{1}(%M:%L) : %m%n%wEx" />
<Policies>
<TimeBasedTriggeringPolicy /><!-- Rotated everyday -->
<SizeBasedTriggeringPolicy size="${log.file.size}" /> <!-- Or every 100 MB -->
</Policies>
</RollingFile>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout
pattern="%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%t]}{faint} %clr{%c{1}(%M:%L)}{cyan} %clr{:}{faint} %m%n%wEx" />
</Console>
</Appenders>
<Loggers>
<Logger name="org.hibernate.validator.internal.util.Version"
level="warn" />
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
<Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
<Logger name="org.springframework.web" level="error" />
<Root level="${log.level}">
<AppenderRef ref="Console" />
<AppenderRef ref="file" />
</Root>
</Loggers>
</Configuration>
The properties lookup element allows to refer properties from an external properties file in the log4j configuration.
For your example it should be something like this:
A file env.properties contains the following properties:
log.file.path=/opt/tomcat/logs
log.file.name=dummydummy
log.file.size=100 MB
log.level=DEBUG
The properties lookup should be defined as properties of the log4j2.xml:
<Configuration>
<Properties>
<property name="log.file.path">${bundle:env:log.file.path}</property>
<property name="log.file.name">${bundle:env:log.file.name}</property>
<property name="log.file.size">${bundle:env:log.file.size}</property>
<property name="log.level">${bundle:env:log.level}</property>
</Properties>
Now the properties may be referred in appenders with ${property_name} notation. Each property reference will be interpolated with the real value from the env.properties.
You can find another example of properties lookup here.
As of Log4j 2.13.0 Log4j 2 now provides a Spring Lookup as part of its Spring Cloud Config support. It will allow you to reference properties defined in your application.properties or application.yml file of your Spring Boot application in the log4j2.xml.
Since log4j 2.14.0, you can now use Spring Boot environment variables without Spring Cloud and without doing direct reference to the properties file. You'll need at least Spring Boot 2.0.3
<property name="applicationName">${spring:spring.application.name}</property>
Documentation: https://logging.apache.org/log4j/2.x/log4j-spring-boot/index.html
Maven repository: https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-spring-boot
Ensure that log4j2 starter is added in the classpath and then remove logging related properties in application.properties then spring will load your log4j2.xml from resources folder.
This way you can have full control over logging. If you want to substitute values then refer this link
Note:: If you have actuator in your project then remove spring boot logger starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
Workaround in case you need just different property values in log4j2.xml config for different spring profiles (dev, test, prod, etc.).
You could access spring profile files like: ${bundle:application-${sys:spring.profiles.active}:log.file.name}
application-dev.properties file:
log.file.name=dev_log
application-prod.properties file:
log.file.name=app_name
log4j2.xml config:
<Configuration>
<Properties>
<Property name="file_name">${bundle:application-${sys:spring.profiles.active}:log.file.name}</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile"
fileName="/logs/${file_name}.log"
...
NOTE: You have to add log.file.name property to each spring profile, log4j2 sees it just as separate text files and will not resolve default values from application.properties file and etc.

Using Arquillian Drone with Selenium Grid

I have created a suite of functional UI tests for my web based application using Arquillian Done which I would like to run on a Selenium Grid as opposed to running them locally.
The problem I've got that despite setting the host/port details for the Selenium hub server in the arquillian.xml file, the UI tests are executed locally rather than on one of the Selenium nodes. I've even tried entering the details for a host that doesn't exist but the tests are still run locally and there are no error messages generated. It appears as though Drone is ignoring the configuration in the arquillian.xml file.
Is there something wrong with my configuration in the arquillian.xml file, or is there something else I'm doing wrong? Unfortunately there seems to be very little documentation on using Arquillian Drone with Selenium Grid.
The content of the arquillian.xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/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">
<extension qualifier="webdriver">
<property name="browser">${arquillian.browser}</property>
<property name="remoteAddress">http://selenium-hub:4444</property>
</extension>
<extension qualifier="selenium-server">
<property name="host">selenium-hub</property>
<property name="port">4444</property>
<property name="skip">true</property>
</extension>
<container qualifier="arquillian-glassfish-remote">
<configuration>
...
</configuration>
</container>
</arquillian>
My Maven pom.xml file contains the following dependency and dependencyManagement sections:
<dependencies>
<!-- Various Java EE and Internal Dependencies -->
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver</artifactId>
<version>2.0.3.Final</version>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.8.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.selenium</groupId>
<artifactId>selenium-bom</artifactId>
<version>2.46.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-drone-bom</artifactId>
<version>1.3.1.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
It appears there were two issues preventing the Arquillian Drone tests being executed against a Selenium Grid.
The first issue is that the webdriver section of the arquillian.xml file needs to include either <property name="remote">true</property> or <property name="remoteReusable">true</property> in addition to the remoteAddress property. Without either the remote or remoteReusable then the tests will be run locally.
The second issue was that the remoteAddress did not contain the full URL for the Selenium Grid hub server. The property should be set to <property name="remoteAddress">http://selenium-hub:4444/wd/hub</property>. Obviously selenium-hub needs to be set to the hostname of your Selenium hub server. What through me was accessing this URL via a browser returned a NullPointerException however this appears to be normal behaviour as there are other parameters set when the URL is accessed correctly.
In addition the selenium-server section of the arquillian.xml file appears to be unnecessary.

Deploy web app include testing in Glassfish using Maven2

Recently, I have used Eclipse and Oracle Glassfish server plugin to deploy my webapplications on the server.
However, I would like to do it in batch mode using Maven 2 and also do some testing before deploying.
I would like to do following tasks:
Get required dependencies (if any) from any repository (which shall I use?).
Run unit tests
If tests successful, deploy it
I am running Maven 2 and Glassfish 3.2.1
Can you support me with some example project including pom.xml file? Is there any knowledge resource for this kind of things?
Best regards
The process you describes is very common.
Indeed, maven itselft will
A Build Lifecycle is Made Up of Phases
Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.
For example, the default lifecycle has the following build phases (for a complete list of the build phases, refer to the Lifecycle Reference):
validate - validate the project is correct and all necessary information is available
compile - compile the source code of the project
test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package - take the compiled code and package it in its distributable format, such as a JAR.
integration-test - process and deploy the package if necessary into an environment where integration tests can be run
verify - run any checks to verify the package is valid and meets quality criteria
install - install the package into the local repository, for use as a dependency in other projects locally
deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
These build phases (plus the other build phases not shown here) are executed sequentially to complete the default lifecycle. Given the build phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the package, install the verifed package to the local repository, then deploy the installed package in a specified environment.
To do all those, you only need to call the last build phase to be executed, in this case, deploy:
mvn deploy
You should use the maven glassfish plugin, and then execute
mvn glassfish:deploy
Here the full ewample from the official documentation :
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.1</version>
<configuration>
<glassfishDirectory>${glassfish.home}</glassfishDirectory>
<user>${domain.username}</user>
<adminPassword>${domain.password}</adminPassword>
<!-- <passFile>path/to/asadmin/passfile</passFile> -->
<autoCreate>true</autoCreate>
<debug>true</debug>
<echo>false</echo>
<terse>true</terse>
<skip>${test.int.skip}</skip>
<domain>
<name>${project.artifactId}</name>
<adminPort>4848</adminPort>
<httpPort>8080</httpPort>
<httpsPort>8443</httpsPort>
<iiopPort>3700</iiopPort>
<jmsPort>7676</jmsPort>
<reuse>false</reuse>
<jvmOptions>
<option>-Djava.security.auth.login.config=${project.build.testOutputDirectory}/login.conf</option>
</jvmOptions>
<properties>
<property>
<name>server.log-service.file</name>
<value>${domain.log.dir}/server.log</value>
</property>
</properties>
<auth>
<realm>
<name>testRealm</name>
<className>com.sun.enterprise.security.auth.realm.file.FileRealm</className>
<properties>
<property>
<name>jaas-context</name>
<value>test</value>
</property>
<property>
<name>file</name>
<value>${project.build.outputDirectory}/keyfile</value>
</property>
</properties>
</realm>
</auth>
<!-- <resourceDescriptor>path/to/resources.xml</resourceDescriptor> -->
<resources>
<connectionFactory>
<jndiName>jms/testQueueConnectionFactory</jndiName>
<type>queueConnectionFactory</type>
<properties>
<property>
<name>UserName</name>
<value>guest</value>
</property>
<property>
<name>Password</name>
<value>guest</value>
</property>
<property>
<name>AddressList</name>
<value>localhost:7676</value>
</property>
</properties>
</connectionFactory>
<jmsTopic>
<jndiName>jms/testTopic</jndiName>
<destinationName>TestTopic</destinationName>
<connectionFactory>
<jndiName>jms/testTopicConnectionFactory</jndiName>
<properties>
<property>
<name>UserName</name>
<value>guest</value>
</property>
<property>
<name>Password</name>
<value>guest</value>
</property>
<property>
<name>AddressList</name>
<value>localhost:7676</value>
</property>
</properties>
</connectionFactory>
</jmsTopic>
<jdbcDataSource>
<name>SomeDS</name>
<type>connectionPoolDataSource</type>
<poolName>SomePool</poolName>
<className>com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</className>
<description>Some JDBC Connection Pool</description>
<allowNonComponentCallers>false</allowNonComponentCallers>
<validateConnections>true</validateConnections>
<validationMethod>metaData</validationMethod>
<properties>
<property>
<name>portNumber</name>
<value>3306</value>
</property>
<property>
<name>password</name>
<value>somePassword</value>
</property>
<property>
<name>user</name>
<value>someUser</value>
</property>
<property>
<name>serverName</name>
<value>some.host.somewhere</value>
</property>
<property>
<name>databaseName</name>
<value>SomeDB</value>
</property>
</properties>
</jdbcDataSource>
</resources>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>${project.build.directory}/artifacts/${project.build.finalName}.war</artifact>
</component>
</components>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
</project>
I'm assuming you mean GlassFish Server 3.1.2 :-)
Using Maven with GlassFish documentation is covered in the Embedded Server Guide:
http://docs.oracle.com/cd/E26576_01/doc.312/e24932/embedded-server-guide.htm#gijhs
Hope this helps.

Use of arquillian glassfish container

I used to have the following maven dependencies to use arquillian glassfish container:
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<scope>test</scope>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
I was able to run my tests successfully until I wanted to inject specific resources, that could not be looked up through JNDI.
I improved my domain.xml to have the relevant resources I wanted. But for now, I am not sure arquillian load successfully all the domain.xml (look up failed on "jca/Neo4j/resource").
My arquillian.xml (in src/test/resources):
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.com/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:glassfish="urn:arq:org.jboss.arquillian.container.glassfish.embedded_3">
<glassfish:container>
<glassfish:instanceRoot>src/test/resources/glassfish</glassfish:instanceRoot>
<glassfish:bindPort>9090</glassfish:bindPort>
<glassfish:autoDelete>false</glassfish:autoDelete>
</glassfish:container>
My domain.xml (in src/test/resources/glassfish/config/):
<domain log-root="${com.sun.aas.instanceRoot}/logs" applicationroot="${com.sun.aas.instanceRoot}/applications" version="10.0">
<resources>
<connector-connection-pool name="jca/Neo4j/pool" resource-adapter-name="neo4j-connector-0.1-SNAPSHOT" connection-definition-name="com.netoprise.neo4j.connection.Neo4JConnectionFactory">
<property name="dir" value="${com.sun.aas.instanceRoot}/lib/databases/neo4j"></property>
<property name="xa" value="true"></property>
</connector-connection-pool>
<connector-resource pool-name="jca/Neo4j/pool" jndi-name="jca/Neo4j/resource"></connector-resource>
</resources>
<servers>
<server name="server" config-ref="server-config">
<application-ref ref="neo4j-connector-0.1-SNAPSHOT" virtual-servers="server"></application-ref>
<resource-ref ref="jca/Neo4j/resource"></resource-ref>
</server>
</servers>
...
</domain>
Thanks,
Alex
The Alpha5 was a bit hard to handle :)
Stuff changed a bit and if you like to give the latest 1.0.0.Final-SNAPSHOT a try, you could have a more detailed look at a configuration here:
http://blog.eisele.net/2012/01/arquillian-with-netbeans-glassfish.html
Thanks,
M

using maven variables defined in two separate profiles

I have two profiles in my pom.xml, dev and stage:
<profiles>
<profile>
<id>dev</id>
<properties>
<hostname>vl-wlp1.hk.oracle.com</hostname>
</properties>
<id>stage</id>
<properties>
<hostname>vl-wcfs.hk.oracle.com</hostname>
</properties>
</profile>
</profiles>
And I'd like use these in my site documentation at:
src/site/apt/index.apt
like so:
Dev Site: ${dev.hostname}
Stage Site: ${stage.hostname}
Can I do that or something else that has the same effect?
Not without a huge hack, no.
If you want to read both property values independently, they will have to be two different properties.
How about a pragmatic solution like this:
<properties>
<dev.host>vl-wlp1.hk.oracle.com</dev.host>
<stage.host>vl-wcfs.hk.oracle.com</stage.host>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<hostname>${dev.host}</hostname>
</properties>
<id>stage</id>
<properties>
<hostname>${stage.host}</hostname>
</properties>
</profile>
</profiles>
src/site/apt/index.apt:
Dev Site: ${dev.host}
Stage Site: ${stage.host}
(The huge hack mentioned above would mean programmatically iterating over the current project's profiles and parsing each profile's properties manually, you could do that in a custom maven plugin or in a Groovy Script using GMaven)