Question

I use Maven Cargo (1.2.1) to configure and start an Glassfish 3.1.2 for Integration Tests. I am able to configure the datasource and start the server. But I also need to configure a JDBC Security Realm as well as a Java Mail Session.

But I have no clue how to configure a Security Realm and Java Mail Session with maven cargo, does anybody has an idea?

One way maybe is to use asadmin but I don't know how to use it from cargo.

What I have so far:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>start-container</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-container</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <container>
            <type>installed</type>
            <containerId>glassfish3x</containerId>
            <artifactInstaller>
                <groupId>org.glassfish.main.distributions</groupId>
                <artifactId>glassfish</artifactId>
                <version>3.1.2</version>
                <type>zip</type>
            </artifactInstaller>
            <output>${project.build.directory}/glassfish/container.log</output>
            <log>${project.build.directory}/glassfish/cargo.log</log>
            <append>false</append>
            <dependencies>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc</artifactId>
                </dependency>
            </dependencies>
        </container>
        <configuration>
            <home>${project.build.directory}/cargo/configurations/glassfish</home>
            <properties>
                <cargo.servlet.port>8082</cargo.servlet.port>
                <cargo.datasource.datasource>
                    cargo.datasource.jndi=jdbc/tecisplus|
                    cargo.datasource.type=javax.sql.DataSource|
                    cargo.datasource.driver=oracle.jdbc.OracleDriver|
                    cargo.datasource.url=${it-database.url}|
                    cargo.datasource.username=$[it-database.username}|
                    cargo.datasource.password=${it-database.password}
                </cargo.datasource.datasource>
            </properties>
            <deployables>
                <deployable>
                    <groupId>de.test</groupId>
                    <artifactId>test-ear</artifactId>
                    <type>ear</type>
                </deployable>
            </deployables>
        </configuration>
    </configuration>
</plugin>
Was it helpful?

Solution

The workaround I use at the moment it so have a hand written domain.xml file that already contains all the configuration (JDBC, Realm and JavaMail Session).

Then I instructed cargo to use that domain.xml instead of doing own configuration:

<configuration>
    <home>${project.build.directory}/cargo/configurations/glassfish</home>
    <configfiles>
        <configfile>
            <file>${project.build.directory}/filtered-serverresources/domain.xml</file>
            <todir>cargo-domain/config</todir>
        </configfile>
    </configfiles>
    <deployables>
        <deployable>
            <groupId>de.tecis.tecisplus</groupId>
            <artifactId>tecisplus-ear</artifactId>
            <type>ear</type>
        </deployable>
    </deployables>
</configuration>

the ${project.build.directory}/filtered-serverresources/domain.xml is a small trick to configure the file (cargo can also replace some properties, but I was not able to replace the properties that cargo not knows.) So I use the maven-resource-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <!-- because maven test-resource does not support filter! -->
    <version>2.5</version>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
    <executions>
        <execution>
            <id>filter-glassfish-configuration-domain-file</id>
            <!-- <phase>pre-integration-test</phase> -->
            <phase>process-test-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/filtered-serverresources</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/test/serverresources</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*.xml</include>
                        </includes>
                    </resource>
                </resources>
                <delimiters>
                    <delimiter>~{*}</delimiter>
                </delimiters>
            </configuration>
        </execution>
    </executions>
</plugin>

The modified delimiter ~{ ... } are nesseary because the domain.xml contains a lot of sequences that looks like the default delimiter ${...}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top