Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Push work with WebSockets #63

Closed
cvillfon opened this issue May 17, 2021 · 5 comments
Closed

Make Push work with WebSockets #63

cvillfon opened this issue May 17, 2021 · 5 comments

Comments

@cvillfon
Copy link

Description of the bug / feature

Make Push work with WebSockets

Minimal reproducible example

Starter project and Karaf examples don't work with WebSockets Push

Expected behavior

Push (Atmosphere) should detect and install WebSockets mode correctly

Actual behavior

Atmosphere 2.4.30vaadin1 fails to initialize websockets support in OSGi karaf container

Versions:

- Vaadin / Flow version: 19.0.7/6.0.8
- Java version: 11
- OS version: Fedora 33
- Browser version (if applicable):
- Application Server (if applicable): Karaf 4.3.1
- IDE (if applicable):
@cvillfon
Copy link
Author

I don't know if this is being addressed already, anyway, I created an issue to post a workaround:

I see also there's an issue in Flow about upgrading to Atmosphere 2.6.5 that may solve the issue.

Solution

However, I found a workaround for Karaf that works with the current version of Atmosphere:

OSGi fragment bundle

Create and install an empty fragment bundle with following entries in the Java manifest:

Fragment-Host: javax.websocket-api
Require-Capability: osgi.serviceloader; filter:="(osgi.serviceloader=javax.websocket.server.ServerEndpointConfig$Configurator)";resolution:=optional;cardinality:=multiple, osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)"

I found this in some Atmosphere post but I don't remember the source.

You may need to install it with a low start-level in Karaf so that it starts before the web framework.

This may not be needed anymore or be fixed in current or future versions of karaf or pax web.

Explicitly configure mappingPath to Atmosphere

In Vaadin 8, the above fragment was enough to make it work, however, in the current version, the following is also required:

It seems Atmosphere is unable to read OSGi whiteboard servlet context path or something similar, so it fails to set the mapping path. However, you can explicitly configure it by passing a init parameter to the servlet:

HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX + "org.atmosphere.container.JSR356AsyncSupport.mappingPath=/my-context-path"

@mstahv
Copy link
Member

mstahv commented May 18, 2021

I wonder what is different in our environment 🤔 I switched the Karaf example to use websockets just a while ago, because it works fine for me. I did the switch and tests in Vaadin 20 branch though, but I'm not aware of any changes that might affect this. Pax web or Felix Jetty as http whiteboard implementation?

Would you test the master version of the Karaf example and check if you have issues there?

@denis-anisimov
Copy link

denis-anisimov commented May 18, 2021

I would like to be more verbose with steps to reproduce to avoid any misunderstanding.

https://github.com/vaadin/vaadin-flow-karaf-example

git clone git@github.com:vaadin/vaadin-flow-karaf-example.git
git checkout v19

cd vaadin-flow-karaf-example
mvn clean install -DskipTests

cd starter
mvn install -Prun

wait for artifact deployment and go to browser
Open inspector and Network tab

open page http:localhost:8181

There will be request like this:

http://localhost:8181/?v-r=push&v-uiId=0&v-pushId=42adb087-2a4d-4e0e-ba8e-54d74150f012&X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.3.2.vaadin1-javascript&X-Atmosphere-Transport=long-polling&X-Atmosphere-TrackMessageSize=true&Content-Type=application%2Fjson%3B%20charset%3DUTF-8&X-atmo-protocol=true&_=1621324751754

As a result:

  • Websockets are not used.
  • Push is working but the transport is LONG_POLLING.

We never said that WS are supported because:

  • it's sometimes absolutely not clear how to setup WS inside OSGi container overall
  • because of previous item we have never tried to make it work and find issues with Atmosphere which apparently has issues itself.

I would say this is an issue in the Atmosphere since it has to provide osgi.serviceloader capability requirement from the very beginning.

May be it's fixed in the newer versions but we can't use newer Atmosphere versions out of the box.

I'm not sure what we can do here about this........: WS doesn't have to be a requirement for the project so we may not require capabilities which are WS only related ( though it looks like the capability is generic Atmosphere capability).

Also it seems this is not enough to make WS works...

Anyway this is a know limitation and we have an issue for this : https://github.com/vaadin/flow/issues/5146

This is a duplicate , so I'm closing this.

@denis-anisimov
Copy link

OK, the "steps to reproduce" mentions V19 and I've used v19 branch but it has no any Push config at all.

Push is used in the master branch, I will check it.

@denis-anisimov
Copy link

With the proper steps to reproduce I cannot reproduce the issue:

https://github.com/vaadin/vaadin-flow-karaf-example

git clone git@github.com:vaadin/vaadin-flow-karaf-example.git
// the branch is master: it uses @Push without value which means WS

cd vaadin-flow-karaf-example
mvn clean install -DskipTests

cd main-ui
mvn install -Prun

wait for artifact deployment and go to browser
Open inspector and Network tab

open page http:localhost:8181

There will be request like this:

ws://localhost:8181/?v-r=push&v-uiId=1&v-pushId=f907ede4-a19c-46ba-80eb-58018f6c912d&X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.3.2.vaadin1-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&Content-Type=application/json;%20charset=UTF-8&X-atmo-protocol=true

So there is Push and it uses WS transport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants