hstaudacher / osgi-jax-rs-connector

An OSGi - JAX-RS 2.0 Connector, software repository available on the link below
http://hstaudacher.github.io/osgi-jax-rs-connector
Other
191 stars 98 forks source link

Issues publishing the Rest services using warproduct inside tomcat #163

Closed madhugarimilla closed 8 years ago

madhugarimilla commented 8 years ago

Hi, I have created a sample rest service using this connector which works fine in Jetty. I tried to package it inside an already working eclipse warproduct and tried to deploy it in tomcat. I see the the bundle activator classes are getting loaded but the Rest services are not getting published, that is i am not able to access the rest apis. Is there a way that we can check if the bundle status is active in tomcat? Is there anything i need to add to get this working? I have the following dependent jars added from this connector to my war.

  1. javax.servlet-api_3.0.1.jar
  2. com.eclipsesource.jaxrs.swagger-all_1.5.7.jar
  3. com.eclipsesource.jaxrs.provider.security_2.2.0.201602281253.jar
  4. com.eclipsesource.jaxrs.jersey-min_2.22.2.jar
BryanHunt commented 8 years ago

Bundle the remote shell or the web console to give you visibility to the OSGi framework. I have a project that does what you are trying to do, so I know it can work. Also, servlet API 3.0.1 may be the problem. I think you need at least v3.1.

madhugarimilla commented 8 years ago

Hi Brian, I am fairly new to osgi stuff. Is this what you are referring to (Running without SSH) ? http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fconsole_shell.htm

BryanHunt commented 8 years ago

No, you need the section on running with SSH. When running on Tomcat, you need an OSGi shell that supports either telnet or ssh so you can connect to it. BTW, I'm using Felix instead of Equinox.

madhugarimilla commented 8 years ago

Hey Bryan, Thanks for the help. I got the shell working and i see bundles are active but the rest resources are not accessible.

Inside my Activator class i was trying to get the ConfigurationAdmin which is coming as null.

ServiceReference<?> reference = context.getServiceReference( ConfigurationAdmin.class.getName() );

One of the bundles org.eclipse.equinox.cm@start mentioned in my config.ini is not listed anywhere in my osgi console. I do have the related jar org.eclipse.osgi.services_3.3.100.v20130513-1956.jar in my plugins folder of the war file.

Do you see any problem with my configuration ? Here is my web.xml file for reference.

web_xml.txt

BryanHunt commented 8 years ago

You should never try to get a service in your Activator. This creates an order dependency which is not the OSGi way. You should either use service trackers, or declarative services. I highly recommend using DS. You can look at https://github.com/BryanHunt/web-in-a-box/tree/master/server for examples

madhugarimilla commented 8 years ago

Sorry to bug you again.

I was trying to update the default root using configurationAdmin using this. I have commented out this and using the default root (/services) for testing purpose.

ServiceReference<?> reference = context.getServiceReference( ConfigurationAdmin.class.getName() ); ConfigurationAdmin configAdmin = ( ConfigurationAdmin )context.getService( reference ); configuration = configAdmin.getConfiguration( "com.eclipsesource.jaxrs.connector", null ); properties = new Hashtable<String, Object>(); properties.put( "root", "/rest/v1" ); configuration.update( properties ); context.ungetService( reference );

Now my bundle that has the rest service is Active but still the rest resources are still not available. My rest services are registered in the Activator class like this.

`private final List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();

public void start(BundleContext bundleContext) throws Exception { Activator.context = bundleContext; registrations.add( context.registerService( MyService.class.getName(), new MyService(), null ) ); AuthFilter filter = new AuthFilter(); registrations.add( context.registerService( ContainerRequestFilter.class.getName(), filter, null )); registrations.add( context.registerService( ContainerResponseFilter.class.getName(), filter, null )); }

public void stop(BundleContext bundleContext) throws Exception {

    for( ServiceRegistration serviceRegistration : registrations ) {
          serviceRegistration.unregister();
        }
    Activator.context = null;
}`
BryanHunt commented 8 years ago

I don't see anything obvious. One suggestion would be to get it running outside of Tomcat to reduce the complexity.