Comments (10)
Well, the general idea should better be to extract the boundary name from the header "Content-Type", value is usually "multipart/mixed; boundary=XYZ". "--XYZ" ist then the boundardy to use in the regexp.
AND per can a changeset inside a batchresponse, so if one extracted batch part has also a header "Content-Type", do the same logic recursivly. This will work much better than assuming some specific boundary names.
from o.js.
Hi Chris,
Thanks for your input. We actual have the problem, that we cannot test any batch response because the odata test service does not allow batches. How does your plain response look like? I was using web api and there the --batchresponse
keyword was used to seperate responses, but it might depend on the implementation.
Regards,
Jan
from o.js.
Here are the results of two batched GET requests. I can provide batched POSTs too if it helps. This was just quick and easy. Details of the source/provider in the headers. Must be quite challenging to code without the ability to test.
Request
POST /odata/$batch HTTP/1.1
Host: localhost:80
Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b
Cache-Control: no-cache
--batch_36522ad7-fc75-4b56-8c71-56071383e77b
Content-Type: application/http
Content-Transfer-Encoding:binary
GET Clients(13) HTTP/1.1
--batch_36522ad7-fc75-4b56-8c71-56071383e77b
Content-Type: application/http
Content-Transfer-Encoding:binary
GET Clients(11) HTTP/1.1
--batch_36522ad7-fc75-4b56-8c71-56071383e77b
Response Headers
Cache-Control: no-cache
Content-Length: 3279
Content-Type: multipart/mixed; boundary=batchresponse_d599621c-0bfa-439c-ae1e-c20a25a5d087
Date: Tue, 11 Jul 2017 07:33:28 GMT
Expires: -1
OData-Version: 4.0
Pragma: no-cache
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Response Body
--batchresponse_d599621c-0bfa-439c-ae1e-c20a25a5d087
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true
OData-Version: 4.0
{
"@odata.context": "http://localhost/odata/$metadata#Clients/$entity",
"ClientId": 13,
"Name": "John Smith"
}
--batchresponse_d599621c-0bfa-439c-ae1e-c20a25a5d087
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true
OData-Version: 4.0
{
"@odata.context": "http://localhost/odata/$metadata#Clients/$entity",
"ClientId": 11,
"Name": "Peter Parker"
}
--batchresponse_d599621c-0bfa-439c-ae1e-c20a25a5d087--
from o.js.
Hey Chris
I checked your regex sugestions. Basically its a good idea, but we are using this complicated one because you can have complexer JSON response like the following:
HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true
OData-Version: 4.0
{
"@odata.context": "http://localhost/odata/$metadata#Clients/$entity",
"ClientId": 13,
"Name": "John Smith",
"More": {
"Some": "more"
}
}
--batchresponse_d599621c-0bfa-439c-ae1e-c20a25a5d087
When you have this response your regex is not working anymore. Thats why we use the regex until the --batchresponse_
part and afterwards substringing it. Normaly that should work, don't know what exactly is not working for your part because I checked it in a regex-coach and it marks the correct parts.
Regards
Jan
from o.js.
Sorry it took me so long to respond. I think I might have confused this a bit. Yes, the sample I posted above works fine. This one however is quite different, sorry for the confusion.
Request
--batch_b98d80d7-5929-4eb5-a442-28f9f1a18bda
Content-Type: multipart/mixed; boundary=changeset_5d16bad8-07e2-4c94-f537-0897f1024d1c
--changeset_5d16bad8-07e2-4c94-f537-0897f1024d1c
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID:01
POST http://target:8080/odata/ListDetails/ HTTP/1.1
Host: http://target:8080/odata/
Content-Type: application/json
{"ListId":19,"ClientId":12,"IsYes":false,"AttrUserId":1132,"SourceId":11}
--changeset_5d16bad8-07e2-4c94-f537-0897f1024d1c
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID:11
POST http://target:8080/odata/ListDetails/ HTTP/1.1
Host: http://target:8080/odata/
Content-Type: application/json
{"ListId":19,"ClientId":131,"IsYes":false,"AttrUserId":1132,"SourceId":11}
--changeset_5d16bad8-07e2-4c94-f537-0897f1024d1c--
--batch_b98d80d7-5929-4eb5-a442-28f9f1a18bda--
Response
--batchresponse_84059c2c-fddb-4d82-b835-38320e143c52
Content-Type: multipart/mixed; boundary=changesetresponse_b64175cf-4cbf-48d4-8a02-7f2e8a97e748
--changesetresponse_b64175cf-4cbf-48d4-8a02-7f2e8a97e748
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 01
HTTP/1.1 201 Created
Location: http://target:8080/odata/ListDetails(67147)
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
{
"@odata.context":"http://target:8080/odata/$metadata#ListDetails/$entity","ListDetailId":67147,"ListId":19,"ClientId":12,"IsYes":false,"AttrUserId":1132,"IsExported":false,"ExportDtTm":null,"ModifiedId":null,"ModifiedIdentityId":null,"ModifiedDtTm":null,"CreatedId":784,"CreatedIdentityId":null,"CreatedDtTm":"2017-09-04T17:52:20.7467198-10:00","SourceId":11,"IsError":false,"ErrorMsg":null
}
--changesetresponse_b64175cf-4cbf-48d4-8a02-7f2e8a97e748
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 11
HTTP/1.1 201 Created
Location: http://target:8080/odata/MailingListDetails(67148)
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
{
"@odata.context":"http://target:8080/odata/$metadata#ListDetails/$entity","ListDetailId":67148,"ListId":19,"ClientId":131,"IsYes":false,"AttrUserId":1132,"IsExported":false,"ExportDtTm":null,"ModifiedId":null,"ModifiedIdentityId":null,"ModifiedDtTm":null,"CreatedId":784,"CreatedIdentityId":null,"CreatedDtTm":"2017-09-04T17:52:21.4058573-10:00","SourceId":11,"IsError":false,"ErrorMsg":null
}
--changesetresponse_b64175cf-4cbf-48d4-8a02-7f2e8a97e748--
--batchresponse_84059c2c-fddb-4d82-b835-38320e143c52--
This is where I was running into trouble and where I now have updated the regex/substring to
var regex = /({[\s\S]*?--changesetresponse_)/g;
...
parseResponse(result[0].substring(0, result[0].length - 20), tempBase);
Perhaps the header needs to be interpreted to know whether to use "batch" or "changeset." I don't have enough experience with odata $batch support (even within our implementation) to really qualify "changesetresponse" vs "batchresponse" and perhaps if there are variations in vendor implementations, versions, etc.
Not sure if this is really helping (you)...
Best,
Chris
from o.js.
Maybe we can generalize the regex and use this one: /({[\s\S]*?}\n--)/g
that would match change and batch only responses. What do you think?
from o.js.
You shoud definitly parse the Content-Type and use the boundary from there to parse the body. This can then be kind of recursive, ie changeset inside batch.
Eg SAP OData implementation uses only GUIDs as boundaries.
from o.js.
Hey, i have the same issue on Batch-Requests...
that works in my case, could that be problematic?
var regex = /({[\s\S]*?--)/g;
var result;
do {
var result = regex.exec(ajaxRequest.responseText);
if (result) {
parseResponse(result[0].substring(0, result[0].length - 3), tempBase);
dataArray.push(tempBase.data);
}
} while (result);
Unfortunately, I do not know all the variations of batch-odata...
from o.js.
Totally agree with you @DerGuteWolf .
But the Content-Type needs to parsed as well... so the complete logic of the parseResponse
must be reviewed.
from o.js.
#83 uses the Content-Type header to parse the $batch request.
from o.js.
Related Issues (20)
- Can make count to work HOT 2
- Node incompatibility HOT 8
- Changes in 1.3.0 didn't make it into NPM HOT 1
- Bundle size pretty big, since universal-url HOT 6
- Support for FormData HOT 1
- `application/x-www-form-urlencoded` encoding in `applyQuery` is incompatible with Apache Olingo - no way to overwrite HOT 10
- can't get @odata.count data from response HOT 1
- Not compatible with node v18.2.0? HOT 2
- Connect reuse policy in O.js HOT 1
- Credentials problem, am I doing something wrong? HOT 1
- Chaining no longer possible with o.js HOT 1
- `onError` is not called when a network error occurs in `query` and `batch` methods HOT 3
- Topic to consider on OHandler HOT 1
- o constructor taking two parameters when there should should be 1 parameter HOT 3
- request should return a promise but instead returns void HOT 1
- HTTPS mutual certificate example HOT 1
- Invalid referrer HOT 1
- Can't we get the URL-building functionality only? HOT 2
- How to show actual URL called HOT 5
- Always failed to send delete requests in batch mode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from o.js.