Skip to content

Commit

Permalink
Quick start with simple http proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
kendarorg committed Jan 17, 2024
1 parent 0778f10 commit f75948b
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The AnsweringMachine is built to overcome this troubles
## New!!

* <b>[Automatic recording of http](docs/plugins/socks5.md) without configuration :zap: </b>
* <b>[Quickstart for any server application](docs/quickstartany.md) :zap: </b>
* <b>[Quickstart for any server application](docs/generated/quickstartproxy.md) :zap: </b>
* <b>Migrated to docker-compose 3.2</b>
* <b>Migrated php sample and php base docker image to php 8.1</b>
<br>
Expand Down
14 changes: 14 additions & 0 deletions docs/gen_scripts/quickstartproxy.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@echo off

cd %~dp0

set TARGET=..\generated\quickstartproxy.md
set SOURCE=..\gen_sources

type noedit.htm > %TARGET%
echo In this demo you will >> %TARGET%
type quickstartproxy.md >> %TARGET%
type %SOURCE%\proxy.md >> %TARGET%
type %SOURCE%\approxy.md >> %TARGET%
type %SOURCE%\runproxyham.md >> %TARGET%
type %SOURCE%\createrecording.md >> %TARGET%
12 changes: 12 additions & 0 deletions docs/gen_scripts/quickstartproxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

* Install Java 11
* Start locally HAM server
* Connect to it through proxy

Download the ham tar.gz from [github releases](https://github.com/kendarorg/HttpAnsweringMachine/releases)
and extract it


<b>Ensure your application is calling -ONLY- http pages or it will not record the
interactions content</b>

36 changes: 36 additions & 0 deletions docs/gen_sources/approxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

## Configure the application proxy<a id="appproxy_01"></a>

Here is configured for both http and https BUT only http traffic will be intercepted

### On the application

* [On Baeldung for java](https://www.baeldung.com/java-connect-via-proxy-server)

Just add to the java command to start the application the following:

<pre>
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=1081
-Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=1081
</pre>

* [Some C# suggestions](https://dotnetcoretutorials.com/2021/07/11/socks-proxy-support-in-net/?series)

### On HAM configuration

First ensure that all the ports called by your application are set on the
file httpproxy.external.json in the "http" section. In the example here the
http listen on 80, 8081 and 8082

<pre>
{
"id": "http",
"system": true,
"active": true,
"port": "80;8081;8082",
"backlog": 50,
"useCachedExecutor": true
},
</pre>


20 changes: 20 additions & 0 deletions docs/gen_sources/createrecording.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

## Record some interaction<a id="createrecording_01"></a>

You can now check ham application going on http://localhost

* You can create a recording on the [recording page](http://www.local.test/plugins/recording)

<img alt="Create recording" src="../images/create_recording.gif" width="500"/>

* Once you create the recording you can start recording!

<img alt="Start recording" src="../images/start_recording.gif" width="500"/>

* Do some interaction on your application
* And stop the recording!
* Now you will se all the calls on the just created recording!

<img alt="Start recording" src="../images/calendar_recorded.gif" width="500"/>

* "Download" the recording as "Sample.json"
5 changes: 5 additions & 0 deletions docs/gen_sources/runproxyham.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

## Run!!

Start the HAM application with the "httpproxy.run.bat/sh"
Start your appplication
110 changes: 110 additions & 0 deletions docs/generated/quickstartproxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

<!--This file is autogenerated. Do not edit!-->
In this demo you will

* Install Java 11
* Start locally HAM server
* Connect to it through proxy

Download the ham tar.gz from [github releases](https://github.com/kendarorg/HttpAnsweringMachine/releases)
and extract it


<b>Ensure your application is calling -ONLY- http pages or it will not record the
interactions content</b>


## Configure proxy<a id="proxy_01"></a>

Should set the proxy to 127.0.0.1 And port 1080 for socks5 or 1081 for http/https

<details>
<summary>Click me for more explanations</summary>

* Chrome:
* Install [Proxy Switch Omega](https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif)
* Go to options
* Add http and https proxy server with
* Address: 127.0.0.1
* Port 1081.

<img alt="Ham Proxyes" src="../images/chrome_proxy.gif" width="500"/>
* Select "proxy" from the extension menu and back to "direct" when you want to disconnect
*
<img alt="Ham Proxyes" src="../images/chrome_proxy_switch.gif" width="100"/>
* Firefox
* Navigate to [about:preferences](about:preferences)
* Search for "proxy"
* Click on "Settings"
* Go to "Manual proxy Configuration"
* Select the socks5 proxy
* Address: 127.0.0.1
* Port 1080
* Check the "Proxy DNS when using SOCKS v5" flag
* Clean the settings when needed

<img alt="Ham Proxyes" src="../images/firefox_proxy.gif" width="500"/>

</details>


## Configure the application proxy<a id="appproxy_01"></a>

Here is configured for both http and https BUT only http traffic will be intercepted

### On the application

* [On Baeldung for java](https://www.baeldung.com/java-connect-via-proxy-server)

Just add to the java command to start the application the following:

<pre>
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=1081
-Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=1081
</pre>

* [Some C# suggestions](https://dotnetcoretutorials.com/2021/07/11/socks-proxy-support-in-net/?series)

### On HAM configuration

First ensure that all the ports called by your application are set on the
file httpproxy.external.json in the "http" section. In the example here the
http listen on 80, 8081 and 8082

<pre>
{
"id": "http",
"system": true,
"active": true,
"port": "80;8081;8082",
"backlog": 50,
"useCachedExecutor": true
},
</pre>



## Run!!

Start the HAM application with the "httpproxy.run.bat/sh"
Start your appplication
## Record some interaction<a id="createrecording_01"></a>

You can now check ham application going on http://localhost

* You can create a recording on the [recording page](http://www.local.test/plugins/recording)

<img alt="Create recording" src="../images/create_recording.gif" width="500"/>

* Once you create the recording you can start recording!

<img alt="Start recording" src="../images/start_recording.gif" width="500"/>

* Do some interaction on your application
* And stop the recording!
* Now you will se all the calls on the just created recording!

<img alt="Start recording" src="../images/calendar_recorded.gif" width="500"/>

* "Download" the recording as "Sample.json"
76 changes: 76 additions & 0 deletions ham/httproxy.external.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[
"#include:external/dns.json",
{
"id": "staticPage",
"system": true,
"staticPages": [
]
},
{
"id": "http",
"system": true,
"active": true,
"port": "80",
"backlog": 50,
"useCachedExecutor": true
},
"#include:external/proxy.json",
"#include:external/dbproxy.json",
"#include:external/ssl.json",
"#include:external/https.json",
"#include:external/mongo.json",
{
"id": "global",
"system": true,
"db": {
"url": "jdbc:h2:tcp://localhost/ham;MODE=MYSQL;",
"login": "sa",
"password": "sa",
"startInternalH2": true,
"driver": "org.h2.Driver",
"hibernateDialect": "org.hibernate.dialect.MySQLDialect"
},
"localAddress": "localhost",
"logging": {
"logLevel": "INFO",
"loggers": {
"org.kendar.servers.http.Request": "OFF",
"org.kendar.servers.http.Response": "OFF",
"org.kendar.servers.http.StaticRequest": "OFF",
"org.kendar.servers.http.DynamicRequest": "OFF",
"org.kendar.dns.DnsQueries": "OFF",
"org.kendar.servers.http.InternalRequest": "OFF",
"org.hibernate": "OFF",
"org.kendar.mongo.logging.MongoLogClient": "OFF",
"org.kendar.mongo.logging.MongoLogServer": "OFF",
"org.mongodb.driver": "OFF",
"com.sun.net.httpserver": "ERROR"
}
},
"filters": {
"12363272": false
}
},
{
"id": "oidc.server",
"tokenExpiration": 86400,
"active": false
},
{
"id": "js.filters",
"path": "jsplugins",
"active": true
},
{
"id": "replayer.server",
"path": "replayerdata",
"active": true
},
{
"id": "socks5.server",
"port": 1080,
"httpProxyPort": 1081,
"interceptAllHttp":true,
"active": true
}
]
18 changes: 18 additions & 0 deletions scripts/templates/releasebuild/ham/httpproxy.run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@ECHO OFF

REM Initialize
set SCRIPT_DIR=%~dp0
cd %SCRIPT_DIR%

REM Retrieve the jar name
dir /b %SCRIPT_DIR%\*.jar > .temp.txt
set /p JAR_NAME=<.temp.txt
del /s /f /q .temp.txt 2>&1 1>NUL




REM Start the application
java "-Dloader.path=%SCRIPT_DIR%/libs" -Dloader.main=org.kendar.Main ^
"-Djsonconfig=%SCRIPT_DIR%\httpproxy.external.json" ^
-jar %JAR_NAME% org.springframework.boot.loader.PropertiesLauncher
17 changes: 17 additions & 0 deletions scripts/templates/releasebuild/ham/httpproxy.run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Initialize
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR

# Retrieve the jar name
ls -lA|grep -oE '[^ ]+$'|grep .jar$ > tmp_txt
export JAR_NAME=$(head -1 tmp_txt)
rm tmp_txt || true



# Start the application
java "-Dloader.path=$SCRIPT_DIR/libs" -Dloader.main=org.kendar.Main \
"-Djsonconfig=$SCRIPT_DIR/httpproxy.external.json" \
-jar "$JAR_NAME" org.springframework.boot.loader.PropertiesLauncher

0 comments on commit f75948b

Please sign in to comment.