Skip to content

Latest commit

 

History

History
175 lines (127 loc) · 5.8 KB

File metadata and controls

175 lines (127 loc) · 5.8 KB

In this demo you will

  • Start locally HAM server
  • Start the sample application
  • Connect to it through proxy
  • Record the db interactions of the sample application
  • Simulate the DB

For more infos check here

Download the last release

Download the two tar.gz, ham and ham-samples from github releases and extract them in the same directory

Starting the sample application

Go on the "calendar" directory and run "runcalendardbproxy.bat/sh"

This will start

First you should choose if you want to recreate the db go for Y the first time

Then you will have to wait a bit. Now DO NOT START THE BE!!

The calendar sample project

It's composed of three parts

  • FE, that calls gateway for all its needs
  • GATEWAY, that acts a "middleman" between FE and BE
  • BE, with the database that is called only by the GATEWAY

Configure proxy

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

Click me for more explanations
  • Chrome:

    • Install Proxy Switch Omega
    • Go to options
    • Add http and https proxy server with
      • Address: 127.0.0.1

      • Port 1081.

        Ham Proxyes
    • Select "proxy" from the extension menu and back to "direct" when you want to disconnect
    • Ham Proxyes
  • Firefox

    • Navigate to 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

      Ham Proxyes

Record some interaction

You can now check the configuration

  • Going on ham proxyes you can verify that all proxies are ok if they don't work just "Refresh Status"

Ham Proxyes

  • And a db proxy for be

Ham Proxyes

Create recording

  • Once you create the recording you can start recording! CHECKING THE "Record db calls"

Start recording

  • Now you can start the application on the command line :)

  • Go then on the application and do some interaction

    • Add an Employee "John Doe"
    • Go on Appointements
    • Add an Appointment with "Doctor" as description
    • Change the state of the appointament till it shows "Confirmed"
    • Delete the appointment
    • Back on employee, delete the employee too
  • And stop the recording!

  • Now you will se all the calls on the just created recording

  • First the hibernate initialization phase

Start recording

  • ..or see how an employee is created.
    • First a post to the gateway
    • Forwarded to the be
    • Then the be opens the connections and run the query

Start recording

  • You can even see the details of the queries there are many visualisations available
    • JSON: the native format of Janus-Jdbc (editable)
    • Component: the "easy editable visualisation", when available
    • Tree: the structure of the json message (that include the data types)

Start recording

Analyzing the Json we identify a prepared statement with one Long parameter with set the index 1 (the first to set JDBC prepared statement parameters)

{
	"command": {
		"sql": "
            select 
              employee0_.id as id1_1_0_, 
              employee0_.name as name2_1_0_, 
              employee0_.role as role3_1_0_ 
            from 
              employee employee0_ 
            where employee0_.id=?",
		":sql:": "java.lang.String",
		"parameters": [
			{
				"_": {
					"columnindex": 1,
					":columnindex:": "java.lang.Integer",
					"value": 0,
					":value:": "java.lang.Long"
				},
				":_:": "org.kendar.janus.cmd.preparedstatement.parameters.LongParameter"
			}
		],
		":parameters:": "java.util.ArrayList"
	},
	":command:": "org.kendar.janus.cmd.preparedstatement.PreparedStatementExecuteQuery"
}

Replay everything!

  • "Download" the recording as "FullDb.json"
  • You can now delete all the request with at least one of the following, leaving only db calls
  • "Download" the recording as "DbOnly.json"
  • Now stop the H2 database AND the BE application
  • Start replaying the recording with "Play" when started
  • Restart the BE with the be.bat/sh
  • When the initialisation is complete go again of www.sample.test and redo all the steps (John Doe etc)
  • Everything will work :D