1. Daniel Grenier
  2. PowerBuilder
  3. Wednesday, 12 May 2021 20:48 PM UTC

Hello Appeon Community. Been using Powerbuilder for quite some time. Had been using Powerbuilder 12.5 for the past few years and I finally migrated an application to Powerbuilder 2019 R3.

By migrating, I was happy to see that I could use the HTTPCLient object in order to get/download files rather than use third-party programs to access those files.

One of the implementations of HttpClient we do is to read an XML file that's hosted on our website.

Here is the code

 

HttpClient lnv_HttpClient
lnv_HttpClient = Create HttpClient

 

lnv_HttpClient.SetRequestHeader("Content-Type", "text/xml;charset=UTF-8")
li_rc = lnv_HttpClient.SendRequest("GET", "https://ouwerbsite.com/Software/Software_update.xml")

IF li_rc = 1 THEN
    li_StatusCode = lnv_HttpClient.GetResponseStatusCode()
    IF li_StatusCode = 200 THEN
        lnv_HttpClient.GetResponseBody(lblb_blob) // Obtain the response data and convert to a blob
        ll_file = FileOpen(gs_application_path+"\Updates\Software_update.xml", StreamMode!, Write!, LockWrite!, Replace!)
        FileWriteEx(ll_file, lblb_blob)
        FileClose(ll_file)
      
        RETURN TRUE
 
    ELSE

        RETURN FALSE
    END IF

ELSE

    RETURN FALSE

END IF

 

As you can see, It's a simple GET request for an XML file that is hosted on our website in that particular Software folder. The weird thing that is happening, is that the data that is downloaded and written into the file locally remains the same even though I change the content of the file on the website.

For example, if the XML file contains the following

<Software_Update>

  <Software_Update_row>

   <version> 45011 </version>

  </Software_Update_row>

</Software_Update>

If I run the code above, It will retrieve the data and write the local file exactly as is above. If I change that XML file (let's say I change the version to 45012 instead of 45011) and I upload it to the website (replacing the previous file). If I go ahead and run the same code above, it will still write the local file with version 45011. It almost feels like Powerbuilder is using some kind of cached data instead of getting the new data from the file. Even if I remove the file completely, it will still download and write that same data.

This is really strange. Anything come to mind? is Powerbuilder using a browser in the background which would leverage cache? Why doesn't it recognize the new values in my file?

 

Thanks

 

 

Daniel Grenier Accepted Answer Pending Moderation
  1. Thursday, 13 May 2021 13:35 PM UTC
  2. PowerBuilder
  3. # 1

Good morning.

Just a little background info. This is for a Powerbuilder 2019 win32/win64 application. We use an XML file that's hosted on our website to keep track of version changes. Essentially, the application loads this XML file in which we have software corrections listed by version number and patch ID.

So if the current software used is 4.5.7 and the current patch ID is 1. When we release a new update, we will recompile the software as 4.5.7 with a Patch ID of 2 and then in this XML file we will add lines for version 4.5.7 Patch 2 and list the software fixes or new features.

The software running 4.5.7 patch 1 downloads this new XML file, lods it up into a datastore, filters the data for (> current_version_number) or (= current_version_number and > current_patch_id). This filters out the information leaving only the new release fixes and features so that the user can consult them. This is also what triggers the application to go ahead and download this new build.

The issue was that even when I was uploading a new XML file, with version 4.5.7 patch 2, When the app was doing the GET request, it was still downloading the previous XML file which had 4.5.7 Patch 1 as the last entry. If I opened the URL in Firefox or Chrome, I could see that last Patch 2 entry just fine. It looks like this was a caching issue because when I came in this morning, it finally downloaded the Patch 2 XML file. But yesterday it kept downloading Patch 1.

I toyed with it this morning and created a Patch 3 file just to see if it would download it properly and it still didn't. It was still downloading the Patch 2 although I could see the Patch 3 data within the browser or with Postman.

I tried to add the Cache-Control header as recommended by Daryl and Patch 3 showed up right away. So I went ahead and created a fake Patch 4 entry and it showed that Patch 4 in the download right away. So it looks like this was a cache problem. Not sure why it didn't manifest itself when browsing directly to the XML file with the browsers but whatever engine Powerbuilder is using in the backend was caching the XML file.

So the code now looks like this and appears to be working

lnv_HttpClient.SetRequestHeader("Content-Type", "text/xml;charset=UTF-16")
lnv_HttpClient.SetRequestHeader("Cache-Control", "no-store")
li_rc = lnv_HttpClient.SendRequest("GET", "http://OurWebsite/Software//Software_update.xml")

 

Thanks for all the timely replies

Comment
  1. Armeen Mazda @Appeon
  2. Thursday, 13 May 2021 14:47 PM UTC
Thanks for sharing the solution!
  1. Helpful
There are no comments made yet.
Daryl Foster Accepted Answer Pending Moderation
  1. Thursday, 13 May 2021 04:43 AM UTC
  2. PowerBuilder
  3. # 2

Hi Daniel,


Are you sure the server isn't caching the request?  Can you retrieve the updated file successfully from a web browser?

Maybe you could send a Cache-Control header with your request and see if that makes any difference.  Here is some information about http caching - https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching

 

Comment
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Wednesday, 12 May 2021 21:24 PM UTC
  2. PowerBuilder
  3. # 3

you sure that your local OS doesn't have the file locked?  If it does, then your open fails, your write fails and yet you still return true.

 

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.