Nhut, could you provide a link to a sample repo that we could use to debug?
- Ray On Wed, Aug 29, 2018 at 9:44 AM, Nhut Thai Le <[email protected]> wrote: > Hi Carlos, > > As you can see from previous email, when listing the service provided by > the bundle, I can see my filter listed with component.id=0, I also add a > reference to the filter from my api and I see it not null when the rest > call is made: > @Component( > //immediate=true, > service = Api.class, > property = { > "osgi.jaxrs.name=RestApi", > "osgi.jaxrs.resource=true", > "osgi.jaxrs.application.select=(osgi.jaxrs.name=RestApp)" > } > ) > @Path("/common") > public final class Api { > public static final Response EMPTY_RESPONSE = Response.noContent().type( > MediaType.TEXT_HTML_TYPE).build(); > > @Reference > JaxrsServiceRuntime runtimeRef; > @Reference > ContainerRequestFilter filter; //THIS IS NOT NULL SO I THINK THE > COMPONENT IS REGISTERED AND INSTANTIATED BY THE WHITEBOARD CORRECTLY > > @GET > @Path("/getObject") > @Produces(MediaType.APPLICATION_JSON) > public String getObject() { > RuntimeDTO runtimeDto = runtimeRef.getRuntimeDTO(); > try { > filter.filter(null); //I GOT AN INSTANCE OF THE FILTER HERE > } > catch(Exception e) { > int x =2; > } > return "Rest call 2"; //$NON-NLS-1$ > } > } > > so I think the whiteboard does created the component and registered it, > but jaxrs does not use this component in the rest call processing nor > recognize it as a jaxrs extension. Do i need to include anything else but > the aries.component-dsl.component-dsl, aries.javax.jax.rs-api, > aries.jax.rs.whiteboard, aries.util and their dependenies in my run env? > > > Thai > > > On Tue, Aug 28, 2018 at 5:07 PM, Carlos Sierra Andrés <[email protected]> > wrote: > >> hi Thai, >> >> this is weird indeed. In your fisrt message, when you had the component >> with "immediate=true", you said the breakpoint was never hit. If I remember >> correctly, but maybe I am wrong, having "immediate=true" should make the >> SCR to immediately instantiate and activate your component. If that did not >> happen that would indicate a problem before the whiteboard gets to know >> about the extension. >> >> Carlos. >> >> El 28/8/18 a las 22:33, Nhut Thai Le escribió: >> >> Hi Carlos, >> >> Here is the result of getRuntimeDto: >> { >> "serviceDTO": null, >> "defaultApplication": { >> "resourceMethods": [ >> { >> "method": "GET", >> "consumingMimeType": null, >> "producingMimeType": [ >> "text/css" >> ], >> "nameBindings": null, >> "path": "/" >> }, >> { >> "method": "GET", >> "consumingMimeType": null, >> "producingMimeType": [ >> "text/html" >> ], >> "nameBindings": null, >> "path": "/" >> }, >> { >> "method": "GET", >> "consumingMimeType": null, >> "producingMimeType": [ >> "image/gif" >> ], >> "nameBindings": null, >> "path": "/" >> }, >> { >> "method": "GET", >> "consumingMimeType": null, >> "producingMimeType": [ >> "text/javascript" >> ], >> "nameBindings": null, >> "path": "/" >> }, >> { >> "method": "GET", >> "consumingMimeType": null, >> "producingMimeType": [ >> "text/css" >> ], >> "nameBindings": null, >> "path": "/" >> } >> ], >> "base": "/", >> "resourceDTOs": [], >> "extensionDTOs": [], >> "name": ".default", >> "serviceId": 92 >> }, >> "applicationDTOs": [ >> { >> "resourceMethods": [], >> "base": "/rest", >> "resourceDTOs": [ >> { >> "resourceMethods": [ >> { >> "method": "GET", >> "consumingMimeType": null, >> "producingMimeType": [ >> "application/json" >> ], >> "nameBindings": null, >> "path": "\\\\common\\getObject\\" >> } >> ], >> "name": ".generated.for.91", >> "serviceId": 91 >> } >> ], >> "extensionDTOs": [], >> "name": "RestApp", >> "serviceId": 44 >> } >> ], >> "failedResourceDTOs": [], >> "failedExtensionDTOs": [], >> "failedApplicationDTOs": [] >> } >> >> As it shown, my extension is not even loaded. Although it show up as an >> osgi service when I inspect the bundle: >> >> osgi>bundle 27 >> com.castortech.iris.ba.web.home_1.0.0.qualifier [27] >> Id=27, Status=ACTIVE Data Root=C:\Users\ntle\eclipseWSos >> gi30\.metadata\.plugins\org.eclipse.pde.core\Pax\org.eclipse.osgi\27\data >> "Registered Services" >> {javax.ws.rs.container.ContainerRequestFilter}={service.id=43, >> osgi.jaxrs.extension=true, service.bundleid=27, service.scope=prototype, >> osgi.jaxrs.application.select=(osgi.jaxrs.name=RestApp), component.name >> =com.castortech.iris.ba.web.home.JaxrsAuthenticationFilter, component.id >> =0} >> {javax.ws.rs.core.Application}={osgi.jaxrs.application.base=/rest, >> service.id=44, service.bundleid=27, service.scope=bundle, >> authentication.with=keycloak, osgi.jaxrs.name=RestApp, component.name >> =com.castortech.iris.ba.web.home.RestApiApp, component.id=1} >> {com.castortech.iris.ba.web.home.Api}={osgi.jaxrs.resource=true, >> service.id=91, service.bundleid=27, service.scope=bundle, >> osgi.jaxrs.application.select=(osgi.jaxrs.name=RestApp), component.name >> =com.castortech.iris.ba.web.home.Api, component.id=2} >> Services in use: >> {com.castortech.iris.ba.web.home.Api}={osgi.jaxrs.resource=true, >> service.id=91, service.bundleid=27, service.scope=bundle, >> osgi.jaxrs.application.select=(osgi.jaxrs.name=RestApp), component.name >> =com.castortech.iris.ba.web.home.Api, component.id=2} >> {org.osgi.service.jaxrs.runtime.JaxrsServiceRuntime}={service.id=90, >> osgi.jaxrs.endpoint=[0.0.0.0:8080], service.bundleid=96, >> service.scope=singleton, service.ranking=-2147483648, >> service.changecount=3, service.pid=org.apache.aries.j >> ax.rs.whiteboard.default} >> {org.osgi.service.log.LogService, org.eclipse.equinox.log.Extend >> edLogService}={service.id=2, service.bundleid=0, service.scope=bundle} >> Exported packages >> com.castortech.iris.ba.web.home; version="0.0.0"[exported] >> org.keycloak.jaxrs; version="0.0.0"[exported] >> Imported packages >> ... >> >> I can even get a reference to that filter from the API but for some >> reason, jaxrs whiteboard does not register this filter >> >> Thai >> >> On Tue, Aug 28, 2018 at 3:05 PM, Carlos Sierra Andrés <[email protected]> >> wrote: >> >>> 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] >>> > 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=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=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 >>> <https://maps.google.com/?q=460+rue+St-Catherine+St&entry=gmail&source=g> >>> Ouest, Suite 613 >>> Montréal, Québec H3B-1A7 >>> (514) 360-7208 o >>> (514) 798-2044 f >>> [email protected] >>> 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. >>> >>> >>> >> >> >> -- >> Castor Technologies Inc >> 460 rue St-Catherine St >> <https://maps.google.com/?q=460+rue+St-Catherine+St&entry=gmail&source=g> >> Ouest, Suite 613 >> Montréal, Québec H3B-1A7 >> (514) 360-7208 o >> (514) 798-2044 f >> [email protected] >> 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. >> >> >> > > > -- > Castor Technologies Inc > 460 rue St-Catherine St > <https://maps.google.com/?q=460+rue+St-Catherine+St&entry=gmail&source=g> > Ouest, Suite 613 > Montréal, Québec H3B-1A7 > (514) 360-7208 o > (514) 798-2044 f > [email protected] > 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. > -- *Raymond Augé* <http://www.liferay.com/web/raymond.auge/profile> (@rotty3000) Senior Software Architect *Liferay, Inc.* <http://www.liferay.com> (@Liferay) Board Member & EEG Co-Chair, OSGi Alliance <http://osgi.org> (@OSGiAlliance)
