Permalink
Browse files

Updated pom.xml & README.md, as well as some minor cleanup and slight…

…ly more error checking in the EJB.
  • Loading branch information...
1 parent 2b8d0de commit 1185660edb1024b68a4671f88f38319f85afcda4 @snowolfe committed Apr 16, 2012
View
89 temperature-converter/README.md
@@ -1,4 +1,4 @@
-temperature-converter-slsb: Stateless Session EJB
+temperature-converter: Stateless Session EJB
=================================================
Author: Bruce Wolfe
@@ -10,77 +10,74 @@ Deployment occurs via a war archive for deployment to *JBoss AS 7*.
These are the steps that occur:
-1. A JSF page asks the user for a temperature and scale.
-2. On clicking convert, the temperature string is handed to the TemperatureConverter controller (managed) bean.
-3. This then invokes the TemperatureConvertEJB, which was injected to the managed bean (notice the field annotated with @Inject).
-4. The response from invoking the TemperatureConvertEJB is stored in a field (temperature) of the managed bean.
+1. The user interface is a JSF page that asks for a temperature and a scale (Fahrenheit or Celsius).
+2. When you click on `Convert`, the temperature string is passed to the TemperatureConverter controller (managed) bean.
+3. The managed bean then invokes the `convert()` method of the injected TemperatureConvertEJB (notice the field annotated with @Inject).
+4. The response from TemperatureConvertEJB is stored in the `temperature` field of the managed bean.
5. The managed bean is annotated as @SessionScoped, so the same managed bean instance is used for the entire session.
+
System requirements
-------------------
-All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven
-3.0 or better.
+All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.
+
+The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7.
-The application this project produces is designed to be run on a JBoss AS 7 or JBoss Enterprise Application Platform 6.
-The following instructions target JBoss AS 7, but they also apply to JBoss Enterprise Application Platform 6.
+
+Configure Maven
+---------------
-With the prerequisites out of the way, you're ready to build and deploy.
+If you have not yet done so, you must [Configure Maven](../README.md#mavenconfiguration) before testing the quickstarts.
-Deploying the application
+
+Start JBoss Enterprise Application Platform 6 or JBoss AS 7 with the Web Profile
-------------------------
-First you need to start JBoss AS 7 (or JBoss Enterprise Application Platform 6). To do this, run
+1. Open a command line and navigate to the root of the JBoss server directory.
+2. The following shows the command line to start the server with the web profile:
- $JBOSS_HOME/bin/standalone.sh
+ For Linux: JBOSS_HOME/bin/standalone.sh
+ For Windows: JBOSS_HOME\bin\standalone.bat
-or if you are using windows
- $JBOSS_HOME/bin/standalone.bat
+Build and Deploy the Quickstart
+-------------------------
-To deploy the application, you first need to produce the archive to deploy using
-the following Maven goal:
+_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Build and Deploy the Quickstarts](../README.md#buildanddeploy) for complete instructions and additional options._
- mvn package
+1. Make sure you have started the JBoss Server as described above.
+2. Open a command line and navigate to the root directory of this quickstart.
+3. Type this command to build and deploy the archive:
-You can now deploy the artifact to JBoss AS by executing the following command:
+ mvn clean package jboss-as:deploy
- mvn jboss-as:deploy
+4. This will deploy `target/jboss-as-temperature-converter.war` to the running instance of the server.
+
-This will deploy `target/temperatureconvert`.
+Access the application
+---------------------
-The application will be running at the following URL <http://localhost:8080/temperatureconvert>.
+The application will be running at the following URL: <http://localhost:8080/jboss-as-temperature-converter/>.
-To undeploy from JBoss AS, run this command:
+You will be presented with a simple form for temperature conversion.
- mvn jboss-as:undeploy
+1. Optionally, Select a scale: Celsius or Fahrenheit.
+2. Enter a temperature.
+3. Press the `Convert` button to see the results.
-You can also start JBoss AS 7 and deploy the project using Eclipse. See the JBoss AS 7
-<a href="https://docs.jboss.org/author/display/AS71/Getting+Started+Developing+Applications+Guide" title="Getting Started Developing Applications Guide">Getting Started Developing Applications Guide</a>
-for more information.
-Importing the project into an IDE
-=================================
+Run the Quickstart in JBoss Developer Studio or Eclipse
+-------------------------------------
+You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md/#useeclipse)
-If you created the project using the Maven archetype wizard in your IDE
-(Eclipse, NetBeans or IntelliJ IDEA), then there is nothing to do. You should
-already have an IDE project.
-Detailed instructions for using Eclipse with JBoss AS 7 are provided in the
-JBoss AS 7 <a href="https://docs.jboss.org/author/display/AS71/Getting+Started+Developing+Applications+Guide" title="Getting Started Developing Applications Guide">Getting Started Developing Applications Guide</a>.
+Debug the Application
+------------------------------------
-If you created the project from the commandline using archetype:generate, then
-you need to import the project into your IDE. If you are using NetBeans 6.8 or
-IntelliJ IDEA 9, then all you have to do is open the project as an existing
-project. Both of these IDEs recognize Maven projects natively.
+If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.
-Downloading the sources and Javadocs
-====================================
+ mvn dependency:sources
+ mvn dependency:resolve -Dclassifier=javadoc
-If you want to be able to debug into the source code or look at the Javadocs
-of any library in the project, you can run either of the following two
-commands to pull them into your local repository. The IDE should then detect
-them.
- mvn dependency:sources
- mvn dependency:resolve -Dclassifier=javadoc
View
21 temperature-converter/pom.xml
@@ -4,13 +4,20 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.as.quickstarts</groupId>
- <artifactId>jboss-as-temperature-converter-slsb</artifactId>
- <version>7.0.2-SNAPSHOT</version>
+ <artifactId>jboss-as-temperature-converter</artifactId>
+ <version>7.1.1.SNAPSHOT</version>
<packaging>war</packaging>
<name>JBoss AS Quickstarts: Temperature Converter</name>
<description>JBoss AS Quickstarts: Temperature Converter. Given Celsius return Fahrenheit; Given Fahrenheit return Celsius</description>
-
+ <url>http://jboss.org/jbossas</url>
+ <licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <distribution>repo</distribution>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
+ </license>
+ </licenses>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
@@ -35,7 +42,7 @@
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
- <version>3.0.0.Beta1</version>
+ <version>3.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -64,7 +71,7 @@
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
- <artifactId>jboss-jsf-api_2.0_spec</artifactId>
+ <artifactId>jboss-jsf-api_2.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the EJB API, we use provided scope as the API is included in
@@ -80,7 +87,7 @@
<build>
<!-- Set the name of the war, used as the context root when the app
is deployed -->
- <finalName>jboss-as-temperature-converter-slsb</finalName>
+ <finalName>jboss-as-temperature-converter</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
@@ -95,7 +102,7 @@
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
- <version>7.1.0.CR1</version>
+ <version>7.1.1.Final</version>
</plugin>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates
annotation processors -->
View
5 ...n/java/org/jboss/as/quickstarts/temperatureconverter/controller/TemperatureConverter.java
@@ -19,7 +19,7 @@
@Named("temperatureConverter")
@SessionScoped
public class TemperatureConverter implements Serializable {
-
+ private static final long serialVersionUID = 1785201108L;
/**
* Injected TemperatureConvertEJB client
*/
@@ -35,7 +35,8 @@
/**
* Invoke temperatureConvertEJB.convert() and store the temperature
*
- * @param temperatureFrom The temperature to be converted
+ * @param sourceTemperature The temperature to be converted
+ * @param defaultScale The default source temperature scale
*/
public void convert() {
temperature = temperatureConvertEJB.convert(sourceTemperature, defaultScale);
View
13 ...rc/main/java/org/jboss/as/quickstarts/temperatureconverter/ejb/TemperatureConvertEJB.java
@@ -31,7 +31,9 @@ public String convert(String sourceTemperature, String defaultScale) {
String convertToScale = " Err";
String conversionError = convertedTemperature + convertToScale;
- // Set up the use of RegEx to extract the temperature and scale (if passed).
+ /* Set up the use of RegEx to extract the temperature and scale (if passed).
+ * NB: Could get more clever and insist on C|F being after the number, and a single char...
+ * but that is an exercise for someone else to try */
Pattern temperaturePattern = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+");
Pattern scalePattern = Pattern.compile("[CF]", Pattern.CASE_INSENSITIVE);
Matcher extractTemperature = temperaturePattern.matcher(sourceTemperature);
@@ -41,13 +43,14 @@ public String convert(String sourceTemperature, String defaultScale) {
if (extractScale.find()) {
convertScale = extractScale.group();
} else {
- convertScale = defaultScale;
+ // Make sure defaultScale has a valid value also
+ convertScale = extractScale.reset(defaultScale).find() ? extractScale.group() : "";
}
- // Check we were passed a scale. Should never occur!
+ // Check we were passed a scale. Should never occur in current JSF > ManagedBean > SLSB model.
if (convertScale.trim().isEmpty()) {
FacesContext.getCurrentInstance().addMessage(null,
- new FacesMessage("You must provide a valid temperature scale - 'C|F'"));
+ new FacesMessage("You must provide a valid temperature scale- 'C|F'"));
return conversionError;
}
@@ -56,7 +59,7 @@ public String convert(String sourceTemperature, String defaultScale) {
temperatureToConvert = Double.parseDouble(extractTemperature.group());
} else {
FacesContext.getCurrentInstance().addMessage(null,
- new FacesMessage("You must provide a valid temperature to convert - 'XX.X'"));
+ new FacesMessage("You must provide a valid temperature to convert- 'XX.X'"));
return conversionError;
}
View
6 temperature-converter/src/main/webapp/temperatureconvert.xhtml
@@ -10,15 +10,15 @@
<body>
<h1>JBoss Temperature Converter Service</h1>
- <p>Enter the temperature you wish to convert, optionally type the scale as well ('C' for Celsius, 'F' for Farhenheit).</p>
+ <p>Enter the temperature you wish to convert, optionally type the scale as well ('C' for Celsius, 'F' for Fahrenheit).</p>
<p>Scale passed with the temperature will take precedence.</p>
<div id="container">
<h:form id="convertForm">
<h:panelGrid columns="2">
<h:outputLabel for="radio">Scale (default):</h:outputLabel>
<h:selectOneRadio value="#{temperatureConverter.defaultScale}" id="radio">
<f:selectItem itemValue="C" itemLabel="Celsius" />
- <f:selectItem itemValue="F" itemLabel="Farhenheit" />
+ <f:selectItem itemValue="F" itemLabel="Fahrenheit" />
</h:selectOneRadio>
<h:outputLabel for="sourceTemperature">Temperature:</h:outputLabel>
<h:inputText id="sourceTemperature" value="#{temperatureConverter.sourceTemperature}" />
@@ -32,6 +32,8 @@
<h:outputLabel id="temperature" value="#{temperatureConverter.temperature}" />
</h:panelGrid>
</h:form>
+ <hr />
+ <p>How the conversion works:</p>
<p>The temperature string is parsed using two regular expressions that look for, firstly, a valid floating point
number, and then also, the first instance of either 'C' or 'F'. It only uses the radio buttons when it cannot find a
valid scale in the temperature-string. Consequently, the conversion will work on any string that has a number

0 comments on commit 1185660

Please sign in to comment.