View source | Discuss this page | Page history | Printable version   

How to Add Server Side Hooks



Hooks provide an easy mechanism to extend functionality from external module. It basically consists on a lightweight mechanism (build using WELD) that allows to inject dependencies from third party modules.

There are two roles for hooks:

How to define a server side hook in the base module

Base module needs to define which are the points other modules can extend through hooks. This is done with the following code:

step 1:

Define the abstract class for the new hook:

package org.openbravo.retail.posterminal;
public abstract class MyNewHook {
  public abstract void exec(Object param1, Object param2)
      throws Exception;

step 2:

Define a function to call to every classes which are registered in the defined hooks.

  private void executeHooks(Instance<? extends Object> hooks, Object param1, Object param2) throws Exception {
    for (Iterator<? extends Object> procIter = hooks.iterator(); procIter.hasNext();) {
      Object proc =;
      ((MyNewHook) proc).exec(param1, param2);

step 3:

Execute hooks in the desired point of your module.

  private Instance<MyNewHook> myNewHook;
  //your code
  executeHooks(myNewHook, myParam, null);

When this code is reached, all the hooks defined by external modules for this hookName will be sequentially executed.

How to provide logic in external modules

When there is a base module that defines a hook as mentioned in the previous section, external modules can provide logic to be executed at that point creating a new class in following manner:

package org.openbravo.retail.posterminal;
import javax.enterprise.context.ApplicationScoped;
public class MyNewHookExtension extends MyNewHook {
  public void exec(Object param1, Object param2) throws Exception {
    // Business Logic

Server Side Hooks in Web POS

This document list of server side hooks available in Web POS.

Retrieved from ""

This page has been accessed 5,268 times. This page was last modified on 2 June 2016, at 13:30. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.