/** Adds all Synapse proxy services to the Axis2 configuration. */
  private void deployProxyServices() {

    boolean failSafeProxyEnabled =
        SynapseConfigUtils.isFailSafeEnabled(SynapseConstants.FAIL_SAFE_MODE_PROXY_SERVICES);

    log.info("Deploying Proxy services...");
    String thisServerName = serverConfigurationInformation.getServerName();
    if (thisServerName == null || "".equals(thisServerName)) {
      thisServerName = serverConfigurationInformation.getHostName();
      if (thisServerName == null || "".equals(thisServerName)) {
        thisServerName = "localhost";
      }
    }

    for (ProxyService proxy : synapseConfiguration.getProxyServices()) {

      // start proxy service if either, pinned server name list is empty
      // or pinned server list has this server name
      List pinnedServers = proxy.getPinnedServers();
      if (pinnedServers != null && !pinnedServers.isEmpty()) {
        if (!pinnedServers.contains(thisServerName)) {
          log.info(
              "Server name not in pinned servers list."
                  + " Not deploying Proxy service : "
                  + proxy.getName());
          continue;
        }
      }

      try {
        AxisService proxyService =
            proxy.buildAxisService(
                synapseConfiguration, configurationContext.getAxisConfiguration());
        if (proxyService != null) {
          log.info("Deployed Proxy service : " + proxy.getName());
          if (!proxy.isStartOnLoad()) {
            proxy.stop(synapseConfiguration);
          }
        } else {
          log.warn("The proxy service " + proxy.getName() + " will NOT be available");
        }
      } catch (SynapseException e) {
        if (failSafeProxyEnabled) {
          log.warn(
              "The proxy service "
                  + proxy.getName()
                  + " cannot be deployed - "
                  + "Continue in Proxy Service fail-safe mode.");
        } else {
          handleException("The proxy service " + proxy.getName() + " : Deployment Error");
        }
      }
    }
  }
  /**
   * Create the *single* instance of this class that would be used by all anonymous services used
   * for outgoing messaging.
   *
   * @param synCfg the Synapse configuration
   * @param contextInformation server runtime information
   */
  public SynapseCallbackReceiver(
      SynapseConfiguration synCfg, ServerContextInformation contextInformation) {

    //        callbackStore = Collections.synchronizedMap(new HashMap<String, AxisCallback>());

    // create the Timer object and a TimeoutHandler task
    TimeoutHandler timeoutHandler = new TimeoutHandler(callbackStore, contextInformation);

    Timer timeOutTimer = synCfg.getSynapseTimer();
    long timeoutHandlerInterval = SynapseConfigUtils.getTimeoutHandlerInterval();

    // schedule timeout handler to run every n seconds (n : specified or defaults to 15s)
    timeOutTimer.schedule(timeoutHandler, 0, timeoutHandlerInterval);
  }
  private Object convertValue(String value, String type) {
    if (type == null) {
      // If no type is set we simply return the string value
      return value;
    }

    try {
      XMLConfigConstants.DATA_TYPES dataType = XMLConfigConstants.DATA_TYPES.valueOf(type);
      switch (dataType) {
        case BOOLEAN:
          return JavaUtils.isTrueExplicitly(value);
        case DOUBLE:
          return Double.parseDouble(value);
        case FLOAT:
          return Float.parseFloat(value);
        case INTEGER:
          return Integer.parseInt(value);
        case LONG:
          return Long.parseLong(value);
        case OM:
          return SynapseConfigUtils.stringToOM(value);
        case SHORT:
          return Short.parseShort(value);
        default:
          return value;
      }
    } catch (IllegalArgumentException e) {
      String msg =
          "Unknown type : "
              + type
              + " for the property mediator or the "
              + "property value cannot be converted into the specified type.";
      log.error(msg, e);
      throw new SynapseException(msg, e);
    }
  }
 private static OMElement createOMElement(String xml) {
   return SynapseConfigUtils.stringToOM(xml);
 }
  public static Entry createEntry(OMElement elem, Properties properties) {
    String customFactory = SynapsePropertiesLoader.getPropertyValue("synapse.entry.factory", "");
    if (customFactory != null && !"".equals(customFactory)) {
      try {
        Class c = Class.forName(customFactory);
        Object o = c.newInstance();
        if (o instanceof IEntryFactory) {
          return ((IEntryFactory) o).createEntry(elem);
        }
      } catch (ClassNotFoundException e) {
        handleException(
            "Class specified by the synapse.entry.factory "
                + "synapse property not found: "
                + customFactory,
            e);
      } catch (InstantiationException e) {
        handleException(
            "Class specified by the synapse.entry.factory "
                + "synapse property cannot be instantiated: "
                + customFactory,
            e);
      } catch (IllegalAccessException e) {
        handleException(
            "Class specified by the synapse.entry.factory "
                + "synapse property cannot be accessed: "
                + customFactory,
            e);
      }
    }

    OMAttribute key = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
    if (key == null) {
      handleException("The 'key' attribute is required for a local registry entry");
      return null;

    } else {

      Entry entry = new Entry(key.getAttributeValue());

      OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
      if (descriptionElem != null) {
        entry.setDescription(descriptionElem.getText());
        descriptionElem.detach();
      }

      String src = elem.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "src"));

      // if a src attribute is present, this is a URL source resource,
      // it would now be loaded from the URL source, as all static properties
      // are initialized at startup
      if (src != null) {
        try {
          entry.setSrc(new URL(src.trim()));
          entry.setType(Entry.URL_SRC);
          entry.setValue(SynapseConfigUtils.getObject(entry.getSrc(), properties));
        } catch (MalformedURLException e) {
          handleException("The entry with key : " + key + " refers to an invalid URL");
        }

      } else {
        OMNode nodeValue = elem.getFirstOMChild();
        OMElement elemValue = elem.getFirstElement();

        if (elemValue != null) {
          entry.setType(Entry.INLINE_XML);
          entry.setValue(elemValue);
        } else if (nodeValue != null && nodeValue instanceof OMText) {
          entry.setType(Entry.INLINE_TEXT);
          entry.setValue(elem.getText().trim());
        }
      }

      return entry;
    }
  }