Requests are not in the same batch - odata

I'm having several calls that should be launched in parallel in a single batch request. This requests are function import call and two read requests. sapui5 version is 1.38.17 and odata model v2 used in this issue.
Here is request calls.
var oContext = this.getView().getBindingContext();
var oModel = this.getModel();
oModel.setDeferredGroups(["CSC"]);
oModel.setChangeGroups({
"FunctionImport1": {
groupId: "CSC",
changeSetId: "CSC1",
single: false
},
"ToRead1Set": {
groupId: "CSC",
changeSetId: "CSC1",
single: false
},
"ToRead2Set": {
groupId: "CSC",
changeSetId: "CSC1",
single: false
}
});
oModel.callFunction("/FunctionImport1", {
method: "POST",
groupId: "CSC",
changeSetId: "CSC1",
urlParameters: {
"Arg1": oContext.getObject("GUID"),
"Arg2": "",
"Arg3": ""
}
});
var sGUID1= oContext.getObject("ToRead1/GUID");
var sGUID2 = oContext.getObject("ToRead2/GUID");
oModel.read(oModel.createKey("/ToRead1Set", { GUID: sGUID2 }), {
groupId: "CSC",
changeSetId: "CSC1"
});
oModel.read(oModel.createKey("/ToRead2Set", { GUID: sGUID2 }), {
groupId: "CSC",
changeSetId: "CSC1"
});
oModel.submitChanges({
groupId: "CSC"
});
Initially there was only callFunction and read operations calls.
After I noticed that requests are not in the same batch I added setDeferredGroup call, but that didn't helped. After that I tried to add setChangesGroups that didn't worked either.
Here is what sapui5 odata model is sending.
--batch_e90b-96a1-4abd
Content-Type: multipart/mixed; boundary=changeset_f22c-3b40-d8af
--changeset_f22c-3b40-d8af
Content-Type: application/http
Content-Transfer-Encoding: binary
POST FunctionImport1?Arg1='123123123123'&Arg2=''&Arg3='' HTTP/1.1
sap-contextid-accept: header
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
x-csrf-token: prD6hap9bHc_pk8kt1Q7pg==
Content-Type: application/json
--changeset_f22c-3b40-d8af--
--batch_e90b-96a1-4abd
Content-Type: application/http
Content-Transfer-Encoding: binary
GET ToRead1Set('') HTTP/1.1
sap-contextid-accept: header
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
x-csrf-token: prD6hap9bHc_pk8kt1Q7pg==
--batch_e90b-96a1-4abd
Content-Type: application/http
Content-Transfer-Encoding: binary
GET ToRead2Set('') HTTP/1.1
sap-contextid-accept: header
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
x-csrf-token: prD6hap9bHc_pk8kt1Q7pg==
--batch_e90b-96a1-4abd--
Notice that batch ids and changesSet ids are the same, so, logically it is the same batch for every request, but, in practice backend and SAP Netweaver Gateway Service thinks that it is a three separate batch requests.
So, the questions are
1. Is it SAPUI5 bug or Gateway bug, if it is a bug at all?
2. How can I put this requests into single batch requests without this psychical division of requests with --batch lines.
I'm beginning to think about catching the formed payload and manually cut --batch separators between requests for this particular case, because can't find another way to do that.

Related

Mismatch with expected vs. actual results Dredd

Currently I'm running the uber.yaml found here. I'm currently getting mismatches on the actual versus expected values:
expected:
headers:
Content-Type: application/json
actual:
statusCode: 301
headers:
server: nginx
date: Tue, 13 Dec 2016 20:32:28 GMT
content-type: text/html
content-length: 178
location: https://api.uber.com/v1/history
connection: close
age: 0
Anyone know how to fix this? I have edited the the uber.yaml to include an expected content-type as follows:
- name: Content-Type
in: header
type: string
required: true
default: application/json
The problem is that the API responds with status code 301 and Content Type text/html, but your API description says it should respond with Content Type application/json.

Cannot exchange authorization code for long-lived access token with SurveyMonkey API

I've got the initial half of an OAuth flow working with the SurveyMonkey API, but when I try to exchange the short-lived authorization code for a long-lived OAuth access token, I get an HTTP 400 response. This is step 3 of the SurveyMonkey OAuth Guide.
Here's a scrubbed version of the full exchange:
POST /oauth/token?api_key=<removed> HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 338
Content-Type: application/json; charset=utf-8
Host: api.surveymonkey.net
User-Agent: HTTPie/0.7.2
{
"client_id": "<removed>",
"client_secret": "<removed>",
"code": "dKkIJYnimBli3TMHoTdHoT-zkzkUFzfHeaWJJyPVmrYG35R5Q-jLLU-Y7Fg3BR0n3tVTQ6sAmDnwVxHXSjZVdiYTJ7u7SWbLCKgQa061bKJYXSpRhTsEL0v5GMWcMEBC2vje5UjRHp3SScFQEwIIjHKZH5raC5RQJJh.JYWEOqw8Iy-2Ds7km1zYaHGGlxqu",
"grant_type": "authorization_code",
"redirect_uri": "https://app.hubspotqa.com"
}
HTTP/1.1 400 Bad Request
Cache-Control: no-store
Connection: keep-alive
Content-Length: 96
Content-Type: application/json; charset=UTF-8
Date: Fri, 24 Jan 2014 00:05:53 GMT
SM-Request-ID: 41264d11-b93d-4f8b-ad1a-c656ccfa268b
Server: nginx
{
"error": "invalid_request",
"error_description": "Invalid POST body or Content-Type received."
}
I'm able to reproduce the exact same error using other HTTP clients as well, but I have no trouble manually getting an access token using the SurveyMonkey API console. What am I doing wrong?
Side question: the OAuth guide says that step 3 accepts a redirect_uri but the example Python guide uses redirect_url. Which is the correct parameter? Can I omit it entirely? My server certainly does not care about getting redirected anywhere.
As it turns out, the required Content-Type for this POST is form encoding – application/x-www-form-urlencoded, not JSON.
Note that the documentation does not actually say that anywhere; it's implied by the example usage of the Python requests library.

OAuth 2.0 access token isn't refreshed, gives 401 Error : Token Invalid when used

I am currently using the Youtube API for a desktop application in C++. I am trying to implement the direct upload, which requires an authentication. I naturally choose OAuth 2.0, I followed the Google example and apparently everything worked well, I've got an access token and a refresh token, without any error returned.
However, when I try to use the access token to upload a video (I put it in the Authorization : Bearer header), I get an error 401 : Unauthorized with the description Token Invalid.
I then tried to refresh the access token right before requesting the upload (which means I try to refresh right after retrieving the access token, since the two operations are consecutive in my application's flow). The access token remained unchanged : I received the same access token from the refresh request and the exchange request.
I first thought it meant an access token should be refreshed only when it expires, but it is apparently not true : using the OAuth 2.0 Playground, it seems clear that refreshing a not yet expired token works fine and gives a different access token.
Any idea on what the problem could be ? Is the 401 error linked to the fact that I am not able to refresh the token ?
Edit : Here are the request and the response as shown in Fiddler
Request :
POST http://uploads.gdata.youtube.com/feeds/api/users/default/uploads HTTP/1.1
Accept: */*
Accept-Language: xx
Authorization: Bearer MY_ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=MY_DEV_KEY
Slug: test.avi
Content-Type: multipart/related; boundary="f93dcbA3"
Pragma: no-cache
User-Agent: SOME_STUFF
Host: uploads.gdata.youtube.com
Content-Length: 23686
Connection: Keep-Alive
--f93dcbA3
Content-Type: application/atom+xml; charset=UTF-8
<?xml version="1.0"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"><media:group><media:title type="plain">Bad Wedding Toast</media:title><media:description type="plain">I gave a bad toast at my friend's wedding.</media:description><media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category><media:keywords>toast, wedding</media:keywords></media:group></entry>
--f93dcbA3
Content-Type: video/avi
Content-Transfer-Encoding: binary
<My file binary data>
--f93dcbA3--
Response
HTTP/1.1 401 Unauthorized
X-GData-User-Country: FR
WWW-Authenticate: Bearer realm="https://accounts.google.com/o/oauth2/auth",service="youtube"
Content-Type: text/html; charset=UTF-8
Content-Length: 13
X-GUploader-UploadID: AEnB2UrVDA94Fk5VFn1ng-2q9VFOo2KifLvIEHFOxQ4m66IUSC8sRf3mo5S8UH94mLyupbfANeLQvxMPhPLo6L0wlcaguQW9CQ
Date: Wed, 17 Jul 2013 09:51:23 GMT
Server: HTTP Upload Server Built on Jul 8 2013 15:32:26 (1373322746)
Token invalid
Edit 2 : Request and response using Youtube API v3
Request :
POST /upload/youtube/v3/videos?part="snippet" HTTP/1.1
Host: www.googleapis.com
X-gdata-key: DEV_KEY
Content-length: 42190
Content-type: multipart/related; boundary="===============1679429526=="
Authorization: ACCESS_TOKEN
--===============1679429526==
Content-type: application/json
{
"snippet":
{
"title": "test"
}
}
--===============1679429526==
Content-type: video/avi
<BINARY DATA - 41984B>
--===============1679429526==--
Response :
HTTP/1.1 400 Bad Request
Content-length: 229
Via: HTTP/1.1 GWA
X-google-cache-control: remote-fetch
Server: HTTP Upload Server Built on Jul 8 2013 15:32:26 (1373322746)
Date: Wed, 17 Jul 2013 22:14:03 GMT
Content-type: application/json
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badContent",
"message": "Unsupported content with type: video/avi"
}
],
"code": 400,
"message": "Unsupported content with type: video/avi"
}
}

404 error when posting new forum post in Desire2Learn 10.0

I'm working with the D2L API,and am having difficulty with some POST requests.
Doing a version check (POST) using the JSON object:
[{ "ProductCode": "lp", "Version": "1.0" }]
returns correctly, providing me a valid JSON object in response, that being said I'm confident that my code to issue the call is working correctly.
When I issue a POST to create a post in a forum, however, I get a 404 in response. The JSON object I'm sending for this call is:
[
{
"ParentPostId": null,
"Subject": "API Posted",
"Message": {
"Text": "This message has been posted by the API",
"HTML": "This message has been posted by the API"
},
"IsAnonymous": false
}
]
And the URL submitted to is /d2l/api/le/{ver}/{orgId}/discussions/forums/{forumId}/topics/{topicId}/posts/
I've verified that ver/orgId/forumId/topicId are all valid using a GET of a post in the same forum and topic. I've also tried quoting the values for ParentPostId and IsAnonymous both separately and in unison.
Try removing the square brackets from the JSON.
An example of a successful request and response follows:
REQUEST
POST https://valence.desire2learn.com/d2l/api/le/1.0/7664/discussions/forums/203/topics/508/posts/?x_b=TwULqrltMXvTE8utuLCN5O&x_a=L2Hd9WvDTcyiyu5n2AEgpg&x_d=nF61tBeuzd0EPTW7nm8iGc4MB7NeJZaNM2VlzHp0bwU&x_c=I3i_k2aANTIf2X6aFsiOdvlElSR_avvOYnA2ibcWabA&x_t=1343335429 HTTP/1.1
Accept-Encoding: gzip,deflate
Accept: application/json
Content-Type: application/json
{ "ParentPostId": null, "Subject": "API Posted", "Message": { "Content": "This message has been posted by the API", "Type": "HTML" }, "IsAnonymous": false }
RESPONSE
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Length: 369
Content-Type: application/json; charset=UTF-8
Expires: -1
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Date: Thu, 26 Jul 2012 20:43:58 GMT
{"ForumId":203,"PostId":574,"TopicId":508,"PostingUserId":3667,"ThreadId":205,"ParentPostId":null,"Message":{"Text":"","Html":"This message has been posted by the API"},"Subject":"API Posted","DatePosted":"2012-07-26T20:43:58.920Z","IsAnonymous":false,"RequiresApproval":false,"IsDeleted":false,"LastEditDate":null,"LastEditedBy":null,"CanRate":false,"ReplyPostIds":[]}
Looking at the documentation for that route at http://docs.valence.desire2learn.com/res/discuss.html#post--d2l-api-le-(D2LVERSION-version)-(D2LID-orgUnitId)-discussions-forums-(D2LID-forumId)-topics-(D2LID-topicId)-posts-, it looks like the required data structure uses a RichTextInput not a RichText for Message.
Try changing your Message field to:
{
"Content": "This message has been posted by the API",
"Type": "Text"
}

Neo4j REST Encoding

I'm using neo4jclient. When I try to create/update an node, special chars like äöü are replaced with �.
Do I have to set a specific http header like content-type, content-encoding? If yes, what kind of header and what is the value of this header?
Thanks.
EDIT:
This is how the request looks like:
POST http://...........:7474/db/data/batch HTTP/1.1
Accept: application/json;stream=true
User-Agent: RestSharp 103.1.0.0
Content-Type: application/json
Host: ............:7474
Content-Length: 267
Accept-Encoding: gzip, deflate
[
{
"method": "POST",
"to": "/node",
"body": {
"Name": "äöü",
"State": "Active",
"Id": 0,
"CreateDate": "2012-07-12T18:48:45.3343526+02:00",
"ChangeDate": "0001-01-01T00:00:00+00:00"
},
"id": 0
}
]
Or is it bug in the batch execution? If yes, I'll need the fix very quick:)
Now it works
After analyzing the messages.log we found out, that the file.encoding wasn't utf-8.
--> DEBUG [neo4j.diagnostics]: file.encoding = Cp1252
So we set in the neo4j-wrapper.conf file this property:
wrapper.java.additional.3=-Dfile.encoding=UTF-8
Now it works!!! :)
Thanks to my brother! Always good to know a Java developer. :)
There are tests for this in the codebase, so it should be handled correctly, see https://github.com/neo4j/community/blob/master/server/src/functionaltest/java/org/neo4j/server/rest/BatchOperationFunctionalTest.java#L322 . However, there might be encoding problems in the client?

Resources