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.

However, in the runtime, you could indeed observe the folder resources and the sap-ui-core.js inside it via Chrome development tool, tab “Sources”:

In 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?

How 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:

Now go back to your webapps folder, you should have a folder mymap which is automatically unzipped from war file by Tomcat.

Now just search by keyword “Resource”, and unzip the first hit jar file.

After 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.


Since now we have source code at hand, we could do further investigation on this servlet.

More 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

From line 616 and 617, we get to know if the current application runs under Dev mode, it is supported to print out the url of the found resource in http response header.
Just switch on Dev mode by making following settings in web.xml:

after that you could observe the x-sap-ResourceUrl attribute for sap-ui-core.js in Chrome Network tab, which shows where Tomcat loads this js file in the runtime.

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

You 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 ):

in class ServletResourceLocator which implements interface ResourceLocator, the instance for found ServletResource is initialized with corresponding source category, “CLASSPATH” or “REMOTE”, according to different approaches how they are actually loaded:

And ResourceServlet will print out this property for each found resource between a pair of “[ ]”:

this is the reason why you could see lots of CLASSPATH in tomcat output:

understand HTTP 304 status
For example, why I get a HTTP 304 Not Modified for this file?

The answer is in line 625 of ResourceServlet class:

In this example, the second condition after && is always true, since I never make any modifications on this standard library js file:

So we only need to evaluate the result of CacheControlFilter.hasNoCacheHeader(request). The source code of this method is listed below:

In my example since there is no such Cache-Control in request header, this method will return false and finally leads to a 304 status code.

So now if we click the checkbox “Disable cache” in Chrome, we then get a HTTP 200 status code instead, since this checkbox adds a Cache-Control header with value “no-cache”:

With the approach introduced in this blog, you could also explore another servlet by yourself, which you could also find and configure it in web.xml: com.sap.ui5.proxy.SimpleProxyServlet.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

com.sap.ui5.resource.ResourceServlet的工作原理介绍相关推荐

  1. SAP UI5 Negative cache的工作原理

    I am testing my Fiori extension project created based on SAP standard Fiori application "My Opp ...

  2. SAP Fiori Elements 框架里 Smart Table 控件的工作原理介绍

    这是 Jerry 2021 年的第 34 篇文章,也是汪子熙公众号总共第 310 篇原创文章. Jerry 前一篇文章 深入掌握 SAP Fiori Elements 工作原理系列之二:如何给 Fio ...

  3. SAP UI5 应用开发教程之六十二 - 基于 OData V4 的 SAP UI5 表格控件使用方法介绍试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  4. SAP UI5 初学者教程之二十八 - SAP UI5 应用的集成测试工具 OPA 介绍试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 初学者教程之一:Hello World SAP UI5 初学者教程之二:SAP UI5 ...

  5. SAP UI5 初学者教程之二十七 - SAP UI5 应用的单元测试工具 QUnit 介绍试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 初学者教程之一:Hello World SAP UI5 初学者教程之二:SAP UI5 ...

  6. Express中间件工作原理介绍

    Express中间件工作原理介绍 中间件是Express框架学习中最难的部分,同时也是最为核心的技术,我们的学习路线如下 1.什么是中间件 2.Express中间件的本质及工作原理 3.自定义解析po ...

  7. 时间同步装置(卫星时钟同步)工作原理介绍

    时间同步装置(卫星时钟同步)工作原理介绍 时间同步装置(卫星时钟同步)工作原理介绍 微软从Windows2000开始,系统就支持使用NTP同步的方式获取时间,Windows系统默认的时间源都来自tim ...

  8. 【原理】#01红外热成像仪的工作原理介绍

    红外热成像仪是电测中比较特殊的一种仪器设备,在温度测试领域有着广泛的应用. 红外热成像仪测温的原理是怎么样的?如何选择合适的热成像仪? 安泰小课堂将分两期视频为大家进行揭秘. 本期内容将重点讲解红外热 ...

  9. 石英加速度计工作原理介绍

    石英加速度计工作原理介绍 加速度是一种用来反映物体在运动过程中的速度变化状态的物理量,其无法直接测量,当前的加速度传感器(加速度计)采用间接测量以及力的平衡等技术来获取物体的加速度.加速度传感器的工作 ...

最新文章

  1. 只用一张训练图像进行图像的恢复
  2. 阿里巴巴使命、愿景、价值观、绩效管理中的六大价值观、
  3. 企业正确进行数字化转型的7个秘诀
  4. C# 无法识别的转义序列
  5. 学习使用Ansj分词工具(一)
  6. pytest文档4-测试用例setup和teardown
  7. How to Become a Better Learner
  8. C# 网页自动填表自动登录 .
  9. 贵州大学旧物交易系统
  10. JDK9API网盘下载
  11. 比特率控制模式ABR、VBR、CBR
  12. python3.0编程软件_震惊!国内已知第一款Scratch 3.0编程软件KittenBlock推出Python编程功能!...
  13. Tableau Server9.1.2 配置集群
  14. c语言小饭店等位就餐程序,小饭店预约登记管理系统,
  15. HTTP代理服务器的实现
  16. 大家应该如何选择短线交易?
  17. 2015年数模B题学习报告
  18. RK3568 使用iperf3的丢包率测试
  19. 数据挖掘知识点整理(期末复习版)
  20. 安卓逆向013之DDMS去广告(车来了)

热门文章

  1. Beginning SDL 2.0(4) YUV加载及渲染
  2. centos下配置vsftpd
  3. java编程思想 学习笔记(2)
  4. quartz 2.2.1 jdbc 连接池参数配置
  5. javascript 常用类
  6. zookeeper集群配置说明以及window单台机器集群搭建
  7. web服务器 http请求返回 不同返回码的 对应 语意
  8. /bin/bash^M: bad interpreter: 没有那个文件或目录
  9. 20应用统计考研复试要点(part14)--应用多元分析
  10. python与正则表达式(part6)--re模块使用