aws / aws/aws-sam-cli-app-templates
Behind Firewall/Proxy - mvn Test, sam build, sam invoke failures for HelloworldFunctions
- Dominant language
- Python
- Stars
- 534
- Forks
- 264
- PR merge metrics
- No merged PRs in 30d
Description
If you are behind a firewall/proxy; The lines shown below projects cause failures If you are clonning graddle or maven projects or any other templates during "sam init" command, and building the application through maven(clean install/gradle(gradlew build);
1. HelloWorldFunction [java8] (https://github.com/aws/aws-sam-cli-app-templates/blob/88380eb265d58c496ea80685d4a5701e3cfc13d2/java8/hello-maven/%7B%7Bcookiecutter.project_name%7D%7D/HelloWorldFunction/src/main/java/helloworld/App.java#L29)
2. HelloWorldFunction [java8.al2](https://github.com/aws/aws-sam-cli-app-templates/blob/88380eb265d58c496ea80685d4a5701e3cfc13d2/java8.al2/hello-maven/%7B%7Bcookiecutter.project_name%7D%7D/HelloWorldFunction/src/main/java/helloworld/App.java#L24)
3. HelloWorldFunction [java11](https://github.com/aws/aws-sam-cli-app-templates/blob/88380eb265d58c496ea80685d4a5701e3cfc13d2/java11/hello-maven/%7B%7Bcookiecutter.project_name%7D%7D/HelloWorldFunction/src/main/java/helloworld/App.java#L29)
4. HelloWorldFunction [java17](https://github.com/aws/aws-sam-cli-app-templates/blob/88380eb265d58c496ea80685d4a5701e3cfc13d2/java17/hello-maven/%7B%7Bcookiecutter.project_name%7D%7D/HelloWorldFunction/src/main/java/helloworld/App.java#L29)
--------------------------------------------------------------------------------------------------------------
T E S T S
--------------------------------------------------------------------------------------------------------------
```
Running helloworld.AppTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.874 sec <<< FAILURE!
successfulResponse(helloworld.AppTest) Time elapsed: 0.852 sec <<< FAILURE!
java.lang.AssertionError: expected:<200> but was:<500>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:647)
at org.junit.Assert.assertEquals(Assert.java:633)
at helloworld.AppTest.successfulResponse(AppTest.java:13)
```
--------------------------------------------------------------------------------------------------------------
**How to Reproduce:**
1. Block the firewall access to https://checkip.amazonaws.com
2. sam init, Choose all Option, "Hello World Example", java 8, maven, provide sam-app name (hello-world-example-sam-app),
3. cd hello-world-example-sam-app/HelloWorldFunction && mvn clean install && cd .. && sam build --template-file template.yaml
--------------------------------------------------------------------------------------------------------------
**Solutions/Work-Arounds:**
**Option - 0:**
Comment out/replace the line ```final String pageContents = this.getPageContents("https://checkip.amazonaws.com");``` with the line final String pageContents = "0.1.1.1" // Actual content of the line
**Option - 1:**
Add the below java contents just before the lines as shown in the links
System.setProperty("https.proxyHost", "");
System.setProperty("https.proxyPort", "");
**Option - 2**
Or during maven install invoke as follows;
GoTo Wifi, Check Wifi Settings, Check Proxies, If Proxy Settings is correctly setup, then use the following command to build HelloWorldFuction Project
mvn clean install -Djava.net.useSystemProxies=true
Else Check with System Administrator to get the Proxy Details PROXY_SERVER_NAME and PROXY_PORT_NUMBER
mvn clean install -Dhttps.proxyHost=PROXY_SERVER_NAME -Dhttps.proxyPort=PROXY_PORT_NUMBER
**Option - 3**
The below option(s) will solve the project build(mvn clean install) and sam build, sam invoke, sam start-api command. No other change required.
The change in the HelloWorldFunction/pom.xml under segments
```
org.apache.maven.plugins
maven-surefire-plugin
-Djava.net.useSystemProxies=true
**OR**
org.apache.maven.plugins
maven-surefire-plugin
-Dhttps.proxyHost=PROXY_SERVER_NAME -Dhttps.proxyPort=PROXY_PORT_NUMBER
```
--------------------------------------------------------------------------------------------------------------
Contributor guide
Research direction
Start with the linked App.java files for the java8, java8.al2, java11, and java17 hello-maven templates, then inspect HelloWorldFunction/pom.xml. Reproduce with mvn clean install and sam build --template-file template.yaml while blocking checkip.amazonaws.com; done means the HelloWorldFunction test and the documented SAM workflow work behind a firewall or proxy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100