Hi Jean,
Yeah, the LoggingFeature has this method addBinaryContentMediaTypes which
basically along with setLogBinary determines what should or shouldn't be logged.
I think you could add "application/json" to this list if you don't want it to be
logged. Hope it helps. Thank you.
Best Regards,
Andriy Redko
Wednesday, June 4, 2025, 5:22:37 AM, you wrote:
> Hi andriy,
>
> I am trying to configure the CXF logging feature for my JAXRS client to log
> the headers for the binary attachments but not the content. I thought that
> creating my client in the following way would do what I intended:
>
> private PT getThreadsafeProxy(String baseAddress) {
> JacksonJsonProvider jjProvider = new
> JacksonJsonProvider(new CustomObjectMapper());
> List<Object> providers = Arrays.asList(new
> MultipartProvider(), jjProvider);
>
> final JAXRSClientFactoryBean factory = new
> JAXRSClientFactoryBean();
> factory.setAddress(baseAddress);
>
> factory.setServiceClass(getPTClass());
> factory.setProviders(providers);
> factory.setThreadSafe(true);
>
> //only for testing the sending of attachments
> as multipart/form-data
> LoggingFeature feature = new LoggingFeature();
> feature.setLogMultipart(true);
> feature.setLogBinary(true);
> feature.setLimit(2*1024);
>
> feature.addBinaryContentMediaTypes(MediaType.APPLICATION_OCTET_STREAM);
>
> feature.addBinaryContentMediaTypes("application/pdf");
> factory.setFeatures(Arrays.asList(feature));
>
> //Now create client proxy
> PT api = (PT) factory.create(getPTClass());
> ClientConfiguration config =
> WebClient.getConfig(api);
>
> //Set timeouts on client
> HTTPConduit conduit = config.getHttpConduit();
> conduit.getClient().setReceiveTimeout(60000);
> /* 60 secs */
>
> conduit.getClient().setConnectionTimeout(10000); /* 10 sec */
>
> //Set client TLS parameters if present
> addTLSClientParameters(config.getHttpConduit());
>
> return api;
> }
>
> But it still logs (part of since it is limited to 2K bytes) the binary
> content, e.g. here is an extract of my log file:
>
> 2025-06-04 11:14:36,055 [Thread-9] INFO
> (org.apache.cxf.ext.logging.slf4j.Slf4jEventSender:84) - REQ_OUT
> Address: http://localhost:8084/epplus/services/magdadocsim/messages
> HttpMethod: POST
> Content-Type: multipart/form-data;
> boundary="uuid:512a0d48-22c5-4ae7-a2fd-15fbe220811d"
> ExchangeId: 6b34950d-e87e-4f64-a7fa-44db06f27c98
> Headers: {Authorization=Bearer 80dea42a-3f06-4607-8034-85ee7b690a58,
> Accept=application/json, Idempotency-Key=2024-EP-0054-b_04,
> x-correlation-id=f0641a67-cfdb-46ce-8979-7e98e27499c3}
> Payload:
> --uuid:512a0d48-22c5-4ae7-a2fd-15fbe220811d
> Content-Type: application/json
> Content-Transfer-Encoding: binary
> Content-ID: <null>
> Content-Disposition: form-data; name="messageToSend"
>
> {
> "delivery" : "EBOX",
> "eboxDeliveryData" : {
> "recipient" : {
> "eboxType" : "ENTERPRISE",
> "enterpriseNumber" : "0684564929",
> "eboxIdValue" : "0684564929"
> },
> "subject" : {
> "nl" : "ProjectGunstigMail Project:2024-EP-0054"
> },
> "expirationDate" : "2026-06-04T11:14:31.348+02:00",
> "registeredMail" : false,
> "attachments" : [ {
> "httpPartName" : "upfile1",
> "mainContent" : true,
> "attachmentSigned" : false
> }, {
> "httpPartName" : "upfile2",
> "mainContent" : false,
> "attachmentSigned" : false
> } ],
> "bodyMainContent" : false,
> "businessDataList" : [ ],
> "replyAuthorized" : false,
> "messageActions" : [ ]
> },
> "businessData" : [ ]
> }
> --uuid:512a0d48-22c5-4ae7-a2fd-15fbe220811d
> Content-Type: application/pdf
> Content-Transfer-Encoding: binary
> Content-Disposition: form-data; name="upfile1"; filename="projectGunstig.pdf"
>
> %PDF-1.4
> %����
> 1 0 obj
> <<
> /Creator (Apache FOP Version 2.10)
> /Producer (Apache FOP Version 2.10)
> /CreationDate (D:20250604111433+02'00')
>>>
> endobj
> 2 0 obj
> <<
> /N 3
> /Length 3 0 R
> /Filter /FlateDecode
>>>
> stream
> x��gPTY��{�
> �M���I�� $�$A��@w�i��AQdpF I� ���
> AFQ ŀ((��N#��2
> �"**K�٭���U[�g��x�sO�s�[����
> 1���
> ���M��:�1��C�
>
> If I set:
> feature.setLogBinary(false);
>
> then the attachment of type ‘application/pdf’ isn’t logged (but the first one
> of type ‘application/json’ is).
> Am I misunderstanding the logging features?
>
> Regards,
>
> Jean-Pierre Urkens
> Lead Consultant
> Creative Tech
> 0478838336
> [email protected]
>
>