Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-2241

HttpResponseInterceptor is never called on errors

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Information Provided
    • 4.5.13
    • None
    • HttpClient (classic)
    • None

    Description

      We are registering two interceptors for logging purposes. One for request and response. Our response Interceptor is never called when we encounter an error, like a 404.   Is there another interceptor or way to capture this info or is this a bug. We are using Jersey with Apache client under the covers.  

      Here is a unit test that that requires Slf4j, logback and apache http client.

      @Test
      public void testResponseLoggingInterceptor2(){
      Logger logger = (Logger) LoggerFactory.getLogger(ResponseLoggingInterceptor.class);
      
      // create and start a ListAppender
      ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
      listAppender.start();
      // add the appender to the logger
      logger.addAppender(listAppender);
      
      ClientConfig clientConfig = new ClientConfig();
      clientConfig.connectorProvider(new ApacheConnectorProvider());
      Client client = ClientBuilder.newBuilder().withConfig(clientConfig).build();
      
      client.register((ApacheHttpClientBuilderConfigurator) httpClientBuilder ->
      httpClientBuilder
      .addInterceptorLast(new RequestLoggingInterceptor())
      .addInterceptorFirst(new ResponseLoggingInterceptor()));//This is never hit when hitting endpoint that does not exists
      
      try {
      WebTarget target = client.target("https://localhost:8080/not/exists");
      Response response = target.request("application/json").get();
      }catch (Exception ignored){
      //nothing
      }
      List<ILoggingEvent> logsList = listAppender.list;
      assertEquals("test message", logsList.get(0).getFormattedMessage());
      }

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            patrickjamesbarry Patrick Barry
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: