Skip to content

Behind Firewall/Proxy - mvn Test, sam build, sam invoke failures for HelloworldFunctions  #449

Open
@nilayamkamila

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] (
    final String pageContents = this.getPageContents("https://checkip.amazonaws.com");
    )
  2. HelloWorldFunction java8.al2
  3. HelloWorldFunction java11
  4. 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:

  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", "<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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestjavaPull requests that update Java code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions