Conflict between aries-jax-rs-whiteboard and pax-web jetty handler

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Conflict between aries-jax-rs-whiteboard and pax-web jetty handler

Nhut Thai Le-2
Hello,

I'm using aries-jax-rs-whiteboard to host my REST api as follow:
--------the app
@Component(
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 resource
@Component(
service = Api.class,
property = {
"osgi.jaxrs.name=RestApi",
"osgi.jaxrs.resource=true",
"osgi.jaxrs.application.select=(osgi.jaxrs.name=RestApp)"
}
)
@Path("/object")
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 some json
}
}

The API works fine, now i need to add a jetty handler to return some static js and icon, so in the Activator of my bundle, i add:
ResourceHandler bootstrapResource = new ResourceHandler();
bootstrapResource.setResourceBase("bootstrap");
bootstrapResource.setDirectoriesListed(true);
ContextHandler bootstrapContext = new ContextHandler();
bootstrapContext.setContextPath("bootstrap");
bootstrapContext.setHandler(bootstrapResource);
bootstrapResourceHandler = context.registerService(Handler.class, bootstrapContext, null);


Now when i start the server i got this error:
!ENTRY org.apache.aries.jax.rs.whiteboard 4 0 2018-09-05 19:13:20.976
!MESSAGE FrameworkEvent ERROR
!STACK 0
java.lang.IllegalStateException: The service has been unregistered
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getReferenceImpl(ServiceRegistrationImpl.java:285)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getReference(ServiceRegistrationImpl.java:274)
at org.apache.aries.jax.rs.whiteboard.internal.utils.Utils.updateProperty(Utils.java:188)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard$ServiceRegistrationChangeCounter.inc(Whiteboard.java:1318)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.lambda$countChanges$88(Whiteboard.java:1148)
at org.apache.aries.component.dsl.OSGi.lambda$null$69(OSGi.java:614)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.OSGi.lambda$null$71(OSGi.java:682)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:74)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:56)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi.lambda$new$0(ServiceReferenceOSGi.java:50)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$filter$72(OSGi.java:678)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$splitBy$87(OSGi.java:749)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$distribute$65(OSGi.java:581)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.IgnoreImpl.lambda$new$1(IgnoreImpl.java:29)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:44)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.start(Whiteboard.java:184)
at org.apache.aries.component.dsl.internal.EffectsOSGi.lambda$new$1(EffectsOSGi.java:30)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$null$73(OSGi.java:693)
at org.apache.aries.component.dsl.OSGi.lambda$null$69(OSGi.java:617)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:25)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Collections$2.tryAdvance(Unknown Source)
at java.util.Collections$2.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.JustOSGiImpl.lambda$new$2(JustOSGiImpl.java:42)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$flatMap$74(OSGi.java:693)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$null$73(OSGi.java:693)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:74)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:56)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:487)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:1004)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.registerService(ExtendedHttpServiceRuntime.java:144)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.serviceChanged(ExtendedHttpServiceRuntime.java:116)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.serviceChanged(ExtendedHttpServiceRuntime.java:44)
at org.ops4j.pax.web.extender.whiteboard.internal.util.tracker.ReplaceableService.bind(ReplaceableService.java:86)
at org.ops4j.pax.web.extender.whiteboard.internal.util.tracker.ReplaceableService$Customizer.addingService(ReplaceableService.java:105)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
at org.ops4j.pax.web.service.internal.Activator.updateController(Activator.java:399)
at org.ops4j.pax.web.service.internal.Activator.lambda$scheduleUpdateFactory$1(Activator.java:331)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

hence my API does not work anymore, sending request to the API endpoint result in 404.


Does anyone have an idea what may happened  and what can I do to fix this?

Thank you in advance

Thai
Reply | Threaded
Open this post in threaded view
|

Re: Conflict between aries-jax-rs-whiteboard and pax-web jetty handler

Raymond Auge
You don't need any extra bundles to serve static resources because Aries JAX-RS whiteboard is built using Http Whiteboard which means that all you need to serve your static resources is to place them in a bundle with the following component:

@Component(
  property= {
    "osgi.http.whiteboard.resource.pattern=/static/*",
    "osgi.http.whiteboard.resource.prefix=/path/in/bundle/to/static/resources"
  },
  service = Resources.class
)
public Resources {}


- Ray

On Wed, Sep 5, 2018 at 7:23 PM, Nhut Thai Le <[hidden email]> wrote:
Hello,

I'm using aries-jax-rs-whiteboard to host my REST api as follow:
--------the app
@Component(
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 resource
@Component(
service = Api.class,
property = {
"osgi.jaxrs.name=RestApi",
"osgi.jaxrs.resource=true",
"osgi.jaxrs.application.select=(osgi.jaxrs.name=RestApp)"
}
)
@Path("/object")
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 some json
}
}

The API works fine, now i need to add a jetty handler to return some static js and icon, so in the Activator of my bundle, i add:
ResourceHandler bootstrapResource = new ResourceHandler();
bootstrapResource.setResourceBase("bootstrap");
bootstrapResource.setDirectoriesListed(true);
ContextHandler bootstrapContext = new ContextHandler();
bootstrapContext.setContextPath("bootstrap");
bootstrapContext.setHandler(bootstrapResource);
bootstrapResourceHandler = context.registerService(Handler.class, bootstrapContext, null);


Now when i start the server i got this error:
!ENTRY org.apache.aries.jax.rs.whiteboard 4 0 2018-09-05 19:13:20.976
!MESSAGE FrameworkEvent ERROR
!STACK 0
java.lang.IllegalStateException: The service has been unregistered
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getReferenceImpl(ServiceRegistrationImpl.java:285)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getReference(ServiceRegistrationImpl.java:274)
at org.apache.aries.jax.rs.whiteboard.internal.utils.Utils.updateProperty(Utils.java:188)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard$ServiceRegistrationChangeCounter.inc(Whiteboard.java:1318)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.lambda$countChanges$88(Whiteboard.java:1148)
at org.apache.aries.component.dsl.OSGi.lambda$null$69(OSGi.java:614)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.OSGi.lambda$null$71(OSGi.java:682)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:74)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:56)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi.lambda$new$0(ServiceReferenceOSGi.java:50)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$filter$72(OSGi.java:678)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$splitBy$87(OSGi.java:749)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$distribute$65(OSGi.java:581)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.IgnoreImpl.lambda$new$1(IgnoreImpl.java:29)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:44)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.start(Whiteboard.java:184)
at org.apache.aries.component.dsl.internal.EffectsOSGi.lambda$new$1(EffectsOSGi.java:30)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$null$73(OSGi.java:693)
at org.apache.aries.component.dsl.OSGi.lambda$null$69(OSGi.java:617)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:25)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Collections$2.tryAdvance(Unknown Source)
at java.util.Collections$2.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.JustOSGiImpl.lambda$new$2(JustOSGiImpl.java:42)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$flatMap$74(OSGi.java:693)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$null$73(OSGi.java:693)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:74)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:56)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:487)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:1004)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.registerService(ExtendedHttpServiceRuntime.java:144)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.serviceChanged(ExtendedHttpServiceRuntime.java:116)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.serviceChanged(ExtendedHttpServiceRuntime.java:44)
at org.ops4j.pax.web.extender.whiteboard.internal.util.tracker.ReplaceableService.bind(ReplaceableService.java:86)
at org.ops4j.pax.web.extender.whiteboard.internal.util.tracker.ReplaceableService$Customizer.addingService(ReplaceableService.java:105)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
at org.ops4j.pax.web.service.internal.Activator.updateController(Activator.java:399)
at org.ops4j.pax.web.service.internal.Activator.lambda$scheduleUpdateFactory$1(Activator.java:331)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

hence my API does not work anymore, sending request to the API endpoint result in 404.


Does anyone have an idea what may happened  and what can I do to fix this?

Thank you in advance

Thai



--
Raymond Augé (@rotty3000)
Senior Software Architect Liferay, Inc. (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance (@OSGiAlliance)
Reply | Threaded
Open this post in threaded view
|

Re: Conflict between aries-jax-rs-whiteboard and pax-web jetty handler

Nhut Thai Le
Thank you for your suggestion, however, that approach binds a patterns to one resource location only. I have few bundles, each have an icons folders that need to be served with the same pattern /icons/*. The reason for this is that the url to the static resources (icons) are dynamically generated and the generator does not know in advance which bundle should provides the icon so it just generated something like "http://mysite.com/icons/car.png".

Thai



On Thu, Sep 6, 2018 at 10:05 AM, Raymond Auge <[hidden email]> wrote:
You don't need any extra bundles to serve static resources because Aries JAX-RS whiteboard is built using Http Whiteboard which means that all you need to serve your static resources is to place them in a bundle with the following component:

@Component(
  property= {
    "osgi.http.whiteboard.resource.pattern=/static/*",
    "osgi.http.whiteboard.resource.prefix=/path/in/bundle/to/static/resources"
  },
  service = Resources.class
)
public Resources {}


- Ray

On Wed, Sep 5, 2018 at 7:23 PM, Nhut Thai Le <[hidden email]> wrote:
Hello,

I'm using aries-jax-rs-whiteboard to host my REST api as follow:
--------the app
@Component(
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 resource
@Component(
service = Api.class,
property = {
"osgi.jaxrs.name=RestApi",
"osgi.jaxrs.resource=true",
"osgi.jaxrs.application.select=(osgi.jaxrs.name=RestApp)"
}
)
@Path("/object")
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 some json
}
}

The API works fine, now i need to add a jetty handler to return some static js and icon, so in the Activator of my bundle, i add:
ResourceHandler bootstrapResource = new ResourceHandler();
bootstrapResource.setResourceBase("bootstrap");
bootstrapResource.setDirectoriesListed(true);
ContextHandler bootstrapContext = new ContextHandler();
bootstrapContext.setContextPath("bootstrap");
bootstrapContext.setHandler(bootstrapResource);
bootstrapResourceHandler = context.registerService(Handler.class, bootstrapContext, null);


Now when i start the server i got this error:
!ENTRY org.apache.aries.jax.rs.whiteboard 4 0 2018-09-05 19:13:20.976
!MESSAGE FrameworkEvent ERROR
!STACK 0
java.lang.IllegalStateException: The service has been unregistered
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getReferenceImpl(ServiceRegistrationImpl.java:285)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getReference(ServiceRegistrationImpl.java:274)
at org.apache.aries.jax.rs.whiteboard.internal.utils.Utils.updateProperty(Utils.java:188)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard$ServiceRegistrationChangeCounter.inc(Whiteboard.java:1318)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.lambda$countChanges$88(Whiteboard.java:1148)
at org.apache.aries.component.dsl.OSGi.lambda$null$69(OSGi.java:614)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.OSGi.lambda$null$71(OSGi.java:682)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:74)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:56)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi.lambda$new$0(ServiceReferenceOSGi.java:50)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$filter$72(OSGi.java:678)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$splitBy$87(OSGi.java:749)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$distribute$65(OSGi.java:581)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.IgnoreImpl.lambda$new$1(IgnoreImpl.java:29)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:44)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.start(Whiteboard.java:184)
at org.apache.aries.component.dsl.internal.EffectsOSGi.lambda$new$1(EffectsOSGi.java:30)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$null$73(OSGi.java:693)
at org.apache.aries.component.dsl.OSGi.lambda$null$69(OSGi.java:617)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:25)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Collections$2.tryAdvance(Unknown Source)
at java.util.Collections$2.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.JustOSGiImpl.lambda$new$2(JustOSGiImpl.java:42)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$flatMap$74(OSGi.java:693)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$null$73(OSGi.java:693)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:74)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:56)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:487)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:1004)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.registerService(ExtendedHttpServiceRuntime.java:144)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.serviceChanged(ExtendedHttpServiceRuntime.java:116)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.serviceChanged(ExtendedHttpServiceRuntime.java:44)
at org.ops4j.pax.web.extender.whiteboard.internal.util.tracker.ReplaceableService.bind(ReplaceableService.java:86)
at org.ops4j.pax.web.extender.whiteboard.internal.util.tracker.ReplaceableService$Customizer.addingService(ReplaceableService.java:105)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
at org.ops4j.pax.web.service.internal.Activator.updateController(Activator.java:399)
at org.ops4j.pax.web.service.internal.Activator.lambda$scheduleUpdateFactory$1(Activator.java:331)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

hence my API does not work anymore, sending request to the API endpoint result in 404.


Does anyone have an idea what may happened  and what can I do to fix this?

Thank you in advance

Thai



--
Raymond Augé (@rotty3000)
Senior Software Architect Liferay, Inc. (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance (@OSGiAlliance)



--
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

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.
Reply | Threaded
Open this post in threaded view
|

Re: Conflict between aries-jax-rs-whiteboard and pax-web jetty handler

Raymond Auge
Then bind to specific path in each bundle! It's perfectly fine to specify a full path in the pattern. If each is unique there is no trouble. if they are not, then only the "best" (as in natural service ordering) will be served.

- Ray

On Thu, Sep 6, 2018 at 11:58 AM, Nhut Thai Le <[hidden email]> wrote:
Thank you for your suggestion, however, that approach binds a patterns to one resource location only. I have few bundles, each have an icons folders that need to be served with the same pattern /icons/*. The reason for this is that the url to the static resources (icons) are dynamically generated and the generator does not know in advance which bundle should provides the icon so it just generated something like "http://mysite.com/icons/car.png".

Thai



On Thu, Sep 6, 2018 at 10:05 AM, Raymond Auge <[hidden email]> wrote:
You don't need any extra bundles to serve static resources because Aries JAX-RS whiteboard is built using Http Whiteboard which means that all you need to serve your static resources is to place them in a bundle with the following component:

@Component(
  property= {
    "osgi.http.whiteboard.resource.pattern=/static/*",
    "osgi.http.whiteboard.resource.prefix=/path/in/bundle/to/static/resources"
  },
  service = Resources.class
)
public Resources {}


- Ray

On Wed, Sep 5, 2018 at 7:23 PM, Nhut Thai Le <[hidden email]> wrote:
Hello,

I'm using aries-jax-rs-whiteboard to host my REST api as follow:
--------the app
@Component(
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 resource
@Component(
service = Api.class,
property = {
"osgi.jaxrs.name=RestApi",
"osgi.jaxrs.resource=true",
"osgi.jaxrs.application.select=(osgi.jaxrs.name=RestApp)"
}
)
@Path("/object")
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 some json
}
}

The API works fine, now i need to add a jetty handler to return some static js and icon, so in the Activator of my bundle, i add:
ResourceHandler bootstrapResource = new ResourceHandler();
bootstrapResource.setResourceBase("bootstrap");
bootstrapResource.setDirectoriesListed(true);
ContextHandler bootstrapContext = new ContextHandler();
bootstrapContext.setContextPath("bootstrap");
bootstrapContext.setHandler(bootstrapResource);
bootstrapResourceHandler = context.registerService(Handler.class, bootstrapContext, null);


Now when i start the server i got this error:
!ENTRY org.apache.aries.jax.rs.whiteboard 4 0 2018-09-05 19:13:20.976
!MESSAGE FrameworkEvent ERROR
!STACK 0
java.lang.IllegalStateException: The service has been unregistered
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getReferenceImpl(ServiceRegistrationImpl.java:285)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getReference(ServiceRegistrationImpl.java:274)
at org.apache.aries.jax.rs.whiteboard.internal.utils.Utils.updateProperty(Utils.java:188)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard$ServiceRegistrationChangeCounter.inc(Whiteboard.java:1318)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.lambda$countChanges$88(Whiteboard.java:1148)
at org.apache.aries.component.dsl.OSGi.lambda$null$69(OSGi.java:614)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.OSGi.lambda$null$71(OSGi.java:682)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:74)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:56)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi.lambda$new$0(ServiceReferenceOSGi.java:50)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$filter$72(OSGi.java:678)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$splitBy$87(OSGi.java:749)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$distribute$65(OSGi.java:581)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.IgnoreImpl.lambda$new$1(IgnoreImpl.java:29)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:44)
at org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.start(Whiteboard.java:184)
at org.apache.aries.component.dsl.internal.EffectsOSGi.lambda$new$1(EffectsOSGi.java:30)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$null$0(AllOSGi.java:40)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.AllOSGi.lambda$new$2(AllOSGi.java:41)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$null$73(OSGi.java:693)
at org.apache.aries.component.dsl.OSGi.lambda$null$69(OSGi.java:617)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:25)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Collections$2.tryAdvance(Unknown Source)
at java.util.Collections$2.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.apache.aries.component.dsl.internal.JustOSGiImpl.lambda$new$2(JustOSGiImpl.java:42)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$effects$70(OSGi.java:611)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$flatMap$74(OSGi.java:693)
at org.apache.aries.component.dsl.internal.OSGiImpl.lambda$create$0(OSGiImpl.java:39)
at org.apache.aries.component.dsl.internal.OSGiImpl.run(OSGiImpl.java:50)
at org.apache.aries.component.dsl.OSGi.lambda$null$73(OSGi.java:693)
at org.apache.aries.component.dsl.Publisher.apply(Publisher.java:28)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:74)
at org.apache.aries.component.dsl.internal.ServiceReferenceOSGi$DefaultServiceTrackerCustomizer.addingService(ServiceReferenceOSGi.java:56)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:487)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:1004)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.registerService(ExtendedHttpServiceRuntime.java:144)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.serviceChanged(ExtendedHttpServiceRuntime.java:116)
at org.ops4j.pax.web.extender.whiteboard.internal.ExtendedHttpServiceRuntime.serviceChanged(ExtendedHttpServiceRuntime.java:44)
at org.ops4j.pax.web.extender.whiteboard.internal.util.tracker.ReplaceableService.bind(ReplaceableService.java:86)
at org.ops4j.pax.web.extender.whiteboard.internal.util.tracker.ReplaceableService$Customizer.addingService(ReplaceableService.java:105)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
at org.ops4j.pax.web.service.internal.Activator.updateController(Activator.java:399)
at org.ops4j.pax.web.service.internal.Activator.lambda$scheduleUpdateFactory$1(Activator.java:331)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

hence my API does not work anymore, sending request to the API endpoint result in 404.


Does anyone have an idea what may happened  and what can I do to fix this?

Thank you in advance

Thai



--
Raymond Augé (@rotty3000)
Senior Software Architect Liferay, Inc. (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance (@OSGiAlliance)



--
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

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é (@rotty3000)
Senior Software Architect Liferay, Inc. (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance (@OSGiAlliance)