I'm developing a modular application with OSGI.
The central idea is: A central Bundle defines a JAX-RS application and
A set of bundles that define resources to be dynamically attached to the JAX-RS application.
The problem is as follows:
If I define an WAB Application and define the application JAX-RS as commonly done:
@ApplicationPath ("rest")
KratosRestApplication public class extends Application {
}
and configure this in web.xml.
Now, I do not know how to get the instance of this application in order to manipulate dynamically the resources when these are detected in other bundles.
Now, if I use the HTTPService in the WAB application directly to register the JAX-RS aplication, I do not know how to access to resources (services) in the navigator, because /app/rest fails.
public class Activator implements BundleActivator {
private BundleContext bc;
private ServiceTracker tracker;
private HttpService httpService = null;
private KernelJaxApplication application = null;
private ServletContainer container = null;
public void start(BundleContext bundleContext) throws Exception {
this.bc = bundleContext;
System.out.println("STARTING HTTP SERVICE BUNDLE");
this.tracker = new ServiceTracker(this.bc, HttpService.class.getName(), null) {
@Override
public Object addingService(ServiceReference serviceRef) {
httpService = (HttpService) super.addingService(serviceRef);
System.out.println("HTTP SERVICE: " + httpService.getClass().getCanonicalName());
registerServlets();
return httpService;
}
@Override
public void removedService(ServiceReference ref, Object service) {
if (httpService == service) {
//unregisterServlets();
httpService = null;
}
super.removedService(ref, service);
}
};
this.tracker.open();
System.out.println("TRACKER OPEN....");
}
private void registerServlets() {
try {
application = new KernelJaxApplication();
container = new ServletContainer(application);
httpService.registerServlet("/rest", container, getJerseyServletParams(), null);
System.out.println("HTTPSERVICE .....");
} catch (ServletException ex) {
Logger.getLogger(Activator.class.getName()).log(Level.SEVERE, null, ex);
} catch (NamespaceException ex) {
Logger.getLogger(Activator.class.getName()).log(Level.SEVERE, null, ex);
}
}
...
...
}
In the pom.xml this is the bundle configuration:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>ejb</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>jar</supportedProjectType>
</supportedProjectTypes>
<instructions>
<!-- Read all OSGi configuration info from this optional file -->
<!--_include>-osgi.properties</_include-->
<!--_include>resources/core.properties</_include-->
<!-- By default, we don't export anything -->
<!--Export-Package>!\*.impl.\*, \*</Export-Package-->
<Import-Package>
javax.ws.rs.core;version="[2.0,3)",
javax.ws.rs.ext;version="[2.0,3)",
org.glassfish.jersey.server;version="2.0",
org.glassfish.jersey.server.spi;version="2.0",
org.glassfish.jersey.servlet;version="2.0",
*
</Import-Package>
<Web-ContextPath>/app</Web-ContextPath>
<Webapp-Context>/app</Webapp-Context>
<Bundle-SymbolicName>core</Bundle-SymbolicName>
<Bundle-Activator>com.workingflows.kratos.kernel.Activator</Bundle-Activator>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
<execution>
<id>bundle-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
Any suggestions?