You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Andriy Redko <re...@apache.org> on 2017/10/04 13:29:49 UTC

Re: Does SSE + CDI work?

Sorry for delayed response, somehow missed this thread. Yes, we should be able to discover features automatically when using CDI. The @Provider may not be required, we rely on javax.ws.rs.core.Feature implementors instead. But John is right, in the sample the SseFeature is manually registered (but transport part is tuned from the extension). I will look into the issue shortly.

On 2017-09-18 03:36, Sergey Beryozkin <sb...@gmail.com> wrote: 
> Ok, I added
> @Provider(value = Type.Feature, scope = Scope.Server)
> 
> Andriy, will CXF CDI auto-discover it now or will it have to be updated 
> a bit to have CXF features/interceptors picked up, same way we can do it 
> for Spring ?
> 
> Thanks, Sergey
> On 18/09/17 11:27, Sergey Beryozkin wrote:
> > On 18/09/17 11:14, John D. Ament wrote:
> >> I'm assuming you mean
> >> https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsApplication.java#L39 
> >>
> >> ?
> >> That looks manually registered.
> > It should not be there,
> > 
> > we need to add a CXF @Provider(type=Feature) to
> > 
> > https://github.com/apache/cxf/blob/master/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/SseFeature.java 
> > 
> > 
> >>
> >> For my #1 its a CDI 2.0 feature.  I think it'll work with this approach
> >> though.
> >>
> >> Any thoughts on the instability?
> > Well, it's a totally new feature. I know Andriy found some issues while 
> > working on the integration with Atmosphere, my understanding there were 
> > many timing related test issues, but what is more important is how it 
> > works once the server is up an running, for a regular application, is 
> > not stable in your case ?
> > 
> > Sergey
> >>
> >> John
> >>
> >> On Mon, Sep 18, 2017 at 5:09 AM Sergey Beryozkin <sb...@gmail.com>
> >> wrote:
> >>
> >>> Have a look at the sse cdi demo Andriy added to the distribution,
> >>> the feature (the one dealing with SSE) is expected to be 
> >>> auto-registered.
> >>>
> >>> Re the transport id, by default CXF assumes it is 'plain' HTTP, so it
> >>> needs a hint.
> >>>
> >>> What did you mean with 1) ?
> >>>
> >>> Sergey
> >>>
> >>> On 18/09/17 00:57, John D. Ament wrote:
> >>>> Ok, i was able to work a bit deeper into this.
> >>>>
> >>>> 1. the integration works, but firing async events doesn't work.  I'm 
> >>>> not
> >>>> sure it should, since you're just appending to the request; but I 
> >>>> want to
> >>>> play with async requests a bit.
> >>>>
> >>>> 2. The integration seems flakey I'm afraid.  I'll run a test, almost
> >>> always
> >>>> it passes, but then every off test run will cause SSE to not get
> >>>> activated.  I have no reproducer for this.
> >>>>
> >>>> When it does fail, all I get on the log is
> >>>>
> >>>> Sep 17, 2017 7:50:33 PM
> >>> org.apache.cxf.transport.servlet.ServletController
> >>>> invoke
> >>>> WARNING: Can't find the request for http://my-hostname:4403/rest's
> >>> Observer
> >>>>
> >>>> However, I see none of the atmosphere bootstrap occurring when this
> >>>> happens.  Here's full logs for both failure and success:
> >>>> https://paste.apache.org/rWwj
> >>>>
> >>>> 3. I had to manually install the feature.  Does CXF have any notion of
> >>>> automatically registering features?
> >>>>
> >>>> 4. I also had to customize the transport id.  It would be good if this
> >>> was
> >>>> automatic.
> >>>>
> >>>> John
> >>>>
> >>>> On Sun, Sep 17, 2017 at 4:21 PM John D. Ament <jo...@apache.org>
> >>> wrote:
> >>>>
> >>>>> I'm trying to create a very basic example of using SSE + CDI 
> >>>>> events.  To
> >>>>> do that, I created a basic endpoint based on a CXF systest that I 
> >>>>> found,
> >>>>> but tried to adapt it to work with CDI.
> >>>>>
> >>>>> @Path("/sse")
> >>>>> @RequestScoped
> >>>>> public class SseEventEndpoint {
> >>>>>       @Inject
> >>>>>       private Event<SseEvent> event;
> >>>>>       @Context
> >>>>>       private Sse sse;
> >>>>>       @GET
> >>>>>       @Path("{connectionId}")
> >>>>>       @Produces(MediaType.SERVER_SENT_EVENTS)
> >>>>>       public void onEvent(@Context SseEventSink sink,
> >>>>> @PathParam("connectionId") final String id) {
> >>>>>           System.out.println("Received request "+sse);
> >>>>>           event.fireAsync(new SseEvent(sink, sse, id));
> >>>>>       }
> >>>>> }
> >>>>>
> >>>>> However, no matter what I do, the Sse object is null.  Is there
> >>> something
> >>>>> I need to do to enable Sse integration?  This is what my dependencies
> >>> look
> >>>>> like
> >>>>>
> >>>>>           <dependency>
> >>>>>               <groupId>org.apache.cxf</groupId>
> >>>>>               <artifactId>cxf-integration-cdi</artifactId>
> >>>>>           </dependency>
> >>>>>           <dependency>
> >>>>>               <groupId>org.apache.cxf</groupId>
> >>>>>               <artifactId>cxf-rt-rs-client</artifactId>
> >>>>>           </dependency>
> >>>>>           <dependency>
> >>>>>               <groupId>org.apache.cxf</groupId>
> >>>>>               <artifactId>cxf-rt-rs-sse</artifactId>
> >>>>>           </dependency>
> >>>>>           <dependency>
> >>>>>               <groupId>org.apache.cxf</groupId>
> >>>>>               <artifactId>cxf-rt-transports-http</artifactId>
> >>>>>           </dependency>
> >>>>>
> >>>>
> >>>
> >>>
> >>> -- 
> >>> Sergey Beryozkin
> >>>
> >>> Talend Community Coders
> >>> http://coders.talend.com/
> >>>
> >>
> 
> 
> -- 
> Sergey Beryozkin
> 
> Talend Community Coders
> http://coders.talend.com/
>