com.sap.ui5.resource.ResourceServlet的工作原理介绍

简介: com.sap.ui5.resource.ResourceServlet的工作原理介绍

There is one question asking how and where the js file “resources/sap-ui-core.js” is loaded when you run your UI5 application locally ( for example using tomcat )?


In my sample project mymap, there is no folder named resources and thus no sap-ui-core.js either.

image.pngIn order to figure out what happens in the runtime, let’s have a look at the web.xml under folder WEB-INF in the project.


There is a ResourceServlet defined. Actually it is the responsibility of this servlet delivered by SAP, which returns the content of resources like js, css and other type in the runtime. So now if I would like to investigate on this servlet, how could I get its source code?

image.pngHow to get source code of ResourceServlet

Suppose you have already an working Tomcat instance. Right click your UI5 project, choose Export->War file, and manually copy that exported war file to the webapps folder of your tomcat instance folder. In my case the folder is : C:\myProgram\tomcat-7.0.54\webapps.

Now start your tomcat via bat file, in my case: “C:\myProgram\tomcat-7.0.54\bin\startup.bat”:

You should see one information message that the war file is deployed:

image.pngimage.pngAfter that you could find three .class file in the unzipped folder, in my case they are:


(1) “C:\myProgram\tomcat-7.0.54\webapps\mymap\WEB-INF\lib\com.sap.ui5.resource_1.24.1\com\sap\ui5\resource\ResourceServlet.class”


(2) “C:\myProgram\tomcat-7.0.54\webapps\mymap\WEB-INF\lib\com.sap.ui5.resource_1.24.1\com\sap\ui5\resource\impl\ServletResource.class”


(3) “C:\myProgram\tomcat-7.0.54\webapps\mymap\WEB-INF\lib\com.sap.ui5.resource_1.24.1\com\sap\ui5\resource\impl\ServletResourceLocator.class”

The last step, google “jd-gui” and download it. It allows you to directly review source code of a .class file.

image.pngMore investigation on ResourceServlet

The main job of resource handling is wrapped in method serveResource of class ResourceServlet. We could find at least 2 useful hint from this method.


(1) use dev mode to figure out where the resource is loaded

image.pngYou could directly browse your application resource by appending “/resources/” to your application url, in my case it is: http://localhost:8080/mymap/resources/

image.pngYou might already notice the “CLASSPATH”, what does it mean?


The constructor of ServletResource which extends base class Resource has one parameter source, which indicates whether this resource is loaded locally or remotely ( configured through parameter com.sap.ui5.resource.REMOTE_LOCATION ):

image.pngimage.pngimage.pngimage.png



相关文章
|
1月前
|
XML 前端开发 JavaScript
深入介绍 UI5 框架里 Smart Field 控件的工作原理
深入介绍 UI5 框架里 Smart Field 控件的工作原理
18 0
|
2月前
|
XML JavaScript 数据格式
SAP UI5 XML Preprocessor 的工作原理和 instructions 指令详解
SAP UI5 XML Preprocessor 的工作原理和 instructions 指令详解
28 0
|
2月前
SAP Fiori Elements 应用里图片字段(Image)的显示原理介绍试读版
SAP Fiori Elements 应用里图片字段(Image)的显示原理介绍试读版
17 0
|
2月前
|
前端开发
问题解答:SAP UI5 应用设置禁止被其他应用嵌入运行的工作原理解析试读版
问题解答:SAP UI5 应用设置禁止被其他应用嵌入运行的工作原理解析试读版
113 0
|
6月前
|
应用服务中间件 API 数据库
SAP ABAP 应用程序中的锁机制和工作原理介绍试读版
SAP ABAP 应用程序中的锁机制和工作原理介绍试读版
51 0
|
6月前
|
Web App开发 XML 数据格式
SAP Fiori Elements List Report 表格新增列扩展方式的工作原理试读版
SAP Fiori Elements List Report 表格新增列扩展方式的工作原理试读版
42 0
|
6月前
|
Java API
SAP UI5 Library Resource Bundle 的设计原理
SAP UI5 Library Resource Bundle 的设计原理
51 0
|
6月前
|
Web App开发 Linux API
SAP UI5 设备类型检测 Device API 的工作原理
SAP UI5 设备类型检测 Device API 的工作原理
54 0
SAP UI5 设备类型检测 Device API 的工作原理
|
6月前
|
XML 存储 JSON
SAP UI5 应用的 OData XML 格式的元数据请求解析原理,基于 DOMParser
SAP UI5 应用的 OData XML 格式的元数据请求解析原理,基于 DOMParser
34 0
|
6月前
|
XML 存储 JSON
SAP UI5 应用的 OData 元数据请求响应的解析原理分析
SAP UI5 应用的 OData 元数据请求响应的解析原理分析
29 0