- 浏览: 2539810 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Grails(14)Study the Project
1. Reverse the ER from database
Use mysql workbench ----> Database ----> Reverse engineering
Follow the wizard and connect to my local database.
Select the Schemata to be Processed.
I got a nice ER diagram, but it seems not useful.
2. Understand the Configuration
In the controller, it calls
def config = ConfigurationHolder.config
String url = config.sillycat.resturl.base + "dashboard/visitsPerLocation"
In the Config.groovy file, it will be configured like this:
grails.config.locations = [ "file:/opt/conf/SillycatConfig.groovy" ]
From my understanding, we can put list here, and we also can place our configuration in Config.groovy.
3. Implement the JSON REST API
Basic authorization
String authorizationString = "Basic " + 'username:password'.bytes.encodeBase64().toString()
connection.setRequestProperty("authorization",authorizationString)
OAUTH2
Token Implementation
Shiro
I will forget about the authority and try to implement the functions first and then take care about the authority.
Here are my mapping files
// Calls to the Web Services
"/location/$id?" {
format = "json"
controller = "store"
action = [POST:"create", GET:"apiGet"]
}
It will go to find a controller named StoreController the method apiGet with the GET method from HTTP.
The controller implementation will be like this:
def apiGet = {
def storeInstance = params.id ? Store.get(params.id) : null
if (!storeInstance) {
Map map = [errorCode:101, errorMessage: "Can not find the location with id =" + params.id ]
render map as JSON
} else {
render storeInstance as JSON
}
}
And the unit test class will be looking like this:
class StoreControllerTests extends ControllerUnitTestCase {
@Test
public void testGetSuccess() {
List<Store> stores = [
new Store(storeCode:"TS1",storeName:"Test Store 1",enabled:true),
new Store(storeCode:"TS2",storeName:"Test Store 2",enabled:true),
new Store(storeCode:"TS3",storeName:"Test Store 3",enabled:false)]
mockDomain(Store, stores)
def controller = new StoreController()
controller.params.id = 1
controller.apiGet()
assertEquals(controller.response.status, 200)
//System.out.println(controller.response.status)
//System.out.println(controller.response.contentAsString)
}
}
And once the server is on, we can test like this:
@Test
public void testGetSuccessswithServer(){
def client = new RESTClient("http://localhost:8080")
def response
response = client.get(path: "person/1")
System.out.println(response.status)
System.out.println(response.data)
}
References:
http://www.intelligrape.com/blog/2011/11/16/writing-json-apis-part-i-creating-a-secure-rest-json-api-with-grails-and-spring-security-in-3-easy-steps/
https://github.com/svivekkrishna/Json-API-Sample
http://grails.org/doc/latest/ref/Controllers/allowedMethods.html
http://www.intelligrape.com/blog/2011/12/29/writing-json-apis-part-ii-creating-json-named-configs-to-control-what-you-render/
https://github.com/padcom/grails-json-rest-api-examples
http://www.intelligrape.com/blog/2010/04/28/working-with-rest-call/
http://www.ibm.com/developerworks/cn/opensource/os-cn-shiro/index.html
https://github.com/springside/springside4/wiki/Reference
http://oauth.net/
https://github.com/SpringSource/spring-security-oauth/wiki/oAuth2
https://github.com/adaptivecomputing/grails-spring-security-oauth2-provider
http://grails.org/plugin/spring-security-oauth2-provider
http://grails.org/doc/latest/guide/theWebLayer.html#moreOnJSONBuilder
http://www.ibm.com/developerworks/java/library/j-grails10209/index.html
http://jwicz.wordpress.com/2011/07/11/grails-custom-xml-marshaller/
1. Reverse the ER from database
Use mysql workbench ----> Database ----> Reverse engineering
Follow the wizard and connect to my local database.
Select the Schemata to be Processed.
I got a nice ER diagram, but it seems not useful.
2. Understand the Configuration
In the controller, it calls
def config = ConfigurationHolder.config
String url = config.sillycat.resturl.base + "dashboard/visitsPerLocation"
In the Config.groovy file, it will be configured like this:
grails.config.locations = [ "file:/opt/conf/SillycatConfig.groovy" ]
From my understanding, we can put list here, and we also can place our configuration in Config.groovy.
3. Implement the JSON REST API
Basic authorization
String authorizationString = "Basic " + 'username:password'.bytes.encodeBase64().toString()
connection.setRequestProperty("authorization",authorizationString)
OAUTH2
Token Implementation
Shiro
I will forget about the authority and try to implement the functions first and then take care about the authority.
Here are my mapping files
// Calls to the Web Services
"/location/$id?" {
format = "json"
controller = "store"
action = [POST:"create", GET:"apiGet"]
}
It will go to find a controller named StoreController the method apiGet with the GET method from HTTP.
The controller implementation will be like this:
def apiGet = {
def storeInstance = params.id ? Store.get(params.id) : null
if (!storeInstance) {
Map map = [errorCode:101, errorMessage: "Can not find the location with id =" + params.id ]
render map as JSON
} else {
render storeInstance as JSON
}
}
And the unit test class will be looking like this:
class StoreControllerTests extends ControllerUnitTestCase {
@Test
public void testGetSuccess() {
List<Store> stores = [
new Store(storeCode:"TS1",storeName:"Test Store 1",enabled:true),
new Store(storeCode:"TS2",storeName:"Test Store 2",enabled:true),
new Store(storeCode:"TS3",storeName:"Test Store 3",enabled:false)]
mockDomain(Store, stores)
def controller = new StoreController()
controller.params.id = 1
controller.apiGet()
assertEquals(controller.response.status, 200)
//System.out.println(controller.response.status)
//System.out.println(controller.response.contentAsString)
}
}
And once the server is on, we can test like this:
@Test
public void testGetSuccessswithServer(){
def client = new RESTClient("http://localhost:8080")
def response
response = client.get(path: "person/1")
System.out.println(response.status)
System.out.println(response.data)
}
References:
http://www.intelligrape.com/blog/2011/11/16/writing-json-apis-part-i-creating-a-secure-rest-json-api-with-grails-and-spring-security-in-3-easy-steps/
https://github.com/svivekkrishna/Json-API-Sample
http://grails.org/doc/latest/ref/Controllers/allowedMethods.html
http://www.intelligrape.com/blog/2011/12/29/writing-json-apis-part-ii-creating-json-named-configs-to-control-what-you-render/
https://github.com/padcom/grails-json-rest-api-examples
http://www.intelligrape.com/blog/2010/04/28/working-with-rest-call/
http://www.ibm.com/developerworks/cn/opensource/os-cn-shiro/index.html
https://github.com/springside/springside4/wiki/Reference
http://oauth.net/
https://github.com/SpringSource/spring-security-oauth/wiki/oAuth2
https://github.com/adaptivecomputing/grails-spring-security-oauth2-provider
http://grails.org/plugin/spring-security-oauth2-provider
http://grails.org/doc/latest/guide/theWebLayer.html#moreOnJSONBuilder
http://www.ibm.com/developerworks/java/library/j-grails10209/index.html
http://jwicz.wordpress.com/2011/07/11/grails-custom-xml-marshaller/
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 467NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 328Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 428Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 376Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 464NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 413Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 330Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 242GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 443GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 320GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 306Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 310Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 285Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 302Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 276NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 254Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 564NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 255Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 356Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 363Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
**Grails CometD:最佳Web推送技术** 在现代Web开发中,实时通信是不可或缺的一部分,它使得用户可以即时获取服务器端的数据更新,无需频繁刷新页面。Grails CometD框架就是为了实现这种实时交互而设计的。本文将...
《The Definitive Guide to Grails 2》是Grails框架深入学习的重要参考资料,由业界专家撰写,旨在为开发者提供全面、详尽的Grails 2技术指导。这本书结合了理论与实践,不仅介绍了Grails的基本概念,还涵盖了高级...
《Grails 2 的终极指南》是一本深入探讨Grails框架精髓的专业书籍,该书以英文撰写,旨在为读者提供全面、深入的Grails框架学习资料。Grails框架基于Groovy语言,是一种高度动态、敏捷的Java应用开发框架,它简化了...
**Grails 框架详解** Grails 是一个基于 Groovy 语言的开源Web应用程序框架,它构建在Java平台之上,旨在简化开发过程并提高生产力。Grails 的设计深受Ruby on Rails的影响,提供了MVC(模型-视图-控制器)架构模式...
grails参考文档 The Grails Framework - Reference Documentation Authors: Graeme Rocher, Marc Palmer Version: 1.0.3
4. **创建Grails项目**:现在,你可以通过Eclipse的"New" -> "Grails Project"来创建一个新的Grails项目。选择合适的Grails版本和其他配置,然后Eclipse会自动生成项目结构。 5. **开发与调试**:在Eclipse中,你...
《Grails权威指南》是一本全面深入探讨Grails框架的专著,旨在帮助读者掌握这一强大的Web开发工具。Grails是一种基于Groovy语言的开源框架,它为构建现代、高效的应用程序提供了简洁高效的解决方案。本指南针对不同...
【Grails项目搭建详解】 Grails是一个基于Groovy语言的开源Web应用框架,它简化了开发过程,尤其适合快速构建动态网站。在Eclipse中搭建Grails项目可能相对复杂,但通过以下步骤,即使是初学者也能顺利进行。 1. *...
《Grails用户手册》 Grails,作为一个基于Groovy语言的开源Web应用框架,深受开发者喜爱,它简化了Java开发的复杂性,提供了强大的MVC(Model-View-Controller)架构,以及丰富的插件系统。这份用户手册将帮助你...
选择"File" > "New" > "Other",在弹出的对话框中展开"Grails",然后选择"Grails Project"。输入项目名,选择Grails版本,然后点击"Finish"。Eclipse会自动为你的项目生成基本的Grails结构,包括`grails-app`目录,...
Grails 1.1 变更了插件存储路径,默认不再保存在 `PROJECT_HOME/plugins` 目录下。如果你遇到因插件导致的编辑错误,可以在 `grails-app/conf/BuildConfig.groovy` 文件中添加以下配置: ``` grails.project....
### Grails 快速开发 Web 应用程序 #### 一、Grails 概述 Grails 是一种基于 Groovy 的开源应用框架,用于简化 Web 应用程序的开发过程。它采用约定优于配置的原则,这使得开发者可以更快地创建功能丰富的 Web ...
Grails是一个基于Groovy语言的全栈框架,它遵循约定优于配置的原则,并且紧密集成Spring和Hibernate等流行的Java库,简化了开发流程。Grails在IT行业中尤其受到重视,因为它能够帮助开发者快速搭建并部署基于MVC模式...
《Grails 2.4.4 框架深度解析》 Grails 2.4.4 是一个基于Java的开源Web应用框架,它利用Groovy语言的强大特性,为开发者提供了一种高效、灵活的开发环境。这个压缩包“grails-2.4.4.zip”包含了完整的Grails 2.4.4...
【Grails转移项目】是一个基于Groovy语言和Grails框架的软件开发项目,它涉及到将一个现有的Grails应用从一个环境或平台转移到另一个环境或平台的过程。Grails是一个高效的、基于Java平台的开源Web应用程序框架,它...
**Grails 概述** Grails 是一个基于 Groovy 语言的开源 web 应用程序框架,它构建在 Java 平台上,旨在提高开发效率,简化常见 Web 开发任务。Grails 遵循 Model-View-Controller (MVC) 架构模式,允许开发者快速...