Spring Response Warning

Controller annotation to add Warning header on response

License

License

GroupId

GroupId

com.kakawait
ArtifactId

ArtifactId

spring-response-warning
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Spring Response Warning
Controller annotation to add Warning header on response
Project URL

Project URL

https://github.com/kakawait/spring-response-warning
Source Code Management

Source Code Management

https://github.com/kakawait/spring-response-warning

Download spring-response-warning

How to add to project

<!-- https://jarcasting.com/artifacts/com.kakawait/spring-response-warning/ -->
<dependency>
    <groupId>com.kakawait</groupId>
    <artifactId>spring-response-warning</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.kakawait/spring-response-warning/
implementation 'com.kakawait:spring-response-warning:0.1.0'
// https://jarcasting.com/artifacts/com.kakawait/spring-response-warning/
implementation ("com.kakawait:spring-response-warning:0.1.0")
'com.kakawait:spring-response-warning:jar:0.1.0'
<dependency org="com.kakawait" name="spring-response-warning" rev="0.1.0">
  <artifact name="spring-response-warning" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.kakawait', module='spring-response-warning', version='0.1.0')
)
libraryDependencies += "com.kakawait" % "spring-response-warning" % "0.1.0"
[com.kakawait/spring-response-warning "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework : spring-webmvc jar 4.2.6.RELEASE
org.springframework.boot : spring-boot-autoconfigure jar 1.3.5.RELEASE
javax.servlet : javax.servlet-api jar 3.1.0

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.4.1
org.springframework : spring-test jar 4.2.6.RELEASE
org.hamcrest : java-hamcrest jar 2.0.0.0

Project Modules

There are no modules declared in this project.

Warning header for Spring Web MVC

Build Status Issues Coverage Status License Maven Central GitHub release

Spring Warning Response is a library that makes it easy to return Warning header describes on RFC7234 responses from a Spring application.

This library works around a single annotation @ResponseWarning that you can put over every controller methods.

Installation

Add the following dependency to your project:

<dependency>
    <groupId>com.kakawait</groupId>
    <artifactId>spring-response-warning</artifactId>
    <version>${spring-response-warning.version}</version>
</dependency>

Configuration

With Spring-boot (autoconfiguration)

Nothing for Spring-boot application, autoconfiguration will do the job for you.

Without Spring-boot

Simply register ResponseWarningHandlerInterceptor

@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ResponseWarningHandlerInterceptor());
    }
}

Usage

Deprecating API sample:

@RestController
class ProductsController {

    @ResponseWarning(
            code = WarnCode.MISCELLANEOUS_PERSISTENT_WARNING, 
            text = "Deprecated API: use /{productId} instead.")
    @RequestMapping(method = GET, value = "/get", produces = APPLICATION_JSON_VALUE)
    @Deprecated
    public Product getProduct_v0(@RequestParam(value = "id") String productId) {
        return ...;
    }

    @RequestMapping(method = GET, value = "/{productId}", produces = APPLICATION_JSON_VALUE}
    public Product getProduct_v1(String productId) {
        return ...;
    }

}

The following HTTP request will produce the corresponding response:

GET /products?id=123 HTTP/1.1
HTTP/1.1 200 Ok
Content-Type: application/json
Warning: 299 - "Deprecated API: use /{productId} instead." 

...

Getting help

If you have questions, concerns, bug reports, etc., please file an issue in this repository's Issue Tracker.

Getting involved

To contribute, simply make a pull request and add a brief description (1-2 sentences) of your addition or change.

Credits and references

Versions

Version
0.1.0