BingAds / BingAds-Java-SDK

Other
43 stars 48 forks source link

Logging for REST-Requests #186

Closed schabe77 closed 6 months ago

schabe77 commented 6 months ago

Do you provide a way to log the REST requests like the SOAP logging, which is described here?

As far as I can see it is possible to register a jakarta.ws.rs.client.ClientRequestFilter/jakarta.ws.rs.client.ClientRequestFilter like this one on the javax.ws.rs.client.Client, but I don't see anything like this at HttpClientProvider.

dennis-yemelyanov commented 6 months ago

If using CXF, the same logging setting com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump works for both SOAP and REST. But some slf4j implementation needs to be added as well, more details can be found here: Logging service calls

For any custom implementation we can override HttpClientProvider methods like configureClientBuilder() and register LoggingFeature or other filters. An example can be found here: Customizing HTTP client

schabe77 commented 6 months ago

Thank you! With your answer to #184 I managed to integrate a logger:

        GlobalSettings.setHttpClientProvider(new HttpClientProvider() {
            @Override
            protected ClientBuilder configureClientBuilder(ClientBuilder clientBuilder) {
                return super.configureClientBuilder(clientBuilder)
                        .register(org.glassfish.jersey.message.GZipEncoder.class)
                        .register(org.glassfish.jersey.client.filter.EncodingFilter.class)
                        .register(org.glassfish.jersey.logging.LoggingFeature.builder().verbosity(Verbosity.PAYLOAD_ANY).level(Level.FINEST).build());
            }
        });
dennis-yemelyanov commented 6 months ago

Note, there was also a fix in 13.0.20.1 to call readEntity() instead of getEntity() for synchronous calls (apparently getEntity() doesn't invoke some filters). Asynchronous calls (like the ones made by BulkServiceManager) were not affected (they were using readEntity() already): https://github.com/BingAds/BingAds-Java-SDK/commit/f2e69d1f248834834d7a757909b3218d5a7edb55#diff-270a571915d22522c540a948a1b45939dd42f85b18079b7ae77d110a4289288d