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

How to register a new servlet using the jaxrs connector ? #205

Open raul1991 opened 3 years ago

raul1991 commented 3 years ago

Problem:

I have jetty running inside karaf and I am able to register a servlet at "/products" but now I want to have another servlet registered at a different context say : /animals ? How to do that ?

Even if create a separate connector on jetty , I'd still have to override the "root" property of the same jaxrs connector that would mean overwriting the previous one which would mean now /animals would work and /products won't.

Any way around this problem ?


 private void updateConfiguration() throws IOException
    {
        LOGGER.info("Entering in method updateConfiguration,Configuration web services will be published on context path: {}", CONTEXT_PATH);
        configureJerseyConfiguration();
        configureJaxRsPublisher();
    }

    private void configureJerseyConfiguration()
    {

        Configuration componentConfiguration;
        try
        {
            componentConfiguration = getServiceConfiguration(JERSEY_SERVER_PID);
            Dictionary<String, Object> properties = componentConfiguration.getProperties();
            if (properties == null)
            {
                properties = new Hashtable<String, Object>();
            }
            properties.put(JERSEY_CONFIG_SERVER_WADL_DISABLE_WADL, DISABLE_WADL_PROPERTY);
            componentConfiguration.update(properties);
            LOGGER.debug("Inside configureJerseyConfiguration,Configured the Jeresy wadl: {}", DISABLE_WADL_PROPERTY);
        }
        catch (IOException | ConfigurationException e)
        {
            LOGGER.error("Inside configureJerseyConfiguration,There was a problem in upgrading the JAX RS connector configuration,Exception occured is: {}", e.getMessage());
        }
    }

    /**
     * @param componentContext
     */
    private void configureJaxRsPublisher()
    {

        LOGGER.debug("Entering in method configureJaxRsPublisher,Configuring the JAX RS connector.");
        Configuration componentConfiguration;
        try
        {
            componentConfiguration = getServiceConfiguration(JAXRS_CONNECTOR_PID);
            componentConfiguration.getBundleLocation();
            Dictionary<String, Object> properties = componentConfiguration.getProperties();
            if (properties == null)
            {
                properties = new Hashtable<String, Object>();
            }

            properties.put("root", "/products"); // <<<<<<<<<<<<<<< Look here
            componentConfiguration.update(properties);

            LOGGER.debug("Inside configureJaxRsPublisher, Configured the JAX RS connector with contextPath: {}", CONTEXT_PATH);
        }
        catch (IOException | ConfigurationException e)
        {
            LOGGER.error("Inside configureJaxRsPublisher,There was a problem in upgrading the JAX RS connector configuration, Exception occured is: {}", e.getMessage());
        }

    }
raul1991 commented 3 years ago

I can set the jaxrs connector property "root" to "/" and

then tried setting the class level @Path("/")

and my methods have the following annotation

@Path("/animals")

But I still get a 404