- 浏览: 1863772 次
- 性别:
- 来自: 合肥
文章分类
- 全部博客 (514)
- OPEN (41)
- WARN (33)
- EXPER (16)
- RESOURCE (7)
- TOOL (4)
- DWR (10)
- Struts1.x (10)
- Ibtais (18)
- MyEclipse (30)
- Sql Server (64)
- Tomcat (7)
- APACHE (4)
- JSP (18)
- SERVLET (6)
- ENGLISH (0)
- ECSide (8)
- JasperReports (7)
- JAVA (24)
- JS (42)
- XML (26)
- CVS (8)
- Mind (1)
- JQUERY (2)
- IBATIS (6)
- PROJECT (0)
- STRUTS2 (0)
- PROXOOL (0)
- SPRING (4)
- Hibernate (0)
- SSI (0)
- JBPM (11)
- FLEX (3)
- JSON (2)
- GWT (1)
- jeecms v3 (1)
- Flash (2)
- DATA (1)
- ORACLE (3)
- 查询oracle 中逗号分隔字符串中所有值 (1)
最新评论
-
小小西芹菜:
GoEasy web三步轻松实现web实时推送1. 引入goe ...
服务器推送技术 java -
kg_1997:
这个方法太棒了,可以不用to_date函数,实在是棒!!!
java/oracle日期处理 -
wodesunday:
:idea:
SQL的分段统计查询语句 -
wodesunday:
引用
SQL的分段统计查询语句 -
BlueSkator:
讲的有点浅,没有深入进去
tomcat需要的重新发布和重启服务器的几种情况
前一篇介绍了RPC大体的流程,核心方法是RemoteServiceServlet类中的processPost方法
这是一个final方法,无法覆写。不过GWT为我们提供了前置后置方法,供我们覆写:
onBeforeRequestDeserialized 请求反序列化之前的处理
onAfterResponseSerialized 响应序列化之后的处理
下面我们深入这三个步骤
1. readContent(request)
这里调用了内部的一个方法
解析的工作由RPCServletUtils来处理,进入此方法
调用了同名方法,添加了2个参数,分别是请求格式(text/x-gwt-rpc) 编码(utf-8)
进入
此处拿到request的输入流,并将内容转换为String类型返回。
至此readContent结束。
2. processCall(String payload)
处理这个请求的RPC调用
RPC.decodeRequest()方法对提交上来的文本解析,生成一个RPCRequest对象
进入此方法
获得了RPCRequest对象后,通过RPC.invokeAndEncodeResponse()调用业务对象完成RPC
拿到需要返回的序列化结果后,将其写入response
3. writeResponse
在写入response时,还判断浏览器是否支持gzip压缩,如果支持,则调用RPCServletUtils.writeResponse方法时,传参gzipEncod=true
当然内容还会判断,如果响应内容长度小于255,还是不会压缩的。
至此RPC整个请求响应完成
public final void processPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, SerializationException { // Read the request fully. // String requestPayload = readContent(request); // Let subclasses see the serialized request. // onBeforeRequestDeserialized(requestPayload); // Invoke the core dispatching logic, which returns the serialized // result. // String responsePayload = processCall(requestPayload); // Let subclasses see the serialized response. // onAfterResponseSerialized(responsePayload); // Write the response. // writeResponse(request, response, responsePayload); }
这是一个final方法,无法覆写。不过GWT为我们提供了前置后置方法,供我们覆写:
onBeforeRequestDeserialized 请求反序列化之前的处理
onAfterResponseSerialized 响应序列化之后的处理
下面我们深入这三个步骤
1. readContent(request)
这里调用了内部的一个方法
protected String readContent(HttpServletRequest request) throws ServletException, IOException { return RPCServletUtils.readContentAsGwtRpc(request); }
解析的工作由RPCServletUtils来处理,进入此方法
public static String readContentAsGwtRpc(HttpServletRequest request) throws IOException, ServletException { return readContent(request, GWT_RPC_CONTENT_TYPE, CHARSET_UTF8); }
调用了同名方法,添加了2个参数,分别是请求格式(text/x-gwt-rpc) 编码(utf-8)
进入
public static String readContent(HttpServletRequest request, String expectedContentType, String expectedCharSet) throws IOException, ServletException { if (expectedContentType != null) { checkContentTypeIgnoreCase(request, expectedContentType); } if (expectedCharSet != null) { checkCharacterEncodingIgnoreCase(request, expectedCharSet); } /* * Need to support 'Transfer-Encoding: chunked', so do not rely on * presence of a 'Content-Length' request header. */ InputStream in = request.getInputStream(); byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE); try { while (true) { int byteCount = in.read(buffer); if (byteCount == -1) { break; } out.write(buffer, 0, byteCount); } String contentCharSet = expectedCharSet != null ? expectedCharSet : CHARSET_UTF8; return out.toString(contentCharSet); } finally { if (in != null) { in.close(); } } }
此处拿到request的输入流,并将内容转换为String类型返回。
至此readContent结束。
2. processCall(String payload)
处理这个请求的RPC调用
public String processCall(String payload) throws SerializationException { // First, check for possible XSRF situation checkPermutationStrongName(); try { RPCRequest rpcRequest = RPC.decodeRequest(payload, delegate.getClass(), this); onAfterRequestDeserialized(rpcRequest); return RPC.invokeAndEncodeResponse(delegate, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); } catch (IncompatibleRemoteServiceException ex) { log( "An IncompatibleRemoteServiceException was thrown while processing this call.", ex); return RPC.encodeResponseForFailure(null, ex); } }
RPC.decodeRequest()方法对提交上来的文本解析,生成一个RPCRequest对象
进入此方法
public static RPCRequest decodeRequest(String encodedRequest, Class<?> type, SerializationPolicyProvider serializationPolicyProvider) { //….. 省略部分代码 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader( classLoader, serializationPolicyProvider); streamReader.prepareToRead(encodedRequest); //省略大量代码 //此处通过序列化读入流,解析文本,得出请求中需要调用的类名,方法名,已经方法签名数据 根据这些参数创建RPCRequest对象返回 return new RPCRequest(method, parameterValues, serializationPolicy, streamReader.getFlags()); } catch (NoSuchMethodException e) { throw new IncompatibleRemoteServiceException( formatMethodNotFoundErrorMessage(serviceIntf, serviceMethodName, parameterTypes)); } } catch (SerializationException ex) { throw new IncompatibleRemoteServiceException(ex.getMessage(), ex); } }
获得了RPCRequest对象后,通过RPC.invokeAndEncodeResponse()调用业务对象完成RPC
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, SerializationPolicy serializationPolicy, int flags) throws SerializationException { if (serviceMethod == null) { throw new NullPointerException("serviceMethod"); } if (serializationPolicy == null) { throw new NullPointerException("serializationPolicy"); } String responsePayload; try { //利用反射,完成对业务对象的调用 Object result = serviceMethod.invoke(target, args); //把业务对象调用的返回结果序列化编码 并返回 responsePayload = encodeResponseForSuccess(serviceMethod, result, serializationPolicy, flags); } catch (IllegalAccessException e) { SecurityException securityException = new SecurityException( formatIllegalAccessErrorMessage(target, serviceMethod)); securityException.initCause(e); throw securityException; } catch (IllegalArgumentException e) { SecurityException securityException = new SecurityException( formatIllegalArgumentErrorMessage(target, serviceMethod, args)); securityException.initCause(e); throw securityException; } catch (InvocationTargetException e) { // Try to encode the caught exception // Throwable cause = e.getCause(); responsePayload = encodeResponseForFailure(serviceMethod, cause, serializationPolicy, flags); } return responsePayload; }
拿到需要返回的序列化结果后,将其写入response
3. writeResponse
private void writeResponse(HttpServletRequest request, HttpServletResponse response, String responsePayload) throws IOException { boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request) && shouldCompressResponse(request, response, responsePayload); RPCServletUtils.writeResponse(getServletContext(), response, responsePayload, gzipEncode); }
在写入response时,还判断浏览器是否支持gzip压缩,如果支持,则调用RPCServletUtils.writeResponse方法时,传参gzipEncod=true
当然内容还会判断,如果响应内容长度小于255,还是不会压缩的。
至此RPC整个请求响应完成
发表评论
-
Apache FileUpload组件
2013-11-22 15:05 5410Apache FileUpload组件 在最初的 htt ... -
各种数据库对应的jar包、驱动类名和URL格式
2012-11-20 16:38 1468各种数据库对应的jar包、驱动类名和URL格式 2011 ... -
Java Web Start
2011-09-14 10:45 1323一.首先了解一下什么是java web start 1JNL ... -
The template at a glance一目了然的模板
2011-08-05 09:06 1470The template at a glance一目了然的模板 ... -
FreeMarker
2011-08-05 09:04 1104一目了然的数据模型 As you have seen, th ... -
jeecms v3
2011-07-04 15:28 1536好久没有逛jeecms的官方论坛了,今天去看了下,jeecms ... -
gwt整合ibatis
2011-07-02 09:42 2044最近整合gwt整合ibatis,常见错误 控制台报错: 一.N ... -
GWT RPC原理浅析
2011-06-17 15:26 5285GWT中前后台交互有多种方式,包括JSON,XML,RPC 其 ... -
五种开源协议
2011-04-25 14:54 1078五种开源协议(BSD,Apache,G ... -
JAVA代码调用客户端摄像头 初步探讨
2011-02-21 16:51 6717首先到sun下载最新的jmf,然后安装。 然后,说一下 ... -
tomcat部署jbpm项目 loader constraint violation
2011-02-11 14:22 1767当tomcat部署jbpm项目 时,启动项目控制台出错 ja ... -
E3.Tree参考手册
2010-12-10 09:52 3540E3.Tree参考手册 (v1.0) 目录 简介 2 系统 ... -
e3.tree 1.5 发布,很好,很强大,有截图[转]
2010-12-07 14:14 1111E3.Tree是E3平台下一个用于构造树型UI(menu,tr ... -
在Action中获取ServletContext实例
2010-11-25 13:43 37341:在Action中获取servletContext的时候可以 ... -
Bean named 'sqlMapClient' must be of type [org.springframework.orm.ibatis.SqlMap
2010-11-22 09:57 4877在整合spring2.5和ibatis2,出现了ibatis的 ... -
spring,ibatis的笔记
2010-11-22 08:51 1007在上文中,我们把iface ... -
spring,ibatis的笔记
2010-11-22 08:51 943在上文中,我们把iface ... -
后台错误处理
2010-11-17 15:10 1291后台处理 if (!isTokenValid(request) ... -
struts1 和Spring整合jar包
2010-11-17 11:33 4984struts1 和Spring整合 struts1 和Spri ... -
spring 与struts的集成
2010-11-17 08:37 1254Struts与Spring的集成主要有两种方式,即Delega ...
相关推荐
介绍gwtrpc-spring项目限制了Spring GWT-RPC。 其目的是提供后者的简化和更新版本。得到它Spring GWT-RPC在Maven Central上发布: < dependency> < groupId>fr.sertelon.spring</ groupId> < artifactId>spring-gwt...
GWT的环境搭建详细配置说明,GWT中RPC调用的详细例子,内附代码加文档说明。
GWT-RPC-1.pdf
基于GWTRPC的通讯软件源代码 作业源代码
GWT-RPC.pdfGWT-RPC.pdfGWT-RPC.pdfGWT-RPC.pdf
GWT-RPC-2.pdf GWT-RPC-2.pdf
GWT学习经验及实例指导,详细说明了GWT的安装以及使用步骤,结合实例,简单易懂
115提供的那个不知道怎么回事,我一直下不下来,后来在论坛...8. GWT-RPC 9. Ext GWT 10. (实战)俄罗斯方块游戏 11. (实战)费用申请审批流程 12. GWT与Flex整合 13. 图片缓存 CSS Sprite 14. 本地化 15. 其他高级功能
gwt 练习gwt 练习gwt 练习gwt 练习
gwt-rpc-序列化 重用 gwt-storage 和 gwt-rpc 序列化技术在客户端序列化对象的概念证明
EXT-GWT2.0.1+API+DOC gwtdesigner Gwt-Ext基础-中级-进阶 GWT快速开发 GWT入门 GWT中文教程
在本文的第二部分会比较详细的介绍GWT对UI的支持。 2.简单的RPC调用 使用GWT,可以方便的实现客户端和服务器端的通信,特别是使得异步通信变的非常简单。在本文的后面部分将对利用GWT进行RPC调用进行详细介绍。...
fwefwefwGWT工具GWT工具GWT工具GWT工具GWT工具GWT工具
本书内容全面,不仅详细介绍了 GWT 的主要模块和控件、GWT 与 JavaScript 对象的交互、在 GWT 中使用 XML、开发自定义 GWT 控件、GWT-RPC 和 Ext GWT 等必备的基础知识,而且还深入讲解了 GWT 与 Flex整合、图片缓存...
Gwt中文手册,GWt入门Gwt中文手册,GWt入门Gwt中文手册,GWt入门
gwt 入门,是你开始学习gwt的大道 安装之后的目录结构为: C:\程序开发\Java\gwt-windows-1.4.59 doc(文档目录,开发文档和Java API文档) samples(示例代码目录,非常有名的KitchenSink示例代码即在此目录中)...
org.liveSense.sample.gwt.notes.zip,livesense gwt rpc samplelivesense gwt示例
填《GWT揭秘》中8.1节中--GWT中的XMLHTTPRequest:请求动态数据的代码,
GWTPHP RPC 演示: : 巨大的功劳归于 Rafal M.Malinowski,他是 GWT 1.5 的原始 GWTPHP 库的作者。 他的项目网站: : 该项目已经死了很多年了,但我认为这是一个不错的主意,希望通过将其带到 GitHub 并结合最新...
很好的资源,在这边分享下,提供给想要寻找GWT资源的兄弟姐妹们 如果哪位兄弟有好的资源不要忘了分享啊