View source | Discuss this page | Page history | Printable version   
Main Page
Upload file
What links here
Recent changes

PDF Books
Add page
Show collection (0 pages)
Collections help


How to implement custom offline checking


Bulbgraph.png   Starting from RR17Q1 below functionality is available


The OB multi-server architecture explicitly supports managing the offline and online status of store servers. A server is offline when it can not connect to a server on which it depends.

There is standard logic within the OB commerce solution which periodically checks the availability of important servers in the architecture. This check is always relative to the server from which the check is done. So if the internet connection of a store is down, the central server will be not reachable for that store and the store will be offline. This while for other stores the central server is reachable and they are online.

Server Checking Logic

The Server State background process implemented in the ServerStateBackground class.

This class checks all servers defined in the Mobile Server Definition window which have the 'trigger state' flag checked. For each server a ping service is called. If one of the servers does not react then it is offline and the calling server (which runs the process) transitions to offline.

In addition to the servers defined in the Mobile Server Definition the system also calls all implementations of the CheckServerOfflineHandler class.

Implementing a CheckServerOfflineHandler

To add a a new custom check if a custom server is offline implement a subclass of the CheckServerOfflineHandler in your module. No additional configuration is needed, Openbravo will automatically find your subclass and execute it in the loop described in the previous section.

When subclassing you only need implement the isServerOffline method which returns true if the server is offline and false otherwise. If you return true then the server (which runs this process) will transition to offline.

Below an example implementation of a CheckServerOfflineHandler. It is just for illustration purposes as it contains references to custom code/classes.

public class CheckStockOfflineHandler extends CheckServerOfflineHandler {
  private static final String WSNAME = "ISMD_PING";
  private static final String REQUESTMETHOD = "POST";
  private static final Logger log = LoggerFactory.getLogger(CheckStockOfflineHandler.class);
  public boolean isServerOffline() {
    boolean offline = false;
    if (MobileServerController.getInstance().isThisAStoreServer()) {
      INTPWSConf conf = IntegrationUtils.getWSConfiguration(WSNAME);
      if (conf != null) {
        // Connect, send and get the web service response
        try {
          JSONObject requestJSON = getRequestJson();
          if (requestJSON != null) {
            StringWsClient stringWsClient = new StringWsClient();
            String responseStr = stringWsClient.connectAndReturnString(conf.getURL(),
                REQUESTMETHOD, conf.getWSUser(), conf.getWSPassword(), requestJSON.toString());
            JSONObject responseJson = new JSONObject(responseStr);
            JSONObject pingServer = responseJson.getJSONObject("PingServer");
            offline = !"OK".equals(pingServer.getString("Status"));
        } catch (JSONException e) {
          log.error("Error reading the response json", e);
          offline = true;
        } catch (Exception e) {
          log.warn("Error connecting to the web service", e);
          offline = true;
    return offline;
   * Method that creates the request JSON
   * @return the request JSON
  private JSONObject getRequestJson() {
    JSONObject request = null;
    try {
      request = new JSONObject();
      List<MobileServerOrganization> serverOrgList = MobileServerController.getInstance()
      if (!serverOrgList.isEmpty()) {
        request.put("StoreId", serverOrgList.get(0).getServerOrg().getIntpNosStoreid());
    } catch (JSONException e) {
      log.error("Error creating the request json", e);
    return request;

Retrieved from ""

This page has been accessed 78 times. This page was last modified on 21 November 2016, at 12:19. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.