Behind Firewall/Proxy - mvn Test, sam build, sam invoke failures for HelloworldFunctions #449
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);
- HelloWorldFunction [java8] ( )
- HelloWorldFunction java8.al2
- HelloWorldFunction java11
- HelloWorldFunction java17
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:
- Block the firewall access to https://checkip.amazonaws.com
- sam init, Choose all Option, "Hello World Example", java 8, maven, provide sam-app name (hello-world-example-sam-app),
- 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", "<PROXY_SERVER_NAME>");
System.setProperty("https.proxyPort", "<PROXY_PORT_NUMBER>");
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
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- if your system proxy setting is correct(GoTo Wifi, Check Wifi Settings, Check Proxies) -->
<argLine>-Djava.net.useSystemProxies=true</argLine>
</configuration>
</plugin>
</plugins>
**OR**
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dhttps.proxyHost=PROXY_SERVER_NAME -Dhttps.proxyPort=PROXY_PORT_NUMBER</argLine>
</configuration>
</plugin>
<plugins>```
--------------------------------------------------------------------------------------------------------------
Activity