SmartGWT入门 - 企业级web2.0开发轻松入门
- 格式:docx
- 大小:388.83 KB
- 文档页数:11
总共回页首SmartGWT 数据集成在本系列第二篇文章中,我们主要介绍了数据绑定,即界面组件如何和数据源连接并协同工作。
这篇文章将重点介绍数据源和后台数据库如何交互。
在 SmartGWT 中,术语“数据集成”指的是将客户端程序中的数据源(DataSource)和服务器端的数据提供程序连接起来的过程。
数据提供程序可能是关系型数据库,也可能是 Web Services 等能返回数据的网络服务。
集成后的数据源必须能提供 CURD 四种基本数据操作,界面程序通过数据源对后台数据库进行这四种操作。
由于 SmartGWT 本身是用 Java 所写,对数据服务是否使用 Java 做了不同的处理。
据此,分出了两种数据集成:服务器端数据集成和客户端数据集成。
服务器端数据集成指的是,通过使用 SmartGWT 中基于 Java 的服务器程序来连接Java 对象或者 JDBC 访问的数据库。
这里不需要事先存在能访问数据库的 Web 应用,只要数据能用 Java 或 JDBC 访问即可。
SmartGWT 在服务器端提供了将这些 Java 数据服务集成到 Web 应用中的能力,所以称为服务器端数据集成。
客户端数据集成是指将 SmartGWT 的数据源与现有的可以返回 XML,JSON 或其他文本格式的 HTTP 数据服务连接。
由于 HTTP 服务已经存在,SmartGWT 客户端可以直接通过 HTTP 协议来访问数据,SmartGWT 提供的数据连接功能发生在客户端,故称之为客户端数据集成。
下图展示了 SmartGWT 应用中可能的组件结构和数据访问路径。
路径 1 是服务器端数据集成;路径 2,3,4 则表示了客户端数据集成。
图 1. 数据集成路径示意图这么多条路径,如何来选择合适的方式? SmartGWT 的文档中给出了简明的流程图,如图 2 所示。
图 2. 数据集成方式选择示意图如果你不是在使用支持 Java 的 Web 服务器,那么你需要选择客户端数据集成。
WebGoat中文手册版本:5.4webgoat团队2013年1月Revision record 修订记录 项目任务 参与人员 完成时间项目人员协调 Rip,袁明坤,Ivy 2012年7月翻译及整核以往版本袁明坤,傅奎,beer,南国利剑,lion 2012年8月 Webgoat5.4 版本测试袁明坤,傅奎,beer,南国利剑,lion 2012年8月 Webgoat5.4 中文手册傅奎 2012年9月 审核发布阿保,王颉, 王侯宝 2013年1月 前期参与人员 蒋根伟,宋飞,蒋增,贺新朋,吴明,akast ,杨天识,Snake ,孟祥坤,tony ,范俊,胡晓斌,袁明坤[感谢所有关注并参与过OWASP 项目的成员,感谢你们的分享和付出,webgoat 和大家一起成长!如有修改建议,请发送至webgoat@ 我们一起改进,谢谢!目录1 WebGoat简介 (6)1.1 什么是WebGoat (6)1.2 什么是OWASP (6)1.3 WebGoat部署 (6)1.4 用到的工具 (7)1.4.1 WebScarab (7)1.4.2 Firebug和IEwatch (8)1.5 其他说明 (8)2 WebGoat教程 (9)2.1 综合(General) (9)2.1.1 HTTP基础知识(Http Basics) (9)2.1.2 HTTP拆分(HTTP Splitting) (11)2.2 访问控制缺陷(Access Control Flaws) (19)2.2.1 使用访问控制模型(Using an Access Control Matrix) (19)2.2.2 绕过基于路径的访问控制方案(Bypass a Path Based Access Control Scheme) (22)2.2.3 基于角色的访问控制(LAB: Role Based Access Control) (25)2.2.4 远程管理访问(Remote Admin Access) (36)2.3 Ajax安全(Ajax Security) (38)2.3.1 同源策略保护(Same Origin Policy Protection) (38)2.3.2 基于DOM的跨站点访问(LAB: DOM‐Based cross‐site scripting) (39)2.3.3 小实验:客户端过滤(LAB: Client Side Filtering) (43)2.3.4 DOM注入(DOM Injection) (46)2.3.5 XML注入(XML Injection) (49)2.3.6 JSON注入(JSON Injection) (52)2.3.7 静默交易攻击(Silent Transactions Attacks) (54)2.3.8 危险指令使用(Dangerous Use of Eval) (57)2.3.9 不安全的客户端存储(Insecure Client Storage) (59)2.4 认证缺陷(Authentication Flaws) (62)2.4.1 密码强度(Password Strength) (62)2.4.2 忘记密码(Forgot Password) (64)2.4.3 基本认证(Basic Authentication) (66)2.4.4 多级登录1(Multi Level Login 1) (71)2.4.5 多级登录2(Multi Level Login 2) (73)2.5 缓冲区溢出(Buffer Overflows) (74)2.5.1 Off‐by‐One 缓冲区溢出(Off‐by‐One Overflows) (74)2.6 代码质量(Code Quality) (78)2.6.1 在HTML中找线索(Discover Clues in the HTML) (78)2.7 并发(Concurrency) (79)2.7.1 线程安全问题(Thread Safety Problems) (79)2.7.2 购物车并发缺陷(Shopping Cart Concurrency Flaw) (80)2.8 跨站脚本攻击(Cross‐Site Scripting (XSS)) (82)2.8.1 使用XSS钓鱼(Phishing with XSS) (82)2.8.2 小实验:跨站脚本攻击(LAB: Cross Site Scripting) (84)2.8.3 存储型XSS攻击(Stored XSS Attacks) (90)2.8.4 跨站请求伪造(Cross Site Request Forgery (CSRF)) (91)2.8.5 绕过CSRF确认( CSRF Prompt By‐Pass) (93)2.8.6 绕过CSRF Token(CSRF Token By‐Pass) (98)2.8.7 HTTPOnly测试(HTTPOnly Test) (102)2.8.8 跨站跟踪攻击(Cross Site Tracing (XST) Attacks) (103)2.9 不当的错误处理(Improper Error Handling) (105)2.9.1 打开认证失败方案(Fail Open Authentication Scheme) (105)2.10 注入缺陷(Injection Flaws) (107)2.10.1 命令注入(Command Injection) (107)2.10.2 数字型SQL注入(Numeric SQL Injection) (109)2.10.3 日志欺骗(Log Spoofing) (110)2.10.4 XPATH型注入(XPATH Injection) (112)2.10.5 字符串型注入(String SQL Injection) (113)2.10.6 小实验:SQL注入(LAB: SQL Injection) (115)2.10.7 通过SQL注入修改数据(Modify Data with SQL Injection) (119)2.10.8 通过SQL注入添加数据(Add Data with SQL Injection) (120)2.10.9 数据库后门(Database Backdoors) (121)2.10.10 数字型盲注入(Blind Numeric SQL Injection) (123)2.10.11 字符串型盲注入(Blind String SQL Injection) (124)2.11 拒绝服务(Denial of Service) (126)2.11.1 多个登录引起的拒绝服务(Denial of Service from Multiple Logins) (126)2.12 不安全的通信(Insecure Communication) (127)2.12.1 不安全的登录(Insecure Login) (127)2.13 不安全的配置(Insecure Configuration) (130)2.13.1 强制浏览(How to Exploit Forced Browsing) (130)2.14 不安全的存储(Insecure Storage) (131)2.14.1 强制浏览(How to Exploit Forced Browsing) (131)2.15 恶意执行(Malicious Execution) (132)2.15.1 恶意文件执行(Malicious File Execution) (132)2.16 参数篡改(Parameter Tampering) (134)2.16.1 绕过HTML字段限制(Bypass HTML Field Restrictions) (134)2.16.2 利用隐藏字段(Exploit Hidden Fields) (136)2.16.3 利用未检查的E‐mail(Exploit Unchecked Email) (138)2.16.4 绕过客户端JavaScript校验(Bypass Client Side JavaScript Validation) (142)2.17 会话管理缺陷(Session Management Flaws) (148)2.17.1 会话劫持(Hijack a Session) (148)2.17.2 认证Cookie欺骗(Spoof an Authentication Cookie) (154)2.17.3 会话固定(Session Fixation) (158)2.18 Web服务(Web Services) (162)2.18.1 创建SOAP请求(Create a SOAP Request) (162)2.18.2 WSDL扫描(WSDL Scanning) (168)2.18.3 Web Service SAX注入(Web Service SAX Injection) (170)2.18.4 Web Service SQL注入(Web Service SQL Injection) (172)2.19 管理功能(Admin Functions) (175)2.19.1 报告卡(Report Card) (175)2.20 挑战(Challenge) (176)2.20.1 挑战(The CHALLENGE!) (176)1WebGoat简介1.1什么是WebGoatWebGoat是OWASP组织研制出的用于进行web漏洞实验的应用平台,用来说明web 应用中存在的安全漏洞。
Web全栈开发入门指南Web全栈开发是目前市场上非常热门的技术之一,从前端的页面设计到后台的数据存储和逻辑处理,全栈工程师需要掌握多项技术。
本文将为读者提供Web全栈开发的入门指南。
一、前端开发前端开发主要负责网站或应用程序的界面设计和开发,包括设计网页或应用界面、写HTML、CSS 和JavaScript代码。
前端工程师是用户界面(UI)和用户体验(UX)的设计者和开发者。
网站或应用的外观和访问速度都受到前端工程师的影响。
1. HTMLHTML(HyperText Markup Language)是用于创建Web页面和应用程序的标记语言。
HTML描述了Web页面的结构和内容,并且它的语法相对简单。
如果你想要学习前端开发,那么学习HTML是必修课程之一。
2. CSSCSS(Cascading Style Sheets)是用于控制Web页面外观和特效的语言。
CSS为网站或应用程序提供了可定制的视觉风格,使页面更具吸引力。
3. JavaScriptJavaScript是编写Web应用程序的主要编程语言之一,负责动态Web交互和行为。
当用户与网站或应用程序进行交互时,JavaScript能够在不刷新整个页面的情况下改变特定部分的内容、进行表单验证、验证用户输入等操作。
二、后端开发后端开发主要涉及数据存储和数据处理,包括应用程序的逻辑处理、数据库设计和应用程序的服务器端编程。
它的主要功能是处理前端发送的请求,并向前端返回响应。
后端工程师最擅长的是服务端编程语言和数据库设计和操作。
1. 服务器端编程语言服务器端编程语言是Web应用程序的核心,在Web编程中负责实现复杂的业务逻辑和数据存储,是一名合格后端工程师必需掌握的编程语言。
2. 数据库数据库是存储Web应用程序数据的有组织的集合。
有各种各样的数据库类型可供使用,大多是通过SQL查询语言来操作和管理数据。
后端开发人员必须了解数据库的概念和基本操作。
三、全栈开发全栈开发是指开发人员能够开发前端、后端和数据库应用程序。
GWT开发指南范文GWT(Google Web Toolkit)是一种开发Web应用程序的框架,由Google推出并开源。
它允许开发人员使用Java语言编写Web应用程序,然后将其编译为高度优化的JavaScript代码,以在不同的浏览器中运行。
本文将介绍GWT开发的一般流程和一些最佳实践。
一、GWT的基本概念1. 项目结构:一个GWT项目通常包括一个主模块(.gwt.xml文件)和一些客户端类(Java代码),其负责生成JavaScript代码。
GWT还支持使用UI绑定器(UiBinder)将UI和Java代码分离,并支持使用CSS样式表。
2. 生成与调试:GWT支持通过将Java代码编译为JavaScript来生成Web应用程序。
GWT提供了一个开发模式(Development Mode)来简化程序的调试。
开发者可以在浏览器中直接运行应用程序,并通过浏览器的调试工具进行调试。
3. RPC:GWT的远程过程调用(RPC)机制允许开发人员通过定义Java接口和实现类来实现服务器与客户端之间的通信。
开发人员可以使用预定义的RPC机制,也可以通过自定义稍微复杂的通信需求。
二、GWT开发的流程1. 设计界面:首先,开发人员需要设计应用程序的用户界面。
GWT支持使用UI绑定器和CSS样式表来设计界面。
开发人员可以使用GWT提供的预定义部件(Widgets),也可以自定义部件。
2.实现业务逻辑:其次,开发人员需要实现应用程序的业务逻辑。
GWT的客户端类中包含了应用程序的业务逻辑代码。
开发人员可以在客户端类中定义处理用户事件的方法,并通过调用服务器提供的服务来实现与服务器的通信。
3.调试与测试:在实现业务逻辑之后,开发人员需要通过调试和测试来确保应用程序的正确性和稳定性。
GWT提供了一个开发模式,可以方便地进行调试。
开发人员可以在浏览器中运行应用程序,并通过浏览器的调试工具进行调试。
4. 编译与部署:最后,开发人员需要将应用程序编译为JavaScript,并将其部署到Web服务器上。
GWT开发教程范文GWT(Google Web Toolkit)是一个由Google开发的Java框架,用于开发基于Web的应用程序。
它通过将Java代码转化为浏览器可执行的JavaScript代码,使开发者能够使用Java语言来开发Web应用程序,而不需要直接编写JavaScript代码。
GWT框架具有良好的兼容性,支持所有主流的浏览器,并提供了丰富的工具和库,使开发者能够更加高效地构建功能强大、响应迅速的Web应用程序。
GWT的核心概念是模块(module)。
模块是应用程序的组件,定义了应用程序的入口点、所需的资源以及需要与服务器进行通信的服务。
创建一个模块时,需要定义模块的名称和入口点。
入口点是应用程序的入口,用于初始化应用程序并将其与浏览器的DOM进行绑定。
在入口点中,可以添加事件处理程序、添加用户界面组件以及执行其他必要的初始化操作。
在GWT中,与服务器通信是非常重要的一部分。
GWT提供了两种方式来实现与服务器的通信:RPC(Remote Procedure Call)和RESTful服务。
RPC是一种基于方法调用的通信方式,可以远程调用在服务器上定义的方法。
通过RPC,可以在客户端和服务器之间传输Java对象,使得服务器和客户端能够共享数据和状态。
RESTful服务是一种基于HTTP协议的通信方式,可以通过发送HTTP请求来与服务器进行交互。
GWT提供了相应的类和方法来封装HTTP请求和响应,使得与服务器的通信变得更加简单和方便。
在开发GWT应用程序时,还需要考虑到应用程序的可维护性和扩展性。
为了提高代码的可维护性,可以使用模块化的开发方法,将相关的代码组织成模块,使得每个模块都具有清晰的责任和功能。
另外,还可以使用设计模式和面向对象的编程思想,使代码具有良好的结构和可理解性。
为了提高代码的扩展性,可以使用依赖注入、模板模式等设计技术,使得应用程序的功能可以灵活地扩展和修改。
总的来说,GWT是一个功能强大、易用且高效的Java开发框架,可以大大简化Web应用程序的开发过程。
Smart GWT简介1.概览用一句话来概括,Smart GWT 是封装了 SmartClient 的 GWT API。
而 SmartClient 是一个开源的企业级 Ajax 开发框架。
Google Web Toolkit 的发布,大大降低了 Java 开发人员进行 Web 开发的门槛。
然而 GWT 本身提供的控件及功能相对有限。
因此出现了很多第三方开源扩展库。
总体来看,Smart GWT 有如下特色:∙丰富的控件。
很多较为复杂的常用界面都被包装成简单易用的控件。
比如可编辑的树形表格、查询创建器、支持分组交叉的Grid和图表、类似 Google Calendar 的日历等等。
∙内置的数据整合功能。
利用 SmartClient 的 MVC 模式,用户可以通过定义数据源(Data Source),很容易地开发出能对服务器端数据进行创建,更新,获取和删除操作的界面。
甚至只要 10 行以内的代码。
∙Smart GWT 企业版内置了对 JDBC 和 Hibernate 的支持,对这样的数据源,只需通过定制配置文件的方式即可动态的创建,大大简化了开发。
而且数据源将界面组件和后台数据分隔开来,带来的好处是可以替换数据源而不改动任何客户端代码。
∙支持 Skin。
通过 Skin,用户能定制整套风格一致的界面方案。
只需在线切换,就可以换到全新的风格。
2.特征点1.Smart GWT可使用Java代替JavaScript开发Ext风格的界面,并使用GWT编译生成运行时页面(Google提供的GWT Compile进行编译,在Eclipse中进行编译可以安装其插件);2.支持多元化的数据源:SQL、Hibernate、自定义Bean等;3.在数据源配置中利用Spring上下文绑定注入的业务方法,提供对事务的支持;4.封装了请求和响应,使用DMI机制实现对服务器端类及其方法的调用;5.其扩展的客户端组件开发包(SmartClient SDK)种类丰富、功能强大,比较典型的有:●功能强大的Grid组件,支持表头过滤、行编辑、校验,锁定行、列等;●方便实用的Tree及Tree Grid组件,支持拖拽维护树节点等;●交叉分组报表的实现及运行时配置(表头表列自由组合、自动生成图表等);●数据脱机以改善数据操作友好性,延迟加载提升海量数据展示时的速度;●多种格式的数据导出、文件上传、动画、实时动态等。
GWT-Ext体验之旅,第1部分:GWT-Ext入门GWT-Ext是基于Google Web Toolkit(GWT)和ExtJs的功能强大的网页开发控件库。
它非常适用于进行纯Java语言的富Internet应用的快速开发。
本系列文章将详细讲解GWT-Ext的基本结构和功能特点,并通过代码示例来演示该技术的具体实现。
本文是该系列的第一部分,将带领您快速入门GWT-Ext,并演示如何快速搭建GWT-Ext的开发环境。
概述GWT-Ext是基于Google Web Toolkit(GWT)和ExtJs的功能强大的网页开发控件库。
它扩展了GWT,在ExtJs的基础上实现了有排序功能的表格(Grid)、分页、过滤,支持有拖拽功能的树,高度可定制的组合下拉框(Combobox)、目录、对话框、表单(Form)以及功能丰富、强大且易用的API。
GWT-Ext拥有GNU Lesser General Public Licence(LGPL)(请参阅参考资料),V3.0的许可证。
因此它是一个非常灵活,允许在开源和商业中应用的控件库。
GWT的介绍(请参阅参考资料)已经非常丰富,我们这个系列主要关注在GWT-Ext的介绍和应用上。
GWT-Ext是在GWT和ExtJs的基础上对表现层的进一步封装。
我们可以理解GWT提供了Ajax的一套基础框架,而ExtJs提供了以JavaScript和CSS样式表为基础的非常丰富的表现层接口。
那么GWT-Ext 就是在GWT的基础上,将ExtJs的JavaScript接口映射或者封装为Java的接口。
在Java的环境下开发和调试开发表现层,可以大大提高开发的速度。
GWT-Ext开发环境搭建在这个系列中,将通过示例的方式,一步步地介绍如何搭建一个GWT-Ext的开发环境。
本章将通过图解与代码结合的方式搭建演示平台框架,并且演示如何部署这个平台到Tomcat容器中。
下载开发环境我们将使用Eclipse和插件Cypal Studio来搭建控件演示平台。
一、搭建环境1.下载和安装JDK开发GWT应用程序之前,需要做一些准备工作。
Java环境对于开发GWT应用是必不可少的。
GWT工具包的编译需要JDK的支持,因此在安装GWT工具包之前请下载和安装合适的JDK,GWT工具要Java 5以上的版本。
具体步骤如下:第一步:下载jdk,下载地址:/technetwork/java/javase/downloads/index.html下载JDK安装程序(本培训提供jdk1.7安装包)下载后安装到E:\jdk目录下,可以根据实际情况将JDK安装到任意目录下第二步:使用鼠标右击“我的电脑”→“属性”→“高级”→“环境变量”第三步:系统变量->新建->变量名:JAVA_HOME 变量值:e:\jdk\ (该变量值是jdk的安装路径)系统变量->新建->变量名:CLASSPATH 变量值:.;%JAVA_HOME%\lib系统变量->编辑->变量名:Path 在变量值的最前面加上:%JAVA_HOME%\bin;(CLASSPATH的变量值英文中有句号“.”后跟一个分号,表示当前路径的意思) 验证是否配置成功-----进入doc中、输入java和javac命令都能正常显示。
输入java -version 命令能显示jdk的版本号!就可以了提示GWT的调试器依赖32位的SWT界面库。
要在系统上调试GWT项目,必须安装32位JDK。
当然在64位JDK环境中也可以编译GWT项目2. 安装Eclipse和GWT的开发插件开发GWT只需要JDK。
但有个好的开发环境可以极大提高工作效率。
Eclipse是最流行的Java集成开发环境。
Google提供了GWT的Eclipse开发插件。
目前Google提供的插件只支持Eclipse 3.3以上版本。
打开网址/downloads/,进入到Eclipse Downloads页面选择下载Eclipse IDE for Java EE Developers。
S7-200 SMART Web API development manualContents1.What is Web API? (5)2.What can Web API do? (6)2.1 Real-time Control (6)2.2 Network management (7)3.Configure Web API (8)4.Web API basic functions (12)4.1 API list (12)4.2 API using suggestions (13)4.3 API general format (13)4.3.1 JSON-RPC request template (14)4.3.2 JSON-RPC success response template (14)4.3.3 JSON-RPC fail response template (15)4.4 API limitations (15)5.login (16)5.1 Notes (16)5.2 Http request body format (16)5.3 Http response format (17)5.3.1 login success (17)5.3.2 login fail (18)5.4 Example (18)6.logout (19)6.1 Notes (19)6.2 Http request format (20)6.3 Http response format (20)6.3.1 logout success (20)6.3.2 logout fail (21)7.get_permission (22)7.1 Notes (22)7.2 Http request body format (23)7.3 Http response body format (23)7.3.1 get permission success (23)7.4 Example (23)8.read (24)8.1 Notes (24)8.2 Http request body format (25)8.3 Http response body format (26)8.3.1 read success (26)8.3.2 Read fail (28)8.4 Example (28)9.write (30)9.1 Notes (30)9.2 Http request body format (30)9.3 Http response body format (31)9.3.1 write success (31)9.3.2 write fail (33)9.4 Example (33)10.browse (35)10.1 Notes (35)10.2 Http request body format (35)10.3 Http response body format (35)10.3.1 browse success (35)10.3.2 browse fail (36)SIMATIC S7-200 SMART SR/ST 0AA1 CPUs support Web API since version 2.7!Let’s take a look at this new feature!1.W hat is Web API?Before we understand what Web API is, let's see what is an API: In computer programming, an application programming interface (API) is some kind of interface which has a set of functions that allow programmers to access specific features or data of an application, operating system or other services.Web API, as the name suggests, is an API over the Web server which can be accessed using HTTP protocol, a relatively broad concept.In SIMATIC S7-200 SMART CPUs series, Web API we implement is a standard JSON-RPC process, specifically follow JSON-RPC 2.0 specification.JSON (java-script object notation): a lightweight data-interchange format, easily read, write, parse, generate.JSON-RPC 2.0: a kind of open-api framework, a stateless and light weight remote procedure call protocol.2.W hat can Web API do?Web APIs provides the basic ability to remotely access CPU data, according to the authority control system, you can read and write CPU data.So you can integrate Web API into self-defined Web pages, terminals, applications, or shell scripts to manage your CPU.2.1 Real-time Control•Read/Write CPU data.•Adjust CPU time.your benefits:•You can read/write CPU's memory runtime, so you can timelyadjust data for user program.•You can trigger/remove signals manually, interact with yourprogram, such as, alarm lights.•You can synchronize your own clock, such as, dead batterycauses time lost.more...2.2 Network management•Remote monitoring.•Centralized monitoring.•Multi-terminal monitoring.your benefits:•You can fix some issue or logical request remotely, so don'tneed to go to factory area on-site.•You can share device control with other managers remotely,with different accounts and authorities.•You can control Multi-devices at the same time remotely.more...3.C onfigure Web APITo use Web API ability in a new CPU, you should do some necessary configuration through STEP 7-Micro/WIN.Notes: you should surely upgrade both your CPU and STEP 7-Micro/WIN to at least V2.7!1. Connect to CPU through STEP 7-Micro/WIN.Ensure that your Communication Interface and PLC connector cable for Ethernet is working.2. Enable Web server and Web api.1)Open the Web server wizard.2)In the Web Server window, select "Activate Web Server".3)Enter the IP address and station name (optional) of the CPUmodule to which you intend to connect.4)Select "Third party api and user defined Web page (PLC data read)"to set read permission of the connected CPU data on user defined Web pages.5)Click "Next" to continue the Web server configuration.3. Configuring Web server users.1)Click "User Management" in the navigation panel to enter the Usermanagement page.2)Click "Add" to add a line for each Web server user. You can add upto four Web server users.3)Enter usernames and passwords for the user logins that you wantto provide.4)Click "Generate" to save the configuration.4. Download Web configuration to CPU.5. Generate a new TLS certificate.For using Web server of S7-200 SMART CPU, you need to configure the certificates in certificate management wizard in STEP 7-Micro/WIN SMART first.STEP 7-Micro/WIN SMART provides two modes for downloading the certificate:•In "External certificate" mode, device certificate is singed bycertificate authority provided by user•In "internal certificate" mode, device certificate is signed bycertificate authority (CA) generated by the CPU4.W eb API basic functionsThere are things you always need to know before using Web APIs.4.1 API listAll APIs supported by Web API V1.0.0.List Descriptionlogin Login a user, then you can visit CPU with access control.logout Logout a user, the user cookie does not work anymore from now on.get_permission After the successful login, returns a list of actions for whose execution the user is authorized.read Read from CPU with valid user token. write Write to CPU with valid user token. browse Browse API list supported by CPU.4.2 API using suggestions4.3 API general format1. All API data need be encoded in the UTF-8 character encoding.2. The overall payload shall not exceed 15KB. The following is the JSON-RPC 2.0 API general template.ItemsSuggestsCall frequency.It is recommended to call less than once a second.Web API call process takes up a lot of CPU resource. Network communication, TLS encryption, JSON-RPC parse, business check, request too fast may cause subsequent to be blocked.Compress JSON text.It is recommended to use compressed JSON text.Compressed JSON has a very small size and high transmission efficiency.Efficient use Web request.It is recommended to request more data in one request.Each Web request has very large buffer and can read/write with max to 32 nodes of data. Reduce interaction frequency and improve single request efficiency.Use long connections.It is recommended to use keep-alive connections.Building a new TLS chain will take up a lot of resources, it is very slow. But there is a high efficiency interaction in existing connections.4.3.1 JSON-RPC request template4.3.2 JSON-RPC success response template4.3.3 JSON-RPC fail response template4.4 API limitations1. URL of http request MUST be "https://ip_address/Web_api".2. ALL http data MUST be encoded in the UTF-8 character encoding.3. Content-Type of http header MUST be "application/json".4. Http method MUST be POST.5. Current version do not support JSON-RPC batch.5. l oginThe login method checks the login data of the user and on successful verification return a user token for afterwards Web api actions.5.1 Notes5.2 Http request body formata. The Web user shall be configured in Web server wizard.b. The previous user token will be invalid after this successful login.c. When there is no operation within half an hour, this user will be logout automatically.Attributes remarksusername The username should already be configured in Web server wizard. passwordThe password should be ASCII string which is encoded user password with sha512.5.3 Http response format5.3.1 login successAttributes remarkscookieThe user's token of login, use this token in subsequent API request torepresent this user.The user's token will expire after half an hour without operation.5.3.2 login fail5.4 ExampleBefore testing:•This is a windows powershell terminal example, you MUSTsend the example through powershell.•This is a curl command; you MUST check your curl tools inyour machine.•This is a testing user and IP; you MUST modify to a correctaccount and IP.6.l ogoutTo logout an online user.6.1 Notesa. Logout a user who is not online or existing will still get a success.b. You MUST set user's token into the "cookie" of HTTP header to logout the user.6.2 Http request format6.3 Http response format6.3.1 logout success6.3.2 logout fail6.4 ExampleBefore testing:•This is a windows powershell terminal example, you MUSTsend the example through powershell.•This is a curl command; you MUST check your curl tools inyour machine.• 3. This is a testing token and IP; you MUST modify to a correcttoken and IP.7.g et_permissionTo get a login user's permission list.7.1 Notesa. The user should login firstly and you had got the token.b. You MUST set user's token into the "cookie" of HTTP header to logout the user.7.2 Http request body format7.3 Http response body format7.3.1 get permission successAttributes remarkspermission The permission list of login user.7.4 ExampleBefore testing:•This is a windows powershell terminal example, you MUSTsend the example through powershell.•This is a curl command; you MUST check your curl tools inyour machine.• 3. This is a testing token and IP; you MUST modify to a correcttoken and IP.8.r eadTo read data from a specified address.8.1 Notesa. You MUST login before reading.8.2 Http request body formatb. You MUST set user's token into the "cookie" of HTTP header to logout the user.c. You can read with max to 32 addresses of data in one request.d. You can send an empty request in order to get system status.Attributes remarksparams A JSON array object inside with reading nodes, max to 32 nodes. type"type" means the read operation type, currently only support address, and can be omitted.var"var" means the "address" to read. It is case insensitive. MUST be a S7-200 SMART CPU address, all as follow: V*.* , VB* , VW* , VD* I*.* , IB* , IW* , ID*Q*.* , QB* , QW* , QD* M*.* , MB* , MW* , MD* SM*.* , SMB* , SMW* , SMD* AIW* , AQW* T* , C* , HC* , DATEmode"mode" means the returned data mode, and can be omitted. all as follow:"signed": a signed integer. This is default type if omit to specify datamode."unsigned": an unsigned integer. "string": an ascii string. "float": a floating number."raw": a byte array with unsigned integer.8.3 Http response body format8.3.1 read successAttributes remarksstatus "status" contains current system mainly status: Date: time string in format of "YYYY-MM-DD HH:MM:SS". Operating Mode: RUN, STOP.System Status: OK, Error.Force Status: Forced, Not Forced.data A JSON array object inside with read result.The data array, which quantity and order are strictly the same as request.-code &message"code" & "message" shows the result of reading this address.-var "var" is exactly the same as request.-value "value" shows the result of reading this address in format of request asked.8.3.2 Read fail8.4 ExampleBefore testing:•This is a windows powershell terminal example, MUST be sendthe example through powershell.•This is a curl command; you MUST check your curl tools inyour machine.• 3. This is a testing token and IP; you MUST modify to a correcttoken and IP.9. w riteTo write data to a specified address.9.1 Notes9.2 Http request body formata. You MUST login before writing.b. You MUST set user's token into the "cookie" of HTTP header to logout the user.c. You can write with max to 32 addresses of data in one request.d. You can ONLY write data while CPU in run.e. You can write an empty request to get system status.Attributes remarksparams A JSON array object inside with writing nodes, max to 32 nodes.type"type" means the write operation type, currently only support address, and can be omitted.var"var" means the "address" to write. It is case insensitive. MUST be a S7-200 SMART CPU address, all as follow: V*.* , VB* , VW* , VD* I*.* , IB* , IW* , ID*Q*.* , QB* , QW* , QD* M*.* , MB* , MW* , MD* SM*.* , SMB* , SMW* , SMD* AIW* , AQW* T* , C* , HC* , DATEmode"mode" means the writing data mode, and can be omitted. all as follow: "signed": a signed integer. This is default type if omit to specify data mode."unsigned": an unsigned integer. "string": an ascii string. "float": a floating number."raw": a byte array with unsigned integer.9.3 Http response body format9.3.1 write successvalue "value" shall take the data in format of "mode".Attributes remarksstatus "status" contains current system mainly status: Date: time string in format of "YYYY-MM-DD HH:MM:SS". Operating Mode: RUN, STOP.System Status: OK, Error.Force Status: Forced, Not Forced.data A JSON array object inside with write result.The data array, which quantity and order are exactly the same as request.-code &"code" & "message" shows the result of writing this address. message-var "var" is exactly the same as request.9.3.2 write fail9.4 ExampleBefore testing:•This is a windows powershell terminal example, you MUSTsend the example through powershell.•This is a curl command; you MUST check your curl tools inyour machine.•This is a testing token and IP; you MUST modify to a correcttoken and IP.10.browseGet supported API list.10.1 Notesa. no need to login.10.2 Http request body format10.3 Http response body format10.3.1 browse successAttributes remarks version "version" shows the WEB API version string. api A JSON array object inside with APIs list.10.3.2 browse fail10.4 Example Before testing:•This is a windows powershell terminal example, you MUST send the example through powershell.•This is a curl command, you MUST check your curl tools in your machine.•This is a testing user and IP, you MUST modify to a correct。
简介: Google Web Toolkit 发布以来,吸引了广大Java 开发人员投身Web 开发,也涌现出来大量基于GWT 的扩展。
新近推出的SmartGWT 无疑是其中的佼佼者,它是包装了成熟的Ajax 框架SmartClient 的GWT API。
SmartGWT 包含了更丰富的Web 控件,但使之从其它GWT 扩展中脱颖而出的是强大的服务器端数据集成功能,用户能轻松开发出操作业务数据的Web 应用,从而使得它成为企业级Web2.0 开发的利器。
本文将对SmartGWT 的主要特征做全面的介绍,带领您轻松踏上企业级Web2.0 的开发之旅。
SmartGWT 概览用一句话来概括,SmartGWT 是封装了SmartClient 的GWT API。
而SmartClient 是一个开源的企业级Ajax 开发框架。
Google Web Toolkit 的发布,大大降低了Java 开发人员进行Web 开发的门槛。
然而GWT 本身提供的控件及功能相对有限。
因此出现了很多第三方开源扩展库。
很多扩展库都利用GWT,对现有的JavaScript 库做Java 封装,为GWT 提供了更多可用的API。
SmartGWT 是其中的佼佼者,它的底层使用SmartClient 这个成熟的Ajax 库。
SmartGWT 从2008 年开始开发,一直处在非常活跃的发展状态中。
2009 年12 月正式发布了 2.0 版,已经成为一个成熟的Web 2.0 开发框架。
SmartGWT 不仅仅是“又一个Web 控件库”,它最大的特色在于提供了整合客户端和服务器端数据的框架。
由于底层的SmartClient 实现了Ajax 版本的MVC 模式,这使得在SmartGWT 中,后台数据的集成是控件内置的能力,而不是需要用户自己去组装的模块。
需要处理多种类型,结构复杂的业务数据是企业级Web 开发的特点和难点,SmartGWT 对数据操作的关注,大大简化了企业级Web2.0 应用开发的门槛。
正是这一点让SmartGWT 与众不同。
在稍后的介绍中可以看到,一些相当复杂的典型数据应用,在SmartGWT 中只需很少的代码即可实现。
总体来看,SmartGWT 有如下特色:∙丰富的控件。
很多较为复杂的常用界面都被包装成简单易用的控件。
比如可编辑的树形表格、查询常用的过滤器创建器和类似Google Calendar 的日历等等。
∙内置的数据整合功能。
利用SmartClient 的MVC 模式,用户可以通过定义数据源(Data Source),很容易地开发出能对服务器端数据进行创建,更新,获取和删除操作的界面。
甚至只要10 行以内的代码。
∙支持Skin。
通过Skin,用户能定制整套风格一致的界面方案。
只需在线切换,就可以换到全新的风格。
如此强大的功能是否上手也很难呢?否!基于GWT 的SmartGWT 是非常容易使用的,即使很炫的效果,实现代码也非常简短,Java 开发人员很快就可以做出炫目的Web 应用。
SmartGWT 有四个不同的发行版:免费的LGPL 版,收费的专业版,Power 版和企业版。
除了许可证的区别外,功能上的区别主要体现在服务器端。
LGPL 版是纯粹的客户端GWT 库,而其它的收费版本,同时提供了Servlet,SQL 连接器等服务器端组件。
本文主要介绍在LGPL 版本中包含的客户端GWT API。
丰富的UI 组件SmartGWT 提供了极其丰富的UI 组件。
除了传统的表单、菜单和对话框等组件之外,SmartGWT 还包含了具有排序、分页、分组、过滤、汇总、打印预览和实时更新功能的列表,组件元素间的拖拽,手风琴式分区和堆栈式布局等。
可以说,SmartGWT 是一个强大的“高级”组件库。
下面我们介绍一些有特色的组件。
这些例子都来自于SmartGWT 发行版内自带的Showcase 这个示例应用。
∙Pick Tree类似多级菜单的树形选择器。
图 1. 树形选择器清单 1. 树形选择器代码实例Tree tree = new Tree();…PickTreeItem departmentItem = new PickTreeItem(); departmentItem.setValueTree(tree);∙TreeGird树和表格的组合,处理过复杂多级数据的人都想要的控件!图 2. 树形表格清单 2. TreeGrid 代码实例TreeGrid treeGrid = new TreeGrid();TreeGridField nameField = new TreeGridField("Name", 150);…treeGrid.setFields(nameField, jobField,employeeTypeField,employeeStatusField,salaryField, genderField, maritalStatusField);∙类似Google Calendar 的日历控件图 3. 日历清单 3. Calendar 代码实例Calendar calendar = new Calendar();DataSource eventDS = new DataSource();...calendar.setDataSource(eventDS);下面来看两个复杂一点的例子。
∙支持数据过滤的表格如下图所示,ListGrid 控件中显示的数据能根据上面的FilterBuilder 控件所设置的条件进行过滤。
查询条件可以是一个或多个,查询条件之间可以选择and、or 和not 三种逻辑运算符。
图 4. 数据过滤器清单 4. 数据过滤代码实例FilterBuilder filterBuilder = new FilterBuilder();ListGrid countryGrid = new ListGrid();DataSource worldDS = new DataSource();...filterBuilder.setDataSource(worldDS);countryGrid.setDataSource(worldDS);IButton filterButton = new IButton("Filter");filterButton.addClickHandler(new ClickHandler() {public void onClick(ClickEvent event) {countryGrid.filterData(filterBuilder.getCriteria()); }});支持公式计算和总结的表格以下是展示国家人口面积等数据的表格。
如果想显示人口密度,显然是需要计算人口除以面积。
图 5. 原始表格实现如上表格的是SmartGWT 的ListGrid 控件,它内置了对公式和加总的支持。
只需增加以下两行代码:清单 5. 公式加总代码实例countryGrid.setCanAddFormulaFields(true);countryGrid.setCanAddSummaryFields(true);在Show Formula builder 这个按钮中,我们只需要调用一个方法,一行代码:清单 6. 公式编辑支持代码实例public void onClick(ClickEvent event) {countryGrid.addFormulaField();}SmartGWT 为你完成了其它全部功能。
你只需点下按钮,这时会显示如下公式字段创建对话框,很容易即可实现人口密度这个计算而来的字段。
图 6. 公式编辑器保存之后,即可在原先的表格上看到你添加的字段。
是不是太容易了?图7. 增加字段之后的表格看了以上这些非常吸引人的UI 组件,你是不是已经迫不及待开始想要使用SmartGWT 了?强大的数据集成功能图形控件和服务器端数据集成是SmartGWT 的特色。
SmartGWT 中包含一系列以数据为中心的UI 组件。
比如ListGrid,TreeGrid,DynamicForm 等等。
利用这些控件,用户可以很容易地开发出功能全面的数据操作界面。
如下图所示,可以对数据进行编辑和增加的应用,只需要几十行代码就能实现。
图8. 数据操作UI 组件能支持这样强大功能是因为SmartGWT 中封装了SmartClient 的MVC(模型- 视图- 控制器)模式。
这是SmartClient 这一Ajax 框架的独门绝技。
实现数据整合的核心是控制器类数据源(DataSource),它为UI 组件这样的视图和后台数据模型之间架起了互通的桥梁。
图9. SmartGWT 中的数据集成流程由上图,从客户端到服务器的数据访问大体分为两个部分:1. UI 组件和数据源对象的交互2. 数据源对象和服务器实际数据提供者的交互在SmartGWT 中,第一种交互称为数据绑定,第二种交互称为数据集成。
在本系列的后续两篇文章中,我们将分别介绍这两部分技术及应用。
数据源对象看起来像关系数据库,在数据源内支持定义数据模型。
数据源提供的每条数据称为一条记录(Record),对应于数据库中的一行。
数据源内可以定义字段(Field),对应于数据库中的列。
不仅能定义每个字段的类型,还可以定义数据间关系,比如通过主外键关系来确定父子表。
可见数据源类是一个完整的关系型数据的抽象表示。
为UI 组件配置数据源后,对UI 上的操作,数据源会自动进行相关数据的创建,更新,获取和删除等基本操作。
数据源和UI 组件的松耦合模式带来的另一个优势是对于同一个数据源,可以同时有多种表示方式,而用户在任一表示方式中对该数据源进行的操作,能同时更新到其它表示方式中,保持显示数据的一致性。
如下图所示,员工数据在树形表格控件和表格控件中同时显示,在其中一个控件中对员工数据做修改,其更新能自动同步显示到另一个控件中。
图10. 一个数据源,多种显示方式根据用户的定制,数据源对象可以读取XML、JSON 或者数据库等等服务器端数据。
它把实际的数据来源和你的应用隔离开。
带来的好处之一就是易于测试。
在测试的时候,你可以直接在数据源里返回测试数据,而不用访问真正数据源。
使得测试代码可以快速运行。
而在真正运行时,切换不同的数据来源也非常简单。
在SmartGWT 的不同发行版中,最大的不同就是在服务器端的支持能力。
在企业版中,提供了对常用的Java 服务器端数据访问技术的集成,比如Hibernate。
这样用户可以利用现有的Java 数据服务开发新应用,或者快速为现有的Java 数据应用打造一个新的SmartGWT 风格的界面。