UCM Service Handlers and Java Filters

April 25, 2012

Quite often we need to customize our Content Servers using some specific Java code. Usually we accomplish this by creating a custom component and utilizing Service Handlers or Java Filters (or both). Unfortunately, sometimes it might be hard to decide when you should use one over the other. So, let’s dig deeper into both and understand how they work.

Service Handlers

Service Handlers are a mechanism that allows us to add new services or modify existing services by using Java.

Multiple Service Handlers could contain the same Java method, but the Content Server would only execute the one that is contained within the Service Handler that has the lowest Search Order. The Search Order is defined during the creation of the configuration table. The configuration table is a table that exposes your custom code to the Content Server.

Service Handlers could be chained/put-in-place to be executed:

  • Instead of new service actions:
    • Create a Service Handler with a lower Search Order.
  • Before existing service actions:
    • Create a Service Handler with a lower Search Order,
    • Make a call to the same method after your custom java code:
      … custom java code …
      m_service.doCodeEx("<sameMethodName>", this);
  • After existing service actions:
    • Create a Service Handler with a lower Search Order,
    • Make a call to the same method before your custom java code:
      m_service.doCodeEx("<sameMethodName>", this);
      … custom java code …
      Java Filters

Java Filters is an event subscription mechanism through which developers can subscribe to the various events that occur within the Content Server and execute custom Java code.

During the operation of Content Server, there are various events that constantly being fired up. The developer can subscribe to these events and alter the behavior of Content Server. When the desired event would occur the control would be passed to the subscribers of the event and the custom java code could be executed. The Content Server then expects a result of the custom code execution. The results are pretty straight forward:

  • CONTINUE – informs Content Server that everything went accordingly;
  • FINISHED – informs Content Server to stop running any other filters with the similar name;
  • ABORT – informs Content Server to halt execution of the current process.

When to Use Service Handlers versus Java Filters

Java Filters is the least-intrusive and easiest way to customize the behavior of Content Server with Java, whereas Service Handlers require more thorough understanding of the actions that need to be customized.

Java Filters is the preferred and most commonly used way of customization, but it is limited to the existing set of filters within the Content Server. So, if there is no defined filter to which you can subscribe, then you can create your own custom component that uses Service Handlers to customize the behavior.

© 2020 Jason Stortz (version 20200322-120514)