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

How to introduce new MVC Interceptor to OCC extension?

ericyew94
Explorer
0 Kudos
531

I am currently performing an upgrade from the OCC addon to the OCC extension (https://help.sap.com/docs/SAP_COMMERCE/e5d7cec9064f453b84235dc582b886da/d46d19516961438f8939718e87ed...

Before the upgrade, the web context sits on our custom addon. Hence, we can freely add custom mvc interceptors as we want. After the upgrade (with the new OCC extension), we no longer have the web context as we are supposed to rely on the OOTB 'commmercewebservices' web context now. Hence, I am trying to include a custom interceptor to via my custom occ extension's dummyocc-web-spring.xml (I have verified, it is in a correct location). However, my custom interceptor isn't picked up at all.. 

dummyocc-web-spring.xml

<mvc:interceptors>
<ref bean="dummyCatalogVersionInterceptor" />
</mvc:interceptors>

May I ask is it even possible to add a custom mvc interceptor with the new architecture of the OCC extension? Is this the right approach? 

View Entire Topic
Rami_Mansouri
Newcomer
0 Kudos

In your custom occ extension , you can use a HandlerInterceptor : 

@Component

public class CustomHandlerInterceptor implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
//your logic here
}
}

And then add your HandlerInterceptor to the InterceptorRegistry using a WebMvcConfigurer (always in your occ extension) : 

@Configuration

public class OccWebConfig implements WebMvcConfigurer {

@Autowired
private CustomHandlerInterceptor customHandlerInterceptor;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(customHandlerInterceptor)
.addPathPatterns("/**");
}
}

Make sure that your customocc-web-spring.xml is scanning the HandlerInterceptor and the WebMvcConfigurer packages (<context:component-scan base-package="com.project.occ"/>)