Spring-boot MVC interface request/ Response capture application.

Preface (Reason for Building a Wheel)

The company is a technology outsourcing service company, which often involves cooperation with different teams (remote), including front-end, APP end, and interface request analysis with a high frequency. In the past, it was generally solved by Fiddler or Charles or server end log, so it requires a small intrusion, visualization, and no proxy. Can test line interface debugging.

Jimoos – API – tracer profile

Spring-boot HTTP interface Request capture test line interface or client debugging mandatory

Positioned as: Http interface debugger

  • Query interface
  • The details of theRequest/ResponseThe query
  • Slow queries,eg. >1000ms
  • HttpStatusQuery to quickly find 500/400 requests
  • The specified pathPathThe query

Open source project address: github.com/jimoos-cn/j…

Welcome to Star/Fork

Demo Demo (Conscience cloud small water pipe everyone tap)

Demo address: http://150.158.189.200:4000/develop/traces

Password: 123456

Test the Http request at http://150.158.189.200:4000/v1/pings? Q = the Denver nuggets.

Quick learning

1. Initialize the database

CREATE TABLE `JM_API_TRACE`
(
    `id`          bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `request`     text COLLATE utf8mb4_unicode_ci COMMENT The 'request',
    `response`    longtext COLLATE utf8mb4_unicode_ci COMMENT 'Return value',
    `tenant_id`   varchar(128) COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT 'the tenant ID',
    `uri`         varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'path',
    `domain`      varchar(1023) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'domain',
    `method`      varchar(50) COLLATE utf8mb4_unicode_ci   DEFAULT NULL COMMENT 'http method,eg. POST',
    `path`        varchar(255) COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT 'path',
    `ip`          varchar(255) COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT 'request IP',
    `user_agent`  varchar(255) COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT 'user-agent',
    `os_family`   varchar(50) COLLATE utf8mb4_unicode_ci   DEFAULT NULL COMMENT 'the system',
    `correlation` varchar(128) COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT 'correlation',
    `status`      varchar(50) COLLATE utf8mb4_unicode_ci   DEFAULT NULL COMMENT 'Return status',
    `duration`    int(11)                                  DEFAULT NULL COMMENT 'Request time',
    `create_at`   bigint(20)                               DEFAULT NULL COMMENT 'Create event'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT ='Request and Response tracing for THE API';
Copy the code

2. Add dependencies to the interface module (listener)


<dependencies>
    <dependency>
        <groupId>cn.jimoos</groupId>
        <artifactId>jm-api-tracer</artifactId>
        <version>0.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.zalando</groupId>
        <artifactId>logbook-spring-boot-starter</artifactId>
        <version>Against 2.4.1</version>
    </dependency>
    <! -- ua -->
    <dependency>
        <groupId>com.github.ua-parser</groupId>
        <artifactId>uap-java</artifactId>
        <version>1.5.1</version>
    </dependency>
</dependencies>
Copy the code

Now start your Spring-Boot application and your table should have a request/ Response capture in JM_API_TRACE.

-dlogbook.servlet. form-request=parameter should be added in the startup command to solve the problem that application/x-www-form-urlencoded capture body is empty.

Idea debugging is as follows

Start the api-trace-Manager Web service

  • Procedure 1 Download the Manager jar

  • 2 Initialize application.yml

spring:
  application:
  name: jimoos-api-tracer-manager
  datasource:
    url: jdbc:mysql://localhost:3306/jimoos? useUnicode=true&characterEncoding=utf-8
    username: root
    password: 123456
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
mybatis:
  mapper-locations: classpath*:mapper/**/*.xml
  type-aliases-package: cn.jimoos.model
server:
  port: 4000
Copy the code
  • 3 start manager. The jar
Java - Djava. Security. Or egd = file: / dev /. / urandom - jar jm - API - tracer - manager - 0.0.1. Jar --spring.config.location=file:application.ymlCopy the code

Configure database connections that are consistent with your application’s database connections.

  • 4 Open the application http://127.0.0.1:4000

Enter the password: 123456

To view the preview

Use Docker images

docker run -d -p 4000:4000  -v /Users/keepcleargas/tmp/api-trace:/config --name jimoos-api-trace-manager -e TZ=Asia/Shanghai  --entrypoint '/bin/sh' keepcleargas/jm-api-tracer-manager -c 'java -Djava.security.egd=file:/dev/./urandom -jar /app.jar --spring.config.location=file:/config/application.yml'
Copy the code

Change the config mapping file address to the application.yml path.

Open Source Copyright Notice

Lgpl-3.0

Station B is new UP, asking for attention

Share some knowledge of Spring-boot development, Ansible & Docker deployment, project management, etc.

New technology UP, welcome everyone to pay attention to three links with one button.

Five minutes to access the API debugging tool, API debugging is no longer difficult: www.bilibili.com/video/BV1H5…