3

我想在设计器之外使用单独的 java 程序收集 webmethods 集成服务器的特定包的依赖关系。

这些依赖项存储在文件系统中的什么位置?

谢谢你

4

1 回答 1

4

在包级别声明的包依赖项存储在包清单文件中:IntegrationServer/packages/<packageName>/manifest.v3.

例如,Tundra包中的清单文件包含一个元素,该元素列出了它所依赖的三个包(WmFlatFile、WmPublic 和 WmRoot):<record name="requires"...>

<?xml version="1.0" encoding="UTF-8"?>

<Values version="2.0">
  <value name="enabled">yes</value>
  <value name="system_package">no</value>
  <value name="version">0.0.13</value>
  <record name="startup_services" javaclass="com.wm.util.Values">
    <null name="tundra.support:access"/>
  </record>
  <null name="shutdown_services"/>
  <null name="replication_services"/>
  <record name="requires" javaclass="com.wm.util.Values">
    <value name="WmFlatFile">*.*</value>
    <value name="WmPublic">*.*</value>
    <value name="WmRoot">*.*</value>
  </record>
  <value name="listACL">Default</value>
  <value name="description">A package of cool services for webMethods Integration Server 7.1 or higher</value>
  <value name="publisher">Lachlan Dowding &lt;lachlan@permafro.st&gt;</value>
  <value name="webappLoad">yes</value>
</Values>

解析此 XML 的最简单方法是使用com.wm.util.coder.IDataXMLCoder来自 webMethods Integration Server 客户端 JAR 的对象wm-isclient.jar。这是一个简单的例子:

public static String[] getDependencies(String packageName) throws java.io.IOException {
  String filename = ".../IntegrationServer/packages/" + packageName + "/manifest.v3";
  java.io.InputStream in = null;

  try {
    in = new java.io.BufferedInputStream(new java.io.FileInputStream(filename));
    com.wm.util.coder.XMLCoderWrapper codec = new com.wm.util.coder.XMLCoderWrapper();
    com.wm.data.IData manifestDocument = codec.decode(in);

    com.wm.data.IDataCursor manifestCursor = manifestDocument.getCursor();
    com.wm.data.IData requiresDocument = com.wm.data.IDataUtil.getIData(manifestCursor, "requires");
    manifestCursor.destroy();

    java.util.List<String> dependencies = new java.util.ArrayList<String>();
    if (requiresDocument != null) {
      com.wm.data.IDataCursor requiresCursor = requiresDocument.getCursor();

      while(requiresCursor.next()) {
        String dependency = requiresCursor.getKey();
        String version = (String)requiresCursor.getValue();

        dependencies.add(dependency);
      }
      requiresCursor.destroy();
    }

    return dependencies.toArray(new String[dependencies.size()]);
  } finally {
    if (in != null) in.close();
  }
}

如果包依赖项未在包清单中声明,您可以通过使用类似于以下从Tundra.java中挑选的方法的代码检查包中每个服务的引用来计算它们:

import com.wm.app.b2b.server.ns.NSDependencyManager;
import com.wm.app.b2b.server.Package;
import com.wm.app.b2b.server.ns.Namespace;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataFactory;
import com.wm.data.IDataUtil;
import com.wm.lang.ns.DependencyManager;
import com.wm.lang.ns.NSNode;
import com.wm.lang.ns.NSService;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

...

/**
 * Returns the list of services that are dependent on the services in the given package.
 *
 * @param packageName   The package to get dependents for.
 * @return              The list of dependents for the given package.
 */
private static IData getDependents(String packageName) {
    return getDependents(getPackage(packageName));
}

/**
 * Returns the list of services that are dependent on the services in the given package.
 *
 * @param pkg           The package to get dependents for.
 * @return              The list of dependents for the given package.
 */
private static IData getDependents(Package pkg) {
    DependencyManager manager = NSDependencyManager.current();
    Namespace namespace = Namespace.current();

    SortedSet<String> packages = new TreeSet<String>();
    SortedMap<String, IData> nodes = new TreeMap<String, IData>();

    Enumeration services = pkg.getLoaded();
    while(services.hasMoreElements()) {
        String service = (String)services.nextElement();
        if (service != null) {
            NSNode node = namespace.getNode(service);
            if (node != null) {
                IData results = manager.getDependent(node, null);
                if (results != null) {
                    IDataCursor resultsCursor = results.getCursor();
                    IData[] referencedBy = IDataUtil.getIDataArray(resultsCursor, "referencedBy");
                    resultsCursor.destroy();
                    if (referencedBy != null) {
                        for (IData dependent : referencedBy) {
                            if (dependent != null) {
                                IDataCursor dependentCursor = dependent.getCursor();
                                String name = IDataUtil.getString(dependentCursor, "name");
                                dependentCursor.destroy();

                                String[] parts = name.split("\\/");

                                if (parts.length > 1) {
                                    if (!pkg.getName().equals(parts[0])) {
                                        IData result = IDataFactory.create();
                                        IDataCursor resultCursor = result.getCursor();
                                        IDataUtil.put(resultCursor, "package", parts[0]);
                                        IDataUtil.put(resultCursor, "node", parts[1]);
                                        resultCursor.destroy();

                                        packages.add(parts[0]);
                                        nodes.put(name, result);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    IData output = IDataFactory.create();
    IDataCursor cursor = output.getCursor();
    IDataUtil.put(cursor, "packages", packages.toArray(new String[packages.size()]));
    IDataUtil.put(cursor, "packages.length", packages.size());
    IDataUtil.put(cursor, "nodes", nodes.values().toArray(new IData[nodes.size()]));
    IDataUtil.put(cursor, "nodes.length", nodes.size());
    cursor.destroy();

    return output;
}
于 2014-05-21T22:28:23.037 回答