cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Logging OCC APIs request and response

0 Likes
1,273

Hi there,

Anyone here who implemented logging for all OCC API request/response using any library like jersey.

Any help is appreciable.

Thanks
Anil

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Likes

: Your OCC must be implemented in some extension, right ? in that extension, you must have a web.xml and an application configuration file. Add the request logger in the filter chain in that application configuration file and you should be good.

Basically it is all about adding a filter before your request gets processed, it does not matter if it is storefront or web services or OCC or process engine.

0 Likes

Thanks for your inputs Saurabh, I would try that.

Former Member
0 Likes

Hi : Create a Request Logging Filter which implements OncePerRequestFilter and define this filter in your extension's spring-filter.xml file. See example below.

 <alias name="defaultStorefrontTenantDefaultFilterChainList" alias="storefrontTenantDefaultFilterChainList" />
     <util:list id="defaultStorefrontTenantDefaultFilterChainList">
         <!-- generic platform filters -->
         <ref bean="storefrontSessionFilter"/>
         <!-- <ref bean="addOnDevelopmentFilter"/> -->
         <!-- filter to log the current request -->
          <ref bean="requestLoggerFilter"/> 
         <!-- filter to setup the cms integration -->
         <ref bean="cmsSiteFilter"/>
 
         <!-- filter to initialize the storefront -->
         <ref bean="storefrontFilter"/>
 
         <!-- filter to handle url encoding attributes -->
         <ref bean="urlEncoderFilter"/>
 
         <!-- Security -->
         <ref bean="springSecurityFilterChain"/>
 
         <!-- filter to log out guest user if he/she attempts to access a page outside of checkout flow -->
         <ref bean="anonymousCheckoutFilter"/>
 
         <!-- filter to restore items in cart -->
         <ref bean="cartRestorationFilter"/>
     </util:list>


<bean id="requestLoggerFilter" class="com.xxx.storefront.filters.RequestLoggerFilter">

0 Likes

Hi Sourabh, Thanks for the solution, but I wanted to implement it for OCC where I need to log HTTP headers, content type, request/response body etc. But the solution seems to be for storefront.

Could you help me for OCC APIs, also this logging is for both request and response.

Thanks Anil

0 Likes

The proposed solution above does cover your requirements.

A quick google search provides several implementations for the filter. Examples below.

https://gist.github.com/int128/e47217bebdb4c402b2ffa7cc199307ba https://gist.github.com/freemanh/b896a70a21fddb8e2aea2cf08725eb64

There is also a guide here: https://www.baeldung.com/spring-http-logging

Edit: Of course you would be editing the defaultCommerceWebServicesFilterChainListV1 (or V2 if you are using that version) and not the storefront filter chain. The storefront and OCC WS are both using the spring web ecosystem.