Skip to content

Commit

Permalink
Upgrade project to Java EE 7 (+ TomEE 7 webprofile)
Browse files Browse the repository at this point in the history
- upgrade to TomEE 7.0.2 webprofile
- switch to the Java EE 7 API (TomEE provided)
- add Arquillian BOM
- upgrade to Arquillian 1.1.11.Final
- set Java source/target compatibility to 1.8
- use JAX-RS 2 client API in tests
- add JAX-RS 2 client API and providers to test runtime
- annotate Arquillian test with @RunAsClient
- add JAX-RS application initializer (required for portability)
- upgrade Gradle wrapper to 3.2.1
- fix Gradle build, add Arquillian dependencies
- rename ColorService to ColorResource
- use consistent project name
- exclude version from name of war file generated by Maven
- update instructions in README
- fix AsciiDoc syntax in README
- stub in TomEE remote adapter and configuration for tests
  • Loading branch information
mojavelinux committed Dec 26, 2016
1 parent ed0e971 commit ef92fd2
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 93 deletions.
25 changes: 17 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
# Apache TomEE JAX-RS Starter Project
= Apache TomEE JAX-RS Starter Project
:uri-companion-blog-post: http://www.tomitribe.com/blog/2014/06/apache-tomee-jax-rs-and-arquillian-starter-project/

Know JAX-RS, but haven't yet dug into Apache TomEE? Way too busy or impatient to read documentation? This repo is for you.
Know JAX-RS, but haven't yet dug into Apache TomEE?
Way too busy or impatient to read documentation?
This repo is for you!

The only thing better than a Maven archetype is a repo you can fork with everything already setup. Skip the documentation and just fork-and-code. This starter project contains:
The only thing better than a Maven archetype is a repo you can fork with everything already setup.
That's what you've got here.
Skip the documentation and just fork-and-code.

- 1 JAX-RS class, 1 JAXB class and 1 JUnit/Arquillian test
- Maven pom for building a war file
- Arquillian setup for testing against TomEE JAX-RS Embedded
This starter project contains:

- 1 JAX-RS initiator class, 1 JAX-RS resource class, 1 JAXB class, and 1 Arquillian (JUnit) test
- Maven pom for running tests and building a war file
- Gradle build for running tests and building a war file
- Arquillian setup for testing against TomEE JAX-RS Embedded (or Remote)
- TomEE Maven Plugin for deploying and running our war file

Everything ready-to-run with a simple `maven clean install tomee:run`
Everything ready-to-run with a simple `maven package tomee:run`.
Then access the service at http://localhost:8080/tomee-jaxrs-starter-project/color (or any of the other JAX-RS resource paths).

Delete the sample code, replace with your own and you're good to go.

Have time for some reading and curious on how everything works? [Read here](http://www.tomitribe.com/blog/2014/06/apache-tomee-jax-rs-and-arquillian-starter-project/).
Have time for some reading and curious on how everything works? Study {uri-companion-blog-post}[this blog post].
31 changes: 21 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
apply plugin: 'war'

group = 'org.superbiz'
version = '1.0-SNAPSHOT'
version = '1.0.0-SNAPSHOT'

description = "TomEE JAXRS starter project"

sourceCompatibility = 1.7
targetCompatibility = 1.7
description = "TomEE JAX-RS starter project"

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
testCompile group: 'org.apache.openejb', name: 'arquillian-tomee-embedded', version:'1.7.2'
testCompile group: 'org.apache.openejb', name: 'tomee-jaxrs', version:'1.7.2'
testCompile group: 'junit', name: 'junit', version:'4.12'
providedCompile group: 'org.apache.openejb', name: 'javaee-api', version:'6.0-6'
providedCompile 'org.apache.tomee:javaee-api:7.0-1'
testCompile 'junit:junit:4.12'
testCompile 'org.jboss.arquillian.junit:arquillian-junit-container:1.1.11.Final'
testRuntime 'org.apache.tomee:arquillian-tomee-embedded:7.0.2'
// To use the TomEE remote adapter, enable all remaining dependencies in place of the previous one
//testRuntime 'org.apache.tomee:arquillian-tomee-remote:7.0.2'
//testRuntime 'org.apache.geronimo.specs:geronimo-osgi-locator:1.1'
//testRuntime 'org.apache.cxf:cxf-rt-rs-client:3.1.8'
//testRuntime 'org.apache.johnzon:johnzon-jaxrs:0.9.5'
}

test {
systemProperties = [
'arquillian.launch': 'tomee.embedded'
//'arquillian.launch': 'tomee.remote'
]
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 29 17:40:36 CEST 2015
#Sun Dec 25 02:30:32 MST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

Expand Down
93 changes: 77 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,119 @@

<!-- Change: groupId, artifactId, version -->
<groupId>org.superbiz</groupId>
<artifactId>tomee-rest-arquillian</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>tomee-jaxrs-starter-project</artifactId>
<version>1.0.0-SNAPSHOT</version>

<packaging>war</packaging>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.openejb</groupId>
<groupId>org.apache.tomee</groupId>
<artifactId>javaee-api</artifactId>
<version>${openejb.javaee.api}</version>
<version>${tomee.javaee.api}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<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.apache.tomee</groupId>
<artifactId>arquillian-tomee-embedded</artifactId>
<version>${tomee.version}</version>
<scope>test</scope>
</dependency>
<!-- To use the TomEE remote adapter, enable all remaining dependencies in place of the previous one -->
<!-- NOTE geronimo-osgi-locator required by JAX-RS client from CXF unless JAX-RS client jar proceeds Java EE API jar -->
<!-- NOTE JAX-RS JSON integration must be provided on client side, hence the johnzon dependency -->
<!--
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>tomee-jaxrs</artifactId>
<groupId>org.apache.tomee</groupId>
<artifactId>arquillian-tomee-remote</artifactId>
<version>${tomee.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-osgi-locator</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>${cxf.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jaxrs</artifactId>
<version>${johnzon.version}</version>
<scope>test</scope>
</dependency>
-->
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.openejb.maven</groupId>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>${tomee.version}</version>
<configuration>
<tomeeVersion>${tomee.version}</tomeeVersion>
<tomeeClassifier>jaxrs</tomeeClassifier>
<tomeeClassifier>${tomee.classifier}</tomeeClassifier>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<arquillian.launch>tomee.embedded</arquillian.launch>
<!--
<arquillian.launch>tomee.remote</arquillian.launch>
-->
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<tomee.version>1.7.2</tomee.version>
<openejb.javaee.api>6.0-6</openejb.javaee.api>
<tomee.version>7.0.2</tomee.version>
<tomee.classifier>webprofile</tomee.classifier>
<tomee.javaee.api>7.0-1</tomee.javaee.api>
<cxf.version>3.1.8</cxf.version>
<johnzon.version>0.9.5</johnzon.version>
<arquillian.version>1.1.11.Final</arquillian.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
</project>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'tomee-rest-arquillian'
rootProject.name = 'tomee-jaxrs-starter-project'
24 changes: 24 additions & 0 deletions src/main/java/org/superbiz/ColorApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.superbiz;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

// NOTE The JAX-RS application component is optional in TomEE.
@ApplicationPath("/")
public class ColorApplication extends Application {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.superbiz;

import javax.annotation.PostConstruct;
import javax.ejb.Lock;
import javax.ejb.Singleton;
import javax.ws.rs.GET;
Expand All @@ -31,14 +32,9 @@
@Lock(READ)
@Singleton
@Path("/color")
public class ColorService {

public class ColorResource {
private String color;

public ColorService() {
this.color = "white";
}

@GET
public String getColor() {
return color;
Expand All @@ -57,4 +53,9 @@ public void setColor(@PathParam("color") String color) {
public Color getColorObject() {
return new Color("orange", 0xE7, 0x71, 0x00);
}

@PostConstruct
public void init() {
this.color = "white";
}
}
Loading

0 comments on commit ef92fd2

Please sign in to comment.