Spring Boot Interceptor | Handler Interceptor | Web MVC Configuration Support

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 มิ.ย. 2021
  • You will learn how can use an interceptor to add the request header before sending the request to the controller and add the response header before sending the response to the client.
    My Top Playlists:
    Spring Boot with Angular : • Spring Boot + Angular
    Spring Boot with Docker & Docker Compose : • Spring Boot Docker & D...
    Spring Boot with Kubernetes : • Spring Boot Docker Kub...
    Spring Boot with AWS : • Spring Boot + AWS
    Spring Boot with Azure : • Spring Boot Azure
    Spring Data with Redis : • Spring Data with Redis
    Spring Boot with Apache Kafka : • Apache kafka
    Spring Boot with Resilience4J : • SpringBoot Resilience4j
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 21

  • @ashok4harsha
    @ashok4harsha 2 ปีที่แล้ว

    Very useful lectures,simple and easy to understand

  • @hello-again6994
    @hello-again6994 ปีที่แล้ว

    Succinct to-the-point presentation. 👍

  • @user-fn2er6ro3y
    @user-fn2er6ro3y ปีที่แล้ว

    This very important source.Thankyou

  • @Anushaaa_
    @Anushaaa_ 2 ปีที่แล้ว

    Very informative 👏👏

  • @bojrajr3473
    @bojrajr3473 5 หลายเดือนก่อน

    Thanks man❤, that's a useful one

  • @ashu7pathak
    @ashu7pathak ปีที่แล้ว

    Thanks. Also, you could have told about when to use interceptors, but in your description I read - to add request header or response header.
    I'm assuming that we can useinterceptor.preHandle() - for adding request headers and interceptor.postHandle() or interceptor.afterCompletion() for adding response headers.

  • @oluwatosinobatoyinbo5024
    @oluwatosinobatoyinbo5024 ปีที่แล้ว

    Thanks for sharing

  • @poojashegokar2635
    @poojashegokar2635 2 ปีที่แล้ว

    Nice info

  • @ayushgarg5929
    @ayushgarg5929 2 ปีที่แล้ว

    ye overridden method dekhne k liye konsi key press key thi?

  • @suryanarayansubudhi9439
    @suryanarayansubudhi9439 3 ปีที่แล้ว +1

    If possible attach your code git URL in the video description

  • @robinmathew8828
    @robinmathew8828 6 หลายเดือนก่อน

    Hi I have a doubt please respond as soon as possible ,which annotations implementing filter design pattern? @Secured,@Enable@,@Preauthorize

  • @zenhsuld
    @zenhsuld 3 ปีที่แล้ว

    Thanks for the tutorial. How to write all request log to database(IP, USER_ID etc..,) ?

    • @abhinavsharma7818
      @abhinavsharma7818 3 ปีที่แล้ว

      Create a filter which extends OncePerRequestFilter , you can save the request and response as well

    • @technotowntechie9732
      @technotowntechie9732  3 ปีที่แล้ว

      You can either use OncePerRequestFilter or CommonsRequestLoggingFilter.

  • @bhaskarudaya6889
    @bhaskarudaya6889 3 ปีที่แล้ว

    Thanks for all the work, can you help us with spring boot with rabbit mq impl

    • @technotowntechie9732
      @technotowntechie9732  3 ปีที่แล้ว +1

      Sure, I will do it soon.

    • @technotowntechie9732
      @technotowntechie9732  3 ปีที่แล้ว

      I have created spring boot with rabbitmq example. th-cam.com/video/YLsG0mew2dU/w-d-xo.html

  • @Iam_Goutam
    @Iam_Goutam 10 หลายเดือนก่อน

    Please please help how we can configure EndPointInterceptor , pleas help to do that

    • @technotowntechie9732
      @technotowntechie9732  9 หลายเดือนก่อน

      Create an EndpointInterceptor Implementation:
      Create a class that implements the HandlerInterceptor interface or extends the HandlerInterceptorAdapter class. This class will define the pre- and post-processing logic for intercepting requests.
      import org.springframework.web.servlet.HandlerInterceptor;
      import org.springframework.web.servlet.ModelAndView;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      public class CustomEndpointInterceptor implements HandlerInterceptor {
      @Override
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
      // Pre-processing logic before the request is handled by the controller
      return true; // Return true to proceed with the handling of the request
      }
      @Override
      public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
      // Post-processing logic after the request has been handled by the controller
      }
      @Override
      public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
      // After completion logic (e.g., resource cleanup)
      }
      }
      Configure the EndpointInterceptor in your Spring Boot application by overriding the addInterceptors method of WebMvcConfigurerAdapter or WebMvcConfigurer.
      import org.springframework.context.annotation.Configuration;
      import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
      import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
      @Configuration
      public class WebMvcConfig implements WebMvcConfigurer {
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
      registry.addInterceptor(new CustomEndpointInterceptor())
      .addPathPatterns("/**"); // Add path patterns for which this interceptor should be invoked
      }
      }
      You can specify path patterns for the interceptor to apply to specific endpoints. In this example, we've used "/**" to apply the interceptor to all endpoints. Modify the path pattern as needed for your use case.
      registry.addInterceptor(new CustomEndpointInterceptor())
      .addPathPatterns("/api/**"); // Apply to endpoints under the "/api" path

    • @Iam_Goutam
      @Iam_Goutam 9 หลายเดือนก่อน

      @@technotowntechie9732 Many many thanks for your detailed reply, so when I will give a soap call request with this url pattern it will invoke automatically? I am using Jaxws-spring api for webservice and spring mvc

    • @technotowntechie9732
      @technotowntechie9732  9 หลายเดือนก่อน

      For SOAP web services using JAX-WS and Spring, you might want to look into using JAX-WS handlers. Handlers in JAX-WS allow you to intercept and manipulate messages at the SOAP message level, which is appropriate for SOAP-based web services.
      Create a class that implements javax.xml.ws.handler.soap.SOAPHandler interface.
      import javax.xml.ws.handler.soap.*;
      import javax.xml.ws.handler.MessageContext;
      import java.util.Set;
      public class CustomSOAPHandler implements SOAPHandler {
      @Override
      public boolean handleMessage(SOAPMessageContext context) {
      // Handle the SOAP message
      return true;
      }
      @Override
      public boolean handleFault(SOAPMessageContext context) {
      // Handle faults in SOAP message
      return true;
      }
      @Override
      public void close(MessageContext context) {
      // Clean up resources
      }
      @Override
      public Set getHeaders() {
      // Return the set of QNames for headers
      return null;
      }
      }
      Configure the Handler in the Spring context:


      Use the handler in your JAX-WS web service implementation.
      @WebService
      @HandlerChain(file="handler-chain.xml") // You can specify the handler chain in an XML file
      public class MyWebService {
      // Web service methods
      }