[
https://issues.apache.org/jira/browse/HTTPCLIENT-2241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17622875#comment-17622875
]
Patrick Barry commented on HTTPCLIENT-2241:
-------------------------------------------
Upon further research, I found hitting a website that exists but a path that
does not, does result in 400 and goes through response interceptor. If you
provide a url of a site that does not exists, it results in exception being
thrown and response interceptor not hit. I can work around this. Thanks.
> HttpResponseInterceptor is never called on errors
> -------------------------------------------------
>
> Key: HTTPCLIENT-2241
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2241
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient (classic)
> Affects Versions: 4.5.13
> Reporter: Patrick Barry
> Priority: Major
>
> 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.
> {code:java}
> @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());
> }{code}
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]