Skip to content

Commit

Permalink
Syncing round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kborchers committed Mar 9, 2012
1 parent 5e074ad commit 1913048
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 46 deletions.
@@ -1,5 +1,6 @@
${artifactId}
========================
${artifactId}: Example AeroGear Application Using Multiple HTML5, Mobile & JAX-RS Technologies
==============================================================================================
Author: Jay Balunas

What is it?
-----------
Expand All @@ -14,7 +15,7 @@ you get your feet wet with database access in enterprise Java.
This application is built using a technique called Plain Old HTML5 (POH5). This uses a pure HTML
client that interacts with with the application server via restful end-points (JAX-RS). This
application also uses some of the latest HTML5 features and advanced JAX-RS. And since testing
is just as important with POH5 as it is server side core this application also uses QUnit to show
is just as important with POH5 as it is server side, this application also uses QUnit to show
you how to unit test your JavaScript.

What is a modern web application without mobile web support? This application also integrates
Expand All @@ -29,9 +30,9 @@ System requirements
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 AS 7+ or EAP 6+.
The application this project produces is designed to be run on JBoss AS 7 or JBoss Enterprise Application Platform 6.

An HTML5 compatible browser such as Chrome 14+, Safari 5+, Firefox 5+, or IE 9+ are
An HTML5 compatible browser such as Chrome, Safari 5+, Firefox 5+, or IE 9+ are
required. and note that some behaviors will vary slightly (ex. validations) based on browser support,
especially IE 9.

Expand All @@ -43,7 +44,9 @@ With the prerequisites out of the way, you're ready to build and deploy.

Deploying the application
-------------------------


### Deploying locally

First you need to start the JBoss container. To do this, run

$JBOSS_HOME/bin/standalone.sh
Expand All @@ -70,14 +73,38 @@ You can now deploy the artifact by executing the following command:

This will deploy `target/${artifactId}`.

The application will be running at the following URL <http://localhost:8080/${artifactId}/>.
The client application will be running at the following URL <http://localhost:8080/${artifactId}/>.

To undeploy run this command:

mvn jboss-as:undeploy

You can also start the JBoss container and deploy the project using JBoss Tools. See the
Getting Started Guide for Developers for more information.
<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.

### Deploying to OpenShift

You can also deploy the application directly to OpenShift, Red Hat's cloud based PaaS offering, follow the instructions [here](https://community.jboss.org/wiki/DeployingHTML5ApplicationsToOpenshift)

Minification
============================

By default, the project uses the [wro4j](http://code.google.com/p/wro4j/) plugin,
which provides the ability to concatenate, validate and minify JavaScript and CSS
files. These minified files, as well as their unmodified versions are deployed with
the project.

With just a few quick changes to the project, you can link to the minified versions
of your JavaScript and CSS files.

First, in the <project-root>/src/main/webapp/index.html file, search for
references to minification and comment or uncomment the appropriate lines.

Finally, wro4j runs in the compile phase so any standard build command like package,
install, etc. will trigger it. The plugin is in a profile with an id of "minify" so
you will want to specify that profile in your maven build. For example:

mvn clean package jboss-as:deploy -Pminify

Running the Arquillian tests
============================
Expand All @@ -95,12 +122,14 @@ test goal with the following profile activated:
Running the QUnit tests
============================

QUnit is a JavaScript unit testing framework used and built by jQuery.This
application include a set of QUnit tests in order to verify JavaScript that
is core to this HTML5 application. Executing QUnit test cases is quite easy.
Simply load the following HTML is a browser.
QUnit is a JavaScript unit testing framework used and built by jQuery. This
application includes a set of QUnit tests in order to verify JavaScript that
is core to this HTML5 application. Executing QUnit test cases is quite easy. First,
make sure the server is running and the project has been deployed as some of the
tests will be testing the functionality of the services. Then, simply load the
following HTML in the browser you wish to test.

<app-root>/src/test/qunit/index.html
<project-root>/src/test/qunit/index.html

For more information on QUnit tests see http://docs.jquery.com/QUnit

Expand All @@ -112,9 +141,9 @@ If you created the project using the Maven archetype wizard in your IDE
already have an IDE project.

Detailed instructions for using Eclipse / JBoss Tools with are provided in the
Getting Started Guide for Developers.
<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>.

If you created the project from the commandline using archetype:generate, then
If you created the project from the command line 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.
Expand All @@ -129,3 +158,11 @@ them.

mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc

Development notes
=================

Copyright headers
-----------------

To update the copyright headers, just run `mvn license:format -Dyear=<current year>`
@@ -0,0 +1,123 @@
kitchensink-html5-mobile: JAX-RS Services Documentation
=======================================================
Author: Jay Balunas

This example supports various RESTFul end points which also includes JSONP support for cross domain requests.

By default the base URL for services is `/jboss-as-kitchensink-html5-mobile/rest`.

MemberService End Points
------------------------

### List all members
#### /rest/members

* Request type: GET
* Return type: XML
* Response example:

```xml
<?xml version="1.0" encoding="UTF-8"standalone="yes"?>
<collection>
<member>
<email>jane.smith@mailinator.com</email>
<id>1</id>
<name>Jane Smith</name>
<phoneNumber>2125551212</phoneNumber>
</member>
<member>
<email>john.smith@mailinator.com</email>
<id>0</id>
<name>John Smith</name>
<phoneNumber>2125551212</phoneNumber>
</member>
</collection>
```

#### /rest/members/json

* Request type: GET
* Return type: JSON
* Response example:

```javascript
[{"id":1,"name":"Jane Smith","email":"jane.smith@mailinator.com","phoneNumber":"2125551212"},{"id":0,"name":"John Smith","email":"john.smith@mailinator.com","phoneNumber":"2125551212"}]
```

### Create a new members

#### /rest/members

* Request type: POST
* Request type: application/x-www-form-urlencoded
* Request parameters: name, email, phoneNumber
* Return type: JSON
* Response example:
* Success: 200 OK
* Validation error: Collection of `<field name>:<error msg>` for each error

```JavaScript
{"phoneNumber":"10-12 Numbers","email":"Invalid format"}
```

#### /rest/members/new?name=&email=&phoneNumber=
* Request type: GET
* Query parameters: name, email, phoneNumber
* Return type: JSON
* Response example: See POST example above
* Note: JSONP requests do not support error responses

### Get one member by ID

#### /rest/members/\<id>
* Request type: GET
* Return type: XML
* Response example:

```xml
<?xml version="1.0" encoding="UTF-8"standalone="yes"?>
<member>
<email>john.smith@mailinator.com</email>
<id>0</id>
<name>John Smith</name>
<phoneNumber>2125551212</phoneNumber>
</member>
```

#### /rest/members/\<id>/json
* Request type: GET
* Return type: JSON
* Response example:

```javascript
{"id":0,"name":"John Smith","email":"john.smith@mailinator.com","phoneNumber":"2125551212"}
```

JSONP Support
-------------

[JSONP](http://en.wikipedia.org/wiki/JSONP) is a technique for allowing cross domain requests from services. It pads (what the "P" stands for) the service response with a JavaScript callback function that can then access the data on the client.

In order for a request to be padded the following things must be true:

* The request is one of the GET JSON request from above
* POST requests are not support for JSONP requests
* A query parameter named *jsonpcallback* is defined
* The value of this parameter is the method that will be defined in the padding

For example:

http://\<domain:port>/jboss-as-kitchensink-html5-mobile/rest/members/json?jsonpcallback=mycallback

See jQuery's documentation for client access examples:

* http://api.jquery.com/jQuery.getJSON/
* http://api.jquery.com/jQuery.ajax/

__Validation Error Handling__

When using JSONP requests error responses are not supported. This is a known issue with JSONP, and has to do with how JSONP requests are sent to the server using \<script> tags. In the case of a validation issue, or error the success callback will not be thrown, and most client libraries (specifically jquery) will not be able to call the error callback either. There are some workarounds and options, but typically they are limited. See your specific client library for more information.

__Security Considerations__

Before using JSONP in your system be aware of some potential security issues that are possible. There are two primary concerns, cross-site request forgery, and script tag manipulation. This example show one way to add a layer of security, by only processing JSONP requests with "safe" characters, it makes it more difficult for a site to injects harmful scripts into the return. You should always consider this and other aspects of security when exposing services in this way. See the [JSON wiki](http://en.wikipedia.org/wiki/JSONP) for more information.
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2012, Red Hat, Inc., and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
full listing of individual contributors.
Licensed 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.
-->
<groups xmlns="http://www.isdc.ro/wro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.isdc.ro/wro wro.xsd">
Expand Down
@@ -1,21 +1,3 @@
<!--

JBoss, Home of Professional Open Source
Copyright 2012, Red Hat, Inc., and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
full listing of individual contributors.

Licensed 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.

-->
<script type="text/template" id="member-tmpl">
<% _.each(members, function(member) { %>
<tr class="member">
Expand Down
@@ -1,3 +1,21 @@
<!--
JBoss, Home of Professional Open Source
Copyright 2012, Red Hat, Inc., and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
full listing of individual contributors.
Licensed 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.
-->
<!DOCTYPE html>

<!--
Expand Down
@@ -1,39 +1,65 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.
*/
/*
Unit tests that cover basic functionality of app.js.
*/

module('Member Row Construction');

test('Build 2 Member Rows', function() {
expect(1);
expect(1);

var members = [{"email": "jane.doe@company.com", "id": 1, "name": "Jane Doe", "phoneNumber": "12312312311"},{"email": "john.doe@company.com", "id": 0, "name": "John Doe", "phoneNumber": "2125551212"}];
var members = [{"email": "jane.doe@company.com", "id": 1, "name": "Jane Doe", "phoneNumber": "12312312311"},{"email": "john.doe@company.com", "id": 0, "name": "John Doe", "phoneNumber": "2125551212"}];

var html = buildMemberRows(members);
var length = $(html).length;
ok(length == 2, 'Number of rows built: ' + length);
var html = buildMemberRows(members);

ok($(html).length == 2, 'Number of rows built: ' + length);
});

test('Build 0 member Rows', function() {
expect(1);
expect(1);

var members = [];
var members = [];

var html = buildMemberRows(members);
var html = buildMemberRows(members);

ok(html == '', 'Created no rows for empty members');
ok($(html).length == 0, 'Created no rows for empty members');
});

module('Member Restful Calls');

test('Request current member list', function() {
ok(1==1,"TODO");
asyncTest('Request current member list', function() {
expect(1);

$.ajax({
url: "http://localhost:8080/jboss-as-kitchensink-html5-mobile/rest/members/json",
dataType: "jsonp",
jsonp: "jsonpcallback",
success: function(data) {
ok($(data).length, "Initial member returned");
start();
}
});
});

test('Register a new member', function() {
ok(1==1,"TODO");
ok(1==1,"TODO");
});

test('Register a member with a duplicate email', function() {
ok(1==1,"TODO");
ok(1==1,"TODO");
});

0 comments on commit 1913048

Please sign in to comment.