Namespace.current().createService(...)

Greetings,

I want to create Flow Services dynamically. The idea is to create an empty FLOW service with defined inputs and outputs. For this purpose I created a Java service, and trying to use createService for the whole day now. It doesn’t really want to create the service though.


Namespace ns = Namespace.current();
NSPackage pkg = ns.getPackage("MyExamplePackage");
NSService svc = ns.createService(pkg, "myexamplepackage.flow:myDynamicService", 0);

MyExamplePackage.myexamplepackage.flow path exists. That would be another idea to create those also, but last time I created a package with ns.createPackate(NSName.create(packageName)) the integration server encountered a NullPointerException without any more information about the exception itself. For now I only try to create service stubs but the svc:NSService never gets created. There is no error message, exception but the service does not get created. I’ve tried several parameters for the createService with no luck.

Any idea how I can create a service with createService function?

thanks,
Jozsef

Correct me if I am wrong… You want to create empty flow service dynamically with defined inputs and outputs.

Did you have a look at the WmRoot package I am sure it should have the services (not exactly same but similar) to match your requirement.

WmRoot - Use at your own risk :slight_smile:

Well, I won’t correct you. You got the point! As a matter of fact Namespace.createService utilizes WmRoot, I just can’t get it to work. My latest code to create that empty flow service, for not without inputs or outputs:


NSPackage pkg = ns.getPackage(myExamplePackage);
NSService svc = ns.createService(pkg, NSName.create("myexamplepackage.flow:GeneratedService"), NSServiceType.create(NSServiceType.SVC_FLOW, NSServiceType.SVCSUB_DEFAULT));

Then in the server log I get an entry:

But this generated service does not show up in designer even after reloading the package, nor in the package management IS’s web GUI. Tried even to restart the IS to refresh packages but didn’t help.

webMethods version?

Its 8.2(.2).

Hi everyone. I’m looking to do exactly the same thing as Jozsef: create flow services dynamically.

While scouring through the Javadoc I see there are two static methods on the ServerAPI class called registerFlowService, but am having trouble finding all of the Javadoc for some of the params.

I can’t find Javadoc in the javadoc from Empower for FlowRoot, Namspace, and NSSignature. If they are undocumented services in WmRoot, I find it odd that a publicly callable service would be visible in so methods with these undocumented Classes could be used? Strange.

Where can I find Javadoc for these other classes so I can complete the call to ServerAPI.registerFlowService?? I was able to use XStream to serialize the FlowRoot for an existing service, to analyze the structure, however trying to create a new service in it’s own package, own folders, etc, etc. is escaping me.

Any examples of how to make the call to registerFlowService correctly, or links to the appropriate Javadoc so I can figured it out would be amazing. I am using the 9.6 version of the platform.

Thanks you all!
dw

Try the following Java code for creating a flow service in an existing package, which worked for me on Integration Server v8.2.2.

Also, be aware that if you’re using Developer then you have to refresh your session before the new flow service appears (I’m not sure if you have to do this in Designer, since I don’t use it).

// creates a new service in the given package with the given name and the given type
public static void create(String packageName, String serviceName, String type, String subtype) throws com.wm.app.b2b.server.ServiceSetupException {
  com.wm.app.b2b.server.Package pack = com.wm.app.b2b.server.PackageManager.getPackage(packageName);
  if (pack == null) throw new IllegalArgumentException("package does not exist: " + packageName);

  com.wm.lang.ns.NSName svcName = com.wm.lang.ns.NSName.create(serviceName);
  if (com.wm.app.b2b.server.ns.Namespace.current().nodeExists(svcName)) throw new IllegalArgumentException("node already exists: " + serviceName);

  if (type == null) type = com.wm.lang.ns.NSServiceType.SVC_FLOW;
  if (subtype == null) subtype = com.wm.lang.ns.NSServiceType.SVCSUB_UNKNOWN;
  com.wm.lang.ns.NSServiceType serviceType = com.wm.lang.ns.NSServiceType.create(type, subtype);

  com.wm.app.b2b.server.ServerAPI.registerService(packageName, svcName, true, serviceType, null, null, null);
}

// creates a new flow service in the given package with the given name
public static void create(String packageName, String serviceName) throws com.wm.app.b2b.server.ServiceSetupException {
  create(packageName, serviceName, null, null);
}