Skip to content

Commit f75948b

Browse files
committed
Quick start with simple http proxy
1 parent 0778f10 commit f75948b

10 files changed

Lines changed: 309 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The AnsweringMachine is built to overcome this troubles
1313
## New!!
1414

1515
* <b>[Automatic recording of http](docs/plugins/socks5.md) without configuration :zap: </b>
16-
* <b>[Quickstart for any server application](docs/quickstartany.md) :zap: </b>
16+
* <b>[Quickstart for any server application](docs/generated/quickstartproxy.md) :zap: </b>
1717
* <b>Migrated to docker-compose 3.2</b>
1818
* <b>Migrated php sample and php base docker image to php 8.1</b>
1919
<br>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@echo off
2+
3+
cd %~dp0
4+
5+
set TARGET=..\generated\quickstartproxy.md
6+
set SOURCE=..\gen_sources
7+
8+
type noedit.htm > %TARGET%
9+
echo In this demo you will >> %TARGET%
10+
type quickstartproxy.md >> %TARGET%
11+
type %SOURCE%\proxy.md >> %TARGET%
12+
type %SOURCE%\approxy.md >> %TARGET%
13+
type %SOURCE%\runproxyham.md >> %TARGET%
14+
type %SOURCE%\createrecording.md >> %TARGET%
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
* Install Java 11
3+
* Start locally HAM server
4+
* Connect to it through proxy
5+
6+
Download the ham tar.gz from [github releases](https://github.com/kendarorg/HttpAnsweringMachine/releases)
7+
and extract it
8+
9+
10+
<b>Ensure your application is calling -ONLY- http pages or it will not record the
11+
interactions content</b>
12+

docs/gen_sources/approxy.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
## Configure the application proxy<a id="appproxy_01"></a>
3+
4+
Here is configured for both http and https BUT only http traffic will be intercepted
5+
6+
### On the application
7+
8+
* [On Baeldung for java](https://www.baeldung.com/java-connect-via-proxy-server)
9+
10+
Just add to the java command to start the application the following:
11+
12+
<pre>
13+
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=1081
14+
-Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=1081
15+
</pre>
16+
17+
* [Some C# suggestions](https://dotnetcoretutorials.com/2021/07/11/socks-proxy-support-in-net/?series)
18+
19+
### On HAM configuration
20+
21+
First ensure that all the ports called by your application are set on the
22+
file httpproxy.external.json in the "http" section. In the example here the
23+
http listen on 80, 8081 and 8082
24+
25+
<pre>
26+
{
27+
"id": "http",
28+
"system": true,
29+
"active": true,
30+
"port": "80;8081;8082",
31+
"backlog": 50,
32+
"useCachedExecutor": true
33+
},
34+
</pre>
35+
36+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
## Record some interaction<a id="createrecording_01"></a>
3+
4+
You can now check ham application going on http://localhost
5+
6+
* You can create a recording on the [recording page](http://www.local.test/plugins/recording)
7+
8+
<img alt="Create recording" src="../images/create_recording.gif" width="500"/>
9+
10+
* Once you create the recording you can start recording!
11+
12+
<img alt="Start recording" src="../images/start_recording.gif" width="500"/>
13+
14+
* Do some interaction on your application
15+
* And stop the recording!
16+
* Now you will se all the calls on the just created recording!
17+
18+
<img alt="Start recording" src="../images/calendar_recorded.gif" width="500"/>
19+
20+
* "Download" the recording as "Sample.json"

docs/gen_sources/runproxyham.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
## Run!!
3+
4+
Start the HAM application with the "httpproxy.run.bat/sh"
5+
Start your appplication

docs/generated/quickstartproxy.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
<!--This file is autogenerated. Do not edit!-->
3+
In this demo you will
4+
5+
* Install Java 11
6+
* Start locally HAM server
7+
* Connect to it through proxy
8+
9+
Download the ham tar.gz from [github releases](https://github.com/kendarorg/HttpAnsweringMachine/releases)
10+
and extract it
11+
12+
13+
<b>Ensure your application is calling -ONLY- http pages or it will not record the
14+
interactions content</b>
15+
16+
17+
## Configure proxy<a id="proxy_01"></a>
18+
19+
Should set the proxy to 127.0.0.1 And port 1080 for socks5 or 1081 for http/https
20+
21+
<details>
22+
<summary>Click me for more explanations</summary>
23+
24+
* Chrome:
25+
* Install [Proxy Switch Omega](https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif)
26+
* Go to options
27+
* Add http and https proxy server with
28+
* Address: 127.0.0.1
29+
* Port 1081.
30+
31+
<img alt="Ham Proxyes" src="../images/chrome_proxy.gif" width="500"/>
32+
* Select "proxy" from the extension menu and back to "direct" when you want to disconnect
33+
*
34+
<img alt="Ham Proxyes" src="../images/chrome_proxy_switch.gif" width="100"/>
35+
36+
* Firefox
37+
* Navigate to [about:preferences](about:preferences)
38+
* Search for "proxy"
39+
* Click on "Settings"
40+
* Go to "Manual proxy Configuration"
41+
* Select the socks5 proxy
42+
* Address: 127.0.0.1
43+
* Port 1080
44+
* Check the "Proxy DNS when using SOCKS v5" flag
45+
* Clean the settings when needed
46+
47+
<img alt="Ham Proxyes" src="../images/firefox_proxy.gif" width="500"/>
48+
49+
</details>
50+
51+
52+
## Configure the application proxy<a id="appproxy_01"></a>
53+
54+
Here is configured for both http and https BUT only http traffic will be intercepted
55+
56+
### On the application
57+
58+
* [On Baeldung for java](https://www.baeldung.com/java-connect-via-proxy-server)
59+
60+
Just add to the java command to start the application the following:
61+
62+
<pre>
63+
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=1081
64+
-Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=1081
65+
</pre>
66+
67+
* [Some C# suggestions](https://dotnetcoretutorials.com/2021/07/11/socks-proxy-support-in-net/?series)
68+
69+
### On HAM configuration
70+
71+
First ensure that all the ports called by your application are set on the
72+
file httpproxy.external.json in the "http" section. In the example here the
73+
http listen on 80, 8081 and 8082
74+
75+
<pre>
76+
{
77+
"id": "http",
78+
"system": true,
79+
"active": true,
80+
"port": "80;8081;8082",
81+
"backlog": 50,
82+
"useCachedExecutor": true
83+
},
84+
</pre>
85+
86+
87+
88+
## Run!!
89+
90+
Start the HAM application with the "httpproxy.run.bat/sh"
91+
Start your appplication
92+
## Record some interaction<a id="createrecording_01"></a>
93+
94+
You can now check ham application going on http://localhost
95+
96+
* You can create a recording on the [recording page](http://www.local.test/plugins/recording)
97+
98+
<img alt="Create recording" src="../images/create_recording.gif" width="500"/>
99+
100+
* Once you create the recording you can start recording!
101+
102+
<img alt="Start recording" src="../images/start_recording.gif" width="500"/>
103+
104+
* Do some interaction on your application
105+
* And stop the recording!
106+
* Now you will se all the calls on the just created recording!
107+
108+
<img alt="Start recording" src="../images/calendar_recorded.gif" width="500"/>
109+
110+
* "Download" the recording as "Sample.json"

ham/httproxy.external.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[
2+
"#include:external/dns.json",
3+
{
4+
"id": "staticPage",
5+
"system": true,
6+
"staticPages": [
7+
]
8+
},
9+
{
10+
"id": "http",
11+
"system": true,
12+
"active": true,
13+
"port": "80",
14+
"backlog": 50,
15+
"useCachedExecutor": true
16+
},
17+
"#include:external/proxy.json",
18+
"#include:external/dbproxy.json",
19+
"#include:external/ssl.json",
20+
"#include:external/https.json",
21+
"#include:external/mongo.json",
22+
{
23+
"id": "global",
24+
"system": true,
25+
"db": {
26+
"url": "jdbc:h2:tcp://localhost/ham;MODE=MYSQL;",
27+
"login": "sa",
28+
"password": "sa",
29+
"startInternalH2": true,
30+
"driver": "org.h2.Driver",
31+
"hibernateDialect": "org.hibernate.dialect.MySQLDialect"
32+
},
33+
"localAddress": "localhost",
34+
"logging": {
35+
"logLevel": "INFO",
36+
"loggers": {
37+
"org.kendar.servers.http.Request": "OFF",
38+
"org.kendar.servers.http.Response": "OFF",
39+
"org.kendar.servers.http.StaticRequest": "OFF",
40+
"org.kendar.servers.http.DynamicRequest": "OFF",
41+
"org.kendar.dns.DnsQueries": "OFF",
42+
"org.kendar.servers.http.InternalRequest": "OFF",
43+
"org.hibernate": "OFF",
44+
"org.kendar.mongo.logging.MongoLogClient": "OFF",
45+
"org.kendar.mongo.logging.MongoLogServer": "OFF",
46+
"org.mongodb.driver": "OFF",
47+
"com.sun.net.httpserver": "ERROR"
48+
}
49+
},
50+
"filters": {
51+
"12363272": false
52+
}
53+
},
54+
{
55+
"id": "oidc.server",
56+
"tokenExpiration": 86400,
57+
"active": false
58+
},
59+
{
60+
"id": "js.filters",
61+
"path": "jsplugins",
62+
"active": true
63+
},
64+
{
65+
"id": "replayer.server",
66+
"path": "replayerdata",
67+
"active": true
68+
},
69+
{
70+
"id": "socks5.server",
71+
"port": 1080,
72+
"httpProxyPort": 1081,
73+
"interceptAllHttp":true,
74+
"active": true
75+
}
76+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@ECHO OFF
2+
3+
REM Initialize
4+
set SCRIPT_DIR=%~dp0
5+
cd %SCRIPT_DIR%
6+
7+
REM Retrieve the jar name
8+
dir /b %SCRIPT_DIR%\*.jar > .temp.txt
9+
set /p JAR_NAME=<.temp.txt
10+
del /s /f /q .temp.txt 2>&1 1>NUL
11+
12+
13+
14+
15+
REM Start the application
16+
java "-Dloader.path=%SCRIPT_DIR%/libs" -Dloader.main=org.kendar.Main ^
17+
"-Djsonconfig=%SCRIPT_DIR%\httpproxy.external.json" ^
18+
-jar %JAR_NAME% org.springframework.boot.loader.PropertiesLauncher
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Initialize
4+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
5+
cd $SCRIPT_DIR
6+
7+
# Retrieve the jar name
8+
ls -lA|grep -oE '[^ ]+$'|grep .jar$ > tmp_txt
9+
export JAR_NAME=$(head -1 tmp_txt)
10+
rm tmp_txt || true
11+
12+
13+
14+
# Start the application
15+
java "-Dloader.path=$SCRIPT_DIR/libs" -Dloader.main=org.kendar.Main \
16+
"-Djsonconfig=$SCRIPT_DIR/httpproxy.external.json" \
17+
-jar "$JAR_NAME" org.springframework.boot.loader.PropertiesLauncher

0 commit comments

Comments
 (0)