Hi again Thai,
you can try to get a reference to JaxrsServiceRuntime and call
getRuntimeDTO on it. It should give you a snapshot of the state of the
runtime as well as the reason why the extension is not being activated
by the runtime.
Also enabling debug might help you diagnose what's going on.
Carlos.
El 28/8/18 a las 20:47, Nhut Thai Le escribió:
> Hi Carlos,
>
> Thank you for pointing out the order. I tried what you suggested but i
> still not be able to hit the filter, not even its static field
>
> @Component(
> scope=ServiceScope.PROTOTYPE,
> property= {
> "osgi.jaxrs.extension=true",
> "osgi.jaxrs.application.select=(authentication.with=keycloak)"
> }
> )
> @PreMatching
> @Priority(Priorities.AUTHENTICATION)
> public final class JaxrsAuthenticationFilter implements
> ContainerRequestFilter
> {
> public static final int count = 1; //BREAKPOINT NEVER HIT
> @Override
> public void filter(ContainerRequestContext arg0) throws IOException {
> int n = 10; //BREAKPOINT NEVER HIT
> }
> }
>
> Thai
>
> On Tue, Aug 28, 2018 at 1:16 PM, Carlos Sierra Andrés
> <[email protected] <mailto:[email protected]>> wrote:
>
> Hi,
>
> I would say that this:
>
> -----
>
> @Component(
> immediate=true,
> property= {
> "osgi.jaxrs.extension=true",
> "osgi.jaxrs.extension.select=(authentication.with=keycloak)"
> }
> )
> -----
>
> should be:
>
> -----
>
> @Component(
> immediate=true,
> property= {
> "osgi.jaxrs.extension=true",
> "osgi.jaxrs.application.select=(authentication.with=keycloak)"
> }
> )
> -----
>
> note the "extension -> application", otherwise your filter is
> waiting for another extension that never arrives.
>
> I would also suggest that you make your component
> ServiceScope.PROTOTYPE so every application gets its own instance
> of the filter.
>
> Let me know if this helps.
>
> Carlos.
>
> El 28/8/18 a las 19:10, Nhut Thai Le escribió:
>> Hello,
>>
>> I'm using aries-jax-rs-whiteboard to host by REST service and I
>> want to use a ContainerRequestFilter to check for authentication
>> token. However, although the filter is registered as an OSGI
>> service, it is not triggered or even instantiated. Here is my
>> REST api and filter code:
>>
>> =====the application====
>> @Component(
>> immediate = true,
>> service = Application.class,
>> property= {
>> "osgi.jaxrs.name <http://osgi.jaxrs.name/>=RestApp",
>> JAX_RS_APPLICATION_BASE + "=/rest",
>> "authentication.with=keycloak"
>> }
>> )
>> public class RestApiApp extends Application{
>>
>> @Override
>> public Set<Object> getSingletons() {
>> return Collections.singleton(this);
>> }
>> }
>>
>> =====the API==========
>> @Component(
>> immediate=true,
>> service = Api.class,
>> property = {
>> "osgi.jaxrs.application.select=(osgi.jaxrs.name
>> <http://osgi.jaxrs.name/>=RestApp)",
>> "osgi.jaxrs.resource=true"
>> }
>> )
>> @Path("/common")
>> public final class Api {
>> public static final Response EMPTY_RESPONSE =
>> Response.noContent().type(MediaType.TEXT_HTML_TYPE).build();
>>
>> @GET
>> @Path("/getObject")
>> @Produces(MediaType.APPLICATION_JSON)
>> public String getObject() {
>> return "Rest call 2"; //$NON-NLS-1$
>> }
>> }
>>
>> ======the filter==========
>> @Component(
>> immediate=true,
>> property= {
>> "osgi.jaxrs.extension=true",
>> "osgi.jaxrs.extension.select=(authentication.with=keycloak)"
>> }
>> )
>> @PreMatching
>> @Priority(Priorities.AUTHENTICATION)
>> public final class JaxrsAuthenticationFilter extends
>> OsgiJaxrsBearerTokenFilterImpl implements ContainerRequestFilter
>> {
>> public static final int count = 1; //BREAKPOINT NEVER HIT
>> @Override
>> public void filter(ContainerRequestContext arg0) throws IOException {
>> super.filter(arg0); //BREAKPOINT NEVER HIT
>> }
>> }
>>
>> Could anyone give a hint what I may miss?
>>
>
>
>
>
> --
> Castor Technologies Inc
> 460 rue St-Catherine St Ouest, Suite 613
> Montréal, Québec H3B-1A7
> (514) 360-7208 o
> (514) 798-2044 f
> [email protected] <mailto:[email protected]>
> www.castortech.com <http://www.castortech.com>
>
> CONFIDENTIALITY NOTICE: The information contained in this e-mail is
> confidential and may be proprietary information intended only for the
> use of the individual or entity to whom it is addressed. If the reader
> of this message is not the intended recipient, you are hereby notified
> that any viewing, dissemination, distribution, disclosure, copy or use
> of the information contained in this e-mail message is strictly
> prohibited. If you have received and/or are viewing this e-mail in
> error, please immediately notify the sender by reply e-mail, and
> delete it from your system without reading, forwarding, copying or
> saving in any manner. Thank you.
> AVIS DE CONFIDENTIALITE: L’information contenue dans ce message est
> confidentiel, peut être protégé par le secret professionnel et est
> réservé à l'usage exclusif du destinataire. Toute autre personne est
> par les présentes avisée qu'il lui est strictement interdit de
> diffuser, distribuer ou reproduire ce message. Si vous avez reçu cette
> communication par erreur, veuillez la détruire immédiatement et en
> aviser l'expéditeur. Merci.