You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Aki Yoshida <el...@gmail.com> on 2016/10/03 20:28:28 UTC

Re: CXF 3.1 + Tomcat 8 + JAR-RS + Atmosphere + WebSocket

Hi Sergey,
Tomcat7 includes its own implementation and this gets picked up by
atmosphere. Jetty8 works in a similar way. Jetty9 includes both jsr356 and
its own implemtation. By default, atmosphere 2.4 picks up the jsr356 one,
but we are forcing cxf to pick up the native one so that it works with cxf.

I don't know or remember having TomcatWeSocketDestination.

I thought we should change cxf's atmosphere initialization so that it
delays the actual initialization step until the first request comes and
then initializes jsr356 if available, then I think it should work for
jsr356 as well.
 It would be great if someone could look into this direction.

Regards, Aki


On Friday, 30 September 2016, Sergey Beryozkin <sb...@gmail.com> wrote:

> Hi Aki
>
> How would you explain though the fact it works in Tomcat 7 ?
>
> Though I guess it would indeed make a good sense to make our transport be
> aware of the JSR356. I was thinking should we have
> TomcatWebSocketDestination may be, in addition to Jetty and Atmosphere
> ones, I guess may be a would be TomcatWebSocketDestination is something
> that would be JSR356 aware ?
>
> Cheers, Sergey
>
> On 30/09/16 15:57, Aki Yoshida wrote:
>
>> I think this is a known limitation that we have in CXF about how we
>> initialize atmosphere.
>> To initialize atmosphere with JSR356, you need to have a servlet
>> context and the way how atmosphere is initialized in CXF currently
>> does not have an access to a servlet context, hence it can't use
>> JSR356. In other words, we will need to adjust this CXF's atmosphere
>> initialization code so that it will work with JSR356 as well.
>>
>>
>> 2016-09-29 21:40 GMT+02:00 MULLER, Anthony <an...@sap.com>:
>>
>>> Hi Sergey, Aki,
>>>
>>> My application seems to work under Tomcat 8 with the following
>>> modifications:
>>>
>>> 1) Add @ServerEndpoint(value = "/services") on my service class (named
>>> UserService.java)
>>> 2) Add a method into this class with the annotation @OnMessage like:
>>>         @OnMessage
>>>         public String hello(String message) {
>>>                 return "Hello!";
>>>         }
>>> 3) Add the following dependency in my pom.xml
>>>         <dependency>
>>>                 <groupId>javax.websocket</groupId>
>>>                 <artifactId>javax.websocket-api</artifactId>
>>>                 <version>1.0</version>
>>>                 <scope>provided</scope>
>>>         </dependency>
>>>
>>> With these changes, the sample almost works in both Tomcat version (7
>>> and 8), except that all websocket requests are routed to the method having
>>> @OnMessage annotation :)
>>>
>>> It seems it needs some configurations again :)
>>>
>>> Hope this will help.
>>>
>>> Best regards,
>>> Anthony
>>>
>>> -----Original Message-----
>>> From: MULLER, Anthony [mailto:anthony.muller@sap.com]
>>> Sent: jeudi 29 septembre 2016 15:18
>>> To: users@cxf.apache.org
>>> Subject: RE: CXF 3.1 + Tomcat 8 + JAR-RS + Atmosphere + WebSocket
>>>
>>> Hi Sergey,
>>>
>>> Thanks very much, I deployed on Tomcat 7 and it works fine.
>>>
>>> I will investigate deeper to try to understand what's going on with
>>> Tomcat 8...
>>>
>>> Regards,
>>> Anthony
>>>
>>> -----Original Message-----
>>> From: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
>>> Sent: jeudi 29 septembre 2016 12:17
>>> To: users@cxf.apache.org
>>> Subject: Re: CXF 3.1 + Tomcat 8 + JAR-RS + Atmosphere + WebSocket
>>>
>>> Hi Anthony
>>>
>>> Sorry it is my fault, I looked at the master source, not realizing 3.1.7
>>> uses a different Atmosphere version (2.3.7).
>>>
>>> I've run a websocket_web demo with a Tomcat 7 plugin and it works fine
>>> for me. Can you confirm please this demo also works for you ?
>>>
>>> Thanks, Sergey
>>> On 29/09/16 08:47, MULLER, Anthony wrote:
>>>
>>>> Hi Sergey,
>>>>
>>>> I made the recommended changes (upgrade Atmosphere and disable the
>>>> async feature of CXFServlet), I got this error when trying to connect.
>>>>
>>>> Seems there is a mismatch between the used CXF version (3.1.7) and
>>>> Atmosphere (2.4.3).
>>>>
>>>> Best regards,
>>>> Anthony
>>>>
>>>>
>>>> SEVERE: Servlet.service() for servlet [CXF Bootstrap] in context with
>>>> path [/cxf31_websocket] threw exception [Servlet execution threw an
>>>> exception] with root cause
>>>> java.lang.NoSuchMethodError: org.atmosphere.cpr.AtmosphereR
>>>> equest.wrap(Ljavax/servlet/http/HttpServletRequest;)Lorg/
>>>> atmosphere/cpr/AtmosphereRequest;
>>>>       at org.apache.cxf.transport.websocket.atmosphere.AtmosphereWebS
>>>> ocketServletDestination.invoke(AtmosphereWebSocketServ
>>>> letDestination.java:73)
>>>>       at org.apache.cxf.transport.servlet.ServletController.invokeDes
>>>> tination(ServletController.java:234)
>>>>       at org.apache.cxf.transport.servlet.ServletController.invoke(
>>>> ServletController.java:208)
>>>>       at org.apache.cxf.transport.servlet.ServletController.invoke(
>>>> ServletController.java:160)
>>>>       at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(
>>>> CXFNonSpringServlet.java:180)
>>>>       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleR
>>>> equest(AbstractHTTPServlet.java:299)
>>>>       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(
>>>> AbstractHTTPServlet.java:223)
>>>>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
>>>>       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service
>>>> (AbstractHTTPServlet.java:274)
>>>>       at org.apache.catalina.core.ApplicationFilterChain.internalDoFi
>>>> lter(ApplicationFilterChain.java:292)
>>>>       at org.apache.catalina.core.ApplicationFilterChain.doFilter(App
>>>> licationFilterChain.java:207)
>>>>       at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilte
>>>> r.java:52)
>>>>       at org.apache.catalina.core.ApplicationFilterChain.internalDoFi
>>>> lter(ApplicationFilterChain.java:240)
>>>>       at org.apache.catalina.core.ApplicationFilterChain.doFilter(App
>>>> licationFilterChain.java:207)
>>>>       at org.apache.catalina.core.StandardWrapperValve.invoke(Standar
>>>> dWrapperValve.java:212)
>>>>       at org.apache.catalina.core.StandardContextValve.invoke(Standar
>>>> dContextValve.java:106)
>>>>       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(A
>>>> uthenticatorBase.java:502)
>>>>       at org.apache.catalina.core.StandardHostValve.invoke(StandardHo
>>>> stValve.java:141)
>>>>       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorRepo
>>>> rtValve.java:79)
>>>>       at org.apache.catalina.valves.AbstractAccessLogValve.invoke(Abs
>>>> tractAccessLogValve.java:616)
>>>>       at org.apache.catalina.core.StandardEngineValve.invoke(Standard
>>>> EngineValve.java:88)
>>>>       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAd
>>>> apter.java:528)
>>>>       at org.apache.coyote.http11.AbstractHttp11Processor.process(Abs
>>>> tractHttp11Processor.java:1099)
>>>>       at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler
>>>> .process(AbstractProtocol.java:670)
>>>>       at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun
>>>> (NioEndpoint.java:1520)
>>>>       at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(
>>>> NioEndpoint.java:1476)
>>>>       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPool
>>>> Executor.java:1142)
>>>>       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoo
>>>> lExecutor.java:617)
>>>>       at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.
>>>> run(TaskThread.java:61)
>>>>       at java.lang.Thread.run(Thread.java:745)
>>>>
>>>> -----Original Message-----
>>>> From: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
>>>> Sent: mercredi 28 septembre 2016 17:54
>>>> To: users@cxf.apache.org
>>>> Subject: Re: CXF 3.1 + Tomcat 8 + JAR-RS + Atmosphere + WebSocket
>>>>
>>>> Hi Anthony
>>>>
>>>> It all looks OK, except that you select the older Atmosphere version, it
>>>> has to be 2.4.3 - so start from removing that pom section where you get
>>>> an older version from the non-Central maven location.
>>>>
>>>> The other thing - enabling async (suspended) continuations is not needed
>>>> for WebSocket (AFAIK), I'm not sure if it interferes, try disabling this
>>>> CXFServlet setting if using the latest Atmosphere does not help (it
>>>> would an issue of its own - but for now lets try to isolate where the
>>>> problem is)
>>>>
>>>> Sergey
>>>> On 28/09/16 16:26, MULLER, Anthony wrote:
>>>>
>>>>> Hello CXF Experts, Sergey, Aki,
>>>>>
>>>>> I have some issues to implement a simple test using WebSocket with CXF
>>>>> 3.1.7, in a Tomcat 8 Servlet container.
>>>>>
>>>>> To make troubleshooting easier, I shared my demo project (based on the
>>>>> official CXF samples written by Aki):
>>>>> https://github.com/AnthonyMullerPlayground/cxf31_websocket
>>>>>
>>>>> The webapp context is "cxf31_websocket" and it contains a simple
>>>>> RESTful service running under "/services/users" path.
>>>>>
>>>>> The project also contains a basic index.html webpage to test the
>>>>> websocket.
>>>>>
>>>>> CXF is bootstrapped using: org.apache.cxf.transport.servlet.CXFServlet
>>>>>
>>>>> Spring is used to and configured this way with a "beans.xml" file:
>>>>>
>>>>>  <jaxrs:server id="websocketService" address="/" transportId="
>>>>> http://cxf.apache.org/transports/websocket" />
>>>>> <context:component-scan base-package="com.sap.business
>>>>> objects.amuller"/>
>>>>>
>>>>> When I check the websocket using Chrome, the following error is
>>>>> displayed in the Network panel of the developer tools:
>>>>>
>>>>> Request headers:
>>>>> GET ws://localhost:8080/cxf31_websocket/services HTTP/1.1
>>>>> Host: localhost:8080
>>>>> Connection: Upgrade
>>>>> Pragma: no-cache
>>>>> Cache-Control: no-cache
>>>>> Upgrade: websocket
>>>>> Origin: http://localhost:8080
>>>>> Sec-WebSocket-Version: 13
>>>>> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
>>>>> AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
>>>>> Accept-Encoding: gzip, deflate, sdch
>>>>> Accept-Language: en-US,en;q=0.8,fr;q=0.6
>>>>> Sec-WebSocket-Key: Uc/E4OEE/BnKx/EvHUgLtQ==
>>>>> Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
>>>>>
>>>>> Response headers:
>>>>> HTTP/1.1 501 Not Implemented
>>>>> Server: Apache-Coyote/1.1
>>>>> X-Atmosphere-first-request: true
>>>>> X-Atmosphere-tracking-id: aeeb9f45-62e8-45b4-9d37-4657988e20ec
>>>>> X-Atmosphere-error: Websocket protocol not supported
>>>>> Transfer-Encoding: chunked
>>>>> Date: Wed, 28 Sep 2016 15:21:58 GMT
>>>>> Connection: close
>>>>>
>>>>> No error is displayed in the Eclipse console... I'm stuck because I
>>>>> didn't really get the magic behind the scene. It seems that the transportId
>>>>> attribute is enabling the full WebSocket logic? (transportId="
>>>>> http://cxf.apache.org/transports/websocket")
>>>>>
>>>>> Thanks for your help and explanations.
>>>>>
>>>>> Best regards,
>>>>> Anthony MÜLLER
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>