When I am doing a test of comparison between Stateful and Stateless BSP application ( mentioned in blog Stateless and Stateful – Different behavior in application side ), I meet with a strange issue.
The conclusion is stateful BSP application will handle request sequentially. Suppose in client I send two request A and B to server. Request A takes 3 seconds to finish and B 2 seconds.
The request is sent via jQuery API. It means for stateful application, I will observe the following timeline in Chrome network tab:
(1) the start time of both request are almost the same, since I send out two request in client code almost at the same time. (2) even though the second request itself takes 2 seconds to finish, the total processing time for it is 3 seconds waiting for A to finish first + 2 seconds = 5 seconds in the end.
The above test did verify the conclusion. However when I change the approach to send request into ES6 fetch API,
<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<!DOCTYPE html>
<html>
<head>
<title>Jerry Test Stateful</title>
</head>
<body>
<button onclick="fire()">Fire two request</button>
<script>
function wrapperOnFetch(url){
fetch(url).then(function(response){
return response.json();
}).then(function(json){
console.log(url + ":" + json.message);
});
}
function fire(){
wrapperOnFetch("first.json");
wrapperOnFetch("second.json");
}
</script>
</body>
</html>
the testing request for stateful application looks as below this time:
The two requests are handled simultaneously ( request B only takes 2 seconds to finish, no 3 seconds’ wait time for A to finish this time ), the response of second request returns first before the first, which could be observed in console:
why the latest ES6 API causes such discrepancy with known conclusion? Just compare the cookie of requests sent via these two kinds of API:
Through comparison I get to know that the session cookie sap-contextid is not sent together with request triggered by ES6 Fetch API. Then in Fetch documentation I find out that I need to add option credentials: “include”.
function wrapperOnFetch(url){
// enable session cookie sent with request
fetch(url,{ credentials:"include" }).then(function(response){
return response.json();
}).then(function(json){
console.log(url + ":" + json.message);
});
}
After this change the stateful BSP application behaves as expected: the requests are handled in sequence.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
一个微小的ES6 fetch() 包装不需要对API大动干戈
JavaScript ES6函数式编程入门经典
本次将介绍如何使用Fetch API(ES6 +)对REST API的 HTTP请求,还有一些示例提供给大家便于大家理解。具有一定的参考价值,感兴趣的小伙伴们可以参考一下
JavaScript(ES6新增、W3C、MDN)最新参考手册.rar
javascript
JavaScript ES6新增特性
知识点 参考 The Eloquent JavaScript, The Pro MERN Stack
《JavaScript ES6函数式编程入门经典》使用JavaScript ES6带你学习函数式 编程。你将学习柯里化、偏函数、高阶函数以及Monad等概念。 目前,编程语言已经将焦点从对象转移到函数。JavaScript支持函数式编 程,并...
Javali(又名JAVAScript LIbrary)是一个像Create React App这样的CLI,但用于创建JavaScript库。
es6笔记整理
首先,一个常见的问题是,ECMAScript 和 JavaScript 到底是什么关系? ECMAScript是一个国际通过的标准化脚本语言。JavaScript由ECMAScript和DOM、BOM三者组成。可以简单理解为:ECMAScript是JavaScript的语言...
ES6,全称ECMAScript 6.0,正式名称为ECMAScript 2015,是JavaScript的下一个版本标准,于2015年6月17日发布。它的目标是使得JavaScript语言可以用来编写复杂的大型应用程序,成为企业级开发语言。 1997年,...
Javascript – ES6 实战视频课程
JavaScript es6新语法知识点框架,png格式加X-mind格式 可更改,复习,预习必备神器
es6
冴羽写博客的地方,预计写四个系列:JavaScript深入系列、JavaScript专题系列、ES6系列、React系列。
ECMAScript 6 技术扫盲,快速学习ES6,进入Javascript开发ES6时代。
浅析Javascript ES6中的原生Promise_.docx
新版ES6,java客户端操作elasticsearch比较详细的API。