Java 春季如何审核端点通信?

Java 春季如何审核端点通信?,java,spring,spring-boot,spring-mvc,auditing,Java,Spring,Spring Boot,Spring Mvc,Auditing,我的目的是审核通过应用程序端点进行的数据交换。我想检索通过端点交换的json并将其存储在数据库中。为了存储json数据,我将使用Javes(),但我仍然需要弄清楚如何获取端点数据。您可以编写拦截器来对流经应用程序的请求和响应进行额外处理。 如果您使用的是spring,则很容易实现。以下是一个例子: @Component public class RestInterceptor implements ClientHttpRequestInterceptor { @Override publi

我的目的是审核通过应用程序端点进行的数据交换。我想检索通过端点交换的json并将其存储在数据库中。为了存储json数据,我将使用Javes(),但我仍然需要弄清楚如何获取端点数据。

您可以编写拦截器来对流经应用程序的请求和响应进行额外处理。 如果您使用的是
spring
,则很容易实现。以下是一个例子:

@Component
public class RestInterceptor implements ClientHttpRequestInterceptor {

 @Override
 public ClientHttpResponse intercept(HttpRequest request, byte[] body,
  ClientHttpRequestExecution execution) throws IOException {
  traceRequest(request, body);
  ClientHttpResponse response = execution.execute(request, body);
  traceResponse(response);
  return response;
 }

 private void traceRequest(HttpRequest request, byte[] body) throws IOException {
   //track request here
 }


 private void traceResponse(ClientHttpResponse response) throws IOException {
    //track response here
 }

}
现在用rest模板注册它

restTemplate.setInterceptors(Collections.singletonList(new RestInterceptor ()));

编写一个拦截器可以通过实现
clienthttpprequestinterceptor
捕获请求和响应,在短的spring引导应用程序中,我在哪里配置以下“Register clienthttpprequestinterceptor with restemplate”。这里我举了一个例子:howtodoinjava.com/spring-restful/clienthttpprequestinterceptorfollow,您还可以检查对进入应用程序的日志请求的回写访问。答案中的示例记录应用程序发出的请求和响应。