httpUtils - practical problems in real life scenarios

bluedude

Well-Known Member
Licensed User
Longtime User
Hi Erel,

I have been testing the httpUtils code module and service and although it works good I see some practical problems. My main remarks are:

- Using a Jobname and than testing for an URL is not very logical (issucces etc.). Why start using a jobname then?;
- URL's with fast changing parameters (take GPS coordinates for example) wouldn't work. The URL that initiates the PostString could change in under a second with GPS coordinates, so if you want to check with IsSuccess and the url it wouldn't work.;
- Defining process globals for all web service url's that I have wouldn't work either and is a pain.

Real life scenario with GPS
I have built webservices for lots of services and one is GPS tracking. The GPS URL tracking web service looks like this:

http://domain/Location/set/lat/53/long/4.5.json

So I call this with PostString but when I want to check it with issuccess I have a problem, the URL is slightly changed already because my GPS has given me new coordinates already. The coordinates in above URL are variables.

Other problems
The idea of a Jobname is that you can check stuff based on the Jobname. Now in your code you use IsSucces and GetString with an URL instead of a Jobname, that is code style wise at least weird
Also, using the URL's means that for all my URL's I need to define Global variables but that wouldn't work either IMO.

Solution
Change all the code to use Jobnames instead. Link the TaskId to the Jobname and we can do all checking on the JobName. It is much easier to define certain task id's for
all my webservice URL's. Say TaskId 20 is getting the GPS, even when I call this one 10 times in a row it wouldn't be a problem.

I have looked into the code but it isn't really easy to read for me. If you cannot change it that would be a bummer.

Cheers,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should remember that HttpUtils was built to handle jobs made of many URLs. Without HttpUtils developers were facing the RejectedExecutionException when trying to make many calls at once. HttpUtils takes care of this issue.

The JobName is indeed not very important. You can even pass an empty string as the job name. It is helpful when there is a need to issue several different types of jobs.

I don't understand the problem you are facing with the URL changing. Keep a single global variable with the current submitted URL and then use it. You can also use a List or a Map if needed.

You can also go over the results by accessing the list of tasks directly. See FlickrViewer for an example.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
It is not very hard to change the HttpUtils code module and Service to do what you want to do: Track results based on JobID. Whereas that is not a bad idea, I believe you are not doing it for the right reasons.
You should always keep track of what URL you submitted, and there are a LOT of reasons for that.

- URL's with fast changing parameters (take GPS coordinates for example) wouldn't work. The URL that initiates the PostString could change in under a second with GPS coordinates, so if you want to check with IsSuccess and the url it wouldn't work.;
This sounds wrong. The URL that you submitted to the server is the actual URL. If the variables change afterwards it has NO bearing on the server response.

- Defining process globals for all web service url's that I have wouldn't work either and is a pain.
Create a list of URLs submitted to the server. When you receive a response, remove them from the list. It is not very hard.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
It is clear you guys don't get the problem in detail I'm not saying keeping the URL's is wrong but i'm saying using the URL instead of the JobId to track IsSuccess etc. is wrong. Most systems use a jobId and this utility should us that too everywhere. In the sample code with the select case you have to pass two times the URL again, why not simple the JobId you assigned?

How can I ever refer to the correct URL if it can change (GPS sample) in under 1 second? So I make a call with one URL and GPS coordinates and before I have results back the new call with new coordinates is already done again. if I would store that in a global it would have changed already because the second call is already out. Also, I have 45 web service methods and referring to them by the URL is a pain. All these have variables in them.

Checking for URL's by using the URL is not how it works best. It's a little like developers that store category names instead of id's, when you change the name you get into trouble.

Not saying this isn't a great piece of software, I say it would be better to use the JobID to get URL's etc.

Anyway, I would love to use httpUtils and the service but my current httphandler handles the stuff by TaskId and that works better in my situation.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I think you should read Erel's post above.
I agree to an extent that there are applications (maybe such as yours) that could benefit from using a Job/Task ID rather than a URL. In this case it will be your responsibility to make sure they are unique.

Currently in HttpUtils, a Job consists of a batch of URLs.
When you submit a Job (whatever the ID), it will start sending out requests on the URLs in the list (in a variable called Tasks).
Each request will have a unique TaskID within that Job. This is the 'task' variable in HttpUtilsService.
task will always start back from '0' on a new Job.

In your case, you seem to want to submit 1 URL per Job. Disregard JobID for now. Your HttpRequest id being sent will actually be 'task' in in the HttpUtilsService and return id will be TaskID in Response_StreamFinish or HandleError subs.
The easiest way to code around your problem is:
set the 'task' variable in HttpUtilsService from your activity BEFORE you send out a new request. This will be your TaskID.
On return on the StreamFinish you may want to modify:
HttpUtils.SuccessfulUrls.Put(taskToRequest.Get(TaskId), TaskId)
to make TaskID the key:
HttpUtils.SuccessfulUrls.Put(TaskID, taskToRequest.Get(TaskId))
Modify the IsSuccess routine in HttpUtils to take TaskID rather than URL.

With these subtle changes you should be able to make TaskID the ID rather than the URL.

You may need to make a lot of other changes as well depending on what functionality of HttpUtils you are using but this is the basic gist of it.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
So I make a call with one URL and GPS coordinates and before I have results back the new call with new coordinates is already done again.
Also, just realised this is not possible. If HttpUtils is processing a Job, it will not accept another one until the first one is finished.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Ok, I will stick to my own code then and if I have time I will see If I can change it a bit.

Maybe I can use it but Need to investigate more. Right now it is too much hassle with all the URL checks etc. Need to repeat too much code to do that.

Thanks anyway and great work overall!
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Hi thedeso....

Indeed, changed some code and realized that I cannot call multiple requests at once. Because my app. need to give the users a fast response my own http works slightly better because I call 3-4 services at once and it works great.

However, will use httpUtils for a location based wallpaper downloader.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…