コード例 #1
0
  private void addServerIPAndHostEntries() {
    String hostName = serverConfigurationInformation.getHostName();
    String ipAddress = serverConfigurationInformation.getIpAddress();
    if (hostName != null && !"".equals(hostName)) {
      Entry entry = new Entry(SynapseConstants.SERVER_HOST);
      entry.setValue(hostName);
      synapseConfiguration.addEntry(SynapseConstants.SERVER_HOST, entry);
    }

    if (ipAddress != null && !"".equals(ipAddress)) {
      Entry entry = new Entry(SynapseConstants.SERVER_IP);
      entry.setValue(ipAddress);
      if (synapseConfiguration.getAxisConfiguration().getTransportsIn() != null) {
        Map<String, TransportInDescription> transportInConfigMap =
            synapseConfiguration.getAxisConfiguration().getTransportsIn();
        if (transportInConfigMap != null) {
          TransportInDescription transportInDescription = transportInConfigMap.get("http");
          if (transportInDescription != null) {
            Parameter bindAddressParam = transportInDescription.getParameter("bind-address");
            if (bindAddressParam != null) {
              entry.setValue(bindAddressParam.getValue());
            }
          }
        }
      }
      synapseConfiguration.addEntry(SynapseConstants.SERVER_IP, entry);
    }
  }
コード例 #2
0
ファイル: ScriptMediator.java プロジェクト: rcamus/platform
  /**
   * Prepares the mediator for the invocation of an external script
   *
   * @param synCtx MessageContext script
   * @throws ScriptException For any errors , when compile the script
   */
  protected synchronized void prepareExternalScript(MessageContext synCtx) throws ScriptException {

    // TODO: only need this synchronized method for dynamic registry entries. If there was a way
    // to access the registry entry during mediator initialization then for non-dynamic entries
    // this could be done just the once during mediator initialization.

    // Derive actual key from xpath expression or get static key
    String generatedScriptKey = key.evaluateValue(synCtx);
    Entry entry = synCtx.getConfiguration().getEntryDefinition(generatedScriptKey);
    boolean needsReload =
        (entry != null) && entry.isDynamic() && (!entry.isCached() || entry.isExpired());
    synchronized (resourceLock) {
      if (scriptSourceCode == null || needsReload) {
        Object o = synCtx.getEntry(generatedScriptKey);
        if (o instanceof OMElement) {
          scriptSourceCode = ((OMElement) (o)).getText();
          scriptEngine.eval(scriptSourceCode);
        } else if (o instanceof String) {
          scriptSourceCode = (String) o;
          scriptEngine.eval(scriptSourceCode);
        } else if (o instanceof OMText) {

          DataHandler dataHandler = (DataHandler) ((OMText) o).getDataHandler();
          if (dataHandler != null) {
            BufferedReader reader = null;
            try {
              reader = new BufferedReader(new InputStreamReader(dataHandler.getInputStream()));
              scriptEngine.eval(reader);

            } catch (IOException e) {
              handleException("Error in reading script as a stream ", e, synCtx);
            } finally {

              if (reader != null) {
                try {
                  reader.close();
                } catch (IOException e) {
                  handleException("Error in closing input stream ", e, synCtx);
                }
              }
            }
          }
        }
      }
    }

    // load <include /> scripts; reload each script if needed
    for (Value includeKey : includes.keySet()) {

      String includeSourceCode = (String) includes.get(includeKey);

      String generatedKey = includeKey.evaluateValue(synCtx);

      Entry includeEntry = synCtx.getConfiguration().getEntryDefinition(generatedKey);
      boolean includeEntryNeedsReload =
          (includeEntry != null)
              && includeEntry.isDynamic()
              && (!includeEntry.isCached() || includeEntry.isExpired());
      synchronized (resourceLock) {
        if (includeSourceCode == null || includeEntryNeedsReload) {
          log.debug("Re-/Loading the include script with key " + includeKey);
          Object o = synCtx.getEntry(generatedKey);
          if (o instanceof OMElement) {
            includeSourceCode = ((OMElement) (o)).getText();
            scriptEngine.eval(includeSourceCode);
          } else if (o instanceof String) {
            includeSourceCode = (String) o;
            scriptEngine.eval(includeSourceCode);
          } else if (o instanceof OMText) {

            DataHandler dataHandler = (DataHandler) ((OMText) o).getDataHandler();
            if (dataHandler != null) {
              BufferedReader reader = null;
              try {
                reader = new BufferedReader(new InputStreamReader(dataHandler.getInputStream()));
                scriptEngine.eval(reader);

              } catch (IOException e) {
                handleException("Error in reading script as a stream ", e, synCtx);
              } finally {

                if (reader != null) {
                  try {
                    reader.close();
                  } catch (IOException e) {
                    handleException("Error in closing input" + " stream ", e, synCtx);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
コード例 #3
0
  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;
    }
  }