com.github.meazza:spring-boot-request-copy

Provide Spring MVC @RequestCopy annotation

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

com.github.meazza
ArtifactId

ArtifactId

spring-boot-request-copy
Last Version

Last Version

1.0.6.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

com.github.meazza:spring-boot-request-copy
Provide Spring MVC @RequestCopy annotation
Project URL

Project URL

https://github.com/meazza/spring-boot-request-copy
Source Code Management

Source Code Management

https://github.com/meazza/spring-boot-request-copy

Download spring-boot-request-copy

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.meazza/spring-boot-request-copy/ -->
<dependency>
    <groupId>com.github.meazza</groupId>
    <artifactId>spring-boot-request-copy</artifactId>
    <version>1.0.6.RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.meazza/spring-boot-request-copy/
implementation 'com.github.meazza:spring-boot-request-copy:1.0.6.RELEASE'
// https://jarcasting.com/artifacts/com.github.meazza/spring-boot-request-copy/
implementation ("com.github.meazza:spring-boot-request-copy:1.0.6.RELEASE")
'com.github.meazza:spring-boot-request-copy:jar:1.0.6.RELEASE'
<dependency org="com.github.meazza" name="spring-boot-request-copy" rev="1.0.6.RELEASE">
  <artifact name="spring-boot-request-copy" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.meazza', module='spring-boot-request-copy', version='1.0.6.RELEASE')
)
libraryDependencies += "com.github.meazza" % "spring-boot-request-copy" % "1.0.6.RELEASE"
[com.github.meazza/spring-boot-request-copy "1.0.6.RELEASE"]

Dependencies

compile (4)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-aop jar 2.1.1.RELEASE
org.springframework.boot : spring-boot-starter-web jar 2.1.1.RELEASE
org.projectlombok : lombok Optional jar 1.18.4
com.alibaba : fastjson jar 1.2.54

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.1.1.RELEASE

Project Modules

There are no modules declared in this project.

Introduction

This project is help to implement copying Spring mvc controller request to the other address by a given ratio. The Traditional method to achieve this is using tools like gor or tcpcopy. If these tools could not be used in your Spring Boot project for some reason, please read the following context and it can help you.

How to use it

First, add Maven dependencies in your project

<dependencies>
  <dependency>
    <groupId>com.github.meazza</groupId>
    <artifactId>spring-boot-request-copy</artifactId>
    <version>1.0.5.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.54</version>
  </dependency>
</dependencies>

and then, import configuration classes in main class.

@SpringBootApplication
@RestController
@Import({WebAppConfigurer.class, RequestWrapFilter.class})
public class AnnotationTestApplication { 
 
  public static void main(String[] args) { 
    SpringApplication.run(AnnotationTestApplication.class, args); 
  }
}

Now you can add @RequestCopy annotation on the method that you want the requests received by it to be copied.

// This request is copied to url: http://localhost:8080/test by the ratio of 5%
@RequestMapping(value = "/")
@RequestCopy(url = "http://localhost:8080/test", ratio = 0.05F)
public String hello(@RequestParam(defaultValue = "nobody") String name) {
  System.out.println("hello, " + name);
  return "hello, " + name;
}

What can be supported

All GET requests and POST requests whose headers include "Content-Type:application/json"

Testing the effects

You can test the effects in this project, follow the steps:

  1. Clone the whole project
  2. Modify this parameter in pom.xml: <spring-boot-maven-plugin.skip>false</spring-boot-maven-plugin.skip>
  3. Executing command: mvn spring-boot:run
2018-12-10 09:46:51.768  INFO 10196 --- [nio-8080-exec-7] c.g.m.handler.RequestHandlerInterceptor  : Send copied GET request to url: http://localhost:8080/test?name=meazza, and receive response: hello test, meazza
2018-12-10 09:48:15.747  INFO 10196 --- [nio-8080-exec-3] c.g.m.handler.RequestHandlerInterceptor  : Send copied POST request to url: http://localhost:8080/test/post, body: {"name":"meazza","id":1}, and receive response: hello test, PostBody(id=1, name=meazza)

Versions

Version
1.0.6.RELEASE
1.0.5.RELEASE
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0