xData Behind DreamFactory, FMX client with exception"unexpected end of stream"

Hi
I'm developing a mobile Android app using xData and xData Client, including Service Implementation.
All was working perfectly until I integrate xData Rest API into DreamFactory
API exposed with DreamFactory works fine with

  • PostMan
  • Mobile App in Win32 mode
    But when I run the Mobile App I get an exception when call API with xdata client
    Part of code
ClientxData.HttpClient.OnSendingRequest :=
        procedure(Req: THttpRequest)
        begin
          Req.Headers.SetValue('X-DreamFactory-Session-Token', DM_DreamFactory.SessionToken);
          Req.Headers.SetValue('X-DreamFactory-Api-Key', DM_DreamFactory.ApiKey);
        end;
 . . .
PadMobile       := ClientxData.Service<IPadMobileService>;
UserPosGPS := PadMobile.PadMobile_GPS_from_CP(Loc_Edit_CP.Text);
. . .

When calling function associated to implementation I get an exception
EJNIException
java.net.ProtocolException : unexpected end of stream

It seems link to different size of data between expected and received
And this occurs only with Android (not iOS tested yet).
Direct request to Web Server hosting xData API works fine even with Android.
I guess this can be linked to DreamFactory Proxy behavior but I request help to find a way to focus on.

Thanks

Sylvain

Hi Sylvain,

Hard to tell what's going on, indeed, but one guess it that the size of content response (or maybe request) doesn't match the content-length header. Either there is a mismatch between the header content and the actual size, or the content is chunked but still the content-length is being sent.

Try to inspect the request/response to see actual content and headers, if you can post it here.
One thing you can try is to add the following header to request:

Req.Headers.SetValue('Accept-Encoding', 'identity');

Hi Wagner
Thanks for header proposal, but unfortunately I already tested it without success.
I guess it's DreamFactory which is disturbing the exchange, as the API test from Doc exposed by DreamFactory is working fine.

Please, can you indicate me how to analyse request and response content from xData Client on my FMX app?

Thanks

From Windows, you can use Fiddler. Maybe it's a start, there is a chance that response is the same? If not, you can try it in mobile with a few more setup steps: How to: Capture Android Traffic with Fiddler

For Windows to work, set your proxy configuration to auto: Http Client | TMS Sparkle documentation

Hi
I tried Fiddler but it seems not capturing all requests from my Windows client and it's quite complex with Android.
In parallel, i checked what's happening on DreamFactory in log (debug mode) and I found something strange

[REQUEST] {"API Version":"2.0","Method":"GET","Service":"ecopoi","Resource":"padmobile/padmobileby_km_gps/","Requestor":1} 
[2021-05-28T08:42:28.856509+00:00] local.DEBUG: [REQUEST] {"Parameters":"{\"Latitude\":\"'48.9100651'\",\"Longitude\":\"'2.290791'\",\"Km\":\"20\",\"categories\":\"'emo,'\",\"UUID\":\"''\"}","API Key":"949c100cf510be8807d3e191e9a41d195d28e78c9b47c7d3ab4033e34819c818","JWT":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxZDJhYjE2NDU1OWFhZjhhMzBlZWJmNTE2ZDJmNjNhZCIsImlzcyI6Imh0dHBzOi8vYXBpaHViLmVjb2xvZ2ljLXByZXByb2QubmV0L2FwaS92Mi91c2VyL3Nlc3Npb24iLCJpYXQiOjE2MjIxOTEzNDEsImV4cCI6MTYyMjI3Nzc0MSwibmJmIjoxNjIyMTkxMzQxLCJqdGkiOiJVNFdEeXlBdjd3QjVqSXVDIiwidXNlcl9pZCI6MywiZm9yZXZlciI6ZmFsc2V9.cfXa_3lsk9mv8WGUIV2BtUO7u74A9SOJQplsrex6Kwo"} 
[2021-05-28T08:42:28.859441+00:00] local.DEBUG: Outbound HTTP request: GET: http://XXXXXXX/ecologic/poi/padmobile/padmobileby_km_gps?Latitude=%2748.9100651%27&Longitude=%272.290791%27&Km=20&categories=%27emo%252C%27&UUID=%27%27&categories=%27emo%2C%27  
[2021-05-28T08:42:28.880914+00:00] local.INFO: [RESPONSE] {"Status Code":200,"Content-Type":"application/json"} 

It appears that it's adding "double quote" to all params and URL encodes them to proxied URL
ex : Latitude=48.9100651 >> Latitude=%2748.9100651%27
If I use URL with browser to call xData server it's working (so I guess my WIN32 client is using same lib)
If I use URL with Postman > KO due to value read by incoming xData parser (so I guess it's similar to Android behavior but without length error)

Checking if it's possible to change this behavior on DreamFactory, but I seem not to be the only one facing to such issue.

Wagner
is there a way to clear incoming Request on xData before it's processed by parser?
I mean, to remove %27 from URI incoming elements added by DF.
Because, I'm not really sure to find a solution on DreamFactory

thanks

Hi Sylvain,
Yes, you can preprocess the incoming requests in a very flexible way using the middleware system: Middleware System | TMS Sparkle documentation.

You can use, for example, the generic middleware, to add an arbitrary code that will be executed before it's forwarded to the next middleware and/or XData module: Middleware System | TMS Sparkle documentation

Of course, you will have to implement the full logic to process the existing incoming URL and "generate" a new one. Once you do that, just set it in the request RawUri property:

  Context.Request.RawUri := MyNewUri;

With that, the further request processing will act as if that uri was originally sent by the client.

This request alteration is working fine
Unfortunately it wasn't enough to fix issue with DreamFactory (and none answer from DF support)

I change my API GW to Tyk.io and it's another world

  • everything is working at first attempt (despite of all JSON file based configs)
  • it's very very faster than DF, close to native (direct) API requests

Thanks

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.