OData $batch request using ODataQueryBuilder or VDM - s4sdk

Is there a way to send OData batch requests using either ODataQueryBuilder or VDM generated classes?
Example:
Let's say I'm using the Northwind public OData service (https://services.odata.org/V2/Northwind/Northwind.svc/)
Due to network performance I want to query the Customers, Categories and Regions in one only request, like this:
URL: https://services.odata.org/V2/Northwind/Northwind.svc/$batch
--batch_8008-578f-c3c1
Content-Type: application/http
Content-Transfer-Encoding: binary
GET Customers HTTP/1.1
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
--batch_8008-578f-c3c1
Content-Type: application/http
Content-Transfer-Encoding: binary
GET Categories HTTP/1.1
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
--batch_8008-578f-c3c1
Content-Type: application/http
Content-Transfer-Encoding: binary
GET Regions HTTP/1.1
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
--batch_8008-578f-c3c1--
(I tested this in Postman, it works.)
I have other scenarios where this would be really useful, such as reading several individual entries at once, sending ChangeSets to change several entries in a "transaction", and calling function imports.

This feature is not yet supported but, of course, completely valid. We will update this question once an update regarding this matter is available.

Related

HttpHeaders got changed in spring5 changes causing API to fail 400

right now im migratingour spring application from 4 to 5.
I'm facing issue with particular on spring web module
spring-web-4.3.21.RELEASE.jar to spring-web-5.1.13.RELEASE.jar
I noticed the changes in HttpHeaders class. In spring-web-4.3.21.RELEASE.jar
where HTTP Header was
public HttpHeaders() {
this(new LinkedCaseInsensitiveMap<List<String>>(8, Locale.ENGLISH), false);
}
Now on Spring 5-
this is changed to
public HttpHeaders() {
this(CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH)));
}
Now header is changed from-
{Accept=[application/json], Content-Type=[multipart/form-data;boundary=8HFYfdj_y58sNxrSdXenwlIQDsYiXS50], Content-Length=[51024]}
to
[Accept:"application/json", Content-Type:"multipart/form-data;charset=UTF-8;boundary=lqBw1IeG3PhU9oYKiHGbhABo2SWZ6lBR", Content-Length:"37353"]
I searched a lot found one similar issue
this seems some more closely relevant -
Upgrading to Spring 5 broke RestTemplate MultipartFile upload
Do anyone have any Idea how to deal this.
Hi Found the solution.
when we looked at the raw request found some different thing
POST /XX/XXXX/XXXX HTTP/1.1
Accept: application/json
Content-Type: multipart/form-data;charset=UTF-8;boundary=3gOLqmQ6U7u3Iycd0lRnLnVa7dSIvAYqY7
Content-Length: 470
Host: localhost:XXXX
Connection: Keep-Alive
User-Agent: Apache-HttpClient/X.X.X (Java/11.0.X)
Accept-Encoding: gzip,deflate
--3gOLqmQ6U7u3Iycd0lRnLnVa7dSIvAYqY7
Content-Disposition: form-data; name="upload_file"
Content-Type: application/octet-stream
Content-Length: 48
[{"key":"291c0f23-712e-43p3-aq47-51899270a415"}]
--3gOLqmQ6U7u3Iycd0lRnLnVa7dSIvAYqY7
Content-Disposition: form-data; name="291c0f23-712e-43p3-aq47-51899270a415"; filename="291c0f23-712e-43p3-aq47-51899270a415"
Content-Type: application/octet-stream
Content-Length: 5
--3gOLqmQ6U7u3Iycd0lRnLnVa7dSIvAYqY7--
In the following Content-Type: application/octet-stream got added in our request. this confused the endpoint. previously in older version of spring resttemplate for upload_file there was no Content-Type specified. now in newer version of spring this got added. Now we changed this to application/json. Now it is working fine.

Bad request as a response in jmeter

I'm using a POST request in jmeter as below,
POST https://aumaz-ap-perf-ess-web-2.aumaz-ase-dev002.p.azurewebsites.net/signalr/connect
POST data:
clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22bulkprocesshub%22%7D%5D&connectionToken=DWGWhf7zGj9TyO4cZn2kqH%2Bennba0V7qyAuAE2wIeu3vIoj%2FrLXemcaBz%2Fto3JjEs%2BaVviiFagxtax8E9PbE36cnBAlrByzw5qBwmIu9glop75vPY3XI0me52yTDiWC%2B9Zoalg%3D%3D&processId=b47fe282-8112-4a11-a18c-7629ac31b816&transport=longPolling
Request Headers:
X-Requested-With: XMLHttpRequest
Accept: text/plain, */*; q=0.01
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
Referer: https://aumaz-ap-perf-ess-web-2.aumaz-ase-dev002.p.azurewebsites.net/ESS/DataType
Connection: keep-alive
Connection: keep-alive
Host: aumaz-ap-perf-ess-web-2.aumaz-ase-dev002.p.azurewebsites.net
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Length: 315
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
If I use the same POST request in browser i can able to get the exact response. But in jmeter I'm getting the response as Bad request.
As of now, I'm using jmeter 3.01 and I have installed all the certificates needed. Can anyone please give solution for this
The most problem here seems to be that server doesn't respond with any details of what's wrong with the request. Correct?
Then do two things:
1) Install Fiddler, capture what you're sending through browser, and through JMeter, compare.
That may give you a clue what's the difference.
2) Reach server logs and see what's going on, there may be way more intrinsic information on why request was considered invalid.
I have finally got a solution. If I pass those parameters in parameters it doesn't work but i gave all the parameters with & in the path itself.
And used ${__urlencode{parameter}} to encode the parameters which are passing as encoded value and then I didn't face any Bad request issue.
Even now, I don't know how it worked. But finally got a solution by this way.

Redirect from a Servlet filter, when an AJAX request is made [duplicate]

While trying to redirect user to a URL, it works with GET requests but not with postback requests.
Through firebug's Network window, I can see the redirect response received by browser after the postback request (that should cause redirect) completes. The browser seemingly initiates a GET request for the redirect URL but doesn't actually successfully redirect. It remains there on the same page.
 I use JSF server side. The initiated GET request is not received at all by the server. However initiated by the browser on server's demand. I guess problem is somewhere client side only 
Can anyone please explain how to make redirect work successfully ? Let me know incase I should provide any more information.
Edit:
Request header for redirect:
GET /Px10Application/welcome.xhtml HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.2; rv:20.0) Gecko/20100101 Firefox/20.0
Accept: application/xml, text/xml, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://localhost:8080/Px10Application/channelPages.xhtml?channelId=-3412&type=Group
X-Requested-With: XMLHttpRequest
Faces-Request: partial/ajax
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: hb8=wq::db6a8873-f1dc-4dcc-a784-4514ee9ef83b; JSESSIONID=d40337b14ad665f4ec02f102bb41; oam.Flash.RENDERMAP.TOKEN=-1258fu7hp9
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Response header for redirect:
HTTP/1.1 200 OK
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1 Java/Sun Microsystems Inc./1.6)
Server: GlassFish Server Open Source Edition 3.1
Set-Cookie: oam.Flash.RENDERMAP.TOKEN=-1258fu7hp8; Path=/Px10Application
Pragma: no-cache
Cache-Control: no-cache
Expires: -1
Content-Type: text/xml;charset=UTF-8
Content-Length: 262
Date: Wed, 22 May 2013 17:18:56 GMT
X-Requested-With: XMLHttpRequest
Faces-Request: partial/ajax
You're thus attempting to send a redirect on a JSF ajax request using "plain vanilla" Servlet API's HttpServletResponse#sendRedirect(). This is not right. The XMLHttpRequest does not treat a 302 response as a new window.location, but just as a new ajax request. However as you're returning a complete plain vanilla HTML page as ajax response instead of a predefined XML document with instructions which HTML parts to update, the JSF ajax engine has no clues what to do with the response of the redirected ajax request. You end up with a JS error (didn't you see it in the JS console?) and no form of visual feedback if you don't have the jsf.ajax.onError() handler configured.
In order to instruct the JSF ajax engine to change the window.location, you need to return a special XML response. If you have used ExternalContext#redirect() instead, then it would have taken place fully transparently.
externalContext.redirect(redirectURL);
However, if you're not inside JSF context, e.g. in a servlet filter or so, and thus don't have the FacesContext at hands, then you should be manually creating and returning the special XML response.
if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
response.setContentType("text/xml");
response.getWriter()
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
.printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", redirectURL);
} else {
response.sendRedirect(redirectURL);
}
If you happen to use JSF utility library OmniFaces, then you can also use Servlets#facesRedirect() for the job:
Servlets.facesRedirect(request, response, redirectURL);
See also:
Authorization redirect on session expiration does not work on submitting a JSF form, page stays the same
JSF Filter not redirecting After Initial Redirect

Can't get Access-Control-Allow-Origin header to work as I expected

There are a lot of questions on this subject, but I still can't seem to resolve my issue.
I have a game that I'm trying to get working with HTML 5 in Chrome. Link here.
The game is written using libgdx and I'm posting json data from my app engine hosted back end. I've done quite a bit of reading and I think I understand the issue with cross domain access, I also think I understand how to resolve it but can't.
The full error is
XMLHttpRequest cannot load http://1-1-51.wordbuzzweb.appspot.com/Login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://wordbuzzhtml5.appspot.com' is therefore not allowed access.
As you can see, this says No 'Access-Control-Allow-Origin' header is present on the requested resource.. But if I look at the headers for the requested resource, they are as follows.
Date: Thu, 18 Jun 2015 21:59:34 GMT
Content-Encoding: gzip
Server: Google Frontend
Vary: Accept-Encoding
Access-Control-Allow-Methods: GET, POST
Content-Type: application/json
Access-Control-Allow-Origin: *
Alternate-Protocol: 80:quic,p=0
Cache-Control: private
Access-Control-Allow-Headers: Content-Type
Content-Length: 127
As you can see, there is an Access-Control-Allow-Origin header included.
If someone could please tell me what I'm doing wrong, that'd be appreciated.
The request header is as follows using the POST method.
Host: 192.168.254.1:8081
Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost:8080/
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36
Accept: */*
Referer: http://localhost:8080/html/
Accept-Language: en-GB,en;q=0.8
Content-Length: 25
Content-Type: application/json
Since you are getting some headers back in the response, that's a good indication that the request IS reaching the server, however, the fact that it isn't hitting your server route points to the problem being the request being made doesn't match any of your routes. The request is likely an OPTIONS request rather than a POST request, which commonly happens when you make a CORS request from the browser that isn't a "simple request".
The solution would be to either make it a "simple request", or to have your server respond to OPTIONS requests. It's far easier to just make your server respond to OPTIONS requests, because sometimes even "simple requests" still send OPTIONS requests.

PUT, DELETE with JS Application (spine.js)

I'm coding a small api in node.js (express) for my spine.js application.
Getting and creating new objects in the database is working pretty well. But on deleting/editing I've git a problem right now.
Every object gets an individual id created by the JS app.
In the database every entry has a unique key, too.
When I call object.destroy() I can see the ajax request which is sent to my server. But as parameter for the id I always have the id which was given by the app.
But for deleting/updating stuff in the database I need the key which is stored in the database (mongoDB in my case)
So how can I send the right id to the server or identify the right entry on the server side!?
Why not send the correct id back when creating your model like shown in the Spine documentation.
After a new Page record has been created, Spine sends a POST request
to /pages containing the following:
POST /pages HTTP/1.1 Host: spine-rails3.herokuapp.com Accept:
application/json, text/javascript, */*; q=0.01 Content-Type:
application/json; charset=UTF-8 X-Requested-With: XMLHttpRequest
Content-Length: 65
{"name":"Dummy page","id":"EEAF4B17-5F1D-4C06-B535-D9B58D84142F"}
Then the server should respond with something like this:
HTTP/1.1 201 Created Content-Type: application/json; charset=utf-8
Location: http://spine-rails3.herokuapp.com/pages/196 Content-Length:
28 Connection: keep-alive
{"name":"Dummy page","id":1}

Resources