Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

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

Open
raul1991 opened this issue May 19, 2021 · 1 comment
Open

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

raul1991 opened this issue May 19, 2021 · 1 comment

Comments

@raul1991
Copy link

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
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant