Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nilayamkamila opened this issue Sep 5, 2023 · 3 comments
Labels
enhancement New feature or request java Pull requests that update Java code

Comments

@nilayamkamila
Copy link

nilayamkamila commented Sep 5, 2023

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>```
--------------------------------------------------------------------------------------------------------------    
@nilayamkamila nilayamkamila added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Sep 5, 2023
@nilayamkamila
Copy link
Author

A Template could be thought to generated at "sam init" command to request developer/user to provide the below information. This can be considered as part of future scope.

  1. Is proxy required[y/N] ?:
  2. Is java.net.useSystemProxies to true[y/N] ?:

Thanks!

@mndeveci
Copy link
Contributor

mndeveci commented Sep 5, 2023

Hi @nilayamkamila,

We have some similar functionality for other runtimes but some of them have this code (where it gets the IP address) commented out for similar reasons that you listed above.

I think we can apply the same solution here. Feel free to raise a pull request if you are interested.

Thanks!

@mndeveci mndeveci added enhancement New feature or request java Pull requests that update Java code and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Sep 5, 2023
@nilayamkamila
Copy link
Author

Sure. Thanks @mndeveci; I'll check on this. Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request java Pull requests that update Java code
Projects
None yet
Development

No branches or pull requests

2 participants