users@jersey.java.net

[Jersey] Re: Container reload: ResourceConfig is locked

From: Miroslav Fuksa <miroslav.fuksa_at_oracle.com>
Date: Mon, 01 Jul 2013 14:33:05 +0200

Hi,

thanks for you email. We have checked the code and there is a bug in
Jersey. Can you file a bug into jersey jira including details from your
case?

https://java.net/jira/browse/JERSEY


There is a workaround you can use. When you want to reload the
application, don't use the old ResourceConfig but create a new instance
of ResourceConfig and initialize it from the old one. It has a
constructor which accepts the ResourceConfig:

public ResourceConfig(final ResourceConfig original) {}

Then the reload will not fail.

You can check an jersey example "reload" (in <jersey
project>/examples/reload) which runs on ServletContainer and invokes
reload.


Mira

On 07/01/2013 01:00 AM, Maarten Winkels wrote:
> Hi All,
>
> I would like to use Jersey 2.0 in a situation where resources are
> registered at runtime. I use this in an OSGi container, where bundles
> are installed and can register services that should be exposed as REST
> web services in Jersey.
>
> In Jersey 1(.17.1) this worked fine, by 'reload'-ing the
> ServletContainer. If I try the same thing in Jersey 2.0, however, I
> get the following error:
>
> java.lang.IllegalStateException: The resource configuration is not
> modifiable in this context.
> at
> org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:257)
> at
> org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:205)
> at
> org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:435)
> at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:261)
> at
> org.glassfish.jersey.servlet.ServletContainer.reload(ServletContainer.java:568)
> at
> org.glassfish.jersey.servlet.ServletContainer.reload(ServletContainer.java:562)
>
> It seems that reloading of a (standard) ResourceConfig is no longer
> possible?
> I have initialised the ResourceConfig.fromApplication(new
> MyApplication()).
>
> It looks like the ResourceConfig is locked and can no longer be
> changed after initialisation. Even the ServletContainer.reload method
> cannot reload the resource config.
>
> Is there any other way to implement my required behaviour?
>
> Thanks in advance,
>
> Maarten Winkels | IWelcome BV
>
> Wiersedreef 5-7
> 3433 ZX Nieuwegein
> The Netherlands
>
> Tel: +31 (0) 30 6592254
> Mob. +31 (0) 6 10038878
> Email: maarten.winkels_at_iwelcome.com <mailto:maarten.winkels_at_iwelcome.nl>
> Website: http://www.iwelcome.com <http://www.iwelcome.nl/>
>
>
>
>
>
> The information in this Internet email is confidential and may be
> legally privileged. It is intended solely for the addressee. Access to
> this Internet email by anyone else is unauthorised. If you are not the
> intended recipient, any disclosure, copying, distribution or any
> action taken or omitted to be taken in reliance on it is prohibited
> and may be unlawful. When addressed to our clients any opinions or
> advice contained in this Internet email are subject to the terms and
> conditions expressed in any applicable governing Everett terms of
> business or client engagement letter.
>
>
>