0

I'm building an OSGi application containing (at the moment) only business logic. Since I want my users to interact with my software via browser I'm thinking on trying to add an application server inside my application via commands like:

public void startApplicationServer();
public void stopApplciationServer();
public void deployApp(App appToDeploy);
public void undeployApp(App appToUndeploy);

After some thought, the application server I've chosen is "wildfly 10". However, I'm failing to find any resource allowing me to call wildfly programmatically. My question is do you know a procedure to follow or general steps in order to achieve my goal?

Some info you can find useful to help me:

  1. I've chosen Wildfly becuase it fully support Java EE 7, run on JDK8 and it is released under LGPL (I preferred open source glassfish, but it was release under GPL, hence it would have been mandatory to make the source available. Since (in the future) I would like to make this software commercial, I was forced to discard it);
  2. Maybe some of you may suggest to build my whole application on the application server itself. I prefer not to do so because the web interface may be only one possible User Interface of my application (who knows, maybe in the future I want to switch to another interface, like CLI or desktop-like);
  3. I've look at several content, like wildfly-swarm or Arquillian: I know these projects targets are completely different from mine, but maybe they can be part of the solution? It's just my personal (and possible wrong) thought;

I'm a newbie in the whole "application server" world, so it's highly possible that I'm missing something.

Thanks for any kind reply.

Koldar
  • 1,317
  • 15
  • 35
  • 1
    [This](http://stackoverflow.com/questions/29168150/is-it-possible-to-deploy-application-with-wildfly-as-bundle) may be related. Note that your issue number 2 is flawed. Creating your software as a webapp doesn't prevent creating other user interfaces for it later on, especially if you've thought of it beforehand. – Kayaman Sep 19 '16 at 17:03
  • I've already looked at the resource you posted. Fully integrating wildfly with OSGi would be awesome, but it appears the project was dismissed after wildfly 8.0.0 alpha. About the flaw in the issue number 2: It's not related to the question but can you link me a resource to improve my knowledge about this argument? It would be really awesome! – Koldar Sep 19 '16 at 17:48
  • 1
    Well, let's say you create the view layer with some javascript framework like angularjs, and your business logic as a REST interface, you can then create any kind of user interface that uses the REST interface to perform the actions. Of course if you don't have previous experience of them, it's quite a bit to learn first. – Kayaman Sep 19 '16 at 18:01
  • I never used angularjs but I'm aware of the concept behind the framework. I'm also familiar with REST interface; You are right, if my business logic communicate with the view via REST then there would be no problem at all. I realize my second point was driven by the thought that I would like my business logic to be independent from the application server: in an installation there might be no application server at all (eg. only CLI UI) , thereby I don't want my application to be relying on the existence of the application server at all. Of course maybe it's just me implementing a bad design! – Koldar Sep 19 '16 at 18:16

2 Answers2

2

You might want to have a look at WildFly Swarm.

While not documented, there is also the WildFly launcher API. You can see some examples of how it's used in the wildfly-maven-plugn.

Another option would be the application client. Though I'd probably lean towards WildFly Swarm for your use case.

James R. Perkins
  • 16,800
  • 44
  • 60
  • I've tried with wildfly swarm but apparently it generates an uber executable jar with inside all the applciation logic of your software. My needs are different: I just want a connector to be able to start/stop, deploy/undeploy applications from the embedded server. I feel swarm may be a solution. Do you know the location of the start/stop methods inside wildfly source code? Those entry point should be the answer of my quesiton! – Koldar Sep 20 '16 at 10:13
  • Just to understand, you want to launch a Java process you create which will start and stop WildFly correct? If so you can use the launcher API to do that, but it will launch an additional process. – James R. Perkins Sep 20 '16 at 17:30
  • I was trying to start the server within the same process, but apparently the easy way is to just use the launcher API you kindly have provided me. I'll give it a shot (sorry, I realized only now that what you provided me was already the entry point I was looking for!) – Koldar Sep 20 '16 at 20:32
  • I personally find the separate process the easiest. For deploying you could the core part of the maven plugin https://github.com/wildfly/wildfly-maven-plugin/tree/master/core. – James R. Perkins Sep 20 '16 at 20:40
1

I ended up embedding tomcat 8 within OSGi environment. I really wanted to use the same JVM process for both OSGi and application server (at least to me having 2 separate processes with all the ensuing overhead made no sense), hence embedding tomcat was perfect. Giving up Java EE 7 Full Profile wasn't a big loss since I only needed Web Profile (+ Jersey for web services).

I've written a guide on how to embed tomcat on OSGi here: in case the link will break down, I'll write down here the most important phases:

  1. add to maven all the "tomcat embed" dependencies;
  2. add "felix.service.urlhandlers=false" to config.properties;
  3. Create a new JarScanner from StandardJarScanner where URIs like "http://.extensions:/" are ignored;
  4. Use context.setJarScanner(JarScanner js) method for every context= tomcat.addWebApp(String, String) call;
  5. Make the "tomcat bundle" a framework extension bundle (see OSGi R6 3.15 section);
  6. Register the "tomcat bundle" service via an "extension bundle activator" via the normal ServiceRegistration procedure;
  7. add the tomcat interface bundle package to "org.osgi.framework.system.packages.extra" config.properties (e.g. if the interface of "tomcat bundle" is inside com.acme.applicationserver package add "com.acme.applicationserver"

I won't mark this answer as the correct one simply because my question was related to wildfly. I consider this answer only as a workaround (even though for me this answer definitely solve my issue)

Koldar
  • 1,317
  • 15
  • 35