Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
268 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
jboss-html5-mobile-archetype/src/main/resources/archetype-resources/SERVICES.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
18 changes: 18 additions & 0 deletions
18
...5-mobile-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/wro.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
...-mobile-archetype/src/main/resources/archetype-resources/src/main/webapp/tmpl/member.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...s-html5-mobile-archetype/src/main/resources/archetype-resources/src/test/qunit/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 39 additions & 13 deletions
52
...html5-mobile-archetype/src/main/resources/archetype-resources/src/test/qunit/test/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); |
Oops, something went wrong.