`
JerryWang_SAP
  • 浏览: 1057811 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

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.

 

 

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的原创文章,请关注公众号"汪子熙":

0
2
分享到:
评论

相关推荐

    com.sap.aii.mapping.api PI MAPPING开发必须jar包

    XI PI MAPPING开发必须jar包 import com.sap.aii.mapping.api.*; import com.sap.aii.mapping.api.*; import com.sap.aii.mapping.lookup.*; import com.sap.aii.mappingtool.tf7.rt.*;

    hana jdbc ngdbc.jar com.sap.db.jdbc.Driver

    标题 "hana jdbc ngdbc.jar com.sap.db.jdbc.Driver" 指的是 SAP HANA 数据库的 JDBC 驱动程序,其核心组件是一个名为 `ngdbc.jar` 的 Java 类库。这个驱动程序允许 Java 应用程序通过 JDBC(Java Database ...

    com.sap.xpi.ib.mapping.lib

    com.sap.xpi.ib.mapping.lib.jar SAP PI JAVA MAPPING 必备JAR包

    SAP PI 7.1 com.sap.aii.adapter.lib.sda

    SAP PI 7.1 com.sap.aii.adapter.lib.sda

    SAP PI Java Mapping com.sap.aii.mapping.api PI MAPPING开发必须jar包

    标题提到的"com.sap.aii.mapping.api PI MAPPING开发必须jar包"是Java Mapping开发的核心依赖库,它们包含了API和其他必要的组件,使得开发人员能够创建自定义的映射逻辑。以下将详细讲解SAP PI Java Mapping的开发...

    sap.m.sample.Image.zip_UI5_sap ui5_sap.m.Image

    【标题】"sap.m.sample.Image.zip_UI5_sap ui5_sap.m.Image"是一个与SAP UI5框架相关的示例项目,重点展示了如何在应用程序中使用`sap.m.Image`控件来显示图像。这个压缩包包含了开发和运行该示例所需的所有文件。 ...

    com.sap.security.core.jar

    jar包,官方版本,自测可用

    SAPJCO.jar包下载

    通过导入相关的包,如`com.sap.conn.jco.*`,开发者可以创建RFC连接,定义参数,执行函数模块调用等操作。 提供的帮助文档通常会包含详细的安装指南、API参考、示例代码以及故障排查信息。这对于初学者来说尤其重要...

    sap.m.sample.LightBox.zip_UI5_proudx4v_sap ui5

    【标题】"sap.m.sample.LightBox.zip_UI5_proudx4v_sap_ui5" 提供的是一个关于 SAP UI5 的示例项目,名为 "LightBox",它使用了 "proudX4v" 版本的 SAP UI5 技术栈。LightBox 在 UI5 中通常指的是一个组件,用于展示...

    SAP UI5 Reference for SAP HANA

    2. 快速入门指南,详细介绍了如何选择合适的浏览器来运行SAP UI5应用,以及如何创建第一个移动应用或者SAP UI5应用程序。 3. 模型-视图-控制器(MVC)设计模式,这是SAP UI5中的核心概念之一,用于分离应用逻辑、...

    SAP UI5 文档

    SAP UI5(用户界面5)是SAP公司开发的一个用于创建企业级Web应用程序的框架,特别是那些与SAP系统交互的应用程序。SAP UI5建立在HTML5、CSS3和JavaScript的基础上,使用了响应式设计原则,让应用程序可以在各种设备...

    Microsoft.Adapter.SAP.SAPProvider.dll

    c# 连SAP 库文件 Microsoft.Adapter.SAP.SAPProvider.dll库文件

    UIPATH机器人实现登录SAP的功能

    在实际的企业环境中,SAP作为一款强大的ERP(Enterprise Resource Planning)系统,涵盖了财务管理、供应链管理、人力资源等多个模块,而UiPath能够帮助自动化这些模块中的流程,实现端到端的业务自动化。...

    SAP UI5入门

    **注**:您可以通过在线方式访问 Demo Kit:[SAP UI5 Demo Kit on SAP HANA Cloud](https://sapui5.hana.ondemand.com/)。请注意,这可能并不是您本地版本的 Demo Kit。 #### 三、选择浏览器 SAP UI5 对浏览器的...

    com.sap.security.api.jar

    jar包,官方版本,自测可用

    sapjco30/sapjco3.dll/sapjco3.jar SAP官网2017/7/18更新版本

    SAP JCo (Java Connector) 是一款用于连接Java应用程序与SAP系统的关键组件,它提供了在Java环境中访问SAP R/3系统或者SAP NetWeaver应用服务器的能力。"sapjco30"指的是SAP JCo的第三版,这个版本对应于JCo 3.0,是...

    SAP UI5打包成APP

    在如今数字化转型的浪潮中,SAP UI5作为一种面向企业级应用的开发框架,越来越多的企业选择使用它来构建和部署应用程序。SAP UI5以其丰富的控件库、良好的集成性以及适应性而受到企业的青睐。然而,随着移动设备的...

    SAP UI5入门概述

    ### SAP UI5 入门知识点概述 #### 一、SAP Fiori与SAP UI5基础知识 ##### 1.1 SAP Fiori 概念及重要性 - **SAP Fiori 定义**:SAP Fiori 是 SAP 推出的新一代用户交互系统 (User Experience, UX),旨在为用户提供...

    SAPUI5(SAP Fiori)运行环境介绍

    SAPUI5与SAP Fiori紧密相连,Fiori是SAP用户界面设计的一套原则和模式,它定义了应用应该如何表现和工作,而SAPUI5就是实现这些原则和模式的技术框架。SAPUI5运行环境是指使用该框架开发的应用可以部署和运行的平台...

    SAP HANA数据库连接 ngdbc.jar

    SAP HANA数据库连接jar ngdbc.jar DRIVER = "com.sap.db.jdbc.Driver"; url="jdbc:sap://<HANA数据库主机名>:30015?reconnect=true

Global site tag (gtag.js) - Google Analytics