This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit 123426ce4fe0866e624945590676a5db3a18a9d3
Author: Josh Tynjala <[email protected]>
AuthorDate: Mon May 5 14:54:23 2025 -0700

    BE0011_Loading_external_data_through_HTTPService: option to load a mocked 
JSON response due to Content-Security-Policy restrictions
---
 .../asconfig.json                                  |  8 +++-
 .../pom.xml                                        | 46 +++++++++++++++++++++-
 .../src/main/resources/mock-response.json          | 19 +++++++++
 ..._Loading_external_data_through_HTTPService.mxml | 17 +++++++-
 4 files changed, 87 insertions(+), 3 deletions(-)

diff --git 
a/examples/blog/BE0011_Loading_external_data_through_HTTPService/asconfig.json 
b/examples/blog/BE0011_Loading_external_data_through_HTTPService/asconfig.json
index 5eaca27075..2939addd1c 100644
--- 
a/examples/blog/BE0011_Loading_external_data_through_HTTPService/asconfig.json
+++ 
b/examples/blog/BE0011_Loading_external_data_through_HTTPService/asconfig.json
@@ -23,7 +23,13 @@
         "targets": ["JSRoyale"],
         "source-map": true,
         "html-template": 
"src/main/resources/jewel-example-index-template.html",
-        "theme": 
"${royalelib}/themes/JewelTheme/src/main/resources/defaults.css"
+        "theme": 
"${royalelib}/themes/JewelTheme/src/main/resources/defaults.css",
+        "define": [
+            {
+                "name": "CONFIG::MOCK_RESPONSE",
+                "value": false
+            }
+        ]
     },
     "copySourcePathAssets": true,
     "additionalOptions": "-remove-circulars 
-js-output-optimization=skipAsCoercions",
diff --git 
a/examples/blog/BE0011_Loading_external_data_through_HTTPService/pom.xml 
b/examples/blog/BE0011_Loading_external_data_through_HTTPService/pom.xml
index fa007e94bf..bff998098b 100644
--- a/examples/blog/BE0011_Loading_external_data_through_HTTPService/pom.xml
+++ b/examples/blog/BE0011_Loading_external_data_through_HTTPService/pom.xml
@@ -43,9 +43,53 @@
           <targets>${royale.targets}</targets>
           <debug>false</debug>
           
<htmlTemplate>${basedir}/target/javascript/bin/js-debug/jewel-example-index-template.html</htmlTemplate>
-          
<additionalCompilerOptions>-source-map=true;-js-dynamic-access-unknown-members=true</additionalCompilerOptions>
+          <additionalCompilerOptions>
+            -source-map=true;
+            -js-dynamic-access-unknown-members=true;
+            -define+=CONFIG::MOCK_RESPONSE,false;
+          </additionalCompilerOptions>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>3.1.0</version>
+        <executions>
+          <execution>
+            <id>copy-resources-debug</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>copy-resources</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>${compiler.output-dir-debug}</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>src/main/resources</directory>
+                  <filtering>true</filtering>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+          <execution>
+            <id>copy-resources-release</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>copy-resources</goal>
+            </goals>
+            <configuration>
+              <!-- Copy the assets to the assets output directory -->
+              <outputDirectory>${compiler.output-dir-release}</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>src/main/resources</directory>
+                  <filtering>true</filtering>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 
diff --git 
a/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/resources/mock-response.json
 
b/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/resources/mock-response.json
new file mode 100644
index 0000000000..edd4cb0eb6
--- /dev/null
+++ 
b/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/resources/mock-response.json
@@ -0,0 +1,19 @@
+{
+       "name": "BE0011_Loading_external_data_through_HTTPService.mxml",
+       "path": 
"examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml",
+       "sha": "dd2590eb3bbf27e69f1bcc0912295f067b3a5fc6",
+       "size": 3647,
+       "url": 
"https://api.github.com/repos/apache/royale-asjs/contents/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml?ref=develop";,
+       "html_url": 
"https://github.com/apache/royale-asjs/blob/develop/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml";,
+       "git_url": 
"https://api.github.com/repos/apache/royale-asjs/git/blobs/dd2590eb3bbf27e69f1bcc0912295f067b3a5fc6";,
+       "download_url": 
"https://raw.githubusercontent.com/apache/royale-asjs/develop/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml";,
+       "type": "file",
+       "content": 
"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCEtLQoK\nICBMaWNlbnNlZCB0byB0aGUgQXBhY2hlIFNvZnR3YXJlIEZvdW5kYXRpb24g\nKEFTRikgdW5kZXIgb25lIG9yIG1vcmUKICBjb250cmlidXRvciBsaWNlbnNl\nIGFncmVlbWVudHMuICBTZWUgdGhlIE5PVElDRSBmaWxlIGRpc3RyaWJ1dGVk\nIHdpdGgKICB0aGlzIHdvcmsgZm9yIGFkZGl0aW9uYWwgaW5mb3JtYXRpb24g\ncmVnYXJkaW5nIGNvcHlyaWdodCBvd25lcnNoaXAuCiAgVGhlIEFTRiBsaWNl\nbnNlcyB0aGlzIGZpbGUgdG8gWW91IHVuZGVyIHRoZSBBcGFjaGUgTGljZW5z\nZSwgVmVyc2lvbiAyLjAKICAodGhlICJMaWNlbnNlIik7I
 [...]
+       "encoding": "base64",
+       "_links": {
+         "self": 
"https://api.github.com/repos/apache/royale-asjs/contents/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml?ref=develop";,
+         "git": 
"https://api.github.com/repos/apache/royale-asjs/git/blobs/dd2590eb3bbf27e69f1bcc0912295f067b3a5fc6";,
+         "html": 
"https://github.com/apache/royale-asjs/blob/develop/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml";
+       }
+  }
+  
\ No newline at end of file
diff --git 
a/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml
 
b/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml
index dd2590eb3b..1ec6d5f2d0 100644
--- 
a/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml
+++ 
b/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml
@@ -31,6 +31,22 @@
 
             public function getGithubContent(event:MouseEvent):void
             {
+                if (CONFIG::MOCK_RESPONSE)
+                {
+                    // the ASF's servers are configured to block URL requests 
to
+                    // external APIs, so to display a working version of this
+                    // example on royale.apache.org, we load a JSON file that
+                    // is also on royale.apache.org.
+                    // this is still a valid demonstration of how to load data
+                    // files in a Royale app using HTTPService.
+                    service.sourceCodeUrl = "mock-response.json";
+                }
+                else
+                {
+                    // however, if CONFIG::MOCK_RESPONSE is false, we can make
+                    // a call to the real GitHub API
+                    service.sourceCodeUrl = 
"https://api.github.com/repos/apache/royale-asjs/contents/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml";;
+                }
                 service.getContent();
             }
             
@@ -47,7 +63,6 @@
     
     <fx:Declarations>
         <services:GitHubService id="service" 
-            
sourceCodeUrl="https://api.github.com/repos/apache/royale-asjs/contents/examples/blog/BE0011_Loading_external_data_through_HTTPService/src/main/royale/BE0011_Loading_external_data_through_HTTPService.mxml";
             dataReady="dataReadyHandler(event)"/> 
     </fx:Declarations>
 

Reply via email to